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** MemoryBufferSink.h
7**
8** Implement a live555 Sink that store time slices in memory
9**
10** -------------------------------------------------------------------------*/
11
12#pragma once
13
14#include <string>
15#include <map>
16
17#include "MediaSink.hh"
18
19class MemoryBufferSink : public MediaSink
20{
21 public:
22 static MemoryBufferSink* createNew(UsageEnvironment& env, unsigned int bufferSize, unsigned int sliceDuration)
23 {
24 return new MemoryBufferSink(env, bufferSize, sliceDuration);
25 }
26
27 protected:
28 MemoryBufferSink(UsageEnvironment& env, unsigned bufferSize, unsigned int sliceDuration);
29 virtual ~MemoryBufferSink();
30
31 virtual Boolean continuePlaying();
32
33 static void afterGettingFrame(void* clientData, unsigned frameSize,
34 unsigned numTruncatedBytes,
35 struct timeval presentationTime,
36 unsigned durationInMicroseconds) {
37 MemoryBufferSink* sink = (MemoryBufferSink*)clientData;
38 sink->afterGettingFrame(frameSize, numTruncatedBytes, presentationTime);
39 }
40
41 void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime);
42
43 public:
44 unsigned int getBufferSize(unsigned int slice);
45 std::string getBuffer(unsigned int slice);
46 unsigned int firstTime();
47 unsigned int duration();
48 unsigned int getSliceDuration() { return m_sliceDuration; }
49
50 private:
51 unsigned char * m_buffer;
52 unsigned int m_bufferSize;
53 std::map<unsigned int,std::string> m_outputBuffers;
54 unsigned int m_refTime;
55 unsigned int m_sliceDuration;
56};
57
58