~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to daemon/src/video/video_camera.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
 
3
 *  Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 *
 
19
 *  Additional permission under GNU GPL version 3 section 7:
 
20
 *
 
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.
 
29
 */
 
30
 
 
31
#include "video_camera.h"
 
32
#include "video_decoder.h"
 
33
#include "check.h"
 
34
 
 
35
#include "manager.h"
 
36
#include "client/video_controls.h"
 
37
 
 
38
#include <map>
 
39
#include <string>
 
40
 
 
41
#define SINK_ID "local"
 
42
 
 
43
namespace sfl_video {
 
44
 
 
45
using std::string;
 
46
 
 
47
VideoCamera::VideoCamera(const std::map<std::string, std::string> &args) :
 
48
    VideoGenerator::VideoGenerator()
 
49
    , id_(SINK_ID)
 
50
    , args_(args)
 
51
    , decoder_(0)
 
52
    , sink_()
 
53
    , sinkWidth_(0)
 
54
    , sinkHeight_(0)
 
55
{ start(); }
 
56
 
 
57
VideoCamera::~VideoCamera()
 
58
{
 
59
    stop();
 
60
    join();
 
61
}
 
62
 
 
63
bool VideoCamera::setup()
 
64
{
 
65
    // it's a v4l device if starting with /dev/video
 
66
    static const char * const V4L_PATH = "/dev/video";
 
67
 
 
68
    string format_str;
 
69
    string input = args_["input"];
 
70
 
 
71
    decoder_ = new VideoDecoder();
 
72
 
 
73
    if (args_["input"].find(V4L_PATH) != std::string::npos) {
 
74
        DEBUG("Using v4l2 format");
 
75
        format_str = "video4linux2";
 
76
    }
 
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());
 
83
 
 
84
    decoder_->setInterruptCallback(interruptCb, this);
 
85
 
 
86
    EXIT_IF_FAIL(decoder_->openInput(input, format_str) >= 0,
 
87
                 "Could not open input \"%s\"", input.c_str());
 
88
 
 
89
    /* Data available, finish the decoding */
 
90
    EXIT_IF_FAIL(!decoder_->setupFromVideoData(),
 
91
                 "decoder IO startup failed");
 
92
 
 
93
    /* Preview frame size? (defaults from decoder) */
 
94
    if (!args_["width"].empty())
 
95
        sinkWidth_ = atoi(args_["width"].c_str());
 
96
    else
 
97
        sinkWidth_ = decoder_->getWidth();
 
98
    if (!args_["height"].empty())
 
99
        sinkHeight_ = atoi(args_["height"].c_str());
 
100
    else
 
101
        sinkHeight_ = decoder_->getHeight();
 
102
 
 
103
    /* Sink setup */
 
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_);
 
109
    }
 
110
 
 
111
    return true;
 
112
}
 
113
 
 
114
void VideoCamera::process()
 
115
{ captureFrame(); }
 
116
 
 
117
void VideoCamera::cleanup()
 
118
{
 
119
    if (detach(&sink_)) {
 
120
        Manager::instance().getVideoControls()->stoppedDecoding(id_, sink_.openedName());
 
121
        sink_.stop();
 
122
    }
 
123
 
 
124
    delete decoder_;
 
125
}
 
126
 
 
127
int VideoCamera::interruptCb(void *data)
 
128
{
 
129
    VideoCamera *context = static_cast<VideoCamera*>(data);
 
130
    return not context->isRunning();
 
131
}
 
132
 
 
133
bool VideoCamera::captureFrame()
 
134
{
 
135
    VideoFrame& frame = getNewFrame();
 
136
    int ret = decoder_->decode(frame);
 
137
 
 
138
    if (ret <= 0) {
 
139
        if (ret < 0)
 
140
            stop();
 
141
        return false;
 
142
    }
 
143
 
 
144
    frame.mirror();
 
145
    publishFrame();
 
146
    return true;
 
147
}
 
148
 
 
149
int VideoCamera::getWidth() const
 
150
{ return decoder_->getWidth(); }
 
151
 
 
152
int VideoCamera::getHeight() const
 
153
{ return decoder_->getHeight(); }
 
154
 
 
155
int VideoCamera::getPixelFormat() const
 
156
{ return decoder_->getPixelFormat(); }
 
157
 
 
158
 
 
159
 
 
160
} // end namespace sfl_video