I have implemented CSocketReader class derived from DataReader that reads a UDP based MPEG TS stream. I have adhered to UMC coding style as much as possible. I would like to contribute this to the IPP library or to other people who are interested.
If anyone is interested please let me know and where to upload the files?
Thanks you for help to the community. I think you can attach your implementation to this thread, so people can take your implementation from here.
I am posting the code in the attached zip file, there are 4 files:
SocketReader.h, SocketReade.cpp: Derived from UMC::DataReader. Internally it creates a socket, spawns a new thread which writes the incoming TS packetsto a circular buffer. The demuxer thread picks up the data through the normal ReadData, CacheData, and MovePosition operations.
CircularBuffer.h, .cpp: I downloadedthis circular buffer code from codeproject.com (original author and copyright notice included).I made the following changes to the original code:
Fixed race condition and memory leakbugs,
Replaced allWindows specific API with standardC++. (E.g. variable typedefs, synchronization objects, etc.)
Instead of using mutexes to synchronize read/write operations from multiple threads I use the one byte open strategy to prevent data corruption. (http://en.wikipedia.org/wiki/Circular_buffer). Thisis sufficientfor the one reader thread and one writer thread model.
Note: The socket code is Windows specific and I have not tested the multicast option.