关注push模式,大家可以参考这个例子.(很完整的filter编写)

capboy 2002-06-03 12:28:39
相信很多人都改写过memfile的例子了,这个例子的局限是延时问题.因为本身是为了播放文件的.所有不适合在时时播放的地方.
使用push模式可以解决这个问题.最近在这里的一个帖子中看到了个winrtp的程序.下载看了看,写的很好.
这个例子有很完整的代码,从source filter,trans filter,render filter都是自己写的,也就是一整套的都有,建立一个完整的graph,大家应该可以从这里了解很多的东西.虽然只是个播放音频的例子.也自己看看他的mediatype的设置,连接,应该可以解决一些问题.
大家可以参考来完成自己的push模式的程序.
下载地址:
http://www.vovida.org/applications/downloads/winRTP/
...全文
160 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
capboy 2002-06-08
  • 打赏
  • 举报
回复
我到www.live.com看了,可是没有看到音频视频同步的东西啊.在Streaming Media部分么?其他的都是组播的东西.可是Streaming Media我打不开...气死人了.


to wf_quxq():
播放的是标准的媒体文件了?建议你的filter这个部分
AMOVIESETUP_FILTER sudFilterReg = {
&CLSID_SomeFilter, // Filter CLSID.
g_wszName, // Filter name.
MERIT_NORMAL, // Merit.
1, // Number of pin types.
&sudPins // Pointer to pin information.
};
Merit设置为MERIT_PREFERRED...不知道播放的时候是不是真的可以有首选的位置.:)
这个问题还真不知道.

还是自己写一个程序,自己调用自己的source filter吧.是不是有特殊要求?
yanf_99 2002-06-08
  • 打赏
  • 举报
回复
下载library和源码 http://sourceforge.net/projects/live
答问 http://www.live.com/liveMedia/live-devel.mbx
一个实时播放的例子,应该同一时间只有声音或影像 - 要是可以同步出现,请告诉我一声, 谢谢。http://www.live.com/multikit/playRTPMPEG.html
yanf_99 2002-06-08
  • 打赏
  • 举报
回复
应该是Streaming Media部分。那个作者还没有完成音频同步的东西,可他把自己写的整个library和一些例子都放在那儿了,我怀疑它可能在windows以外的平台也可以运行,因为源码是.tar.gz,在linux上解压后,用makefile在VC上编译, 最终的library和openRTSP.exe, testMP3Receiver.exe, testMPEGAudioVideoStreamer.exe, testMPEGVideoReceiver.exe, playRTPMPEGSetup.exe等等例子都不错。不过它好像是独立于DirectShow的,除openRTSPplay和另外下载的RTPMPEGSetup.exe外好像也不支持实时播放。另外那个作者非常好,每次都亲自回答别人对RTP,MPEG等的问题。不大会打中文,这段话打了半个钟头,好在老板短周不上班。:D
yanf_99 2002-06-07
  • 打赏
  • 举报
回复
谢谢行天,其实我也不熟,都是从google找来的。:p
yanf_99 2002-06-06
  • 打赏
  • 举报
回复
和大家一样,我也不喜欢英文,假如我的贴子让人看着心烦,对不起。可公司电脑的确没有中文输入。我刚下载了南极星,只因为看了楼上的话。。。我只想说,每个人都有自己的喜好,也受到不同的限制,为什么要因自己的喜好去伤害别人的感情呢?像是看到瘸子就憎恶人家学铁拐李一样,有没有想过别人的感受?做不出东西已经很难过,还要莫名其妙被人骂。。

还是很感激CapBoy和友善的朋友们。希望大家工作顺利,愉快。
levinson 2002-06-06
  • 打赏
  • 举报
回复
我最受不了假洋鬼子。
xingtian713 2002-06-06
  • 打赏
  • 举报
回复
yanf_99,谢谢你的指点,我现在正在看这个程序,有问题还得向你请教,我对rtp协议那部分很感兴趣。你的英文确实不错,我很羡慕!
yanf_99 2002-06-06
  • 打赏
  • 举报
回复
For your reference, http://www.vbrick.com/WhitePapers/MPEG_and_RTP.pdf could be found at: http://www.vbrick.com/Whitpapr.asp
:p Hope it works.
yanf_99 2002-06-06
  • 打赏
  • 举报
回复
Thanks again to CapBoy.

I agree and trying on the approach,
source filter (video outputpin)->video decoder->video render
(audio outputpin)->audio deocder->audio render
but, "我相信,只要你的音频和视频数据本来就是同步的话,自己分解,在分别给解压部分,应该是不会有同步问题.因为数据源是同步,不会造成解压不同步的情况", I'm not sure because I think it's possible for video and audio to be transferred at different rate? I mean like they are made and sent at the same time but reach the receiver at different time? Hmm, I don't know if you took a look on www.live.com, I think that man did perfect job, however, he mentioned video audio synchronization but never implement it yet... Anyway, I have some other work now and hopefully I'll have more time on this..
wf_quxq 2002-06-06
  • 打赏
  • 举报
回复
Capboy:
你好,请问如何解决下列问题:
具体“需求”如下:
·自己编写的流媒体服务器,使用自己开发的应用层协议,设其名为:ssp协议。
·ssp协议基于tcp协议,用于传输多媒体数据和控制,功能层次等同于rtp协议或者http等协议,相当于rtp协议和rtsp协议的综合。
·客户端使用windows media player,加载的当然是上面提到的自己开发的source filter。
·用户操作流程是这样:在windows media player地址栏中输入如下格式地址:
vod://www.somecom.com.cn:8089/movies/trainingday.avi
然后用户点击播放。或者在页面中media player控件的参数设为:
<PARAM NAME="Filename" VALUE="vod://www.somecom.com.cn:8089/movies/trainingday.avi">
请问我的过滤器如何取得参数:"www.somecom.com.cn:8089/movies/trainingday.avi"以及
请问如何才能让media player根据"vod://"来加载我的sourcefilter呢?
多谢!
yanf_99 2002-06-06
  • 打赏
  • 举报
回复
Hi xingtian, if you want use the JAVA program to test it (or simply find jni.h), you need to have java sdk installed first and put
%JAVA_PATH%\include (e.g.: C:\jdk1.3.1\include)
%JAVA_PATH%\include\win32 (e.g.: C:\jdk1.3.1\include)
in VC Tools->Options->Directories->Include Files

Actually, someone had written a VB program to test the project -

(From: http://www.vovida.org/pipermail/winrtp.mbox/winrtp.mbox)
From jiang.wu@zinglabs.com Tue May 22 01:56:52 2001
Received: from www11.chinadns.com ([211.99.199.80])
by www.vovida.org (8.11.0/8.11.0) with SMTP id f4M8unT05235
for <winrtp@vovida.org>; Tue, 22 May 2001 01:56:50 -0700
Received: (qmail 91612 invoked from network); 22 May 2001 08:34:54 -0000
Received: from gj-05-059.bta.net.cn (HELO wu) (202.106.5.59)
by 211.99.199.80 with SMTP; 22 May 2001 08:34:54 -0000
Message-ID: <001801c0e298$800e96c0$6c00a8c0@wu>
From: "Jiang Wu" <jiang.wu@zinglabs.com>
To: "Robert Harris" <brthrjon@yahoo.com>, <winrtp@vovida.org>
References: <20010522034302.97191.qmail@web13608.mail.yahoo.com>
Subject: Re: [Winrtp] Multiply Defined Symbols + Example Program
Date: Tue, 22 May 2001 16:21:36 +0800
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.00.2919.6700
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from base64 to 8bit by www.vovida.org id f4M8unT05235
Sender: winrtp-admin@vovida.org
Errors-To: winrtp-admin@vovida.org
X-BeenThere: winrtp@vovida.org
X-Mailman-Version: 2.0.1
Precedence: bulk
List-Help: <mailto:winrtp-request@vovida.org?subject=help>
List-Post: <mailto:winrtp@vovida.org>
List-Subscribe: <http://www.vovida.org/mailman/listinfo/winrtp>,
<mailto:winrtp-request@vovida.org?subject=subscribe>
List-Id: WinRTP <winrtp.vovida.org>
List-Unsubscribe: <http://www.vovida.org/mailman/listinfo/winrtp>,
<mailto:winrtp-request@vovida.org?subject=unsubscribe>
List-Archive: <http://www.vovida.org/pipermail/winrtp/>

Hi Robert,

Below is the sample VB code. But first you need make the change to CCNSMT and rebuilt it:
Change the data type of the parameter of SetAudioCodecTX() from "unsighed short" to "long", for VB can not recognize this type from a dll.

Regards,
Jiang Wu

VB code:

Dim phone As CCNMediaTerm

Private Sub Start_command()
On Error Resume Next
phone.Initialize
Call phone.SetAudioCodecTX(2, 30, 0, 0, 1, 0)
Call phone.SetAudioDestination(Dest_IP, Dest_port)
Call phone.SetAudioCodecRX(2, 30, 0, 0)
Call phone.SetAudioReceivePort(Listen_port)
phone.StartTX
phone.StartRX
phone.StartMicrophone
phone.StartAudioReceive
End Sub

Private Sub Exit_command()
phone.UnInitialize
Set phone = Nothing
End
End Sub

Private Sub Stop_command()
On Error Resume Next
phone.StopAudioReceive
phone.StopMicrophone
phone.StopRX
phone.StopTX
End Sub

The VB program works fine. :)
yanf_99 2002-06-05
  • 打赏
  • 举报
回复
Thanks, Capboy, as everybody said, you're really nice. :p

1. The GetMediaType should take a pointer to CMediaType (inherited from AM_MEDIA_TYPE), as I have no idea what should be the bFixedSizeSamples, bTemporalCompression, etc, I choosed to use CreateAudioMediaType method which will generate me a pointer to a new AM_MEDIA_TYPE...

virtual HRESULT GetMediaType(
int iPosition,
CMediaType *pMediaType
);

typedef struct _MediaType {
GUID majortype;
GUID subtype;
BOOL bFixedSizeSamples;
BOOL bTemporalCompression;
ULONG lSampleSize;
GUID formattype;
IUnknown *pUnk;
ULONG cbFormat;
/* [size_is] */ BYTE *pbFormat;
} AM_MEDIA_TYPE;

STDAPI CreateAudioMediaType(
const WAVEFORMATEX *pwfx,
AM_MEDIA_TYPE *pmt,
BOOL bSetFormat
);

2. About FillBuffer, I'm thinking of the buffer size or MAX_SAMPLE_SIZE, maybe my setting is bad, any suggestion? When i let the filter graph sleep (20000) before stop it, the receiver only take maybe 3 secs receive data then wait for the rest 17 secs and in the end called DecideBufferSize, that's all. Maybe I have to study the push model again..

3. Aiya!!!!! :p Thanks Capboy... I found that it's "MPEG video decoder" and "video render" I was using - as I tried to modify the receiver to get video infomation before. Now it's for audio:

CoCreateInstance(CLSID_CiscoRtpIn, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&g_pSource);
CoCreateInstance(CLSID_CMpegVideoCodec, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&g_pDecode);
CoCreateInstance(CLSID_VideoRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&g_pRenderer);

(uuids.h)
// 4a2286e0-7bef-11ce-9bd9-0000e202599c MPEG audio decoder
OUR_GUID_ENTRY(CLSID_CMpegAudioCodec,
0x4a2286e0, 0x7bef, 0x11ce, 0x9b, 0xd9, 0x0, 0x0, 0xe2, 0x2, 0x59, 0x9c)

// 79376820-07D0-11cf-A24D-0020AFD79767 DSound audio renderer
OUR_GUID_ENTRY(CLSID_DSoundRender,
0x79376820, 0x07D0, 0x11CF, 0xA2, 0x4D, 0x0, 0x20, 0xAF, 0xD7, 0x97, 0x67)

and it seems the problem mentioned in 2. is now ok. :)

4. Process MPEG (MPEG-1 temporarily) Video and Audio seperately... I'm not very sure. However the receiver is supposed to listen to a port and get 2 independent stremas (video & audio) via RTP/UDP.. my understanding's like: http://www.vbrick.com/WhitePapers/MPEG_and_RTP.pdf
What I don't understand is - "一个音频,一个视频,如果是system流的话,你不需要关心同步问题了(应该是自己就把数据分解)...有音频就给audio decoder filter,否则个video decoder filter(使用不同的outputpin递交数据来完成这个工作)" - I got all the packets together as they come to the same port, is that I could remove the header and directly pass them to audio decoder filter and video decoder? What if the bandwidth for audio and video's not the same and the they don't come together? The above link mentioned RTP timestamps... :( All my VC/C++ experiences are 2 or 3 assignments in college and I could still remember segmentation fault was my nightmare back to the old days. God save me, Help~ :p

Thanks again, happy coding, and have a nice day.
xingtian713 2002-06-05
  • 打赏
  • 举报
回复
我把它的源代码载下来后,编译TraceServer项目时,找不到jni.h文件,不知capboy你是否编译通过,如果解决不妨告诉我一声,我也想仔细研究一下这个程序
capboy 2002-06-05
  • 打赏
  • 举报
回复
我没有办法打开http://www.vbrick.com/WhitePapers/MPEG_and_RTP.pdf...
不知道为什么.

如果你想使用push模式的话,我没有发现好的splitter filter支持.
所以走别的路,把splitter filter给去掉,这个工作在source filter做.也就是你自己需要把音频和视频分开了,这样的结果是:
source filter (video outputpin)->video decoder->video render
(audio outputpin)->audio deocder->audio render
我相信,只要你的音频和视频数据本来就是同步的话,自己分解,在分别给解压部分,应该是不会有同步问题.因为数据源是同步,不会造成解压不同步的情况.
capboy 2002-06-04
  • 打赏
  • 举报
回复
我对于格式不熟悉.你可以参考这个:
MPEG-1 Audio Packet
Major type: MEDIATYPE_Audio
Minor type: MEDIASUBTYPE_MPEG1Packet

Format: MPEG1WAVEFORMAT

Sample contents: Single MPEG-1 packet including packet header

MPEG-1 Audio payload
Major type: MEDIATYPE_Audio
Minor type: MEDIASUBTYPE_MPEG1Payload

Format: MPEG1WAVEFORMAT

Sample contents: Byte-aligned MPEG-1 audio data

估计还需要指定major type和minor type吧.

为什么FillBuffer不调用?是不是你的graph就建立的不正确,或者没有成功的建立呢?
你能够告诉我你的graph是有那几个filter么?

同时有音频和视频数据?mpeg的为什么要分开处理呢?
不是使用system流来工作么?

需要支持音频和视频的话,你需要两个outputpin了.一个音频,一个视频,如果是system流的话,你不需要关心同步问题了(应该是自己就把数据分解)...有音频就给audio decoder filter,否则个video decoder filter(使用不同的outputpin递交数据来完成这个工作),如果本来音频和视频就是分离的,估计同步比较麻烦吧.解码好象需要统一的参考时钟吧...那你的数据这些信息是怎么写的呢?
zxylily 2002-06-04
  • 打赏
  • 举报
回复
谢谢你,帽子男孩!
ququshb 2002-06-04
  • 打赏
  • 举报
回复
好人啊。。
yanf_99 2002-06-04
  • 打赏
  • 举报
回复
Hi, I had tried WinRTP sometime back. As Cap said it made use of push model, it's complete and neat... However, I have problem in using the programs - actually, what all I need is a receiver filter and a filter graph. I tried to make use of WinRTP's "RTP Receiver Filter"...

To be simple, I removed some COM interface (ICiscoRtpIn) and did necessary setting in the CRtpInStreamAudio constructor. Add multicast support in blocksock. I don't have audio source for those Cisco things and MPEG's what I care about. I modified the GetMediaType part to at least let it support MPEG audio first:
wfx.wFormatTag = WAVE_FORMAT_MPEG;
wfx.cbSize = 22;
wfx.nBlockAlign = 4; //??
wfx.nChannels = 2;
wfx.nSamplesPerSec = 44100;
wfx.wBitsPerSample = 0;
wfx.nAvgBytesPerSec = 176400; //??
hr = CreateAudioMediaType( &wfx, (AM_MEDIA_TYPE *) pmt, TRUE);
break;

I'm not sure if it is alright, maybe it's supposed to be generated dynamically when reading the packet...? Whatever, I built the ax file, registered it and added it to the graphedit (or to my filter graph), render it, everything seems to be ok. However, I just can hear NOTHING!!!! (There is a streamer which sent RTP streams to the network.)

I tired some printf and found that the packets are received but FillBuffer has never been called!? Could you please kindly tell me
1. what's wrong and what should I do?
2. Any suggestion on GetMediaType? - I don't think hardcode is a good idea and I'm even not sure what should be hardcoded there, esp nBlockAlign and nAvgBytesPerSec. Are they have to be read from the RTP data, for example the first MPEG packet received?
3. As the streamer sent both Video and Audio RTP streams to the same destination, packets the receiver got are the both, would that be a reason I can't hear it? Sorry if the question doesn't make sense.
4. For further development, Video should be added but how to synchronize the two?
5. Hmm, may be more later. :p Thanks!!
sunshine_djh 2002-06-03
  • 打赏
  • 举报
回复
capboy真是个大好人!
GengSing 2002-06-03
  • 打赏
  • 举报
回复
谢谢!
加载更多回复(1)

8,301

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧