1/* ---------------------------------------------------------------------------
2** This software is in the public domain, furnished "as is", without technical
3** support, and with no warranty, express or implied, as to its usefulness for
4** any purpose.
5**
6** V4l2Output.cpp
7**
8** V4L2 wrapper
9**
10** -------------------------------------------------------------------------*/
11
12#include <string.h>
13
14// libv4l2
15#include <linux/videodev2.h>
16
17// project
18#include "logger.h"
19
20#include "V4l2Output.h"
21#include "V4l2MmapDevice.h"
22#include "V4l2ReadWriteDevice.h"
23
24// -----------------------------------------
25// create video output interface
26// -----------------------------------------
27V4l2Output* V4l2Output::create(const V4L2DeviceParameters & param, IoType iotype)
28{
29 V4l2Output* videoOutput = NULL;
30 V4l2Device* videoDevice = NULL;
31 int caps = V4L2_CAP_VIDEO_OUTPUT;
32 switch (iotype)
33 {
34 case IOTYPE_MMAP:
35 videoDevice = new V4l2MmapDevice(param, V4L2_BUF_TYPE_VIDEO_OUTPUT);
36 caps |= V4L2_CAP_STREAMING;
37 break;
38 case IOTYPE_READWRITE:
39 videoDevice = new V4l2ReadWriteDevice(param, V4L2_BUF_TYPE_VIDEO_OUTPUT);
40 caps |= V4L2_CAP_READWRITE;
41 break;
42 }
43
44 if (videoDevice && !videoDevice->init(caps))
45 {
46 delete videoDevice;
47 videoDevice=NULL;
48 }
49
50 if (videoDevice)
51 {
52 videoOutput = new V4l2Output(videoDevice);
53 }
54 return videoOutput;
55}
56
57// -----------------------------------------
58// constructor
59// -----------------------------------------
60V4l2Output::V4l2Output(V4l2Device* device) : V4l2Access(device)
61{
62}
63
64// -----------------------------------------
65// destructor
66// -----------------------------------------
67V4l2Output::~V4l2Output()
68{
69}
70
71// -----------------------------------------
72// check writability
73// -----------------------------------------
74int V4l2Output::isWritable(timeval* tv)
75{
76 int fd = m_device->getFd();
77 fd_set fdset;
78 FD_ZERO(&fdset);
79 FD_SET(fd, &fdset);
80 return select(fd+1, NULL, &fdset, NULL, tv);
81}
82
83// -----------------------------------------
84// write to V4l2Device
85// -----------------------------------------
86size_t V4l2Output::write(char* buffer, size_t bufferSize)
87{
88 return m_device->writeInternal(buffer, bufferSize);
89}
90
91
92bool V4l2Output::startPartialWrite(void)
93{
94 return m_device->startPartialWrite();
95}
96
97size_t V4l2Output::writePartial(char* buffer, size_t bufferSize)
98{
99 return m_device->writePartialInternal(buffer, bufferSize);
100}
101
102bool V4l2Output::endPartialWrite(void)
103{
104 return m_device->endPartialWrite();
105}
106
107