comparison libdlna-0.2.3/src/audio_amr.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 #include "containers.h"
28
29 /* Profile for audio media class content */
30 static dlna_profile_t amr = {
31 .id = "AMR_3GPP",
32 .mime = MIME_AUDIO_MPEG_4,
33 .label = LABEL_AUDIO_MONO
34 };
35
36 /* Profile for audio media class content */
37 static dlna_profile_t three_gpp = {
38 .id = "AMR_3GPP",
39 .mime = MIME_AUDIO_3GP,
40 .label = LABEL_AUDIO_MONO
41 };
42
43 /* Profile for audio media class content */
44 static dlna_profile_t amr_wbplus = {
45 .id = "AMR_WBplus",
46 .mime = MIME_AUDIO_3GP,
47 .label = LABEL_AUDIO_2CH
48 };
49
50 static int
51 audio_is_valid_amr (AVCodecContext *ac)
52 {
53 if (!ac)
54 return 0;
55
56 if (ac->codec_id != CODEC_ID_AMR_NB)
57 return 0;
58
59 /* only mono is supported */
60 if (ac->channels != 1)
61 return 0;
62
63 /* only supports 8 kHz sampling rate */
64 if (ac->sample_rate != 8000)
65 return 0;
66
67 /* valid CBR bitrates: 4.75, 5.15, 5.9, 6.7, 7.4, 7.95, 10.2, 12.2 Kbps */
68 switch (ac->bit_rate)
69 {
70 case 4750:
71 case 5150:
72 case 5900:
73 case 6700:
74 case 7400:
75 case 7950:
76 case 10200:
77 case 12200:
78 return 1;
79 default:
80 break;
81 }
82
83 return 0;
84 }
85
86 static int
87 audio_is_valid_amr_wb (AVCodecContext *ac)
88 {
89 if (!ac)
90 return 0;
91
92 if (ac->codec_id != CODEC_ID_AMR_WB)
93 return 0;
94
95 /* valid sampling rates: 8, 16, 24, 32 and 48 kHz */
96 if (ac->sample_rate != 8000 &&
97 ac->sample_rate != 16000 &&
98 ac->sample_rate != 24000 &&
99 ac->sample_rate != 32000 &&
100 ac->sample_rate != 48000)
101 return 0;
102
103 /* supported bit rates: 5.2 Kbps - 48 Kbps */
104 if (ac->bit_rate < 5200 || ac->bit_rate > 48000)
105 return 0;
106
107 /* only mono and stereo are supported */
108 if (ac->channels > 2)
109 return 0;
110
111 return 1;
112 }
113
114 audio_profile_t
115 audio_profile_guess_amr (AVCodecContext *ac)
116 {
117 if (!ac)
118 return AUDIO_PROFILE_INVALID;
119
120 if (audio_is_valid_amr (ac))
121 return AUDIO_PROFILE_AMR;
122 else if (audio_is_valid_amr_wb (ac))
123 return AUDIO_PROFILE_AMR_WB;
124
125 return AUDIO_PROFILE_INVALID;
126 }
127
128 static dlna_profile_t *
129 probe_amr (AVFormatContext *ctx dlna_unused,
130 dlna_container_type_t st,
131 av_codecs_t *codecs)
132 {
133 if (!stream_ctx_is_audio (codecs))
134 return NULL;
135
136 /* check for supported container */
137 if (st != CT_AMR && st != CT_3GP && st != CT_MP4)
138 return NULL;
139
140 /* check for AMR NB/WB audio codec */
141 if (audio_is_valid_amr (codecs->ac))
142 return (st == CT_3GP) ? &three_gpp : &amr;
143
144 if (audio_is_valid_amr_wb (codecs->ac))
145 return &amr_wbplus;
146
147 return NULL;
148 }
149
150 dlna_registered_profile_t dlna_profile_audio_amr = {
151 .id = DLNA_PROFILE_AUDIO_AMR,
152 .class = DLNA_CLASS_AUDIO,
153 .extensions = "amr,3gp,mp4",
154 .probe = probe_amr,
155 .next = NULL
156 };