3
* Ekiga -- A VoIP and Video-Conferencing application
4
* Copyright (C) 2000-2007 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
* videooutput-core.cpp - description
29
* ------------------------------------------
30
* begin : written in 2007 by Matthias Schneider
31
* copyright : (c) 2007 by Matthias Schneider
32
* description : declaration of the interface of a videooutput core.
33
* A videooutput core manages VideoOutputManagers.
42
#include "videooutput-core.h"
43
#include "videooutput-manager.h"
47
using namespace Ekiga;
49
VideoOutputCore::VideoOutputCore ()
51
PWaitAndSignal m(core_mutex);
53
videooutput_stats.rx_width = videooutput_stats.rx_height = videooutput_stats.rx_fps = 0;
54
videooutput_stats.tx_width = videooutput_stats.tx_height = videooutput_stats.tx_fps = 0;
55
videooutput_stats.rx_frames = 0;
56
videooutput_stats.tx_frames = 0;
57
number_times_started = 0;
58
videooutput_core_conf_bridge = NULL;
61
VideoOutputCore::~VideoOutputCore ()
63
PWaitAndSignal m(core_mutex);
65
if (videooutput_core_conf_bridge)
66
delete videooutput_core_conf_bridge;
68
for (std::set<VideoOutputManager *>::iterator iter = managers.begin ();
69
iter != managers.end ();
76
void VideoOutputCore::setup_conf_bridge ()
78
PWaitAndSignal m(core_mutex);
80
videooutput_core_conf_bridge = new VideoOutputCoreConfBridge (*this);
83
void VideoOutputCore::add_manager (VideoOutputManager &manager)
85
PWaitAndSignal m(core_mutex);
87
managers.insert (&manager);
88
manager_added.emit (manager);
90
manager.device_opened.connect (sigc::bind (sigc::mem_fun (this, &VideoOutputCore::on_device_opened), &manager));
91
manager.device_closed.connect (sigc::bind (sigc::mem_fun (this, &VideoOutputCore::on_device_closed), &manager));
92
manager.device_error.connect (sigc::bind (sigc::mem_fun (this, &VideoOutputCore::on_device_error), &manager));
93
manager.fullscreen_mode_changed.connect (sigc::bind (sigc::mem_fun (this, &VideoOutputCore::on_fullscreen_mode_changed), &manager));
94
manager.size_changed.connect (sigc::bind (sigc::mem_fun (this, &VideoOutputCore::on_size_changed), &manager));
98
void VideoOutputCore::visit_managers (sigc::slot<bool, VideoOutputManager &> visitor)
102
for (std::set<VideoOutputManager *>::iterator iter = managers.begin ();
103
iter != managers.end () && go_on;
105
go_on = visitor (*(*iter));
109
void VideoOutputCore::start ()
111
PWaitAndSignal m(core_mutex);
113
number_times_started++;
114
if (number_times_started > 1)
117
g_get_current_time (&last_stats);
119
for (std::set<VideoOutputManager *>::iterator iter = managers.begin ();
120
iter != managers.end ();
126
void VideoOutputCore::stop ()
128
PWaitAndSignal m(core_mutex);
130
number_times_started--;
132
if (number_times_started < 0) {
133
number_times_started = 0;
137
if (number_times_started != 0)
140
for (std::set<VideoOutputManager *>::iterator iter = managers.begin ();
141
iter != managers.end ();
145
videooutput_stats.rx_width = videooutput_stats.rx_height = videooutput_stats.rx_fps = 0;
146
videooutput_stats.tx_width = videooutput_stats.tx_height = videooutput_stats.tx_fps = 0;
147
videooutput_stats.rx_frames = 0;
148
videooutput_stats.tx_frames = 0;
151
void VideoOutputCore::set_frame_data (const char *data,
160
videooutput_stats.tx_frames++;
161
videooutput_stats.tx_width = width;
162
videooutput_stats.tx_height = height;
165
videooutput_stats.rx_frames++;
166
videooutput_stats.rx_width = width;
167
videooutput_stats.rx_height = height;
170
GTimeVal current_time;
171
g_get_current_time (¤t_time);
173
long unsigned milliseconds = ((current_time.tv_sec - last_stats.tv_sec) * 1000)
174
+ ((current_time.tv_usec - last_stats.tv_usec) / 1000);
176
if (milliseconds > 2000) {
177
videooutput_stats.tx_fps = round ((videooutput_stats.tx_frames * 1000) / milliseconds);
178
videooutput_stats.rx_fps = round ((videooutput_stats.rx_frames * 1000) / milliseconds);
179
videooutput_stats.rx_frames = 0;
180
videooutput_stats.tx_frames = 0;
181
g_get_current_time (&last_stats);
184
core_mutex.Signal ();
186
for (std::set<VideoOutputManager *>::iterator iter = managers.begin ();
187
iter != managers.end ();
189
(*iter)->set_frame_data (data,width, height, local, devices_nbr);
193
void VideoOutputCore::set_display_info (const DisplayInfo & _display_info)
195
PWaitAndSignal m(core_mutex);
197
for (std::set<VideoOutputManager *>::iterator iter = managers.begin ();
198
iter != managers.end ();
200
(*iter)->set_display_info (_display_info);
205
void VideoOutputCore::on_device_opened (VideoOutputAccel videooutput_accel, VideoOutputMode mode, unsigned zoom, bool both_streams, VideoOutputManager *manager)
207
device_opened.emit (*manager, videooutput_accel, mode, zoom, both_streams);
210
void VideoOutputCore::on_device_closed ( VideoOutputManager *manager)
212
device_closed.emit (*manager);
215
void VideoOutputCore::on_device_error (VideoOutputErrorCodes error_code, VideoOutputManager *manager)
217
device_error.emit (*manager, error_code);
220
void VideoOutputCore::on_fullscreen_mode_changed ( VideoOutputFSToggle toggle, VideoOutputManager *manager)
222
fullscreen_mode_changed.emit (*manager, toggle);
225
void VideoOutputCore::on_size_changed ( unsigned width, unsigned height, VideoOutputManager *manager)
227
size_changed.emit (*manager, width, height);