日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

mediastream2使用指南(转载)

發布時間:2023/12/19 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mediastream2使用指南(转载) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://blog.sina.com.cn/s/blog_59d649610100diui.html

?

??定義

Filter: 媒體庫中處理數據的組件。一個filter有0到數個輸入流和0到數個輸出流。

?

下面是可以使用Filter的例子:

???捕獲音頻或者視頻數據.

???播放音頻或者顯示視頻數據.

???發送或者接受RTP數據.

???對音頻或者視頻數據的編解碼

???變化 (視頻大小調整, 音頻取樣等等) 數據.

???復制數據.

???混和音頻視頻數據.

Graph: 是管理幾個連接在一起的filter的組件. 它能夠把數據從輸出流傳輸到輸入流 并且負責管理這些filters.

?

如何使用媒體庫?

媒體庫提供許多功能, 它主要用來管理RTP 音頻和視頻 會話.你將需要使用API函數創建filters,并且把它們連接進一個graph. 然后使用API函數能夠用來啟動和停止graph.

最簡單的graph 例子:

??AUDIO CAPTURE???-->???ENCODE??-->?????RTP

??????FILTER??????-->???FILTER??-->????FILTER

上面的graph 由三個 filters組成. Audio capture filter沒有輸入,直接從驅動捕獲音頻數據然后提供給輸出流. 然后把輸出流連接到encoder filter 的輸入流上,coder filter 把這些音頻數據進行編碼以后然后送給輸出流.最后把這個輸出流連接到rtp filter的輸入流上,然后由rtp filter把數據封裝成rtp送出去。

該模塊的設計可以讓應用開發者使用自己的encode/decode filter 替代已有的"encode/decode filter" . 該媒體庫支持g711u, g711a, h263的encode filter. 應用開發者也可以動態加入自己實現的encode filter,用來支持其他的編碼格式。

媒體庫的初始化

要使用媒體庫, 首先需要對他進行初始化:

????ms_init();

媒體庫提供許多filters. 這些filter必須被連接在一起以至一個filter的輸出能夠變成其他filter的輸入.

通常, filters 被用來處理音頻和視頻數據. 他們能夠捕獲音頻和視頻數據,播放音頻和視頻數據, 對這些數據進行編解碼, 合成這些數據 , 轉換這些數據.最重要的filters 是RTP filters,他能夠接收和發送RTP數據.

Graph的例子

要真正使用媒體庫進行通話, 就必須構建兩個graphs. 當然這兩個graph都相當簡單。

第一個graph需要三個filter,從聲卡捕獲數據,然后進行編碼,最后把編碼后的數據發送給RTP session.

?????????????AUDIO????->????ENCODER???->???RTP

????????????CAPTURE???->??????????????->??SENDER

第二個graph同樣需要三個filter, 從一個RTP session接收數據,然后解碼,最后把解碼后的數據發送給播放設備.

????????RTP??????->????DECODER???->???AUDIO

???????RECEIVER??->??????????????->??PLAYBACK

初始化Graph的例子

為了便于閱讀和理解,下面的代碼沒有差錯檢查.為了構造一個graph, 需要一些而外的輸入輸出設備:比如需要選擇一個聲卡用來捕獲和播放音頻,同時還需要使用創建一個RTP session用來發送和接受rtp流.

??????MSSndCard *sndcard;

??????sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());

???????

??????MSFilter *soundread=ms_snd_card_create_reader(captcard);

??????MSFilter *soundwrite=ms_snd_card_create_writer(playcard);

??????MSFilter *encoder=ms_filter_create_encoder("PCMU");

??????MSFilter *decoder=ms_filter_create_decoder("PCMU");

??????MSFilter *rtpsend=ms_filter_new(MS_RTP_SEND_ID);

??????MSFilter *rtprecv=ms_filter_new(MS_RTP_RECV_ID);

??????RtpSession *rtp_session = *** your_ortp_session *** ;

??????ms_filter_call_method(rtpsend,MS_RTP_SEND_SET_SESSION,rtp_session);

??????ms_filter_call_method(rtprecv,MS_RTP_RECV_SET_SESSION,rtp_session);

??????MSFilter *dtmfgen=ms_filter_new(MS_DTMF_GEN_ID);

大多數情況下上面的graph還是不夠的: 通常還需要對filter進行一些配置. ,比如還需要設置聲卡filters的取樣率。

??????int sr = 8000;

??????int chan=1;

??????ms_filter_call_method(soundread,MS_FILTER_SET_SAMPLE_RATE,&sr);

??????ms_filter_call_method(soundwrite,MS_FILTER_SET_SAMPLE_RATE,&sr);

??????ms_filter_call_method(stream->encoder,MS_FILTER_SET_SAMPLE_RATE,&sr);

??????ms_filter_call_method(stream->decoder,MS_FILTER_SET_SAMPLE_RATE,&sr);

??????ms_filter_call_method(soundwrite,MS_FILTER_SET_NCHANNELS, &chan);

?????

??????MSTicker *ticker=ms_ticker_new();

??????ms_ticker_attach(ticker,soundread);

??????ms_ticker_attach(ticker,rtprecv);

解除filters并且停止graph的例子

??????ms_ticker_detach(ticker,soundread);

??????ms_ticker_detach(ticker,rtprecv);

??????ms_filter_unlink(stream->soundread,0,stream->encoder,0);

??????ms_filter_unlink(stream->encoder,0,stream->rtpsend,0);

??????ms_filter_unlink(stream->rtprecv,0,stream->decoder,0);

??????ms_filter_unlink(stream->decoder,0,stream->dtmfgen,0);

??????ms_filter_unlink(stream->dtmfgen,0,stream->soundwrite,0);

??????if (rtp_session!=NULL) rtp_session_destroy(rtp_session);

??????if (rtpsend!=NULL) ms_filter_destroy(rtpsend);

??????if (rtprecv!=NULL) ms_filter_destroy(rtprecv);

??????if (soundread!=NULL) ms_filter_destroy(soundread);

??????if (soundwrite!=NULL) ms_filter_destroy(soundwrite);

??????if (encoder!=NULL) ms_filter_destroy(encoder);

??????if (decoder!=NULL) ms_filter_destroy(decoder);

??????if (dtmfgen!=NULL) ms_filter_destroy(dtmfgen);

??????if (ticker!=NULL) ms_ticker_destroy(ticker);

?

mediastream.c的一些說明

?http://blog.sina.com.cn/s/blog_59d649610100diua.html

2009/6/29

mediastream.c的一些說明






???????????????????????????????????????

轉載,出處。(http://eatdrinkmanwoman.spaces.live.com/blog/cns!97719476F5BAEDA4!1003.entry)

mediastream.c是mediastream2庫自帶的一個test,也是最為復雜的一個test,學習它有助于加深對mediastreamer2的理解。

簡介一下它的功能
1 利用mediastreamer2庫封裝的filter完成:從聲卡捕捉聲音,編碼后通過rtp發送給遠端主機,同時接收遠端主機發來的rtp包,解碼到聲卡回放。
??filter graph如下:
??soundread -> ec -> encoder -> rtpsend
??rtprecv -> decode -> dtmfgen -> ec -> soundwrite

2 利用mediastreamer2庫封裝的filter完成:從攝像頭捕捉圖像,編碼后通過rtp發送給遠端主機(有本地視頻預覽),同時接收遠端主機發來的rtp包,解碼后視頻回放。
??filter graph如下:
??source -> pixconv -> tee -> encoder -> rtpsend
???????????????????????tee -> output
??rtprecv -> decoder -> output

這個程序沒有實現:用2個session來分別同時傳送視頻和音頻。所以不要造成誤解。
它實現的是:用1個全雙工的session來傳送視頻或者音頻,不管是本機還是遠端主機,運行的都是同一個程序,一次只能選擇一種payload。
牢 記rfc3550 Page 17中的所說“Separate audio and video streams SHOULD NOT be carried in a single RTP session and demultiplexed based on the payload type or SSRC fields. ”

程序中audio_stream_new() video_stream_new()內使用create_duplex_rtpsession()建立起監聽端口。
比較奇怪的是video_stream_start()最后沒有attach上rtprecv。而audio_stream_start_full()里有attach rtprecv。

編譯的時候,別忘了加-D VIDEO_ENABLED啟用視頻支持。

程序命令參數
mediastream --local <port> --remote <ip:port> --payload <payload type number>
??????????[ --fmtp <fmtpline>] [ --jitter <miliseconds>]

這里fmtp和jitter是可選
fmtp的介紹如下:
Sets a send parameters (fmtp) for the PayloadType. This method is provided for applications using RTP with SDP, but actually the ftmp information is not used for RTP processing.
jitter就是設定緩沖時間,也就是隊列的閥值。具體可以參見Comer所著TCP/IP 卷一的RTP一章。默認是80ms(還是50ms?),沒必要修改它。

舉一個使用的例子。
主機A IP 10.10.104.198
主機B IP 10.10.104.199
主機A 運行 ./mediastream --local 5010 --remote 10.10.104.199:6014 --payload 110
主機B 運行 ./mediastream --local 6014 --remote 10.10.104.198:5010 --payload 110

這里我使用的是音頻傳輸,speex_nb編碼。視頻沒有使用,懷疑是SDL有些問題,視頻預覽的時候是綠屏。

注意:程序代碼里提到的音頻編碼有lpc1015,speex_nb,speex_wb,ilbc等,視頻編碼有h263_1998,theora,mp4v,x_snow,h264等。但是你卻不一定能用得起來。這要看之前編譯ffmpeg時,究竟是否指定了如上編碼。
如果你的機子上并沒有這些庫,卻又指定了這些庫的payload type,那么mediastreamer2初始化的時候,會在終端輸出錯誤信息找不到xxx.so之類,那么請換另一種payload type。
一般來說,speex,theora,xvid(h264)這三個比較容易編譯。


關于rtp session,不知道你會不會像我有一些誤解(尤其是雙工的session)。
我 覺得session是一個難以一言蔽之的概念(否則rfc3550上也不會嘮嘮叨叨說一大堆,Page 9),雖然也可以精煉說成“The distinguishing feature of an RTP session is that each maintains a full, separate space of SSRC identifiers”,但是這樣沒什么意義,讓人理解起來反而更困難。
我個人認為不必深究session的確切定義,而要細細體會rfc3550 Page 68 Section 11。(我每次有疑問時,就再來看一遍這一節)
1.RTP relies on the underlying protocol(s) to provide demultiplexing of RTP data and RTCP control streams.??For UDP and similar protocols,RTP SHOULD use an even destination port number and the corresponding RTCP stream SHOULD use the next higher (odd) destination port number.
2.For applications in which the RTP and RTCP destination port numbers are specified via explicit, separate parameters (using a signaling protocol or other means), the application MAY disregard the restrictions that the port numbers be even/odd and consecutive although the use of an even/odd port pair is still encouraged.?
3.The RTP and RTCP port numbers MUST NOT be the same since RTP relies on the port numbers to demultiplex the RTP data and RTCP control streams.
4.In a unicast session, both participants need to identify a port pair for receiving RTP and RTCP packets.??Both participants MAY use the same port pair.??A participant MUST NOT assume that the source port of the incoming RTP or RTCP packet can be used as the destination port for outgoing RTP or RTCP packets.
5.RTP data packets contain no length field or other delineation,therefore RTP relies on the underlying protocol(s) to provide a length indication.??The maximum length of RTP packets is limited only by the underlying protocols.
6.(原話找不到了)RTP本身并不知道該使用remote host的什么端口來傳輸,這需要用Non-RTP means來告知(比如和遠端主機之間的信令交互得知),而本程序中沒有信令交互,是顯式指定。


最后把主機A上的運行結果貼一下

[atom@localhost code]$ ./mediastream --local 5010 --remote 10.10.104.199:6014 --payload 110 > atom
ortp-message-Registering all filters...
ortp-message-Registering all soundcard handlers
ortp-message-Card ALSA: default device added
ortp-message-Card ALSA: Ensoniq AudioPCI added
ortp-message-Card OSS: /dev/dsp added
ortp-message-Card OSS: /dev/dsp added
ortp-message-Loading plugins
ortp-message-Cannot open directory /usr/lib/mediastreamer/plugins: No such file or directory
ortp-message-ms_init() done
ortp-message-Setting audio encoder network bitrate to 8000
ortp-message-ms_filter_link: MSAlsaRead:0x93f0db0,0-->MSSpeexEnc:0x93f0ea0,0
ortp-message-ms_filter_link: MSDtmfGen:0x93f0d30,0-->MSAlsaWrite:0x93f0e28,0
ortp-message-ms_filter_link: MSSpeexEnc:0x93f0ea0,0-->MSRtpSend:0x93f0c18,0
ortp-message-ms_filter_link: MSRtpRecv:0x93f0c88,0-->MSSpeexDec:0x93f0f60,0
ortp-message-ms_filter_link: MSSpeexDec:0x93f0f60,0-->MSDtmfGen:0x93f0d30,0
ortp-message-Using bitrate 2150 for speex encoder.
ortp-message-alsa_open_r: opening default at 8000Hz, bits=16, stereo=0
ortp-message-synchronizing timestamp, diff=960
ortp-message-synchronizing timestamp, diff=320
ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=47
?number of rtp bytes sent=1636 bytes
?number of rtp packet received=49
?number of rtp bytes received=1927 bytes
?number of incoming rtp bytes successfully delivered to the application=1739
?number of times the application queried a packet that didn't exist=107
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=99
?number of rtp bytes sent=3254 bytes
?number of rtp packet received=102
?number of rtp bytes received=3683 bytes
?number of incoming rtp bytes successfully delivered to the application=3629
?number of times the application queried a packet that didn't exist=213
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=152
?number of rtp bytes sent=5554 bytes
?number of rtp packet received=154
?number of rtp bytes received=5077 bytes
?number of incoming rtp bytes successfully delivered to the application=5038
?number of times the application queried a packet that didn't exist=318
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=205
?number of rtp bytes sent=6671 bytes
?number of rtp packet received=207
?number of rtp bytes received=5964 bytes
?number of incoming rtp bytes successfully delivered to the application=5925
?number of times the application queried a packet that didn't exist=424
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=258
?number of rtp bytes sent=8632 bytes
?number of rtp packet received=260
?number of rtp bytes received=7422 bytes
?number of incoming rtp bytes successfully delivered to the application=7292
?number of times the application queried a packet that didn't exist=530
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-Receiving RTCP SR
ortp-message-interarrival jitter=121
ortp-message-Receiving RTCP SDES
ortp-message-Found CNAME=unknown@unknown
ortp-message-Found TOOL=oRTP-0.14.2
ortp-message-Found NOTE=This is free sofware (LGPL) !
ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=312
?number of rtp bytes sent=10280 bytes
?number of rtp packet received=314
?number of rtp bytes received=10202 bytes
?number of incoming rtp bytes successfully delivered to the application=9970
?number of times the application queried a packet that didn't exist=636
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=364
?number of rtp bytes sent=12382 bytes
?number of rtp packet received=365
?number of rtp bytes received=11527 bytes
?number of incoming rtp bytes successfully delivered to the application=11501
?number of times the application queried a packet that didn't exist=742
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=416
?number of rtp bytes sent=14337 bytes
?number of rtp packet received=419
?number of rtp bytes received=14520 bytes
?number of incoming rtp bytes successfully delivered to the application=14346
?number of times the application queried a packet that didn't exist=847
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=470
?number of rtp bytes sent=16216 bytes
?number of rtp packet received=472
?number of rtp bytes received=15832 bytes
?number of incoming rtp bytes successfully delivered to the application=15752
?number of times the application queried a packet that didn't exist=953
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=523
?number of rtp bytes sent=18399 bytes
?number of rtp packet received=524
?number of rtp bytes received=16604 bytes
?number of incoming rtp bytes successfully delivered to the application=16578
?number of times the application queried a packet that didn't exist=1059
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-Receiving RTCP SR
ortp-message-interarrival jitter=133
ortp-message-Receiving RTCP SDES
ortp-message-Found CNAME=unknown@unknown
ortp-message-Found TOOL=oRTP-0.14.2
ortp-message-Found NOTE=This is free sofware (LGPL) !
ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=575
?number of rtp bytes sent=20072 bytes
?number of rtp packet received=578
?number of rtp bytes received=17986 bytes
?number of incoming rtp bytes successfully delivered to the application=17754
?number of times the application queried a packet that didn't exist=1164
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=629
?number of rtp bytes sent=22106 bytes
?number of rtp packet received=630
?number of rtp bytes received=20753 bytes
?number of incoming rtp bytes successfully delivered to the application=20637
?number of times the application queried a packet that didn't exist=1270
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=681
?number of rtp bytes sent=24917 bytes
?number of rtp packet received=683
?number of rtp bytes received=21885 bytes
?number of incoming rtp bytes successfully delivered to the application=21859
?number of times the application queried a packet that didn't exist=1376
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=734
?number of rtp bytes sent=27703 bytes
?number of rtp packet received=736
?number of rtp bytes received=22594 bytes
?number of incoming rtp bytes successfully delivered to the application=22555
?number of times the application queried a packet that didn't exist=1481
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=788
?number of rtp bytes sent=28977 bytes
?number of rtp packet received=789
?number of rtp bytes received=23637 bytes
?number of incoming rtp bytes successfully delivered to the application=23483
?number of times the application queried a packet that didn't exist=1587
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-Receiving RTCP SR
ortp-message-interarrival jitter=127
ortp-message-Receiving RTCP SDES
ortp-message-Found CNAME=unknown@unknown
ortp-message-Found TOOL=oRTP-0.14.2
ortp-message-Found NOTE=This is free sofware (LGPL) !
ortp-message-oRTP-stats:
???Global statistics :
?number of rtp packet sent=840
?number of rtp bytes sent=30072 bytes
?number of rtp packet received=837
?number of rtp bytes received=25564 bytes
?number of incoming rtp bytes successfully delivered to the application=25564
?number of times the application queried a packet that didn't exist=1692
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-oRTP-stats:
???Audio session's RTP statistics :
?number of rtp packet sent=840
?number of rtp bytes sent=30072 bytes
?number of rtp packet received=837
?number of rtp bytes received=25564 bytes
?number of incoming rtp bytes successfully delivered to the application=25564
?number of times the application queried a packet that didn't exist=1693
?number of rtp packet lost=0
?number of rtp packets received too late=0
?number of bad formatted rtp packets=0
?number of packet discarded because of queue overflow=0

ortp-message-ms_filter_unlink: MSAlsaRead:0x93f0db0,0-->MSSpeexEnc:0x93f0ea0,0
ortp-message-ms_filter_unlink: MSDtmfGen:0x93f0d30,0-->MSAlsaWrite:0x93f0e28,0
ortp-message-ms_filter_unlink: MSSpeexEnc:0x93f0ea0,0-->MSRtpSend:0x93f0c18,0
ortp-message-ms_filter_unlink: MSRtpRecv:0x93f0c88,0-->MSSpeexDec:0x93f0f60,0
ortp-message-ms_filter_unlink: MSSpeexDec:0x93f0f60,0-->MSDtmfGen:0x93f0d30,0
ortp-message-MSTicker thread exiting

Remote addr: ip=10.10.104.199 port=6014
Starting audio stream.
Bandwidth usage: download=26.614873 kbits/sec, upload=24.850787 kbits/sec
Bandwidth usage: download=24.757891 kbits/sec, upload=23.288695 kbits/sec
Bandwidth usage: download=21.915512 kbits/sec, upload=28.845805 kbits/sec
Bandwidth usage: download=18.254627 kbits/sec, upload=19.849715 kbits/sec
Bandwidth usage: download=22.314123 kbits/sec, upload=26.907152 kbits/sec
Bandwidth usage: download=33.280316 kbits/sec, upload=24.266766 kbits/sec
Bandwidth usage: download=21.465322 kbits/sec, upload=27.740203 kbits/sec
Bandwidth usage: download=34.365668 kbits/sec, upload=26.550016 kbits/sec
Bandwidth usage: download=21.669883 kbits/sec, upload=26.035174 kbits/sec
Bandwidth usage: download=17.581689 kbits/sec, upload=28.368437 kbits/sec
Bandwidth usage: download=22.050596 kbits/sec, upload=23.840863 kbits/sec
Bandwidth usage: download=32.469631 kbits/sec, upload=27.263791 kbits/sec
Bandwidth usage: download=19.910096 kbits/sec, upload=32.475279 kbits/sec
Bandwidth usage: download=16.712168 kbits/sec, upload=32.902848 kbits/sec
Bandwidth usage: download=19.092574 kbits/sec, upload=21.455217 kbits/sec
Bandwidth usage: download=24.896035 kbits/sec, upload=19.984568 kbits/sec
stoping all... 用mediastream+ortp庫使用本機攝像頭的簡單程序 http://blog.sina.com.cn/s/blog_6a9032c10100lyjz.html

用mediastream+ortp庫使用本機攝像頭的簡單程序

#include "mediastreamer2/mediastream.h"?
#include "mediastreamer2/msvideoout.h"?
#include "mediastreamer2/msv4l.h"

int main(int argc, char *argv[]){?
VideoStream *vs;?
MSWebCam *cam;?
MSVideoSize?vsize;?
int i;

vsize.width=MS_VIDEO_SIZE_CIF_W;?
vsize.height=MS_VIDEO_SIZE_CIF_H;

ortp_init();?
ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);?
ms_init();?
cam=ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get());?
//vs=video_preview_start(cam,vsize);?
//while(1);?
?
for(i=0;i<1;++i){?
int n;?
vs=video_preview_start(cam,vsize);

for(n=0;n<1000;++n){?
#ifdef WIN32?
MSG msg;?
Sleep(100);?
while (PeekMessage(&msg, NULL, 0, 0,1)){?
TranslateMessage(&msg);?
DispatchMessage(&msg);?
}?
#else?
struct timespec ts;?
ts.tv_sec=0;?
ts.tv_nsec=10000000;?
nanosleep(&ts,NULL);

if (vs) video_stream_iterate(vs);?
#endif

?
if (n==400)?
{?
printf("this is 400\n");?
ms_ticker_detach (vs->ticker, vs->source);

vs->tee = ms_filter_new(MS_TEE_ID);

ms_filter_unlink(vs->pixconv,0, vs->output,0);

ms_filter_link(vs->pixconv,0,vs->tee,0);?
ms_filter_link(vs->tee,0,vs->output,0);?
ms_filter_link(vs->tee,1,vs->output,1);?

//ms_filter_unlink(vs->tee,0,vs->output,0);?
ms_ticker_attach?(vs->ticker, vs->source);

}?
if (n==500)?
{?
printf("this is 500\n");?
int corner=1;?
ms_filter_call_method(vs->output,MS_VIDEO_OUT_SET_CORNER,&corner);?
}?
if (n==600)?
{?
printf("this is 600\n");?
int corner=2;?
ms_filter_call_method(vs->output,MS_VIDEO_OUT_SET_CORNER,&corner);?
}?
if (n==700)?
{?
printf("this is 700\n");?
int corner=3;?
ms_filter_call_method(vs->output,MS_VIDEO_OUT_SET_CORNER,&corner);?
}?
if (n==800)?
{?
printf("this is 800\n");?
int corner=-1;?
ms_filter_call_method(vs->output,MS_VIDEO_OUT_SET_CORNER,&corner);?
}?
if (n==900)?
{?
printf("this is 900\n");?
ms_ticker_detach (vs->ticker, vs->source);

ms_filter_unlink(vs->pixconv,0,vs->tee,0);?
ms_filter_unlink(vs->tee,0,vs->output,0);?
ms_filter_unlink(vs->tee,1,vs->output,1);?
ms_filter_destroy(vs->tee);?
vs->tee=NULL;

ms_filter_link(vs->pixconv,0, vs->output,0);


ms_ticker_attach (vs->ticker, vs->source);?
}?
}?
video_preview_stop(vs);?
}?
return 0;?
}?

轉載于:https://www.cnblogs.com/virusolf/p/5016953.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的mediastream2使用指南(转载)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。