81 lines
1.5 KiB
C++
Executable file
81 lines
1.5 KiB
C++
Executable file
#include "Output.h"
|
|
#include "MmapDevice.h"
|
|
#include "ReadWriteDevice.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
namespace Video
|
|
{
|
|
namespace V4L2
|
|
{
|
|
Output* Output::create(const DeviceParameters& param)
|
|
{
|
|
Output* videoOutput = NULL;
|
|
Device* videoDevice = NULL;
|
|
int caps = V4L2_CAP_VIDEO_OUTPUT;
|
|
switch (param.m_iotype)
|
|
{
|
|
case IOTYPE_MMAP:
|
|
videoDevice = new MmapDevice(param, V4L2_BUF_TYPE_VIDEO_OUTPUT);
|
|
caps |= V4L2_CAP_STREAMING;
|
|
break;
|
|
|
|
case IOTYPE_READWRITE:
|
|
videoDevice = new ReadWriteDevice(param, V4L2_BUF_TYPE_VIDEO_OUTPUT);
|
|
caps |= V4L2_CAP_READWRITE;
|
|
break;
|
|
}
|
|
|
|
if (videoDevice && !videoDevice->init(caps))
|
|
{
|
|
delete videoDevice;
|
|
videoDevice = NULL;
|
|
}
|
|
|
|
if (videoDevice)
|
|
{
|
|
videoOutput = new Output(videoDevice);
|
|
}
|
|
return videoOutput;
|
|
}
|
|
|
|
Output::Output(Device* device): Access(device)
|
|
{
|
|
}
|
|
|
|
Output::~Output()
|
|
{
|
|
}
|
|
|
|
bool Output::isWritable(timeval* tv)
|
|
{
|
|
int fd = m_device->getFd();
|
|
fd_set fdset;
|
|
FD_ZERO(&fdset);
|
|
FD_SET(fd, &fdset);
|
|
return (select(fd + 1, NULL, &fdset, NULL, tv) == 1);
|
|
}
|
|
|
|
size_t Output::write(char* buffer, size_t bufferSize)
|
|
{
|
|
return m_device->writeInternal(buffer, bufferSize);
|
|
}
|
|
|
|
bool Output::startPartialWrite()
|
|
{
|
|
return m_device->startPartialWrite();
|
|
}
|
|
|
|
size_t Output::writePartial(char* buffer, size_t bufferSize)
|
|
{
|
|
return m_device->writePartialInternal(buffer, bufferSize);
|
|
}
|
|
|
|
bool Output::endPartialWrite()
|
|
{
|
|
return m_device->endPartialWrite();
|
|
}
|
|
}
|
|
}
|