v4l2rtspserver/inc/DeviceSourceFactory.h

54 lines
2.3 KiB
C
Raw Normal View History

2020-05-30 09:21: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.
**
** DeviceSourceFactory.h
**
** V4L2 live555 source
**
** -------------------------------------------------------------------------*/
#pragma once
#include <linux/videodev2.h>
#include "V4L2DeviceSource.h"
2020-05-30 09:21:14 +00:00
#include "H264_V4l2DeviceSource.h"
2022-10-23 09:00:00 +00:00
#include "H265_V4l2DeviceSource.h"
2020-05-30 09:21:14 +00:00
class DeviceSourceFactory {
public:
2021-11-07 16:56:36 +00:00
static FramedSource* createFramedSource(UsageEnvironment* env, int format, DeviceInterface* devCapture, int queueSize = 5, V4L2DeviceSource::CaptureMode captureMode = V4L2DeviceSource::CAPTURE_INTERNAL_THREAD, int outfd = -1, bool repeatConfig = true) {
2020-05-30 09:21:14 +00:00
FramedSource* source = NULL;
if (format == V4L2_PIX_FMT_H264)
{
2021-11-07 16:56:36 +00:00
source = H264_V4L2DeviceSource::createNew(*env, devCapture, outfd, queueSize, captureMode, repeatConfig, false);
2020-05-30 09:21:14 +00:00
}
else if (format == V4L2_PIX_FMT_HEVC)
{
2021-11-07 16:56:36 +00:00
source = H265_V4L2DeviceSource::createNew(*env, devCapture, outfd, queueSize, captureMode, repeatConfig, false);
2020-05-30 09:21:14 +00:00
}
else
{
2021-11-07 16:56:36 +00:00
source = V4L2DeviceSource::createNew(*env, devCapture, outfd, queueSize, captureMode);
2020-05-30 09:21:14 +00:00
}
return source;
}
2021-11-07 16:56:36 +00:00
static StreamReplicator* createStreamReplicator(UsageEnvironment* env, int format, DeviceInterface* devCapture, int queueSize = 5, V4L2DeviceSource::CaptureMode captureMode = V4L2DeviceSource::CAPTURE_INTERNAL_THREAD, int outfd = -1, bool repeatConfig = true) {
2020-05-30 09:21:14 +00:00
StreamReplicator* replicator = NULL;
2021-11-07 16:56:36 +00:00
FramedSource* framedSource = DeviceSourceFactory::createFramedSource(env, format, devCapture, queueSize, captureMode, outfd, repeatConfig);
2020-05-30 09:21:14 +00:00
if (framedSource != NULL)
{
// extend buffer size if needed
if (devCapture->getBufferSize() > OutPacketBuffer::maxSize)
{
OutPacketBuffer::maxSize = devCapture->getBufferSize();
}
replicator = StreamReplicator::createNew(*env, framedSource, false);
}
return replicator;
}
};