RtvcRtpSink.h

Go to the documentation of this file.
00001 
00034 #pragma once
00035 
00036 // DirectShow includes
00037 #pragma warning(push)     // disable for this header only
00038 #pragma warning(disable:4312) 
00039 // DirectShow
00040 #include <Streams.h>
00041 #pragma warning(pop)      // restore original warning level
00042 
00043 #include <Windows.h>
00044 
00045 // STL
00046 #include <iostream>
00047 
00048 // LiveMedia
00049 #include "MediaSink.hh"
00050 #include <RTPSource.hh>
00051 
00052 // RTVC
00053 #include <Shared/MediaSample.h>
00054 
00060 template<class T>
00061 class RtvcRtpSink : public MediaSink
00062 {
00063 public:
00065         RtvcRtpSink(UsageEnvironment& env, int nSourceID, unsigned bufferSize, T* pSampleHandler)
00066                 : MediaSink(env),
00067                 m_pSampleHandler(pSampleHandler),
00068                 m_bHasBeenSyncedUsingRtcp(false),
00069                 m_nSourceID(nSourceID)
00070         {
00071                 // Create memory buffer
00072                 fBuffer = new unsigned char[bufferSize];
00073                 fBufferSize = bufferSize;
00074         }
00075 
00077         virtual ~RtvcRtpSink( void )
00078         {
00079                 // Free memory
00080                 delete[] fBuffer;
00081         }
00082         
00083 protected:
00085         static void afterGettingFrame( void* clientData, unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds )
00086         {
00087                 RtvcRtpSink* sink = (RtvcRtpSink*)clientData;
00088                 sink->afterGettingFrame1(frameSize, presentationTime);
00089         }
00090 
00092         virtual void afterGettingFrame1( unsigned frameSize, struct timeval presentationTime )
00093         {
00094                 processData(fBuffer, frameSize, presentationTime);
00095                 // Then try getting the next frame:
00096                 continuePlaying();
00097         }
00098 
00100         virtual Boolean continuePlaying()
00101         {
00102                 if (fSource == NULL) return False;
00103 
00104                 fSource->getNextFrame(fBuffer, fBufferSize,
00105                         afterGettingFrame, this,
00106                         onSourceClosure, this);
00107 
00108                 return True;
00109         }
00110 
00111         void processData( unsigned char* data, unsigned dataSize, struct timeval presentationTime )
00112         {
00113                 // Check if stream has been synced using RTCP: to do this we need to get hold of the RTPSource object
00114                 RTPSource* pRtpSource = (RTPSource*)fSource;
00115                 // Convert presentation time to double
00116                 double dStartTime = presentationTime.tv_sec + (presentationTime.tv_usec / 1000000.0);
00117                 // Implicit Template Declaration
00118                 m_pSampleHandler->processMediaSample(m_nSourceID, data, dataSize, dStartTime, pRtpSource->hasBeenSynchronizedUsingRTCP());
00119         }
00120 
00121 private:
00123         T* m_pSampleHandler;
00124 
00126         unsigned char* fBuffer;
00128         unsigned fBufferSize;
00129 
00131         bool m_bHasBeenSyncedUsingRtcp;
00132 
00134         int m_nSourceID;
00135 };

Generated on Fri Mar 13 14:12:38 2009 for RTVC by  doxygen 1.5.3