2014-07-20 14:02:14 +00:00
|
|
|
/* ---------------------------------------------------------------------------
|
|
|
|
** 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.
|
|
|
|
**
|
2014-11-02 15:42:30 +00:00
|
|
|
** V4l2DeviceSource.h
|
2014-07-20 14:02:14 +00:00
|
|
|
**
|
2014-11-02 15:42:30 +00:00
|
|
|
** V4L2 live555 source
|
2014-07-20 14:02:14 +00:00
|
|
|
**
|
|
|
|
** -------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef V4L2_DEVICE_SOURCE
|
|
|
|
#define V4L2_DEVICE_SOURCE
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <iostream>
|
2015-03-01 22:28:17 +00:00
|
|
|
#include <iomanip>
|
2014-07-20 14:02:14 +00:00
|
|
|
|
|
|
|
// live555
|
|
|
|
#include <liveMedia.hh>
|
|
|
|
|
2014-08-23 21:57:07 +00:00
|
|
|
// project
|
2014-11-02 15:42:30 +00:00
|
|
|
#include "V4l2Capture.h"
|
2014-08-23 21:57:07 +00:00
|
|
|
|
2014-07-20 14:02:14 +00:00
|
|
|
// ---------------------------------
|
|
|
|
// V4L2 FramedSource
|
|
|
|
// ---------------------------------
|
2015-03-07 19:25:52 +00:00
|
|
|
class V4L2DeviceSource: public FramedSource
|
2014-07-20 14:02:14 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ---------------------------------
|
|
|
|
// Captured frame
|
|
|
|
// ---------------------------------
|
|
|
|
struct Frame
|
|
|
|
{
|
|
|
|
Frame(char* buffer, int size, timeval timestamp) : m_buffer(buffer), m_size(size), m_timestamp(timestamp) {};
|
2014-10-18 17:50:21 +00:00
|
|
|
Frame(const Frame&);
|
|
|
|
Frame& operator=(const Frame&);
|
2016-04-20 16:16:46 +00:00
|
|
|
~Frame() { delete [] m_buffer; };
|
2014-07-20 14:02:14 +00:00
|
|
|
|
|
|
|
char* m_buffer;
|
|
|
|
int m_size;
|
|
|
|
timeval m_timestamp;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------
|
2014-08-17 15:29:08 +00:00
|
|
|
// Compute simple stats
|
2014-07-20 14:02:14 +00:00
|
|
|
// ---------------------------------
|
2014-08-17 14:42:26 +00:00
|
|
|
class Stats
|
2014-07-20 14:02:14 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-08-17 14:42:26 +00:00
|
|
|
Stats(const std::string & msg) : m_fps(0), m_fps_sec(0), m_size(0), m_msg(msg) {};
|
2014-07-20 14:02:14 +00:00
|
|
|
|
|
|
|
public:
|
2015-03-14 16:00:45 +00:00
|
|
|
int notify(int tv_sec, int framesize);
|
2014-07-20 14:02:14 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int m_fps;
|
|
|
|
int m_fps_sec;
|
2014-08-17 14:42:26 +00:00
|
|
|
int m_size;
|
2014-07-20 14:02:14 +00:00
|
|
|
const std::string m_msg;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2015-03-14 16:00:45 +00:00
|
|
|
static V4L2DeviceSource* createNew(UsageEnvironment& env, V4L2DeviceParameters params, V4l2Capture * device, int outputFd, unsigned int queueSize, bool useThread) ;
|
2015-03-07 19:25:52 +00:00
|
|
|
std::string getAuxLine() { return m_auxLine; };
|
2014-07-20 14:02:14 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-14 16:00:45 +00:00
|
|
|
V4L2DeviceSource(UsageEnvironment& env, V4L2DeviceParameters params, V4l2Capture * device, int outputFd, unsigned int queueSize, bool useThread);
|
2014-07-20 14:02:14 +00:00
|
|
|
virtual ~V4L2DeviceSource();
|
|
|
|
|
2014-08-23 21:57:07 +00:00
|
|
|
protected:
|
2015-01-25 18:31:18 +00:00
|
|
|
static void* threadStub(void* clientData) { return ((V4L2DeviceSource*) clientData)->thread();};
|
|
|
|
void* thread();
|
2014-07-20 14:02:14 +00:00
|
|
|
static void deliverFrameStub(void* clientData) {((V4L2DeviceSource*) clientData)->deliverFrame();};
|
|
|
|
void deliverFrame();
|
2015-04-02 20:14:34 +00:00
|
|
|
static void incomingPacketHandlerStub(void* clientData, int mask) { ((V4L2DeviceSource*) clientData)->incomingPacketHandler(); };
|
|
|
|
void incomingPacketHandler();
|
2015-01-25 18:31:18 +00:00
|
|
|
int getNextFrame();
|
2015-03-01 22:28:17 +00:00
|
|
|
void processFrame(char * frame, int frameSize, const timeval &ref);
|
2014-07-20 14:02:14 +00:00
|
|
|
void queueFrame(char * frame, int frameSize, const timeval &tv);
|
2014-08-16 21:37:40 +00:00
|
|
|
|
2015-03-07 19:25:52 +00:00
|
|
|
// split packet in frames
|
|
|
|
virtual std::list< std::pair<unsigned char*,size_t> > splitFrames(unsigned char* frame, unsigned frameSize);
|
|
|
|
|
2014-08-16 21:37:40 +00:00
|
|
|
// overide FramedSource
|
|
|
|
virtual void doGetNextFrame();
|
|
|
|
virtual void doStopGettingFrames();
|
2014-08-23 21:57:07 +00:00
|
|
|
|
2014-08-16 21:37:40 +00:00
|
|
|
protected:
|
2014-07-20 14:02:14 +00:00
|
|
|
V4L2DeviceParameters m_params;
|
|
|
|
std::list<Frame*> m_captureQueue;
|
2014-08-17 14:42:26 +00:00
|
|
|
Stats m_in;
|
|
|
|
Stats m_out;
|
2014-07-20 14:02:14 +00:00
|
|
|
EventTriggerId m_eventTriggerId;
|
2015-01-17 15:51:47 +00:00
|
|
|
int m_outfd;
|
2014-11-02 15:42:30 +00:00
|
|
|
V4l2Capture * m_device;
|
2014-10-11 19:07:53 +00:00
|
|
|
unsigned int m_queueSize;
|
2015-01-25 18:31:18 +00:00
|
|
|
pthread_t m_thid;
|
2015-03-30 20:09:24 +00:00
|
|
|
pthread_mutex_t m_mutex;
|
2015-03-07 19:25:52 +00:00
|
|
|
std::string m_auxLine;
|
2014-07-20 14:02:14 +00:00
|
|
|
};
|
|
|
|
|
2014-10-11 19:07:53 +00:00
|
|
|
#endif
|