comparison libdlna-0.2.3/src/audio_mp3.c @ 129:4f6d9621ee00

add multi session streaming & add depending librarys. - libupnp-1.6.6 - libdlna-0.2.3
author Naoya OYAMA <naoya.oyama@gmail.com>
date Sun, 10 Oct 2010 15:33:18 +0900
parents
children
comparison
equal deleted inserted replaced
128:3a7d8d2f0585 129:4f6d9621ee00
1 /*
2 * libdlna: reference DLNA standards implementation.
3 * Copyright (C) 2007 Benjamin Zores <ben@geexbox.org>
4 *
5 * This file is part of libdlna.
6 *
7 * libdlna is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * libdlna is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with libdlna; if not, write to the Free Software
19 * Foundation, Inc, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include "dlna_internals.h"
26 #include "profiles.h"
27
28 /* Profile for audio media class content */
29 static dlna_profile_t mp3 = {
30 .id = "MP3",
31 .mime = MIME_AUDIO_MPEG,
32 .label = LABEL_AUDIO_2CH
33 };
34
35 /* Profile for audio media class content with extensions
36 for lower sampling rates and bitrates */
37 static dlna_profile_t mp3x = {
38 .id = "MP3X",
39 .mime = MIME_AUDIO_MPEG,
40 .label = LABEL_AUDIO_2CH
41 };
42
43 static int
44 audio_is_valid_mp3_common (AVCodecContext *ac)
45 {
46 if (!ac)
47 return 0;
48
49 /* check for MP3 codec */
50 if (ac->codec_id != CODEC_ID_MP3)
51 return 0;
52
53 /* only mono and stereo are supported */
54 if (ac->channels > 2)
55 return 0;
56
57 return 1;
58 }
59
60 static int
61 audio_is_valid_mp3 (AVCodecContext *ac)
62 {
63 if (!ac)
64 return 0;
65
66 if (!audio_is_valid_mp3_common (ac))
67 return 0;
68
69 if (ac->sample_rate != 32000 &&
70 ac->sample_rate != 44100 &&
71 ac->sample_rate != 48000)
72 return 0;
73
74 switch (ac->bit_rate)
75 {
76 case 32000:
77 case 40000:
78 case 48000:
79 case 56000:
80 case 64000:
81 case 80000:
82 case 96000:
83 case 112000:
84 case 128000:
85 case 160000:
86 case 192000:
87 case 224000:
88 case 256000:
89 case 320000:
90 return 1;
91 default:
92 break;
93 }
94
95 return 0;
96 }
97
98 static int
99 audio_is_valid_mp3x (AVCodecContext *ac)
100 {
101 if (!ac)
102 return 0;
103
104 if (!audio_is_valid_mp3_common (ac))
105 return 0;
106
107 if (ac->sample_rate != 16000 &&
108 ac->sample_rate != 22050 &&
109 ac->sample_rate != 24000)
110 return 0;
111
112 switch (ac->bit_rate)
113 {
114 case 8000:
115 case 16000:
116 case 24000:
117 case 32000:
118 case 40000:
119 case 48000:
120 case 56000:
121 case 64000:
122 case 80000:
123 case 96000:
124 case 112000:
125 case 128000:
126 case 160000:
127 case 192000:
128 case 224000:
129 case 256000:
130 case 320000:
131 return 1;
132 default:
133 break;
134 }
135
136 return 0;
137 }
138
139 audio_profile_t
140 audio_profile_guess_mp3 (AVCodecContext *ac)
141 {
142 audio_profile_t ap = AUDIO_PROFILE_INVALID;
143
144 if (!ac)
145 return ap;
146
147 if (audio_is_valid_mp3x (ac))
148 return AUDIO_PROFILE_MP3_EXTENDED;
149
150 if (audio_is_valid_mp3 (ac))
151 return AUDIO_PROFILE_MP3;
152
153 return AUDIO_PROFILE_INVALID;
154 }
155
156 /* Audio encoding must be MPEG-1 Layer 3 */
157 static dlna_profile_t *
158 probe_mp3 (AVFormatContext *ctx dlna_unused,
159 dlna_container_type_t st,
160 av_codecs_t *codecs)
161 {
162 if (!stream_ctx_is_audio (codecs))
163 return NULL;
164
165 /* check for supported container */
166 if (st != CT_MP3)
167 return NULL;
168
169 switch (audio_profile_guess_mp3 (codecs->ac))
170 {
171 case AUDIO_PROFILE_MP3:
172 return &mp3;
173 case AUDIO_PROFILE_MP3_EXTENDED:
174 return &mp3x;
175 default:
176 break;
177 }
178
179 return NULL;
180 }
181
182 dlna_registered_profile_t dlna_profile_audio_mp3 = {
183 .id = DLNA_PROFILE_AUDIO_MP3,
184 .class = DLNA_CLASS_AUDIO,
185 .extensions = "mp3",
186 .probe = probe_mp3,
187 .next = NULL
188 };