1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
* Copyright (C) 2009 Nokia Corporation.
*
* Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
* <zeeshan.ali@nokia.com>
*
* This file is part of Rygel.
*
* Rygel is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Rygel is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
using Gst;
using GUPnP;
using Gee;
/**
* Transcoder for linear PCM audio (LPCM).
*/
internal class Rygel.L16Transcoder : Rygel.AudioTranscoder {
private const int CHANNELS = 2;
private const int FREQUENCY = 44100;
private const int WIDTH = 16;
private const int DEPTH = 16;
private const bool SIGNED = true;
private const int ENDIANNESS = ByteOrder.BIG_ENDIAN;
public L16Transcoder () {
var mime_type = "audio/L" + L16Transcoder.WIDTH.to_string () +
";rate=" + L16Transcoder.FREQUENCY.to_string () +
";channels=" + L16Transcoder.CHANNELS.to_string ();
var caps_str = "audio/x-raw-int" +
",channels=" + CHANNELS.to_string () +
",rate=" + FREQUENCY.to_string () +
",width=" + WIDTH.to_string () +
",depth=" + DEPTH.to_string () +
",signed=" + SIGNED.to_string () +
",endianness=" + ENDIANNESS.to_string();
base (mime_type,
"LPCM",
0,
AudioTranscoder.NO_CONTAINER,
caps_str,
"lpcm");
}
public override DIDLLiteResource? add_resource (DIDLLiteItem didl_item,
MediaItem item,
TranscodeManager manager)
throws Error {
var resource = base.add_resource (didl_item, item, manager);
if (resource == null) {
return null;
}
resource.sample_freq = L16Transcoder.FREQUENCY;
resource.audio_channels = L16Transcoder.CHANNELS;
resource.bits_per_sample = L16Transcoder.WIDTH;
// Set bitrate in bytes/second
resource.bitrate = L16Transcoder.FREQUENCY *
L16Transcoder.CHANNELS *
L16Transcoder.WIDTH / 8;
return resource;
}
public override uint get_distance (MediaItem item) {
if (!(item is AudioItem) || item is VideoItem) {
return uint.MAX;
}
var audio_item = item as AudioItem;
var distance = uint.MIN;
if (audio_item.sample_freq > 0) {
distance += (audio_item.sample_freq - FREQUENCY).abs ();
}
if (audio_item.channels > 0) {
distance += (audio_item.channels - CHANNELS).abs ();
}
if (audio_item.bits_per_sample > 0) {
distance += (audio_item.bits_per_sample - WIDTH).abs ();
}
return distance;
}
}
|