~ubuntu-branches/ubuntu/vivid/ekiga/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/engine/videooutput/skel/videooutput-core.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kilian Krause
  • Date: 2011-07-17 00:24:50 UTC
  • mfrom: (5.1.5 upstream) (7.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110717002450-ytg3wsrc1ptd3153
Tags: 3.3.1-1
* New upstream release.
 - Required libpt-dev 2.10 and libopal-dev 3.10
* Fix debian/watch to catch new version
* Remove libnotify0.7.patch - included upstream
* Add libboost-dev and libboost-signals-dev to Build-Depends
* debian/rules: Don't install *.la files for new internal shared libs
* Fix Vcs URIs to point to correct desktop/experimental/ekiga tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/*
3
 
 * Ekiga -- A VoIP and Video-Conferencing application
4
 
 * Copyright (C) 2000-2007 Damien Sandras
5
 
 
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.
13
 
 *
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.
17
 
 *
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.
24
 
 */
25
 
 
26
 
 
27
 
/*
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.
34
 
 *
35
 
 */
36
 
 
37
 
#include <iostream>
38
 
#include <sstream>
39
 
 
40
 
#include "config.h"
41
 
 
42
 
#include "videooutput-core.h"
43
 
#include "videooutput-manager.h"
44
 
 
45
 
#include <math.h>
46
 
 
47
 
using namespace Ekiga;
48
 
 
49
 
VideoOutputCore::VideoOutputCore ()
50
 
{
51
 
  PWaitAndSignal m(core_mutex);
52
 
 
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;
59
 
}
60
 
 
61
 
VideoOutputCore::~VideoOutputCore ()
62
 
{
63
 
  PWaitAndSignal m(core_mutex);
64
 
 
65
 
  if (videooutput_core_conf_bridge)
66
 
    delete videooutput_core_conf_bridge;
67
 
 
68
 
  for (std::set<VideoOutputManager *>::iterator iter = managers.begin ();
69
 
       iter != managers.end ();
70
 
       iter++)
71
 
    delete (*iter);
72
 
 
73
 
  managers.clear();
74
 
}
75
 
 
76
 
void VideoOutputCore::setup_conf_bridge ()
77
 
{
78
 
  PWaitAndSignal m(core_mutex);
79
 
 
80
 
  videooutput_core_conf_bridge = new VideoOutputCoreConfBridge (*this);
81
 
}
82
 
 
83
 
void VideoOutputCore::add_manager (VideoOutputManager &manager)
84
 
{
85
 
  PWaitAndSignal m(core_mutex);
86
 
 
87
 
  managers.insert (&manager);
88
 
  manager_added.emit (manager);
89
 
 
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));
95
 
}
96
 
 
97
 
 
98
 
void VideoOutputCore::visit_managers (sigc::slot<bool, VideoOutputManager &> visitor)
99
 
{
100
 
  bool go_on = true;
101
 
 
102
 
  for (std::set<VideoOutputManager *>::iterator iter = managers.begin ();
103
 
       iter != managers.end () && go_on;
104
 
       iter++)
105
 
    go_on = visitor (*(*iter));
106
 
}
107
 
 
108
 
 
109
 
void VideoOutputCore::start ()
110
 
{
111
 
   PWaitAndSignal m(core_mutex);
112
 
 
113
 
   number_times_started++;
114
 
   if (number_times_started > 1)
115
 
     return;
116
 
 
117
 
  g_get_current_time (&last_stats);
118
 
 
119
 
  for (std::set<VideoOutputManager *>::iterator iter = managers.begin ();
120
 
       iter != managers.end ();
121
 
       iter++) {
122
 
    (*iter)->open ();
123
 
  }
124
 
}
125
 
 
126
 
void VideoOutputCore::stop ()
127
 
{
128
 
  PWaitAndSignal m(core_mutex);
129
 
 
130
 
  number_times_started--;
131
 
 
132
 
  if (number_times_started < 0) {
133
 
    number_times_started = 0;
134
 
    return;
135
 
  }
136
 
 
137
 
  if (number_times_started != 0)
138
 
    return;
139
 
    
140
 
  for (std::set<VideoOutputManager *>::iterator iter = managers.begin ();
141
 
       iter != managers.end ();
142
 
       iter++) {
143
 
    (*iter)->close ();
144
 
  }
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;
149
 
}
150
 
 
151
 
void VideoOutputCore::set_frame_data (const char *data,
152
 
                                  unsigned width,
153
 
                                  unsigned height,
154
 
                                  bool local,
155
 
                                  int devices_nbr)
156
 
{
157
 
  core_mutex.Wait ();
158
 
 
159
 
  if (local) {
160
 
    videooutput_stats.tx_frames++;
161
 
    videooutput_stats.tx_width = width;
162
 
    videooutput_stats.tx_height = height;
163
 
  }
164
 
  else {
165
 
    videooutput_stats.rx_frames++;
166
 
    videooutput_stats.rx_width = width;
167
 
    videooutput_stats.rx_height = height;
168
 
  }
169
 
 
170
 
  GTimeVal current_time;
171
 
  g_get_current_time (&current_time);
172
 
 
173
 
  long unsigned milliseconds = ((current_time.tv_sec - last_stats.tv_sec) * 1000) 
174
 
                             + ((current_time.tv_usec - last_stats.tv_usec) / 1000);
175
 
 
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);
182
 
  }
183
 
 
184
 
  core_mutex.Signal ();
185
 
  
186
 
  for (std::set<VideoOutputManager *>::iterator iter = managers.begin ();
187
 
       iter != managers.end ();
188
 
       iter++) {
189
 
    (*iter)->set_frame_data (data,width, height, local, devices_nbr);
190
 
  }
191
 
}
192
 
 
193
 
void VideoOutputCore::set_display_info (const DisplayInfo & _display_info)
194
 
{
195
 
  PWaitAndSignal m(core_mutex);
196
 
 
197
 
  for (std::set<VideoOutputManager *>::iterator iter = managers.begin ();
198
 
       iter != managers.end ();
199
 
       iter++) {
200
 
    (*iter)->set_display_info (_display_info);
201
 
  }
202
 
}
203
 
 
204
 
 
205
 
void VideoOutputCore::on_device_opened (VideoOutputAccel videooutput_accel, VideoOutputMode mode, unsigned zoom, bool both_streams, VideoOutputManager *manager)
206
 
{
207
 
  device_opened.emit (*manager, videooutput_accel, mode, zoom, both_streams);
208
 
}
209
 
 
210
 
void VideoOutputCore::on_device_closed ( VideoOutputManager *manager)
211
 
{
212
 
  device_closed.emit (*manager);
213
 
}
214
 
 
215
 
void VideoOutputCore::on_device_error (VideoOutputErrorCodes error_code, VideoOutputManager *manager)
216
 
{
217
 
  device_error.emit (*manager, error_code);
218
 
}
219
 
 
220
 
void VideoOutputCore::on_fullscreen_mode_changed ( VideoOutputFSToggle toggle, VideoOutputManager *manager)
221
 
{
222
 
  fullscreen_mode_changed.emit (*manager, toggle);
223
 
}
224
 
 
225
 
void VideoOutputCore::on_size_changed ( unsigned width, unsigned height, VideoOutputManager *manager)
226
 
{
227
 
  size_changed.emit (*manager, width, height);
228
 
}
229