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

« back to all changes in this revision

Viewing changes to src/rygel/rygel-mp3-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
internal enum Rygel.MP3Layer {
 
27
    TWO = 1,
 
28
    THREE = 2
 
29
}
 
30
 
 
31
/**
 
32
 * A Gst.Bin derivative that implements transcoding of any type of media (using
 
33
 * decodebin2) to mpeg 1 layer 2 and 3 format.
 
34
 */
 
35
internal class Rygel.MP3TranscoderBin : Gst.Bin {
 
36
    private const string DECODEBIN = "decodebin2";
 
37
 
 
38
    private const string AUDIO_SRC_PAD = "audio-src-pad";
 
39
    private const string AUDIO_SINK_PAD = "audio-sink-pad";
 
40
 
 
41
    private dynamic Element audio_enc;
 
42
 
 
43
    public MP3TranscoderBin (MediaItem     item,
 
44
                             Element       src,
 
45
                             MP3Transcoder transcoder) throws Error {
 
46
        Element decodebin = GstUtils.create_element (DECODEBIN, DECODEBIN);
 
47
 
 
48
        this.audio_enc = transcoder.create_encoder (item,
 
49
                                                    AUDIO_SRC_PAD,
 
50
                                                    AUDIO_SINK_PAD);
 
51
 
 
52
        this.add_many (src, decodebin, this.audio_enc);
 
53
        src.link (decodebin);
 
54
 
 
55
        var src_pad = this.audio_enc.get_static_pad (AUDIO_SRC_PAD);
 
56
        var ghost = new GhostPad (null, src_pad);
 
57
        this.add_pad (ghost);
 
58
 
 
59
        decodebin.pad_added.connect (this.decodebin_pad_added);
 
60
    }
 
61
 
 
62
    private void decodebin_pad_added (Element decodebin, Pad new_pad) {
 
63
        Pad enc_pad = this.audio_enc.get_pad (AUDIO_SINK_PAD);
 
64
        if (!new_pad.can_link (enc_pad)) {
 
65
            return;
 
66
        }
 
67
 
 
68
        if (new_pad.link (enc_pad) != PadLinkReturn.OK) {
 
69
            var error = new GstError.LINK (_("Failed to link pad %s to %s"),
 
70
                                           new_pad.name,
 
71
                                           enc_pad.name);
 
72
            GstUtils.post_error (this, error);
 
73
 
 
74
            return;
 
75
        }
 
76
    }
 
77
}