2
* Copyright (C) 2009 Nokia Corporation.
4
* Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
5
* <zeeshan.ali@nokia.com>
7
* This file is part of Rygel.
9
* Rygel is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* Rygel is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Lesser General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public License
20
* along with this program; if not, write to the Free Software Foundation,
21
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27
* A Gst.Bin derivative that implements transcoding of any type of media (using
28
* decodebin2) to mpeg transport stream containing mpeg 2 video and mp2 audio.
30
internal class Rygel.MP2TSTranscoderBin : Gst.Bin {
31
private const string DECODEBIN = "decodebin2";
32
private const string MUXER = "mpegtsmux";
34
private const string AUDIO_ENC_SINK = "audio-enc-sink-pad";
35
private const string VIDEO_ENC_SINK = "sink";
37
private dynamic Element audio_enc;
38
private dynamic Element video_enc;
39
private dynamic Element muxer;
41
public MP2TSTranscoderBin (MediaItem item,
43
MP2TSTranscoder transcoder)
45
dynamic Element decodebin = GstUtils.create_element (DECODEBIN,
47
var mp3_transcoder = new MP3Transcoder (MP3Layer.TWO);
48
this.audio_enc = mp3_transcoder.create_encoder (item,
51
this.video_enc = transcoder.create_encoder (item, null, VIDEO_ENC_SINK);
52
this.muxer = GstUtils.create_element (MUXER, MUXER);
61
var src_pad = muxer.get_static_pad ("src");
62
var ghost = new GhostPad (null, src_pad);
65
decodebin.pad_added.connect (this.decodebin_pad_added);
66
decodebin.autoplug_continue.connect (this.autoplug_continue);
69
private bool autoplug_continue (Element decodebin,
72
var muxer_pad = this.muxer.get_compatible_pad (new_pad, null);
74
if (muxer_pad == null) {
77
return new_pad.link (muxer_pad) != PadLinkReturn.OK;
81
private void decodebin_pad_added (Element decodebin, Pad new_pad) {
85
var audio_enc_pad = this.audio_enc.get_pad (AUDIO_ENC_SINK);
86
var video_enc_pad = this.video_enc.get_pad (VIDEO_ENC_SINK);
88
// Check which encoder to use
89
if (new_pad.can_link (audio_enc_pad)) {
90
encoder = this.audio_enc;
91
enc_pad = audio_enc_pad;
92
} else if (new_pad.can_link (video_enc_pad)) {
93
encoder = this.video_enc;
94
enc_pad = video_enc_pad;
99
encoder.link (this.muxer);
101
if (new_pad.link (enc_pad) != PadLinkReturn.OK) {
102
var error = new GstError.LINK (_("Failed to link pad %s to %s"),
105
GstUtils.post_error (this, error);