mirror of
https://github.com/mpromonet/v4l2rtspserver
synced 2024-11-02 03:40:13 +00:00
extract DeviceInterface in a separate include
This commit is contained in:
parent
8fd18e3c23
commit
deb3e2d7dd
50
inc/DeviceInterface.h
Normal file
50
inc/DeviceInterface.h
Normal file
@ -0,0 +1,50 @@
|
||||
/* ---------------------------------------------------------------------------
|
||||
** 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.
|
||||
**
|
||||
** DeviceInterface.h
|
||||
**
|
||||
** -------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef DEVICE_INTERFACE
|
||||
#define DEVICE_INTERFACE
|
||||
|
||||
|
||||
// ---------------------------------
|
||||
// Device Interface
|
||||
// ---------------------------------
|
||||
class DeviceInterface
|
||||
{
|
||||
public:
|
||||
virtual size_t read(char* buffer, size_t bufferSize) = 0;
|
||||
virtual int getFd() = 0;
|
||||
virtual unsigned long getBufferSize() = 0;
|
||||
virtual int getWidth() = 0;
|
||||
virtual int getHeight() = 0;
|
||||
virtual ~DeviceInterface() {};
|
||||
};
|
||||
|
||||
|
||||
// -----------------------------------------
|
||||
// Device Capture Interface template
|
||||
// -----------------------------------------
|
||||
template<typename T>
|
||||
class DeviceCaptureAccess : public DeviceInterface
|
||||
{
|
||||
public:
|
||||
DeviceCaptureAccess(T* device) : m_device(device) {};
|
||||
virtual ~DeviceCaptureAccess() { delete m_device; };
|
||||
|
||||
virtual size_t read(char* buffer, size_t bufferSize) { return m_device->read(buffer, bufferSize); }
|
||||
virtual int getFd() { return m_device->getFd(); }
|
||||
virtual unsigned long getBufferSize() { return m_device->getBufferSize(); }
|
||||
virtual int getWidth() { return m_device->getWidth(); }
|
||||
virtual int getHeight() { return m_device->getHeight(); }
|
||||
|
||||
protected:
|
||||
T* m_device;
|
||||
};
|
||||
|
||||
#endif
|
@ -10,8 +10,8 @@
|
||||
** -------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef V4L2_DEVICE_SOURCE
|
||||
#define V4L2_DEVICE_SOURCE
|
||||
#ifndef DEVICE_SOURCE
|
||||
#define DEVICE_SOURCE
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
@ -21,19 +21,7 @@
|
||||
// live555
|
||||
#include <liveMedia.hh>
|
||||
|
||||
// ---------------------------------
|
||||
// V4L2 FramedSource
|
||||
// ---------------------------------
|
||||
class DeviceCapture
|
||||
{
|
||||
public:
|
||||
virtual size_t read(char* buffer, size_t bufferSize) = 0;
|
||||
virtual int getFd() = 0;
|
||||
virtual unsigned long getBufferSize() = 0;
|
||||
virtual int getWidth() = 0;
|
||||
virtual int getHeight() = 0;
|
||||
virtual ~DeviceCapture() {};
|
||||
};
|
||||
#include "DeviceInterface.h"
|
||||
|
||||
class V4L2DeviceSource: public FramedSource
|
||||
{
|
||||
@ -72,13 +60,13 @@ class V4L2DeviceSource: public FramedSource
|
||||
};
|
||||
|
||||
public:
|
||||
static V4L2DeviceSource* createNew(UsageEnvironment& env, DeviceCapture * device, int outputFd, unsigned int queueSize, bool useThread) ;
|
||||
static V4L2DeviceSource* createNew(UsageEnvironment& env, DeviceInterface * device, int outputFd, unsigned int queueSize, bool useThread) ;
|
||||
std::string getAuxLine() { return m_auxLine; };
|
||||
int getWidth() { return m_device->getWidth(); };
|
||||
int getHeight() { return m_device->getHeight(); };
|
||||
|
||||
protected:
|
||||
V4L2DeviceSource(UsageEnvironment& env, DeviceCapture * device, int outputFd, unsigned int queueSize, bool useThread);
|
||||
V4L2DeviceSource(UsageEnvironment& env, DeviceInterface * device, int outputFd, unsigned int queueSize, bool useThread);
|
||||
virtual ~V4L2DeviceSource();
|
||||
|
||||
protected:
|
||||
@ -105,7 +93,7 @@ class V4L2DeviceSource: public FramedSource
|
||||
Stats m_out;
|
||||
EventTriggerId m_eventTriggerId;
|
||||
int m_outfd;
|
||||
DeviceCapture * m_device;
|
||||
DeviceInterface * m_device;
|
||||
unsigned int m_queueSize;
|
||||
pthread_t m_thid;
|
||||
pthread_mutex_t m_mutex;
|
@ -14,7 +14,7 @@
|
||||
#define H264_V4L2_DEVICE_SOURCE
|
||||
|
||||
// project
|
||||
#include "V4l2DeviceSource.h"
|
||||
#include "DeviceSource.h"
|
||||
|
||||
// ---------------------------------
|
||||
// H264 V4L2 FramedSource
|
||||
@ -24,10 +24,10 @@ const char H264shortmarker[] = {0,0,1};
|
||||
class H264_V4L2DeviceSource : public V4L2DeviceSource
|
||||
{
|
||||
public:
|
||||
static H264_V4L2DeviceSource* createNew(UsageEnvironment& env, DeviceCapture * device, int outputFd, unsigned int queueSize, bool useThread, bool repeatConfig, bool keepMarker) ;
|
||||
static H264_V4L2DeviceSource* createNew(UsageEnvironment& env, DeviceInterface * device, int outputFd, unsigned int queueSize, bool useThread, bool repeatConfig, bool keepMarker) ;
|
||||
|
||||
protected:
|
||||
H264_V4L2DeviceSource(UsageEnvironment& env, DeviceCapture * device, int outputFd, unsigned int queueSize, bool useThread, bool repeatConfig, bool keepMarker);
|
||||
H264_V4L2DeviceSource(UsageEnvironment& env, DeviceInterface * device, int outputFd, unsigned int queueSize, bool useThread, bool repeatConfig, bool keepMarker);
|
||||
virtual ~H264_V4L2DeviceSource();
|
||||
|
||||
unsigned char* extractFrame(unsigned char* frame, size_t& size, size_t& outsize);
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
// project
|
||||
#include "logger.h"
|
||||
#include "V4l2DeviceSource.h"
|
||||
#include "DeviceSource.h"
|
||||
|
||||
// ---------------------------------
|
||||
// V4L2 FramedSource Stats
|
||||
@ -37,7 +37,7 @@ int V4L2DeviceSource::Stats::notify(int tv_sec, int framesize)
|
||||
// ---------------------------------
|
||||
// V4L2 FramedSource
|
||||
// ---------------------------------
|
||||
V4L2DeviceSource* V4L2DeviceSource::createNew(UsageEnvironment& env, DeviceCapture * device, int outputFd, unsigned int queueSize, bool useThread)
|
||||
V4L2DeviceSource* V4L2DeviceSource::createNew(UsageEnvironment& env, DeviceInterface * device, int outputFd, unsigned int queueSize, bool useThread)
|
||||
{
|
||||
V4L2DeviceSource* source = NULL;
|
||||
if (device)
|
||||
@ -48,7 +48,7 @@ V4L2DeviceSource* V4L2DeviceSource::createNew(UsageEnvironment& env, DeviceCaptu
|
||||
}
|
||||
|
||||
// Constructor
|
||||
V4L2DeviceSource::V4L2DeviceSource(UsageEnvironment& env, DeviceCapture * device, int outputFd, unsigned int queueSize, bool useThread)
|
||||
V4L2DeviceSource::V4L2DeviceSource(UsageEnvironment& env, DeviceInterface * device, int outputFd, unsigned int queueSize, bool useThread)
|
||||
: FramedSource(env),
|
||||
m_in("in"),
|
||||
m_out("out") ,
|
@ -21,7 +21,7 @@
|
||||
// ---------------------------------
|
||||
// H264 V4L2 FramedSource
|
||||
// ---------------------------------
|
||||
H264_V4L2DeviceSource* H264_V4L2DeviceSource::createNew(UsageEnvironment& env, DeviceCapture * device, int outputFd, unsigned int queueSize, bool useThread, bool repeatConfig, bool keepMarker)
|
||||
H264_V4L2DeviceSource* H264_V4L2DeviceSource::createNew(UsageEnvironment& env, DeviceInterface * device, int outputFd, unsigned int queueSize, bool useThread, bool repeatConfig, bool keepMarker)
|
||||
{
|
||||
H264_V4L2DeviceSource* source = NULL;
|
||||
if (device)
|
||||
@ -32,7 +32,7 @@ H264_V4L2DeviceSource* H264_V4L2DeviceSource::createNew(UsageEnvironment& env, D
|
||||
}
|
||||
|
||||
// Constructor
|
||||
H264_V4L2DeviceSource::H264_V4L2DeviceSource(UsageEnvironment& env, DeviceCapture * device, int outputFd, unsigned int queueSize, bool useThread, bool repeatConfig, bool keepMarker)
|
||||
H264_V4L2DeviceSource::H264_V4L2DeviceSource(UsageEnvironment& env, DeviceInterface * device, int outputFd, unsigned int queueSize, bool useThread, bool repeatConfig, bool keepMarker)
|
||||
: V4L2DeviceSource(env, device, outputFd, queueSize, useThread), m_repeatConfig(repeatConfig), m_keepMarker(keepMarker), m_frameType(0)
|
||||
{
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
// project
|
||||
#include "ServerMediaSubsession.h"
|
||||
#include "MJPEGVideoSource.h"
|
||||
#include "V4l2DeviceSource.h"
|
||||
#include "DeviceSource.h"
|
||||
|
||||
// ---------------------------------
|
||||
// BaseServerMediaSubsession
|
||||
|
22
src/main.cpp
22
src/main.cpp
@ -43,26 +43,6 @@
|
||||
#include "ALSACapture.h"
|
||||
#endif
|
||||
|
||||
// -----------------------------------------
|
||||
// Device Capture Interface template
|
||||
// -----------------------------------------
|
||||
template<typename T>
|
||||
class DeviceCaptureAccess : public DeviceCapture
|
||||
{
|
||||
public:
|
||||
DeviceCaptureAccess(T* device) : m_device(device) {};
|
||||
virtual ~DeviceCaptureAccess() { delete m_device; };
|
||||
|
||||
virtual size_t read(char* buffer, size_t bufferSize) { return m_device->read(buffer, bufferSize); }
|
||||
virtual int getFd() { return m_device->getFd(); }
|
||||
virtual unsigned long getBufferSize() { return m_device->getBufferSize(); }
|
||||
virtual int getWidth() { return m_device->getWidth(); }
|
||||
virtual int getHeight() { return m_device->getHeight(); }
|
||||
|
||||
protected:
|
||||
T* m_device;
|
||||
};
|
||||
|
||||
// -----------------------------------------
|
||||
// signal handler
|
||||
// -----------------------------------------
|
||||
@ -121,7 +101,7 @@ RTSPServer* createRTSPServer(UsageEnvironment& env, unsigned short rtspPort, uns
|
||||
// -----------------------------------------
|
||||
// create FramedSource server
|
||||
// -----------------------------------------
|
||||
FramedSource* createFramedSource(UsageEnvironment* env, int format, DeviceCapture* videoCapture, int outfd, int queueSize, bool useThread, bool repeatConfig, bool muxTS)
|
||||
FramedSource* createFramedSource(UsageEnvironment* env, int format, DeviceInterface* videoCapture, int outfd, int queueSize, bool useThread, bool repeatConfig, bool muxTS)
|
||||
{
|
||||
FramedSource* source = NULL;
|
||||
if (format == V4L2_PIX_FMT_H264)
|
||||
|
Loading…
Reference in New Issue
Block a user