mirror of
https://github.com/mpromonet/v4l2rtspserver
synced 2024-11-03 23:15:56 +00:00
101 lines
2.8 KiB
C++
101 lines
2.8 KiB
C++
/* ---------------------------------------------------------------------------
|
|
** This software is in the public domain, furnished "as is", without technical
|
|
** support, and with no warranty, express or implied, as to its usefulness for
|
|
** any purpose.
|
|
**
|
|
** V4l2DeviceSource.h
|
|
**
|
|
** V4L2 live555 source
|
|
**
|
|
** -------------------------------------------------------------------------*/
|
|
|
|
|
|
#ifndef V4L2_DEVICE_SOURCE
|
|
#define V4L2_DEVICE_SOURCE
|
|
|
|
#include <string>
|
|
#include <list>
|
|
#include <iostream>
|
|
|
|
// live555
|
|
#include <liveMedia.hh>
|
|
|
|
// project
|
|
#include "V4l2Capture.h"
|
|
|
|
// ---------------------------------
|
|
// V4L2 FramedSource
|
|
// ---------------------------------
|
|
const char marker[] = {0,0,0,1};
|
|
class V4L2DeviceSource: public FramedSource
|
|
{
|
|
public:
|
|
// ---------------------------------
|
|
// Captured frame
|
|
// ---------------------------------
|
|
struct Frame
|
|
{
|
|
Frame(char* buffer, int size, timeval timestamp) : m_buffer(buffer), m_size(size), m_timestamp(timestamp) {};
|
|
Frame(const Frame&);
|
|
Frame& operator=(const Frame&);
|
|
~Frame() { delete m_buffer; };
|
|
|
|
char* m_buffer;
|
|
int m_size;
|
|
timeval m_timestamp;
|
|
};
|
|
|
|
// ---------------------------------
|
|
// Compute simple stats
|
|
// ---------------------------------
|
|
class Stats
|
|
{
|
|
public:
|
|
Stats(const std::string & msg) : m_fps(0), m_fps_sec(0), m_size(0), m_msg(msg) {};
|
|
|
|
public:
|
|
int notify(int tv_sec, int framesize, int verbose);
|
|
|
|
protected:
|
|
int m_fps;
|
|
int m_fps_sec;
|
|
int m_size;
|
|
const std::string m_msg;
|
|
};
|
|
|
|
public:
|
|
static V4L2DeviceSource* createNew(UsageEnvironment& env, V4L2DeviceParameters params, V4l2Capture * device, int outputFd, unsigned int queueSize, int verbose) ;
|
|
std::string getAuxLine() { return m_auxLine; };
|
|
|
|
protected:
|
|
V4L2DeviceSource(UsageEnvironment& env, V4L2DeviceParameters params, V4l2Capture * device, int outputFd, unsigned int queueSize, int verbose);
|
|
virtual ~V4L2DeviceSource();
|
|
|
|
protected:
|
|
static void deliverFrameStub(void* clientData) {((V4L2DeviceSource*) clientData)->deliverFrame();};
|
|
void deliverFrame();
|
|
static void incomingPacketHandlerStub(void* clientData, int mask) { ((V4L2DeviceSource*) clientData)->getNextFrame(); };
|
|
void getNextFrame();
|
|
bool processConfigrationFrame(char * frame, int frameSize);
|
|
void processFrame(char * frame, int &frameSize, const timeval &ref);
|
|
void queueFrame(char * frame, int frameSize, const timeval &tv);
|
|
|
|
// overide FramedSource
|
|
virtual void doGetNextFrame();
|
|
virtual void doStopGettingFrames();
|
|
|
|
protected:
|
|
V4L2DeviceParameters m_params;
|
|
std::list<Frame*> m_captureQueue;
|
|
Stats m_in;
|
|
Stats m_out;
|
|
EventTriggerId m_eventTriggerId;
|
|
int m_outfd;
|
|
std::string m_auxLine;
|
|
V4l2Capture * m_device;
|
|
unsigned int m_queueSize;
|
|
int m_verbose;
|
|
};
|
|
|
|
#endif
|