video-recv

了解 video recv程序


更新記錄

item note
20161205 第一版
20161219 新增: 大小碼流thread比較
20161219 新增: camera motion顯示紅色外框流程

目錄


大小碼流thread比較

  • 大小碼流thread比較
val recv recv_small
save_bufs video_save_bufs video_save_bufs_small
video_play_bufs video_play_bufs_small
audio_live_bufs x
recvbuf[2M] recvbuf[1M]
audio_buf[4K]
connected connected_small
  • camera_info_onapply
    當設定camera,將會重新連線
    chunnel->ip_type_change = 3

which_notebook

  • set_ip620_dual_stream
    ipcam_send->which_notebook = 0

  • do_ipsetvalue3
    ipcam_send->which_notebook = 1

  • ipcam_network_onapply / ipcam_network_onapply3
    ipcam_send->which_notebook = 2

  • ipcam_datetime_onapply / ipcam_datetime_onapply3
    ipcam_send->which_notebook = 3

  • ptz_onapply/ ptz_onapply3
    ipcam_send->which_notebook = 4

  • audio_onapply / audio_onapply3
    ipcam_send->which_notebook = 5

  • motiondetect_onapply / motiondetect_onapply3
    ipcam_send->which_notebook = 6

camera motion顯示紅色外框流程

  • motion dectect thread
    (由api取得camera motion情況)
  • md=1,設定status.motiondetect =1
  • 由recv thread每秒檢查ldvr_video_motion_detect
  1. 若有status.motiondetect發生
    1-0. 設定status.motiondetect = 0
    1-1. 則設定status.motion_check = 1
    此時camera外框會由displayvideo ldvr_motion_mark產生紅色外框
    
  2. 若status.motiondetect==0
    2-1 若motion_check == 1 ,則設定motion_check = 2
    2-1 若motion_check == 2 ,則設定motion_check = 0
    此時會關閉紅色外框,因此紅色外框約顯示2秒
    

video recv

目前系統開啟thread如下:

接收碼流相關

  • loop ch(16,36,64)
    • ldvr_video_recv_small <-chunnel[i].recv_thread
    • ldvr_chunnel_motion <-chunnel[i].motion_thread
    • ldvr_video_recv <-chunnel[i].recv_thread
    • ldvr_audio_recv <-chunnel[i].recv_thread
    • ldvr_video_decode <-chunnel[i].dec_motion_thread
    • ldvr_video_save <-chunnel[i].save_thread

CMS相關

  • xxxx_client_listen
  • xxxx_client_timeout
  • loop cms client(128)
    • xxxx_client_send <- xxxx_client[i].send_thread
    • xxxx_client_recv <- xxxx_client[i].recv_thread

ldvr_video_recv

  • camera type
index type function
0 VIT-6Series ipcam_type_620_recv
1 IP903 ipcam_type_903_recv
2 MP81XX ipcam_type_MP81_recv
3,4 VIH-6Series,VIG-6Series ipcam_type_VIH_recv
5 Onvif ONVIF_recv
  • ldvr_video_recv flow
[ldvr_video_recv]

ipcam_type_620_recv

  • 每秒做一次ldvr_video_motion_detect

  • 系統設定值如下

    1
    2
    3
    system.ini:motion_alarm_times=10
    system.ini:io_alarm_times=10
    system.ini:videolose_alarm_times=10
[ipcam_type_620_recv]

ldvr_video_motion_detect

  • 決定是否開啟(motiondetect)
    • do_command (122) -> do_start_motiondetect
    • ldv_chunnel_motion/nMD=1
    • do_command (233)
[ldvr_video_motion_detect]

ldvr_video_dispense_xxxx

尋找CMS client,判斷是否有此ch的需求
若有則將資料put到vidoe_send_buf/audio_send_buf

[ldvr_video_dispense_xxxx]

beep

[ldvr_beep]

motion thread

  • ldvr_chunnel_motion
    ch motion檢查
    確定有enable及connect,且為VIT/VIG/VIH
    取得camera (input1=%d,input2=%d,md=%d)

  • camera motion動作(md=1)
    設定status.motiondtect = 1

  • 若收到nInput
    則設定status.alarm

[ldvr_chunnel_motion]

motionalarm 設定檔

  • motionalarm.ini
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    alarm=0000000000000000000000000000000000000000000000000000000000000000
    output=0
    sendmail=0 <= E-Mail通知
    record=1 <= 錄影
    notifyclient=1 <= 通知用戶端(client)
    movetopreset=0
    audiable=1 <= 通知用戶端教聲音警報
    relatingrelay=1
    sensitivity=2
    enable=1 <= 啟動移動偵測

system 設定檔

  • system.ini
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    [sys]
    vloss_send_mail=0
    auto_logout_time=30 <= 無作業登出時間
    max_num_play=0
    num_bigstream_dec=2
    auto_logout=0 <= 自動登出
    restart_day=1
    restart_minute=54
    restart_hour=19
    autorestart=0
    tty_debug=0
    enable_check_disk=0
    looprecord=1
    max_camera_num=16
    sync_times=60
    scan_interval=2
    motion_alarm_times=10
    io_alarm_times=10
    beep_times=2
    videolose_alarm_times=20 <= Video Loss 警報延續時間(秒)
    language=2
    timezone=20
    ipcam_num=4
    format=1
    watchdog=1
    ch_num=36
    rootdisk=sda

display_alarm

  • display_alarm[display_alarm]

display layout

  • displayxx[display layout]

alarm change layout log

  • 收到alarm input,切到相對應分割
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    ldvr.c ldvr_chunnel_motion<line:5373> ch=1 event.cgi recv --boundarydonotcross
    Content-Type: text/plain

    input1=0
    input2=1
    md=0
    ,rev_len 76,index 1
    ldvr.c ldvr_chunnel_motion<line:5437> ch=1 alarming_ch_count:-1275066176,
    ldvr.c ldvr_chunnel_motion<line:5452> ch=1 input1=0 input2=1 md=0 change=1 max=1 min=1
    ldvr.c ldvr_chunnel_motion<line:5459> alarm_change call display_alarm
    ldvr.c ldvr_video_motion_detect<line:2285> ch=1 io_alarm_timeout=9 change=0 max=1 min=1 cnt=1
    ldvr.c ldvr_video_motion_detect<line:2285> ch=1 io_alarm_timeout=8 change=0 max=1 min=1 cnt=1
    ldvr.c ldvr_chunnel_motion<line:5373> ch=1 event.cgi recv --boundarydonotcross
    Content-Type: text/plain

    input1=0
    input2=0
    md=0
    ,rev_len 76,index 1
    ldvr.c ldvr_video_motion_detect<line:2285> ch=1 io_alarm_timeout=7 change=0 max=1 min=1 cnt=1
    ldvr.c ldvr_video_motion_detect<line:2285> ch=1 io_alarm_timeout=6 change=0 max=1 min=1 cnt=1
    ldvr.c ldvr_chunnel_motion<line:5373> ch=1 event.cgi recv --boundarydonotcross

ldvr_alarm_manage

  • 針對motion alarm及video loss寄mail[ldvr_alarm_manage]

do_command

  • do command list
type command
101 do_user_login
102 do_get_camera_list
122 do_start_motiondetect
123 do_stop_motiondetect

net server

CMS Client

  • xxxx_client_listen
    等待cms client需求
    若有需求在分派給xxxx_client[i]

  • xxxx_client_timeout
    確認xxxx_client是否有timeout(5S)
    若有示表,client已斷線或連線卡住
    此時將close socket且將used設定為-2

  • loop 128

    • xxxx_client_send => 即core->xxxx_client[i].send_thread
    • xxxx_client_recv => 即core->xxxx_client[i].recv_thread
  • network.ini
    1
    2
    3
    4
    [port]
    mobileport=5577
    videoport=5566
    webport=80

xxxx_cleint_listen

  • xxxx_cleint_listen[xxxx_client_listen]

xxxx_client_timeout

  • xxxx_client_timeout[xxx_client_timeout]

xxxx_client_send

以8K audio取樣為例子, 1秒取8Kbyte,每次傳送320byte,因此1秒至少要傳25.6次
想voido(15FPS)而言是比較高的,因此這邊是傳送4次audio,才傳一次video

  • xxxx_client_send[xxxx_client_send]

其它

select

  • select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO - synchronous I/O multiplexing

    1
    2
    3
    4
    5
    6
    int select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *timeout);

    void FD_CLR(int fd, fd_set *set);
    int FD_ISSET(int fd, fd_set *set);
    void FD_SET(int fd, fd_set *set);
    void FD_ZERO(fd_set *set);
  • select() and pselect() allow a program to monitor multiple file descriptors, waiting until one or more of the file descriptors become “ready” for some class of I/O operation (e.g., input possible)

  • FD_ZERO() clears a set.
  • FD_SET() and FD_CLR() respectively add and remove a given file descriptor from a set
  • nfds is the highest-numbered file descriptor in any of the three sets, plus 1.
  • The timeout argument specifies the minimum interval that select() should block waiting for a file descriptor to become ready.
  • On success, select() and pselect() return the number of file descriptors contained in the three returned descriptor sets
    成功則回傳: 1/2/3表示幾個fd set,
    若回傳0則表示timeout
    若為-1表示有錯誤

參考