~ubuntu-branches/ubuntu/raring/rygel/raring

« back to all changes in this revision

Viewing changes to src/rygel/rygel-audio-transcoder.vala

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2012-09-26 22:34:15 UTC
  • mfrom: (11.1.19 experimental)
  • Revision ID: package-import@ubuntu.com-20120926223415-9day2s783n9td4e8
Tags: 0.16.0-1
ImportedĀ UpstreamĀ versionĀ 0.16.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2011 Nokia Corporation.
3
 
 *
4
 
 * Author: Jens Georg <jensg@openismus.com>
5
 
 *
6
 
 * This file is part of Rygel.
7
 
 *
8
 
 * Rygel is free software; you can redistribute it and/or modify
9
 
 * it under the terms of the GNU Lesser General Public License as published by
10
 
 * the Free Software Foundation; either version 2 of the License, or
11
 
 * (at your option) any later version.
12
 
 *
13
 
 * Rygel is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 * GNU Lesser General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU Lesser General Public License
19
 
 * along with this program; if not, write to the Free Software Foundation,
20
 
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
 
 */
22
 
using Gst;
23
 
using GUPnP;
24
 
 
25
 
/**
26
 
 * Base class for all transcoders that handle audio.
27
 
 */
28
 
internal class Rygel.AudioTranscoder : Rygel.Transcoder {
29
 
    protected int audio_bitrate;
30
 
    protected Caps container_format = null;
31
 
    protected Caps audio_codec_format = null;
32
 
 
33
 
    public const string NO_CONTAINER = null;
34
 
 
35
 
    public AudioTranscoder (string  content_type,
36
 
                            string  dlna_profile,
37
 
                            int     audio_bitrate,
38
 
                            string? container_caps,
39
 
                            string  audio_codec_caps,
40
 
                            string  extension) {
41
 
        base (content_type, dlna_profile, AudioItem.UPNP_CLASS, extension);
42
 
 
43
 
        this.audio_bitrate = audio_bitrate;
44
 
        if (container_caps != null) {
45
 
            this.container_format = Caps.from_string (container_caps);
46
 
        }
47
 
 
48
 
        this.audio_codec_format = Caps.from_string (audio_codec_caps);
49
 
    }
50
 
 
51
 
    public AudioTranscoder.with_class (string  content_type,
52
 
                                       string  dlna_profile,
53
 
                                       string  upnp_class,
54
 
                                       int     audio_bitrate,
55
 
                                       string? container_caps,
56
 
                                       string  audio_codec_caps,
57
 
                                       string  extension) {
58
 
        base (content_type, dlna_profile, upnp_class, extension);
59
 
 
60
 
        this.audio_bitrate = audio_bitrate;
61
 
        if (container_caps != null) {
62
 
            this.container_format = Caps.from_string (container_caps);
63
 
        }
64
 
 
65
 
        this.audio_codec_format = Caps.from_string (audio_codec_caps);
66
 
    }
67
 
 
68
 
 
69
 
    public override DIDLLiteResource? add_resource (DIDLLiteItem     didl_item,
70
 
                                                    MediaItem        item,
71
 
                                                    TranscodeManager manager)
72
 
                                                    throws Error {
73
 
        var resource = base.add_resource (didl_item, item, manager);
74
 
        if (resource == null) {
75
 
            return null;
76
 
        }
77
 
 
78
 
        resource.bitrate = (this.audio_bitrate * 1000) / 8;
79
 
 
80
 
        return resource;
81
 
    }
82
 
 
83
 
    public override uint get_distance (MediaItem item) {
84
 
        if (!(item is AudioItem) || item is VideoItem) {
85
 
            return uint.MAX;
86
 
        }
87
 
 
88
 
        var audio_item = item as AudioItem;
89
 
        var distance = uint.MIN;
90
 
 
91
 
        if (audio_item.bitrate > 0) {
92
 
            distance += (audio_item.bitrate - this.audio_bitrate).abs ();
93
 
        }
94
 
 
95
 
        return distance;
96
 
    }
97
 
 
98
 
    protected override EncodingProfile get_encoding_profile () {
99
 
        var enc_audio_profile = new EncodingAudioProfile (audio_codec_format,
100
 
                                                          null,
101
 
                                                          null,
102
 
                                                          1);
103
 
        enc_audio_profile.set_name ("audio");
104
 
 
105
 
        if (this.container_format != null) {
106
 
            var enc_container_profile = new EncodingContainerProfile ("container",
107
 
                                                                      null,
108
 
                                                                      container_format,
109
 
                                                                      null);
110
 
            enc_container_profile.add_profile (enc_audio_profile);
111
 
 
112
 
            return enc_container_profile;
113
 
        }
114
 
 
115
 
        return enc_audio_profile;
116
 
    }
117
 
}