2
* Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3
* Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
* Additional permission under GNU GPL version 3 section 7:
21
* If you modify this program, or any covered work, by linking or
22
* combining it with the OpenSSL project's OpenSSL library (or a
23
* modified version of that library), containing parts covered by the
24
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
25
* grants you additional permission to convey the resulting work.
26
* Corresponding Source for a non-source form of such a combination
27
* shall include the source code for the parts of OpenSSL used as well
28
* as that of the covered work.
31
#include "video_camera.h"
32
#include "video_decoder.h"
36
#include "client/video_controls.h"
41
#define SINK_ID "local"
47
VideoCamera::VideoCamera(const std::map<std::string, std::string> &args) :
48
VideoGenerator::VideoGenerator()
57
VideoCamera::~VideoCamera()
63
bool VideoCamera::setup()
65
// it's a v4l device if starting with /dev/video
66
static const char * const V4L_PATH = "/dev/video";
69
string input = args_["input"];
71
decoder_ = new VideoDecoder();
73
if (args_["input"].find(V4L_PATH) != std::string::npos) {
74
DEBUG("Using v4l2 format");
75
format_str = "video4linux2";
77
if (!args_["framerate"].empty())
78
decoder_->setOption("framerate", args_["framerate"].c_str());
79
if (!args_["video_size"].empty())
80
decoder_->setOption("video_size", args_["video_size"].c_str());
81
if (!args_["channel"].empty())
82
decoder_->setOption("channel", args_["channel"].c_str());
84
decoder_->setInterruptCallback(interruptCb, this);
86
EXIT_IF_FAIL(decoder_->openInput(input, format_str) >= 0,
87
"Could not open input \"%s\"", input.c_str());
89
/* Data available, finish the decoding */
90
EXIT_IF_FAIL(!decoder_->setupFromVideoData(),
91
"decoder IO startup failed");
93
/* Preview frame size? (defaults from decoder) */
94
if (!args_["width"].empty())
95
sinkWidth_ = atoi(args_["width"].c_str());
97
sinkWidth_ = decoder_->getWidth();
98
if (!args_["height"].empty())
99
sinkHeight_ = atoi(args_["height"].c_str());
101
sinkHeight_ = decoder_->getHeight();
104
EXIT_IF_FAIL(sink_.start(), "Cannot start shared memory sink");
105
if (attach(&sink_)) {
106
Manager::instance().getVideoControls()->startedDecoding(id_, sink_.openedName(), sinkWidth_, sinkHeight_);
107
DEBUG("LOCAL: shm sink <%s> started: size = %dx%d",
108
sink_.openedName().c_str(), sinkWidth_, sinkHeight_);
114
void VideoCamera::process()
117
void VideoCamera::cleanup()
119
if (detach(&sink_)) {
120
Manager::instance().getVideoControls()->stoppedDecoding(id_, sink_.openedName());
127
int VideoCamera::interruptCb(void *data)
129
VideoCamera *context = static_cast<VideoCamera*>(data);
130
return not context->isRunning();
133
bool VideoCamera::captureFrame()
135
VideoFrame& frame = getNewFrame();
136
int ret = decoder_->decode(frame);
149
int VideoCamera::getWidth() const
150
{ return decoder_->getWidth(); }
152
int VideoCamera::getHeight() const
153
{ return decoder_->getHeight(); }
155
int VideoCamera::getPixelFormat() const
156
{ return decoder_->getPixelFormat(); }
160
} // end namespace sfl_video