00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _MJPEGVIDEOSOURCE_H_
00023 #define _MJPEGVIDEOSOURCE_H_
00024
00025
00026 #include <GroupsockHelper.hh>
00027 #include <liveMedia.hh>
00028 #include <JPEGVideoSource.hh>
00029
00030
00031 #include <cv.h>
00032 #include <highgui.h>
00033
00034 #include <time.h>
00035
00036 #include "OStreamConfig.hh"
00037 #include "BaseInputVideo.hh"
00038 #include "OStreamVideoEncoder.hh"
00039
00047 #define JPEG_HEADER_MAX_SIZE 623
00048
00053 #define OUTPUT_PACKET_BUFFER_MAXSIZE 512000
00054
00062 class MJPEGVideoSource : public JPEGVideoSource
00063 {
00064 public:
00079 static MJPEGVideoSource*
00080 createNew( UsageEnvironment& env, BaseInputVideo* input_video,
00081 int stream_id = 0, int frame_rate = 25,
00082 int encoder_internal_buf_size = 1000000 );
00083
00084 virtual ~MJPEGVideoSource();
00085
00086 protected:
00091 MJPEGVideoSource( UsageEnvironment& env, BaseInputVideo* input_video,
00092 int stream_id, int frame_rate, int encoder_internal_buf_size);
00093
00094 private:
00098 void doGetNextFrame();
00099
00101 void deliverFrame();
00102
00104 void startCapture();
00105
00109 u_int8_t type();
00110
00115 u_int8_t qFactor();
00116
00121 u_int8_t width();
00122
00127 u_int8_t height();
00128
00136 u_int8_t const* quantizationTables( u_int8_t& precision, u_int16_t& length );
00137
00138
00145 int setParamsFromHeader( const unsigned char* fJPEGHeader );
00146
00148 Boolean isJPEGVideoSource() const;
00149
00150 private:
00152 bool _initialized;
00153
00154
00155 unsigned fTimePerFrame;
00156
00158 unsigned int fPreferredFrameSize;
00159
00164 const unsigned char* _encoded_frame;
00165
00167 struct timeval fLastCaptureTime;
00168
00170 int _fps;
00171
00173 int _frame_rate_millis;
00174
00176 u_int8_t fLastQFactor, fLastWidth, fLastHeight;
00177
00179 u_int8_t *qTable;
00180
00182 int _encoder_internal_buf_size;
00183
00185 int _stream_id;
00186
00188 BaseInputVideo *_input_video;
00189
00191 OStreamVideoEncoder *_video_encoder;
00192
00193 #ifdef __LINUX__
00194 struct timezone Idunno;
00195 #else
00196 int Idunno;
00197 #endif
00198
00199
00200 };
00201
00202
00203 #endif //_MJPEGVIDEOSOURCE_H_
00204