1/* ---------------------------------------------------------------------------
2** This software is in the public domain, furnished "as is", without technical
3** support, and with no warranty, express or implied, as to its usefulness for
4** any purpose.
5**
6** AddH26xMarkerFilter.h
7**
8** -------------------------------------------------------------------------*/
9
10#pragma once
11
12class AddH26xMarkerFilter : public FramedFilter {
13 public:
14 AddH26xMarkerFilter (UsageEnvironment& env, FramedSource* inputSource): FramedFilter(env, inputSource) {
15 m_bufferSize = OutPacketBuffer::maxSize;
16 m_buffer = new unsigned char[m_bufferSize];
17 }
18 virtual ~AddH26xMarkerFilter () {
19 delete [] m_buffer;
20 }
21
22 private:
23
24 static void afterGettingFrame(void* clientData, unsigned frameSize,
25 unsigned numTruncatedBytes,
26 struct timeval presentationTime,
27 unsigned durationInMicroseconds) {
28 AddH26xMarkerFilter* sink = (AddH26xMarkerFilter*)clientData;
29 sink->afterGettingFrame(frameSize, numTruncatedBytes, presentationTime);
30 }
31
32 void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime)
33 {
34 fPresentationTime = presentationTime;
35 fDurationInMicroseconds = 0;
36 if (numTruncatedBytes > 0)
37 {
38 envir() << "AddH26xMarkerFilter::afterGettingFrame(): The input frame data was too large for our buffer size truncated:" << numTruncatedBytes << " bufferSize:" << m_bufferSize << "\n";
39 m_bufferSize += numTruncatedBytes;
40 delete[] m_buffer;
41 m_buffer = new unsigned char[m_bufferSize];
42 fFrameSize = 0;
43 } else {
44 char marker[] = {0,0,0,1};
45 fFrameSize = frameSize + sizeof(marker);
46 if (fFrameSize > fMaxSize) {
47 fNumTruncatedBytes = fFrameSize - fMaxSize;
48 envir() << "AddH26xMarkerFilter::afterGettingFrame(): buffer too small truncated:" << fNumTruncatedBytes << " bufferSize:" << fFrameSize << "\n";
49 } else {
50 fNumTruncatedBytes = 0;
51 memcpy(fTo, marker, sizeof(marker));
52 memcpy(fTo+sizeof(marker), m_buffer, frameSize);
53 }
54 }
55 afterGetting(this);
56 }
57
58 virtual void doGetNextFrame() {
59 if (fInputSource != NULL)
60 {
61 fInputSource->getNextFrame(m_buffer, m_bufferSize,
62 afterGettingFrame, this,
63 handleClosure, this);
64 }
65 }
66
67 unsigned char* m_buffer;
68 unsigned int m_bufferSize;
69};
70
71
72