~ubuntu-branches/ubuntu/trusty/rygel/trusty

« back to all changes in this revision

Viewing changes to src/rygel/rygel-mp2ts-transcoder-bin.vala

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2011-12-16 15:21:25 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20111216152125-qgn31dkfmhouhrf0
Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009 Nokia Corporation.
 
3
 *
 
4
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 
5
 *                               <zeeshan.ali@nokia.com>
 
6
 *
 
7
 * This file is part of Rygel.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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.
 
22
 */
 
23
 
 
24
using Gst;
 
25
 
 
26
/**
 
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.
 
29
 */
 
30
internal class Rygel.MP2TSTranscoderBin : Gst.Bin {
 
31
    private const string DECODEBIN = "decodebin2";
 
32
    private const string MUXER = "mpegtsmux";
 
33
 
 
34
    private const string AUDIO_ENC_SINK = "audio-enc-sink-pad";
 
35
    private const string VIDEO_ENC_SINK = "sink";
 
36
 
 
37
    private dynamic Element audio_enc;
 
38
    private dynamic Element video_enc;
 
39
    private dynamic Element muxer;
 
40
 
 
41
    public MP2TSTranscoderBin (MediaItem       item,
 
42
                               Element         src,
 
43
                               MP2TSTranscoder transcoder)
 
44
                               throws Error {
 
45
        dynamic Element decodebin = GstUtils.create_element (DECODEBIN,
 
46
                                                             DECODEBIN);
 
47
        var mp3_transcoder = new MP3Transcoder (MP3Layer.TWO);
 
48
        this.audio_enc = mp3_transcoder.create_encoder (item,
 
49
                                                        null,
 
50
                                                        AUDIO_ENC_SINK);
 
51
        this.video_enc = transcoder.create_encoder (item, null, VIDEO_ENC_SINK);
 
52
        this.muxer = GstUtils.create_element (MUXER, MUXER);
 
53
 
 
54
        this.add_many (src,
 
55
                       decodebin,
 
56
                       this.audio_enc,
 
57
                       this.video_enc,
 
58
                       this.muxer);
 
59
        src.link (decodebin);
 
60
 
 
61
        var src_pad = muxer.get_static_pad ("src");
 
62
        var ghost = new GhostPad (null, src_pad);
 
63
        this.add_pad (ghost);
 
64
 
 
65
        decodebin.pad_added.connect (this.decodebin_pad_added);
 
66
        decodebin.autoplug_continue.connect (this.autoplug_continue);
 
67
    }
 
68
 
 
69
    private bool autoplug_continue (Element decodebin,
 
70
                                    Pad     new_pad,
 
71
                                    Caps    caps) {
 
72
        var muxer_pad = this.muxer.get_compatible_pad (new_pad, null);
 
73
 
 
74
        if (muxer_pad == null) {
 
75
            return true;
 
76
        } else {
 
77
            return new_pad.link (muxer_pad) != PadLinkReturn.OK;
 
78
        }
 
79
    }
 
80
 
 
81
    private void decodebin_pad_added (Element decodebin, Pad new_pad) {
 
82
        Element encoder;
 
83
        Pad enc_pad;
 
84
 
 
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);
 
87
 
 
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;
 
95
        } else {
 
96
            return;
 
97
        }
 
98
 
 
99
        encoder.link (this.muxer);
 
100
 
 
101
        if (new_pad.link (enc_pad) != PadLinkReturn.OK) {
 
102
            var error = new GstError.LINK (_("Failed to link pad %s to %s"),
 
103
                                           new_pad.name,
 
104
                                           enc_pad.name);
 
105
            GstUtils.post_error (this, error);
 
106
        }
 
107
    }
 
108
}