整理代码

This commit is contained in:
蒲爽 2026-09-28 21:33:04 +08:00
commit c7b4e178ec
364 changed files with 59691 additions and 0 deletions

63
video/v4l2/Capture.cpp Executable file
View file

@ -0,0 +1,63 @@
#include <linux/videodev2.h>
#include "Capture.h"
#include "MmapDevice.h"
#include "ReadWriteDevice.h"
namespace Video
{
namespace V4L2
{
Capture* Capture::create(const DeviceParameters& param)
{
Capture* videoCapture = NULL;
Device* videoDevice = NULL;
int caps = V4L2_CAP_VIDEO_CAPTURE;
switch (param.m_iotype)
{
case IOTYPE_MMAP:
videoDevice = new MmapDevice(param, V4L2_BUF_TYPE_VIDEO_CAPTURE);
caps |= V4L2_CAP_STREAMING;
break;
case IOTYPE_READWRITE:
videoDevice = new ReadWriteDevice(param, V4L2_BUF_TYPE_VIDEO_CAPTURE);
caps |= V4L2_CAP_READWRITE;
break;
}
if (videoDevice && !videoDevice->init(caps))
{
delete videoDevice;
videoDevice = NULL;
}
if (videoDevice)
{
videoCapture = new Capture(videoDevice);
}
return videoCapture;
}
Capture::Capture(Device* device): Access(device)
{
}
Capture::~Capture()
{
}
bool Capture::isReadable(timeval* tv)
{
int fd = m_device->getFd();
fd_set fdset;
FD_ZERO(&fdset);
FD_SET(fd, &fdset);
return (select(fd + 1, &fdset, NULL, NULL, tv) == 1);
}
size_t Capture::read(char* buffer, size_t bufferSize)
{
return m_device->readInternal(buffer, bufferSize);
}
}
}