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** MJPEGVideoSource.h
7**
8** V4L2 RTSP streamer
9**
10** MJPEG Source for RTSP server
11**
12** -------------------------------------------------------------------------*/
13
14#include "logger.h"
15#include "JPEGVideoSource.hh"
16
17class MJPEGVideoSource : public JPEGVideoSource
18{
19 public:
20 static MJPEGVideoSource* createNew (UsageEnvironment& env, FramedSource* source)
21 {
22 return new MJPEGVideoSource(env,source);
23 }
24 virtual void doGetNextFrame()
25 {
26 if (m_inputSource) {
27 m_inputSource->getNextFrame(fTo, fMaxSize, afterGettingFrameSub, this, FramedSource::handleClosure, this);
28 }
29 }
30 virtual void doStopGettingFrames()
31 {
32 FramedSource::doStopGettingFrames();
33 if (m_inputSource) {
34 m_inputSource->stopGettingFrames();
35 }
36 }
37 static void afterGettingFrameSub(void* clientData, unsigned frameSize,unsigned numTruncatedBytes,struct timeval presentationTime,unsigned durationInMicroseconds)
38 {
39 MJPEGVideoSource* source = (MJPEGVideoSource*)clientData;
40 source->afterGettingFrame(frameSize, numTruncatedBytes, presentationTime, durationInMicroseconds);
41 }
42
43 void afterGettingFrame(unsigned frameSize,unsigned numTruncatedBytes,struct timeval presentationTime,unsigned durationInMicroseconds);
44 virtual u_int8_t type() { return m_type; };
45 virtual u_int8_t qFactor() { return 128; };
46 virtual u_int8_t width() { return m_width; };
47 virtual u_int8_t height() { return m_height; };
48 virtual u_int16_t restartInterval() { return m_restartInterval; }
49
50 u_int8_t const* quantizationTables( u_int8_t& precision, u_int16_t& length );
51
52 protected:
53 MJPEGVideoSource(UsageEnvironment& env, FramedSource* source) : JPEGVideoSource(env),
54 m_inputSource(source),
55 m_width(0), m_height(0), m_qTableSize(0), m_precision(0),
56 m_type(0), m_restartInterval(0)
57 {
58 memset(&m_qTable,0,sizeof(m_qTable));
59 }
60 virtual ~MJPEGVideoSource()
61 {
62 Medium::close(m_inputSource);
63 }
64
65 protected:
66 FramedSource* m_inputSource;
67 u_int8_t m_width;
68 u_int8_t m_height;
69 u_int8_t m_qTable[128*2];
70 unsigned int m_qTableSize;
71 unsigned int m_precision;
72 u_int8_t m_type;
73 u_int16_t m_restartInterval;
74};
75