Reputation: 7043
Is there an easy way to use the data I'm encoding using Media Foundation and streaming it over the network instead of writing it to a WMV file?
Upvotes: 4
Views: 3959
Reputation: 1725
First, I guess, you need to know what format (encoded as/contained in) you are going to stream as.
I am thinking h264. With windows 7 media foundation create h264 helper functions. You need to create a topology. Source reads a file and sink turns the decoded and encoded format to h264. All you need is source and a sink. You dont actually need a decoder and an encoder. Topology builder figures what needs to be plugged in between.
There is a CreateTranscodeTopology function but that wont help you because it writes the encoded data to a file. That is why you need to create your own topology.
Only thing you need to write is a class which implements IMFByteStream.
Your sink should take your implementation of this byte stream. Your implementations "Write" function is going to write to the socket that you want to send the data to. So maybe you can pass your socket to the constructor of your IMFByteStream implementation or a callback function.
I would also suggest you put some print statements in the the other function that you need to implement in IMFByteStream because SinkWriter calls certain stuff like. GetCapabilities so you should at least return.
HRESULT STDMETHODCALLTYPE NetworkOutputStream::GetCapabilities(__RPC__out DWORD *pdwCapabilities){HRESULT hr=S_OK;
printf("GetCapabilities\n");
*pdwCapabilities= (MFBYTESTREAM_IS_READABLE|MFBYTESTREAM_IS_WRITABLE|MFBYTESTREAM_IS_SEEKABLE);
return hr;
}
Having said this, If you have your player on the client ("HTML5 Browser) I would suggest you use "MFCopy" example.
Creating topology is mostly for playback and stuff. So it decodes and encodes it the speed that move should play. But all you need is encode the file and send it of the wire . So take a look at the MFCopy and implement your own IMFByteStream. Instead of creating a sink that write to local file system pass your IMFByteStream to the sink.
Upvotes: 3