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

« back to all changes in this revision

Viewing changes to src/rygel/rygel-transcoder.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:
27
27
 
28
28
/**
29
29
 * The base Transcoder class. Each implementation derives from it and must
30
 
 * implement get_distance and get_encoding_profile methods.
 
30
 * at least implement create_source method.
31
31
 */
32
32
internal abstract class Rygel.Transcoder : GLib.Object {
33
33
    public string mime_type { get; protected set; }
34
34
    public string dlna_profile { get; protected set; }
35
 
    public Gst.Caps decoder_caps;
36
 
 
37
 
    private const string DECODE_BIN = "decodebin2";
38
 
    private const string ENCODE_BIN = "encodebin";
39
35
 
40
36
    // Primary UPnP item class that this transcoder is meant for, doesn't
41
37
    // necessarily mean it cant be used for other classes.
57
53
     *
58
54
     * @return      the new transcoding source
59
55
     */
60
 
    public virtual Element create_source (MediaItem item,
61
 
                                          Element   src) throws Error {
62
 
        dynamic Element decoder = GstUtils.create_element (DECODE_BIN,
63
 
                                                           DECODE_BIN);
64
 
        dynamic Element encoder = GstUtils.create_element (ENCODE_BIN,
65
 
                                                           ENCODE_BIN);
66
 
 
67
 
        encoder.profile = this.get_encoding_profile ();
68
 
 
69
 
        var bin = new Bin ("transcoder-source");
70
 
        bin.add_many (src, decoder, encoder);
71
 
 
72
 
        src.link (decoder);
73
 
 
74
 
        decoder.pad_added.connect (this.on_decoder_pad_added);
75
 
        decoder.autoplug_continue.connect (this.on_autoplug_continue);
76
 
 
77
 
        var pad = encoder.get_static_pad ("src");
78
 
        var ghost = new GhostPad (null, pad);
79
 
        bin.add_pad (ghost);
80
 
 
81
 
        return bin;
82
 
    }
 
56
    public abstract Element create_source (MediaItem item,
 
57
                                           Element   src) throws Error;
83
58
 
84
59
    public virtual DIDLLiteResource? add_resource (DIDLLiteItem     didl_item,
85
60
                                                   MediaItem        item,
131
106
     */
132
107
    public abstract uint get_distance (MediaItem item);
133
108
 
134
 
    /**
135
 
     * Gets the Gst.EncodingProfile for this transcoder.
136
 
     *
137
 
     * @return      the Gst.EncodingProfile for this transcoder.
138
 
     */
139
 
    protected abstract EncodingProfile get_encoding_profile ();
140
 
 
141
109
    protected bool mime_type_is_a (string mime_type1, string mime_type2) {
142
110
        string content_type1 = ContentType.get_mime_type (mime_type1);
143
111
        string content_type2 = ContentType.get_mime_type (mime_type2);
144
112
 
145
113
        return ContentType.is_a (content_type1, content_type2);
146
114
    }
147
 
 
148
 
    private bool on_autoplug_continue (Element decodebin,
149
 
                                       Pad     new_pad,
150
 
                                       Caps    caps) {
151
 
        this.decoder_caps = caps;
152
 
        return !this.connect_decoder_pad (decodebin, new_pad);
153
 
    }
154
 
 
155
 
    private void on_decoder_pad_added (Element decodebin, Pad new_pad) {
156
 
        this.connect_decoder_pad (decodebin, new_pad);
157
 
    }
158
 
 
159
 
    private bool connect_decoder_pad (Element decodebin, Pad new_pad) {
160
 
        var bin = decodebin.get_parent () as Bin;
161
 
        assert (bin != null);
162
 
 
163
 
        var encoder = bin.get_by_name (ENCODE_BIN);
164
 
        assert (encoder != null);
165
 
 
166
 
        Gst.Pad encoder_pad = null;
167
 
        encoder_pad = encoder.get_compatible_pad (new_pad, null);
168
 
        if (encoder_pad == null) {
169
 
            Signal.emit_by_name (encoder,
170
 
                                 "request-pad",
171
 
                                 new_pad.get_caps (),
172
 
                                 out encoder_pad);
173
 
        }
174
 
 
175
 
        if (encoder_pad == null) {
176
 
            debug ("No compatible encodebin pad found for pad '%s', ignoring..",
177
 
                   new_pad.name);
178
 
 
179
 
            return false;
180
 
        } else {
181
 
            debug ("pad '%s' with caps '%s' is compatible with '%s'",
182
 
                   new_pad.name,
183
 
                   this.decoder_caps.to_string (),
184
 
                   encoder_pad.name);
185
 
        }
186
 
 
187
 
        var pad_link_ok = (new_pad.link (encoder_pad) == PadLinkReturn.OK);
188
 
        if (!pad_link_ok) {
189
 
            warning ("Failed to link pad '%s' to '%s'",
190
 
                     new_pad.name,
191
 
                     encoder_pad.name);
192
 
        }
193
 
 
194
 
        return pad_link_ok;
195
 
    }
196
115
}
 
116