Mercurial > pt1.oyama
comparison libdlna-0.2.3/src/av_wmv9.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 /* Summary of VMW9 Profiles | |
23 * Simple and Main profiles are identified by FourCC WMV3 | |
24 * Advanced profile is identified by FourCC WVC1 | |
25 * | |
26 * Profile Level Max. Bitrate Format | |
27 * | |
28 * Simple Low 96 Kbps 176 x 144 @ 15 Hz (QCIF) | |
29 * Medium 384 Kbps 240 x 176 @ 30 Hz | |
30 * 352 x 288 @ 15 Hz (CIF) | |
31 * | |
32 * Main Low 2 Mbps 320 x 240 @ 24 Hz (QVGA) | |
33 * Medium 10 Mbps 720 x 480 @ 30 Hz (480p) | |
34 * 720 x 576 @ 25 Hz (576p) | |
35 * High 20 Mbps 1920 x 1080 @ 30 Hz (1080p) | |
36 * | |
37 * Advanced L0 2 Mbps 352 x 288 @ 30 Hz (CIF) | |
38 * L1 10 Mbps 720 x 480 @ 30 Hz (NTSC-SD) | |
39 * 720 x 576 @ 25 Hz (PAL-SD) | |
40 * L2 20 Mbps 720 x 480 @ 60 Hz (480p) | |
41 * 1280 x 720 @ 30 Hz (720p) | |
42 * L3 45 Mbps 1920 x 1080 @ 24 Hz (1080p) | |
43 * 1920 x 1080 @ 30 Hz (1080i) | |
44 * 1280 x 720 @ 60 Hz (720p) | |
45 * L4 135 Mbps 1920 x 1080 @ 60 Hz (1080p) | |
46 * 2048 x 1536 @ 24 Hz | |
47 */ | |
48 | |
49 #include <stdlib.h> | |
50 #include <string.h> | |
51 | |
52 #include "dlna_internals.h" | |
53 #include "profiles.h" | |
54 #include "containers.h" | |
55 | |
56 typedef enum { | |
57 WMV_VIDEO_PROFILE_INVALID, | |
58 WMV_VIDEO_PROFILE_SIMPLE_LOW, | |
59 WMV_VIDEO_PROFILE_SIMPLE_MEDIUM, | |
60 WMV_VIDEO_PROFILE_MAIN_MEDIUM, | |
61 WMV_VIDEO_PROFILE_MAIN_HIGH | |
62 } wmv_video_profile_t; | |
63 | |
64 typedef struct wmv9_profile_s { | |
65 int max_width; | |
66 int max_height; | |
67 int fps_num; | |
68 int fps_den; | |
69 int max_bitrate; | |
70 } wmv9_profile_t; | |
71 | |
72 static wmv9_profile_t wmv9_profile_simple_low[] = { | |
73 { 176, 144, 15, 1, 96000} | |
74 }; | |
75 | |
76 static wmv9_profile_t wmv9_profile_simple_medium[] = { | |
77 { 240, 176, 30, 1, 384000}, | |
78 { 240, 176, 30000, 1001, 384000}, | |
79 { 352, 288, 15, 1, 384000} | |
80 }; | |
81 | |
82 static wmv9_profile_t wmv9_profile_main_medium[] = { | |
83 { 720, 480, 30, 1, 10000000}, | |
84 { 720, 480, 30000, 1001, 10000000}, | |
85 { 720, 576, 25, 1, 10000000} | |
86 }; | |
87 | |
88 static wmv9_profile_t wmv9_profile_main_high[] = { | |
89 { 1920, 1080, 30, 1, 20000000}, | |
90 { 1920, 1080, 30000, 1001, 20000000} | |
91 }; | |
92 | |
93 /* Medium resolution video (Main profile at Medium Level) | |
94 with baseline WMA audio */ | |
95 static dlna_profile_t wmvmed_base = { | |
96 .id = "WMVMED_BASE", | |
97 .mime = MIME_VIDEO_WMV, | |
98 .label = LABEL_VIDEO_SD | |
99 }; | |
100 | |
101 /* Medium resolution video (Main profile at Medium Level) | |
102 with full WMA audio */ | |
103 static dlna_profile_t wmvmed_full = { | |
104 .id = "WMVMED_FULL", | |
105 .mime = MIME_VIDEO_WMV, | |
106 .label = LABEL_VIDEO_SD | |
107 }; | |
108 | |
109 /* Medium resolution video (Main profile at Medium Level) | |
110 with WMA professional audio */ | |
111 static dlna_profile_t wmvmed_pro = { | |
112 .id = "WMVMED_PRO", | |
113 .mime = MIME_VIDEO_WMV, | |
114 .label = LABEL_VIDEO_HD | |
115 }; | |
116 | |
117 /* High resolution video (Main profile at High Level) | |
118 with full WMA audio */ | |
119 static dlna_profile_t wmvhigh_full = { | |
120 .id = "WMVHIGH_FULL", | |
121 .mime = MIME_VIDEO_WMV, | |
122 .label = LABEL_VIDEO_HD | |
123 }; | |
124 | |
125 /* High resolution video (Main profile at High Level) | |
126 with WMA professional audio */ | |
127 static dlna_profile_t wmvhigh_pro = { | |
128 .id = "WMVHIGH_PRO", | |
129 .mime = MIME_VIDEO_WMV, | |
130 .label = LABEL_VIDEO_HD | |
131 }; | |
132 | |
133 /* HighMAT profile */ | |
134 static dlna_profile_t wmvhm_base dlna_unused = { | |
135 .id = "WMVHM_BASE", | |
136 .mime = MIME_VIDEO_WMV, | |
137 .label = LABEL_VIDEO_SD | |
138 }; | |
139 | |
140 /* Low resolution video (Simple Profile at Low Level) | |
141 with baseline WMA audio */ | |
142 static dlna_profile_t wmvspll_base = { | |
143 .id = "WMVSPLL_BASE", | |
144 .mime = MIME_VIDEO_WMV, | |
145 .label = LABEL_VIDEO_QCIF15 | |
146 }; | |
147 | |
148 /* Low resolution video (Simple Profile at Medium Level) | |
149 with baseline WMA audio */ | |
150 static dlna_profile_t wmvspml_base = { | |
151 .id = "WMVSPML_BASE", | |
152 .mime = MIME_VIDEO_WMV, | |
153 .label = LABEL_VIDEO_CIF15 | |
154 }; | |
155 | |
156 /* Low resolution video (Simple Profile at Medium Level) with MP3 audio */ | |
157 static dlna_profile_t wmvspml_mp3 = { | |
158 .id = "WMVSPML_MP3", | |
159 .mime = MIME_VIDEO_WMV, | |
160 .label = LABEL_VIDEO_CIF15 | |
161 }; | |
162 | |
163 static const struct { | |
164 dlna_profile_t *profile; | |
165 wmv_video_profile_t vp; | |
166 audio_profile_t ap; | |
167 } wmv_profiles_mapping[] = { | |
168 { &wmvmed_base, WMV_VIDEO_PROFILE_MAIN_MEDIUM, | |
169 AUDIO_PROFILE_WMA_BASELINE }, | |
170 { &wmvmed_full, WMV_VIDEO_PROFILE_MAIN_MEDIUM, | |
171 AUDIO_PROFILE_WMA_FULL }, | |
172 { &wmvmed_pro, WMV_VIDEO_PROFILE_MAIN_MEDIUM, | |
173 AUDIO_PROFILE_WMA_PRO }, | |
174 { &wmvhigh_full, WMV_VIDEO_PROFILE_MAIN_HIGH, | |
175 AUDIO_PROFILE_WMA_FULL }, | |
176 { &wmvhigh_pro, WMV_VIDEO_PROFILE_MAIN_HIGH, | |
177 AUDIO_PROFILE_WMA_FULL }, | |
178 { &wmvspll_base, WMV_VIDEO_PROFILE_SIMPLE_LOW, | |
179 AUDIO_PROFILE_WMA_BASELINE }, | |
180 { &wmvspml_base, WMV_VIDEO_PROFILE_SIMPLE_MEDIUM, | |
181 AUDIO_PROFILE_WMA_BASELINE }, | |
182 { &wmvspml_mp3, WMV_VIDEO_PROFILE_SIMPLE_MEDIUM, | |
183 AUDIO_PROFILE_MP3 }, | |
184 { NULL, 0, 0, } | |
185 }; | |
186 | |
187 static int | |
188 is_valid_wmv9_video_profile (wmv9_profile_t profile[], int size, | |
189 AVStream *vs, AVCodecContext *vc) | |
190 { | |
191 int i; | |
192 | |
193 for (i = 0; i < size / (int) sizeof (wmv9_profile_t); i++) | |
194 if (vc->width <= profile[i].max_width && | |
195 vc->height <= profile[i].max_height && | |
196 vs->r_frame_rate.num == profile[i].fps_num && | |
197 vs->r_frame_rate.den == profile[i].fps_den && | |
198 vc->bit_rate <= profile[i].max_bitrate) | |
199 return 1; | |
200 | |
201 /* video properties do not fit the requested profile */ | |
202 return 0; | |
203 } | |
204 | |
205 static wmv_video_profile_t | |
206 wmv_video_profile_get (AVStream *vs, AVCodecContext *vc) | |
207 { | |
208 if (!vs || !vc) | |
209 return WMV_VIDEO_PROFILE_INVALID; | |
210 | |
211 if (is_valid_wmv9_video_profile (wmv9_profile_simple_low, | |
212 sizeof (wmv9_profile_simple_low), vs, vc)) | |
213 return WMV_VIDEO_PROFILE_SIMPLE_LOW; | |
214 | |
215 if (is_valid_wmv9_video_profile (wmv9_profile_simple_medium, | |
216 sizeof (wmv9_profile_simple_medium), | |
217 vs, vc)) | |
218 return WMV_VIDEO_PROFILE_SIMPLE_MEDIUM; | |
219 | |
220 if (is_valid_wmv9_video_profile (wmv9_profile_main_medium, | |
221 sizeof (wmv9_profile_main_medium), vs, vc)) | |
222 return WMV_VIDEO_PROFILE_MAIN_MEDIUM; | |
223 | |
224 if (is_valid_wmv9_video_profile (wmv9_profile_main_high, | |
225 sizeof (wmv9_profile_main_high), vs, vc)) | |
226 return WMV_VIDEO_PROFILE_MAIN_HIGH; | |
227 | |
228 return WMV_VIDEO_PROFILE_INVALID; | |
229 } | |
230 | |
231 static dlna_profile_t * | |
232 probe_wmv9 (AVFormatContext *ctx dlna_unused, | |
233 dlna_container_type_t st, | |
234 av_codecs_t *codecs) | |
235 { | |
236 wmv_video_profile_t vp; | |
237 audio_profile_t ap; | |
238 int i; | |
239 | |
240 if (!stream_ctx_is_av (codecs)) | |
241 return NULL; | |
242 | |
243 /* need to be in ASF container only */ | |
244 if (st != CT_ASF) | |
245 return NULL; | |
246 | |
247 /* check for WMV3 (Simple and Main profiles) video codec */ | |
248 if (codecs->vc->codec_id != CODEC_ID_WMV3) | |
249 return NULL; | |
250 | |
251 /* get video profile */ | |
252 vp = wmv_video_profile_get (codecs->vs, codecs->vc); | |
253 if (vp == WMV_VIDEO_PROFILE_INVALID) | |
254 return NULL; | |
255 | |
256 /* get audio profile */ | |
257 ap = audio_profile_guess (codecs->ac); | |
258 if (ap == AUDIO_PROFILE_INVALID) | |
259 return NULL; | |
260 | |
261 /* find profile according to container type, video and audio profiles */ | |
262 for (i = 0; wmv_profiles_mapping[i].profile; i++) | |
263 if (wmv_profiles_mapping[i].vp == vp && | |
264 wmv_profiles_mapping[i].ap == ap) | |
265 return wmv_profiles_mapping[i].profile; | |
266 | |
267 return NULL; | |
268 } | |
269 | |
270 dlna_registered_profile_t dlna_profile_av_wmv9 = { | |
271 .id = DLNA_PROFILE_AV_WMV9, | |
272 .class = DLNA_CLASS_AV, | |
273 .extensions = "asf,wmv", | |
274 .probe = probe_wmv9, | |
275 .next = NULL | |
276 }; |