179
180
this.dvbbasebin.set ("program-numbers", new_programs);
181
182
create_channel = true;
183
} else { // existing pipeline and existing channel
184
ChannelElements c_element;
185
lock (this.elements_map) {
186
c_element = this.elements_map.get (channel_sid);
190
lock (this.pipeline) {
191
this.pipeline.set_state (State.PAUSED);
192
bin = this.add_sink_bin (sink_element);
195
debug ("Linking %s with %s", tee.get_name (), bin.get_name ());
196
if (!tee.link (bin)) {
197
critical ("Could not link tee and bin");
201
c_element.sinks.add (bin);
202
create_channel = false;
184
} else { // existing pipeline and existing channel
185
ChannelElements c_element;
186
lock (this.elements_map) {
187
c_element = this.elements_map.get (channel_sid);
191
bin = this.add_sink_bin (sink_element);
193
debug ("Linking %s with %s", tee.get_name (), bin.get_name ());
194
if (!tee.link (bin)) {
195
critical ("Could not link tee and bin");
199
c_element.sinks.add (bin);
201
create_channel = false;
278
284
public bool remove_channel (Channel channel, Gst.Element sink) {
279
285
uint channel_sid = channel.Sid;
281
287
if (!this.active_channels.contains (channel)) {
282
288
critical ("Could not find channel with SID %u", channel_sid);
286
// Check if that's the only channel in use
287
if (this.active_channels.size > 1) {
288
string channel_sid_string = channel_sid.to_string ();
290
lock (this.pipeline) {
292
lock (this.elements_map) {
293
ChannelElements celements = this.elements_map.get (channel_sid);
294
if (celements.sinks.size == 1) {
295
// this is the last sink
296
// (no one watches this channel anymore)
297
this.elements_map.remove (channel_sid);
300
// we still have sinks left
301
// (others are still watching this channel)
302
celements.sinks.remove (sink);
303
stop_channel = false;
292
ChannelElements celements;
294
lock (this.elements_map) {
295
celements = this.elements_map.get (channel_sid);
296
/* check if this is the last sink
297
* (no one watches this channel anymore)
298
* or if we still have sinks left
299
* (others are still watching this channel)
301
stop_channel = (celements.sinks.size == 1);
304
lock (this.pipeline) {
305
// Check if that's the only channel in use
306
if (this.active_channels.size > 1) {
309
string channel_sid_string = channel_sid.to_string ();
309
312
dvbbasebin.get ("program-numbers", out programs);
310
313
string[] programs_arr = programs.split (":");
312
315
// Remove SID of channel from program-numbers
313
SList<string> new_programs_list = new SList<string> ();
316
ArrayList<string> new_programs_list = new ArrayList<string> ();
314
317
for (int i=0; i<programs_arr.length; i++) {
315
string val = programs_arr[i];
316
if (val != channel_sid_string)
317
new_programs_list.prepend (val);
320
StringBuilder new_programs = new StringBuilder (new_programs_list.nth_data (0));
321
for (int i=1; i<new_programs_list.length (); i++) {
322
new_programs.append (":" + new_programs_list.nth_data (i));
318
if (programs_arr[i] != channel_sid_string)
319
new_programs_list.add (programs_arr[i]);
322
StringBuilder new_programs = new StringBuilder (new_programs_list.get (0));
323
for (int i=1; i<new_programs_list.size; i++) {
324
new_programs.append (":" + new_programs_list.get (i));
325
327
debug ("Changing program-numbers from %s to %s", programs,
326
328
new_programs.str);
327
329
this.pipeline.set_state (State.PAUSED);
329
331
dvbbasebin.set ("program-numbers", new_programs.str);
331
333
this.pipeline.set_state (State.PLAYING);
333
334
this.active_channels.remove (channel);
336
337
this.remove_sink_bin (channel_sid, sink);
339
lock (this.elements_map) {
340
ChannelElements celements = this.elements_map.get (channel_sid);
341
if (celements.sinks.size == 1) {
340
/* No one watches the channel anymore */
341
debug ("Removing tee %s from pipeline",
342
celements.tee.get_name ());
343
celements.tee.set_state (State.NULL);
344
((Bin)this.pipeline).remove (celements.tee);
345
lock (this.elements_map) {
346
this.elements_map.remove (channel_sid);
350
} else { /* More than one channel in use */
342
352
// this is the last sink
343
// (no one watches this channel anymore)
353
// (no one watches any channel anymore)
346
356
// we still have sinks left
347
357
// (others are still watching this channel)
348
358
this.remove_sink_bin (channel_sid, sink);
349
celements.sinks.remove (sink);
357
366
private void remove_sink_bin (uint channel_sid, Gst.Element sink) {
367
debug ("Removing sink bin of sink %s (%p) of channel %u",
368
sink.get_name (), sink, channel_sid);
358
370
Gst.Element? sink_bin = this.get_sink_bin (channel_sid, sink);
360
372
if (sink_bin == null) {
361
warning ("Could not find sink bin for channel %u and sink %p",
373
critical ("Could not find sink bin for channel %u and sink %s (%p)",
374
channel_sid, sink.get_name (), sink);
365
debug ("Setting state of queue and sink to NULL");
366
sink_bin.set_state (State.NULL);
378
lock (this.elements_map) {
379
ChannelElements celems = this.elements_map.get (channel_sid);
381
debug ("Setting state of queue and sink %s (%p) to NULL",
382
sink.get_name (), sink);
383
celems.tee.unlink (sink_bin);
384
sink_bin.set_state (State.NULL);
386
if (!celems.sinks.remove (sink_bin)) {
387
critical ("Could not find sink bin %s (%p)",
388
sink_bin.get_name (), sink_bin);
368
392
debug ("Removing queue and sink from pipeline");
369
393
((Bin)this.pipeline).remove (sink_bin);