3
* Ekiga -- A VoIP and Video-Conferencing application
4
* Copyright (C) 2000-2008 Damien Sandras
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or (at
9
* your option) any later version. This program is distributed in the hope
10
* that it will be useful, but WITHOUT ANY WARRANTY; without even the
11
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
* See the GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License along
15
* with this program; if not, write to the Free Software Foundation, Inc.,
16
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18
* Ekiga is licensed under the GPL license and as a special exception, you
19
* have permission to link or otherwise combine this program with the
20
* programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
21
* applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
22
* programs, as long as you do follow the requirements of the GNU GPL for all
23
* the rest of the software thus combined.
28
* videoinput-core.h - description
29
* ------------------------------------------
30
* begin : written in 2008 by Matthias Schneider
31
* copyright : (c) 2008 by Matthias Schneider
32
* description : Declaration of the interface of a videoinput core.
33
* A videoinput core manages VideoInputManagers.
37
#ifndef __VIDEOINPUT_CORE_H__
38
#define __VIDEOINPUT_CORE_H__
42
#include "videooutput-core.h"
44
#include "videoinput-gmconf-bridge.h"
45
#include "videoinput-info.h"
47
#include <sigc++/sigc++.h>
51
#include "ptbuildopts.h"
54
#define VIDEO_INPUT_FALLBACK_DEVICE_TYPE "Moving Logo"
55
#define VIDEO_INPUT_FALLBACK_DEVICE_SOURCE "Moving Logo"
56
#define VIDEO_INPUT_FALLBACK_DEVICE_NAME "Moving Logo"
61
* @defgroup videoinput
65
class VideoInputManager;
68
/** Core object for the video input support
69
* The video input core abstracts all functionality related to video input
70
* in a thread safe manner. Typically, most of the functions except start_stream(),
71
* stop_stream(), and get_frame_data() will be called from
72
* a UI thread, while the three mentioned funtions will be used by a video
75
* The video output core abstracts different video input managers, which can
76
* represent different backends like PTLIB, from the application and can
77
* switch the output device transparently for the video streaming thread,
78
* even while capturing is in progress.
80
* If the removal of an video input device is detected by a failed
81
* read or by a message from the HalCore, the video input core will
82
* determine the responsible video input manager and send a signal to the UI,
83
* which can be used to update device lists. Also, if the removed device was the
84
* currently used one, the core falls back to the backup device.
86
* A similar procedure is performed on the addition of a device. In case we fell
87
* back due to a removed device, and the respective device is re-added to the system,
88
* it will be automatically activated.
90
* The video input core can also be used in a preview mode, where it starts a separate
91
* thread (represented by the VideoPreviewManager), which grabs frames from the video
92
* input core and passes them to the video output core. This can be used for displaying
93
* the local camera signal while not being in a call. If the preview is active and them
94
* and the stream is started, the core will automatically determined if the device needs
95
* to be reinitialized (the stream settings may be different from the preview settings
96
* due to the capabilities negotiation). In case preview is set to active and them
97
* the streaming is ended, the core will automatically switch back to preview mode,
98
* also reinitializing the device if preview settings differ from stream settings.
107
* @param _runtime reference to Ekiga runtime.
108
* @param _videooutput_core reference ot the video output core.
110
VideoInputCore (Ekiga::Runtime & _runtime, VideoOutputCore& _videooutput_core);
116
/** Set up gmconf bridge
118
void setup_conf_bridge();
121
/*** Service Implementation ***/
123
/** Returns the name of the service.
124
* @return The service name.
126
const std::string get_name () const
127
{ return "videoinput-core"; }
130
/** Returns the description of the service.
131
* @return The service description.
133
const std::string get_description () const
134
{ return "\tVideoInput Core managing VideoInput Manager objects"; }
136
/** Adds a VideoInputManager to the VideoInputCore service.
137
* @param The manager to be added.
139
void add_manager (VideoInputManager &manager);
141
/** Triggers a callback for all Ekiga::VideoInputManager sources of the
142
* VideoInputCore service.
144
void visit_managers (sigc::slot<bool, VideoInputManager &> visitor);
146
/** This signal is emitted when a Ekiga::VideoInputManager has been
147
* added to the VideoInputCore Service.
149
sigc::signal<void, VideoInputManager &> manager_added;
152
/*** VideoInput Device Management ***/
154
/** Get a list of all devices supported by all managers registered to the core.
155
* @param devices a vector of device names to be filled by the core.
157
void get_devices(std::vector <VideoInputDevice> & devices);
159
/** Set a specific device
160
* This function sets the current video input device. This function can
161
* also be used while in a stream or in preview mode. In that case the old
162
* device is closed and the new device opened automatically.
163
* @param device the new device to be used.
164
* @param channel the new channel to be used.
165
* @param format the new format to be used.
167
void set_device(const VideoInputDevice & device, int channel, VideoInputFormat format);
169
/** Inform the core of an added videoinput device
170
* This function is called by the HalCore when a video device is added.
171
* It determines responsible managers for that specific device and informs the
172
* GUI about the device that was added (via device_added signal).
173
* In case the added device was the desired device and we fell back,
174
* we will reactivate it. MUST be called from main thread.
175
* @param source the device source (e.g. video4linux).
176
* @param device_name the name of the added device.
177
* @param capabilities used for differentiating V4L1 and V4L2.
178
* @param manager the HalManger detected the addition.
180
void add_device (const std::string & source, const std::string & device_name, unsigned capabilities, HalManager* manager);
182
/** Inform the core of a removed videoinput device
183
* This function is called by the HalCore when a video device is removed.
184
* It determines responsible managers for that specific device and informs the
185
* GUI about the device that was removed (via device_removed signal).
186
* In case the removed device was the current device we fall back to the
187
* fallback device. MUST be called from main thread.
188
* @param source the device source (e.g. video4linux).
189
* @param device_name the name of the removed device.
190
* @param capabilities used for differentiating V4L1 and V4L2.
191
* @param manager the HalManger detected the removal.
193
void remove_device (const std::string & source, const std::string & device_name, unsigned capabilities, HalManager* manager);
195
/** Set still image data
196
* In case there is a manager that allows trasmitting a still image,
197
* this function can be used to set the actual image data. All other
198
* managers can safely ignore this function.
199
* @param width the width of the image in pixels.
200
* @param height the height of the image in pixels.
201
* @param data a pointer to the image data in YUV420P format.
203
void set_image_data (unsigned width, unsigned height, const char* data);
206
/*** VideoInput Stream and Preview Management ***/
208
/** Set the preview configuration
209
* This function sets the resolution and framerate for the preview mode. In case
210
* preview is not active (due to active stream or because it is simply off), it will
211
* be applied the next time it is (re)started. In case preview is active,
212
* the new configuration will be applied immediately by closing and reopening the device.
213
* @param width the frame width.
214
* @param height the frame height.
215
* @param fps the frame rate.
217
void set_preview_config (unsigned width, unsigned height, unsigned fps);
219
/** Start the preview mode
220
* Start the preview thread implemented in the PreviewManager.
221
* In case a stream is active, this will not have an effect until the stream is stopped.
223
void start_preview ();
225
/** Stop the preview mode
227
void stop_preview ();
230
/** Set the stream configuration
231
* This function sets the resolution and framerate for the stream mode, which
232
* can be different from the preview configuration due to negotiated capabilities.
233
* The configuration will be applied on the next call of start_stream(), in order
234
* not to confuse simple endpoints that do not support switching of the resolution in
236
* @param width the frame width.
237
* @param height the frame height.
238
* @param fps the frame rate.
240
void set_stream_config (unsigned width, unsigned height, unsigned fps);
242
/** Start the stream mode
243
* In case that the preview mode was active and had a different configuration,
244
* the core will reopen the device automatically.
246
void start_stream ();
248
/** Stop the stream mode
249
* In case preview mode has been started, the core will switch to preview mode.
250
* In that case, and if the preview mode has a different configuration,
251
* the core will reopen the device automatically.
255
/** Get one video frame buffer from the current manager.
256
* This function will block until the buffer is completely filled.
257
* Requires the stream or the preview (when being called from the
258
* VideoPreviewManager) to be started.
259
* In case the device returns an error reading the frame, get_frame_data()
260
* falls back to the fallback device and reads the frame from there. Thus
261
* get_frame_data() always returns a frame.
262
* In case a new brightness, whiteness, etc. has bee set, it will be applied here.
263
* @param data a pointer to the frame buffer that is to be filled. The memory has to be allocated already.
264
* @param width returns the actual width of the frame read.
265
* @param height returns the actual height of the frame read.
267
void get_frame_data (char *data,
272
/** See vidinput-manager.h for the API
274
void set_colour (unsigned colour);
275
void set_brightness (unsigned brightness);
276
void set_whiteness (unsigned whiteness);
277
void set_contrast (unsigned contrast);
280
/*** VideoInput related Signals ***/
282
/** See videoinput-manager.h for the API
284
sigc::signal<void, VideoInputManager &, VideoInputDevice &, VideoInputSettings&> device_opened;
285
sigc::signal<void, VideoInputManager &, VideoInputDevice &> device_closed;
286
sigc::signal<void, VideoInputManager &, VideoInputDevice &, VideoInputErrorCodes> device_error;
288
/** This signal is emitted when a video input has been added to the system.
289
* This signal will be emitted if add_device was called with a device name and
290
* a manager claimed support for this device.
291
* @param device the video input device that was added.
293
sigc::signal<void, VideoInputDevice, bool> device_added;
295
/** This signal is emitted when a video input has been removed from the system.
296
* This signal will be emitted if remove_device was called with a device name and
297
* a manager claimed support for this device.
298
* @param device the video input device that was removed.
300
sigc::signal<void, VideoInputDevice, bool> device_removed;
303
void on_device_opened (VideoInputDevice device,
304
VideoInputSettings settings,
305
VideoInputManager *manager);
306
void on_device_closed (VideoInputDevice device, VideoInputManager *manager);
307
void on_device_error (VideoInputDevice device, VideoInputErrorCodes error_code, VideoInputManager *manager);
309
void internal_set_device(const VideoInputDevice & vidinput_device, int channel, VideoInputFormat format);
310
void internal_set_manager (const VideoInputDevice & vidinput_device, int channel, VideoInputFormat format);
311
void internal_set_fallback ();
313
void internal_open (unsigned width, unsigned height, unsigned fps);
314
void internal_close();
316
void internal_apply_settings();
319
/** VideoPreviewManager thread.
321
* VideoPreviewManager represents a thread that gets frames from the
322
* video input core and passes them to the video output core. This is
323
* used for displaying the preview video. This thread will run only
324
* while preview is active. It is called from the VideoInputCore, which
325
* has the interface to the application for enabling and disabling the preview.
327
class VideoPreviewManager : public PThread
329
PCLASSINFO(VideoPreviewManager, PThread);
333
* @param _videoinput_core reference to the video input core.
334
* @param _videooutput_core reference to the video output core.
336
VideoPreviewManager(VideoInputCore & _videoinput_core, VideoOutputCore & _videooutput_core);
340
~VideoPreviewManager();
342
/** Start the preview thread.
343
* Start the thread represented by the Main() function. Block until the thread is running.
344
* Requires the the current device to be opened.
345
* In case the resolution is changed, the preview manager has to be stopped and restarted.
346
* @param width the frame width in pixels of the preview video.
347
* @param height the frame width in pixels of the preview video.
349
virtual void start(unsigned width, unsigned height);
351
/** Stop the preview thread.
352
* Stop the thread represented by the Main() function. Blocks until the thread has terminated.
363
PSyncPoint thread_paused;
364
PSyncPoint run_thread;
366
VideoInputCore & videoinput_core;
367
VideoOutputCore & videooutput_core;
370
/** Class for storing the device configuration.
372
* This class is used for storing the device configuration when
373
* streaming video or when in preview mode. The device configuration
374
* consists of width, height and framerate. This class can be used to
375
* check whether stream and preview configuration is different and
376
* thus if a device needs to be reopened when switching between stream
379
class VideoDeviceConfig
387
VideoDeviceConfig () {}
388
VideoDeviceConfig (unsigned _width, unsigned _height, unsigned _fps) {
394
friend std::ostream& operator <<(std::ostream & stream, const VideoDeviceConfig & config){
395
stream << config.width << "x" << config.height << "/" << config.fps;
399
VideoDeviceConfig & operator= (const VideoDeviceConfig & rhs)
407
bool operator==( const VideoDeviceConfig & rhs ) const
409
if ( (width == rhs.width) &&
410
(height == rhs.height) &&
417
bool operator!=( const VideoDeviceConfig & rhs ) const
419
return (!(*this==rhs));
425
std::set<VideoInputManager *> managers;
427
Ekiga::Runtime & runtime;
429
VideoDeviceConfig preview_config;
430
VideoDeviceConfig stream_config;
432
VideoInputManager* current_manager;
433
VideoInputDevice desired_device;
434
VideoInputDevice current_device;
435
VideoInputFormat current_format;
437
VideoInputSettings current_settings;
438
VideoInputSettings desired_settings;
441
PMutex settings_mutex;
443
VideoPreviewManager preview_manager;
444
VideoInputCoreConfBridge* videoinput_core_conf_bridge;