remote-play

了解media remote playback程序


更新記錄

item note
20161124 第一版

目錄


media 程序

產生下例5個thread

  • ThreadHttpStream
    • boa介面(/tmp/media_fdipc.sck)
    • 將需求(video%d.m4v,videocif%d.m4v)加入(gMainHttpList[16],gHttpList[16])串列
    • 產生ThreadHttpStreamSend 32條thread(大小碼流各16條)
    • ThreadHttpStreamSend:將資料送到client
  • ThreadP2pStream
  • Rmp_ManagerThd
    • 將remote playback需求(playback.m4v)加到gAgentList,設定gPlayBackSpeed等
  • Rmp_ReadFrameThd
    • 根據gAgenttList,傳送stream給client
  • ThreadAcceptPlayBack
    • boa介面(/tmp/playbackidx_fdipc.sck)
[media] [media struct]
  • regist_ShmClient(shm_path,shm_size)

    • shm_open(shm_path, O_RDWR, (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) );
    • mmap(NULL, shm_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  • start_thread()

    • pthread_attr_init(&attr)
    • pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED)
    • pthread_create(&thread_id, &attr, func, param)
      由於程式裡面沒有pthread_join 或 pthread_detach,
      因此需要代入PTHREAD_CREATE_DETACHED
  • Set Detach State

    • When a thread is created detached (PTHREAD_CREATE_DETACHED), its thread ID and other resources can be reused as soon as the thread terminates.

ThreadHttpStream

  • ThreadHttpStream
    • 產生大小碼流各16條
      ThreadHandle -> ThreadHttpStreamSend
      gMainThreadHandle -> ThreadHttpStreamSend
    • 接受由boa傳進來的cgi command (/tmp/media_fdipc.sck)
    • 將需求(video%d.m4v,videocif%d.m4v)加入(gMainHttpList[16],gHttpList[16])串列
[ThreadHttpStream]
  • 收到範例如下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    --------------  -----------------------------------------------  ----------------
    0 00000000 2f 76 69 64 65 6f 63 69 66 31 35 2e 6d 34 76 00 /videocif15.m4v.
    16 00000010 26 68 74 74 70 5f 75 73 65 72 5f 61 67 65 6e 74 &http_user_agent
    32 00000020 3d 4d 6f 7a 69 6c 6c 61 2f 34 2e 30 20 28 63 6f =Mozilla/4.0 (co
    48 00000030 6d 70 61 74 69 62 6c 65 3b 20 4d 53 49 45 20 37 mpatible; MSIE 7
    64 00000040 2e 30 29 26 68 74 74 70 5f 72 65 6d 6f 74 65 5f .0)&http_remote_
    80 00000050 61 64 64 72 3d 36 31 2e 32 32 31 2e 32 32 35 2e addr=61.221.225.
    96 00000060 33 37 26 68 74 74 70 5f 72 65 6d 6f 74 65 5f 70 37&http_remote_p
    112 00000070 6f 72 74 3d 33 34 30 31 34 26 68 74 74 70 5f 61 ort=34014&http_a
    128 00000080 75 74 68 65 6e 74 3d 42 61 73 69 63 20 59 57 52 uthent=Basic YWR
    144 00000090 74 61 57 34 36 59 57 52 74 61 57 34 3d 00 taW46YWRtaW4=.
    -------------- ----------------------------------------------- ----------------
  • videocif15.m4v
    說明需求連線為小碼第15CH

  • http_remote_addr
  • http_remote_port
  • http_authent=Basic

  • 其它

    • media_check.cgi

      1
      2
      會回傳=>Check Media Process Status, MainStream=0, SubStream=0
      (即MainConnectNumber, ConnectNumber 大小碼流連線數)
    • media_clear.cgi

      1
      2
      3
      4
      5
      會回傳=> Release Media Process Connections, MainStream=0, SubStream=0
      清除目前連線數
      loop i=0-15
      ThreadHttp_ClearList(i, 1); // main stream
      ThreadHttp_ClearList(i, 0); // sub stream

ThreadHttpStreamSend

  • 處理自已頻道(is_big,channel)需求
    • 回應client 200 OK
    • 回應client碼流資訊
    • ReadFromFrameBufferPTS2: 取得MainMediaBuffer_1資料
    • ThreadHttp_Iterator: h264資料如何傳給送client
[ThreadHttpStreamSend]

ReadFromFrameBufferPTS2

  • SManager_RecvProprietaryDataxx:收到碼流,將資料copy一份到MainMediaBuffer_1
    CopyToFrameBuffer(MainMediaBuffer_1,ch,data,FrameSize,,)
  • ReadFromFrameBufferPTS2將資料取出,判斷frame type,決定下個state
[ReadFromFrameBufferPTS2]

ThreadHttp_Iterator

[ThreadHttp_Iterator]

http head

  • Video Head

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    static char VideoHead[] =
    {
    "%s\r\n"
    "Content-Type: image/mpeg4\r\n"
    "Content-Length: %d\r\n"
    "X-Status: 0\r\n"
    "X-Tag: %d\r\n"
    "X-Flags: 0\r\n"
    "X-Alarm: 0\r\n"
    "X-Framerate: %d\r\n"
    "X-Resolution: %d*%d\r\n"
    "X-Audio: 1\r\n"
    "X-Time: %ld\r\n"
    "X-GMTTime: %ld\r\n"
    "X-PTS: %ld\r\n"
    "X-CamTime: %llu\r\n\r\n"
    };
  • Audio Head

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    static char AudioHead[] =
    {
    "%s\r\n"
    "Content-Type: audio/x-wav\r\n"
    "Content-Length: %d\r\n"
    "X-Codec: U-LAW\r\n"
    "X-Bitrate: 8000\r\n"
    "X-Time: %u\r\n"
    "X-GMTTime: %ld\r\n"
    "X-PTS: %ld\r\n"
    "X-Tag: %ld\r\n"
    "X-CamTime: %llu\r\n\r\n"
    };
  • Http 200OK Head

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    static char HttpHeadOk[] =
    {
    "HTTP/1.1 200 OK\r\n"
    "Server: %s\r\n" /* mac address */
    "Connection: Close\r\n"
    "Pragma: no-cache\r\n"
    "Cache-Control: no-store\r\n"
    "Content-Type: multipart/x-mixed-replace;boundary=" Boundary_NAME
    "\r\n\r\n"
    };

Rmp_ManagerThd

[Rmp_ManagerThd]
  • 收到範例如下
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    --------------  -----------------------------------------------  ----------------
    0 00000000 2f 70 6c 61 79 62 61 63 6b 2e 6d 34 76 00 63 68 /playback.m4v.ch
    16 00000010 61 6e 6e 65 6c 3d 34 26 73 70 65 65 64 3d 31 26 annel=4&speed=1&
    32 00000020 73 74 69 6d 65 3d 32 30 31 36 2d 31 31 2d 32 34 stime=2016-11-24
    48 00000030 2b 30 38 3a 30 30 3a 30 30 26 69 73 6d 61 69 6e +08:00:00&ismain
    64 00000040 3d 30 26 26 68 74 74 70 5f 75 73 65 72 5f 61 67 =0&&http_user_ag
    80 00000050 65 6e 74 3d 4d 6f 7a 69 6c 6c 61 2f 34 2e 30 20 ent=Mozilla/4.0
    96 00000060 28 63 6f 6d 70 61 74 69 62 6c 65 3b 20 4d 53 49 (compatible; MSI
    112 00000070 45 20 37 2e 30 29 26 68 74 74 70 5f 72 65 6d 6f E 7.0)&http_remo
    128 00000080 74 65 5f 61 64 64 72 3d 36 31 2e 32 32 31 2e 32 te_addr=61.221.2
    144 00000090 32 35 2e 33 37 26 68 74 74 70 5f 72 65 6d 6f 74 25.37&http_remot
    160 000000a0 65 5f 70 6f 72 74 3d 33 34 37 32 37 26 68 74 74 e_port=34727&htt
    176 000000b0 70 5f 61 75 74 68 65 6e 74 3d 42 61 73 69 63 20 p_authent=Basic
    192 000000c0 59 57 52 74 61 57 34 36 59 57 52 74 61 57 34 3d YWRtaW46YWRtaW4=
    208 000000d0 00 .
    -------------- ----------------------------------------------- ----------------

Rmp_ReadFrameThd

根據gRmpCtrl及gAgenttList
決定將data傳送給client

[Rmp_ReadFrameThd] [Rmp_StreamRead]

AppPlayback_PlayThd

[AppPlayback_PlayThd] [AppPlayback_PlayThd_st]

參考