Mercurial > pt1.oyama
comparison libdlna-0.2.3/src/av_mpeg2.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 #include <unistd.h> | |
25 #include <sys/types.h> | |
26 #include <sys/stat.h> | |
27 #include <fcntl.h> | |
28 | |
29 #include "dlna_internals.h" | |
30 #include "profiles.h" | |
31 #include "containers.h" | |
32 | |
33 typedef struct mpeg_ps_es_stream_s { | |
34 int width; | |
35 int height; | |
36 } mpeg_ps_es_stream_t; | |
37 | |
38 typedef struct mpeg_ts_stream_s { | |
39 int width; | |
40 int height; | |
41 int fps_num; | |
42 int fps_den; | |
43 } mpeg_ts_stream_t; | |
44 | |
45 static mpeg_ps_es_stream_t mpeg_ps_es_valid_streams_ntsc[] = { | |
46 { 720, 480 }, | |
47 { 704, 480 }, | |
48 { 544, 480 }, | |
49 { 480, 480 }, | |
50 { 352, 480 }, | |
51 { 352, 240 } | |
52 }; | |
53 | |
54 static mpeg_ps_es_stream_t mpeg_ps_es_valid_streams_pal[] = { | |
55 { 720, 576 }, | |
56 { 704, 576 }, | |
57 { 544, 576 }, | |
58 { 480, 576 }, | |
59 { 352, 576 }, | |
60 { 352, 288 } | |
61 }; | |
62 | |
63 static mpeg_ts_stream_t mpeg_ts_valid_streams_eu_sd[] = { | |
64 { 720, 576, 25, 1}, | |
65 { 544, 576, 25, 1}, | |
66 { 480, 576, 25, 1}, | |
67 { 352, 576, 25, 1}, | |
68 { 252, 288, 25, 1} | |
69 }; | |
70 | |
71 static mpeg_ts_stream_t mpeg_ts_valid_streams_na_sd[] = { | |
72 { 720, 480, 30, 1001}, | |
73 { 704, 480, 30, 1001}, | |
74 { 704, 480, 30, 1}, | |
75 { 704, 480, 24, 1001}, | |
76 { 704, 480, 24, 1}, | |
77 { 640, 480, 30, 1001}, | |
78 { 640, 480, 30, 1}, | |
79 { 640, 480, 24, 1001}, | |
80 { 640, 480, 24, 1}, | |
81 { 544, 480, 30, 1001}, | |
82 { 480, 480, 30, 1001}, | |
83 { 352, 480, 30, 1001} | |
84 }; | |
85 | |
86 static mpeg_ts_stream_t mpeg_ts_valid_streams_na_hd[] = { | |
87 { 1920, 1080, 30, 1001}, | |
88 { 1920, 1080, 30, 1}, | |
89 { 1920, 1080, 24, 1001}, | |
90 { 1920, 1080, 24, 1}, | |
91 { 1280, 720, 30, 1001}, | |
92 { 1280, 720, 30, 1}, | |
93 { 1280, 720, 24, 1001}, | |
94 { 1280, 720, 24, 1}, | |
95 { 1440, 1080, 30, 1001}, | |
96 { 1440, 1080, 30, 1}, | |
97 { 1440, 1080, 24, 1001}, | |
98 { 1440, 1080, 24, 1}, | |
99 { 1280, 1080, 30, 1001}, | |
100 { 1280, 1080, 30, 1}, | |
101 { 1280, 1080, 24, 1001}, | |
102 { 1280, 1080, 24, 1} | |
103 }; | |
104 | |
105 /* Profile for NTSC-formatted AV class media */ | |
106 static dlna_profile_t mpeg_ps_ntsc = { | |
107 .id = "MPEG_PS_NTSC", | |
108 .mime = MIME_VIDEO_MPEG, | |
109 .label = LABEL_VIDEO_SD | |
110 }; | |
111 | |
112 /* Profile for NTSC-formatted AV class media */ | |
113 static dlna_profile_t mpeg_ps_ntsc_xac3 = { | |
114 .id = "MPEG_PS_NTSC_XAC3", | |
115 .mime = MIME_VIDEO_MPEG, | |
116 .label = LABEL_VIDEO_SD | |
117 }; | |
118 | |
119 /* Profile for PAL-formatted AV class media */ | |
120 static dlna_profile_t mpeg_ps_pal = { | |
121 .id = "MPEG_PS_PAL", | |
122 .mime = MIME_VIDEO_MPEG, | |
123 .label = LABEL_VIDEO_SD | |
124 }; | |
125 | |
126 /* Profile for PAL-formatted AV class media */ | |
127 static dlna_profile_t mpeg_ps_pal_xac3 = { | |
128 .id = "MPEG_PS_PAL_XAC3", | |
129 .mime = MIME_VIDEO_MPEG, | |
130 .label = LABEL_VIDEO_SD | |
131 }; | |
132 | |
133 /* MPEG-2 Main Profile at Low Level AAC LC audio encapsulated in | |
134 MPEG-2 transport stream with zero value timestamp */ | |
135 static dlna_profile_t mpeg_ts_mp_ll_aac = { | |
136 .id = "MPEG_TS_MP_LL_AAC", | |
137 .mime = MIME_VIDEO_MPEG_TS, | |
138 .label = LABEL_VIDEO_CIF30 | |
139 }; | |
140 | |
141 /* MPEG-2 Main Profile at Low Level AAC LC audio encapsulated in | |
142 MPEG-2 transport stream with valid value timestamp */ | |
143 static dlna_profile_t mpeg_ts_mp_ll_aac_t = { | |
144 .id = "MPEG_TS_MP_LL_AAC_T", | |
145 .mime = MIME_VIDEO_MPEG_TS, | |
146 .label = LABEL_VIDEO_CIF30 | |
147 }; | |
148 | |
149 /* MPEG-2 Main Profile at Low Level AAC LC audio encapsulated in | |
150 MPEG-2 transport stream without a Timestamp field */ | |
151 static dlna_profile_t mpeg_ts_mp_ll_aac_iso = { | |
152 .id = "MPEG_TS_MP_LL_AAC_ISO", | |
153 .mime = MIME_VIDEO_MPEG, | |
154 .label = LABEL_VIDEO_CIF30 | |
155 }; | |
156 | |
157 /* European region profile for Standard Definition AV class utilizing | |
158 a DLNA Transport Packet with zero value timestamp */ | |
159 static dlna_profile_t mpeg_ts_sd_eu = { | |
160 .id = "MPEG_TS_SD_EU", | |
161 .mime = MIME_VIDEO_MPEG_TS, | |
162 .label = LABEL_VIDEO_SD | |
163 }; | |
164 | |
165 /* European region profile for Standard Definition AV class utilizing | |
166 a DLNA Transport Packet with a valid non-zero value timestamp */ | |
167 static dlna_profile_t mpeg_ts_sd_eu_t = { | |
168 .id = "MPEG_TS_SD_EU_T", | |
169 .mime = MIME_VIDEO_MPEG_TS, | |
170 .label = LABEL_VIDEO_SD | |
171 }; | |
172 | |
173 /* European region profile for Standard Definition AV class utilizing | |
174 a DLNA Transport Packet without a Timestamp field */ | |
175 static dlna_profile_t mpeg_ts_sd_eu_iso = { | |
176 .id = "MPEG_TS_SD_EU_ISO", | |
177 .mime = MIME_VIDEO_MPEG, | |
178 .label = LABEL_VIDEO_SD | |
179 }; | |
180 | |
181 /* North America region profile for Standard Definition AV class utilizing | |
182 a DLNA Transport Packet with zero value timestamp */ | |
183 static dlna_profile_t mpeg_ts_sd_na = { | |
184 .id = "MPEG_TS_SD_NA", | |
185 .mime = MIME_VIDEO_MPEG_TS, | |
186 .label = LABEL_VIDEO_SD | |
187 }; | |
188 | |
189 /* North America region profile for Standard Definition AV class utilizing | |
190 a DLNA Transport Packet with a valid non-zero value timestamp */ | |
191 static dlna_profile_t mpeg_ts_sd_na_t = { | |
192 .id = "MPEG_TS_SD_NA_T", | |
193 .mime = MIME_VIDEO_MPEG_TS, | |
194 .label = LABEL_VIDEO_SD | |
195 }; | |
196 | |
197 /* North America region profile for Standard Definition AV class utilizing | |
198 a DLNA Transport Packet without a Timestamp field */ | |
199 static dlna_profile_t mpeg_ts_sd_na_iso = { | |
200 .id = "MPEG_TS_SD_NA_ISO", | |
201 .mime = MIME_VIDEO_MPEG, | |
202 .label = LABEL_VIDEO_SD | |
203 }; | |
204 | |
205 /* North America region profile for Standard Definition AV class utilizing | |
206 a DLNA Transport Packet with zero value timestamp */ | |
207 static dlna_profile_t mpeg_ts_sd_na_xac3 = { | |
208 .id = "MPEG_TS_SD_NA_XAC3", | |
209 .mime = MIME_VIDEO_MPEG_TS, | |
210 .label = LABEL_VIDEO_SD | |
211 }; | |
212 | |
213 /* North America region profile for Standard Definition AV class utilizing | |
214 a DLNA Transport Packet with a valid non-zero value timestamp */ | |
215 static dlna_profile_t mpeg_ts_sd_na_xac3_t = { | |
216 .id = "MPEG_TS_SD_NA_XAC3_T", | |
217 .mime = MIME_VIDEO_MPEG_TS, | |
218 .label = LABEL_VIDEO_SD | |
219 }; | |
220 | |
221 /* North America region profile for Standard Definition AV class utilizing | |
222 a DLNA Transport Packet without a Timestamp field */ | |
223 static dlna_profile_t mpeg_ts_sd_na_xac3_iso = { | |
224 .id = "MPEG_TS_SD_NA_XAC3_ISO", | |
225 .mime = MIME_VIDEO_MPEG, | |
226 .label = LABEL_VIDEO_SD | |
227 }; | |
228 | |
229 /* North America region profile for High Definition AV class utilizing | |
230 a DLNA Transport Packet with zero value timestamp */ | |
231 static dlna_profile_t mpeg_ts_hd_na = { | |
232 .id = "MPEG_TS_HD_NA", | |
233 .mime = MIME_VIDEO_MPEG_TS, | |
234 .label = LABEL_VIDEO_HD | |
235 }; | |
236 | |
237 /* North America region profile for High Definition AV class utilizing | |
238 a DLNA Transport Packet with a valid non-zero value timestamp */ | |
239 static dlna_profile_t mpeg_ts_hd_na_t = { | |
240 .id = "MPEG_TS_HD_NA_T", | |
241 .mime = MIME_VIDEO_MPEG_TS, | |
242 .label = LABEL_VIDEO_HD | |
243 }; | |
244 | |
245 /* North America region profile for High Definition AV class utilizing | |
246 a DLNA Transport Packet without a Timestamp field */ | |
247 static dlna_profile_t mpeg_ts_hd_na_iso = { | |
248 .id = "MPEG_TS_HD_NA_ISO", | |
249 .mime = MIME_VIDEO_MPEG, | |
250 .label = LABEL_VIDEO_HD | |
251 }; | |
252 | |
253 /* North America region profile for transcoded High Definition AV class | |
254 media with a zero value timestamp */ | |
255 static dlna_profile_t mpeg_ts_hd_na_xac3 = { | |
256 .id = "MPEG_TS_HD_NA_XAC3", | |
257 .mime = MIME_VIDEO_MPEG_TS, | |
258 .label = LABEL_VIDEO_HD | |
259 }; | |
260 | |
261 /* North America region profile for transcoded High Definition AV class | |
262 media with a valid non-zero value timestamp */ | |
263 static dlna_profile_t mpeg_ts_hd_na_xac3_t = { | |
264 .id = "MPEG_TS_HD_NA_XAC3_T", | |
265 .mime = MIME_VIDEO_MPEG_TS, | |
266 .label = LABEL_VIDEO_HD | |
267 }; | |
268 | |
269 /* North America region profile for transcoded High Definition AV class | |
270 media without a Timestamp field */ | |
271 static dlna_profile_t mpeg_ts_hd_na_xac3_iso = { | |
272 .id = "MPEG_TS_HD_NA_XAC3_ISO", | |
273 .mime = MIME_VIDEO_MPEG, | |
274 .label = LABEL_VIDEO_HD | |
275 }; | |
276 | |
277 /* Profile defining ES encapsulation for transport of MPEG_PS_PAL over RTP */ | |
278 static dlna_profile_t mpeg_es_pal = { | |
279 .id = "MPEG_ES_PAL", | |
280 .mime = MIME_VIDEO_MPEG, | |
281 .label = LABEL_VIDEO_SD | |
282 }; | |
283 | |
284 /* Profile defining ES encapsulation for transport of MPEG_PS_NTSC over RTP */ | |
285 static dlna_profile_t mpeg_es_ntsc = { | |
286 .id = "MPEG_ES_NTSC", | |
287 .mime = MIME_VIDEO_MPEG, | |
288 .label = LABEL_VIDEO_SD | |
289 }; | |
290 | |
291 /* Profile defining ES encapsulation for transport of | |
292 MPEG_PS_PAL_XAC3 over RTP */ | |
293 static dlna_profile_t mpeg_es_pal_xac3 = { | |
294 .id = "MPEG_ES_PAL_XAC3", | |
295 .mime = MIME_VIDEO_MPEG, | |
296 .label = LABEL_VIDEO_SD | |
297 }; | |
298 | |
299 /* Profile defining ES encapsulation for transport of | |
300 MPEG_PS_NTSC_XAC3 over RTP */ | |
301 static dlna_profile_t mpeg_es_ntsc_xac3 = { | |
302 .id = "MPEG_ES_NTSC_XAC3", | |
303 .mime = MIME_VIDEO_MPEG, | |
304 .label = LABEL_VIDEO_SD | |
305 }; | |
306 | |
307 static int | |
308 is_mpeg_ps_es_audio_stream_lpcm (AVFormatContext *ctx dlna_unused, | |
309 av_codecs_t *codecs) | |
310 { | |
311 if (audio_profile_guess_lpcm (codecs->ac) != AUDIO_PROFILE_LPCM) | |
312 return 0; | |
313 | |
314 /* audio bit rate: 1.536 Mbps for stereo, 768 Kbps for mono */ | |
315 if (codecs->ac->channels == 2 && codecs->ac->bit_rate > 1536000) | |
316 return 0; | |
317 if (codecs->ac->channels == 1 && codecs->ac->bit_rate > 768000) | |
318 return 0; | |
319 | |
320 return 1; | |
321 } | |
322 | |
323 static int | |
324 is_mpeg_ps_es_audio_stream_extended_ac3 (AVFormatContext *ctx dlna_unused, | |
325 av_codecs_t *codecs) | |
326 { | |
327 return (audio_profile_guess_ac3 (codecs->ac) == AUDIO_PROFILE_AC3_EXTENDED) | |
328 ? 1 : 0; | |
329 } | |
330 | |
331 static int | |
332 is_mpeg_ps_es_audio_stream_ac3 (AVFormatContext *ctx dlna_unused, | |
333 av_codecs_t *codecs) | |
334 { | |
335 return (audio_profile_guess_ac3 (codecs->ac) == AUDIO_PROFILE_AC3) ? 1 : 0; | |
336 } | |
337 | |
338 static int | |
339 is_mpeg_ps_es_audio_stream_mp2 (AVFormatContext *ctx dlna_unused, | |
340 av_codecs_t *codecs) | |
341 { | |
342 if (audio_profile_guess_mp2 (codecs->ac) != AUDIO_PROFILE_MP2) | |
343 return 0; | |
344 | |
345 /* supported channels: 1/0, 1/0 + 1/0, 2/0 */ | |
346 if (codecs->ac->channels > 2) | |
347 return 0; | |
348 | |
349 /* audio bit rate: 64-192 Kbps for mono, 64-384 Kbps for stereo */ | |
350 if (codecs->ac->channels == 1 && | |
351 (codecs->ac->bit_rate < 64000 || codecs->ac->bit_rate > 192000)) | |
352 return 0; | |
353 if (codecs->ac->channels == 2 && | |
354 (codecs->ac->bit_rate < 64000 || codecs->ac->bit_rate > 384000)) | |
355 return 0; | |
356 | |
357 return 1; | |
358 } | |
359 | |
360 static int | |
361 is_mpeg_ts_audio_stream_mp2 (AVFormatContext *ctx dlna_unused, | |
362 av_codecs_t *codecs) | |
363 { | |
364 return (audio_profile_guess_mp2 (codecs->ac) == AUDIO_PROFILE_MP2) ? 1 : 0; | |
365 } | |
366 | |
367 static int | |
368 is_mpeg_ts_audio_stream_ac3 (AVFormatContext *ctx dlna_unused, | |
369 av_codecs_t *codecs) | |
370 { | |
371 return (audio_profile_guess_ac3 (codecs->ac) == AUDIO_PROFILE_AC3) ? 1 : 0; | |
372 } | |
373 | |
374 static dlna_profile_t * | |
375 probe_mpeg_ps_es (AVFormatContext *ctx, av_codecs_t *codecs, | |
376 dlna_profile_t *pal, dlna_profile_t *pal_xac3, | |
377 dlna_profile_t *ntsc, dlna_profile_t *ntsc_xac3) | |
378 { | |
379 int i; | |
380 | |
381 /* determine region through frame rate */ | |
382 if ((codecs->vs->r_frame_rate.num == 30000 && | |
383 codecs->vs->r_frame_rate.den == 1001)) /* NTSC */ | |
384 { | |
385 for (i = 0; i < (int) (sizeof (mpeg_ps_es_valid_streams_ntsc) | |
386 / sizeof (mpeg_ps_es_stream_t)); i++) | |
387 { | |
388 if (mpeg_ps_es_valid_streams_ntsc[i].width == codecs->vc->width && | |
389 mpeg_ps_es_valid_streams_ntsc[i].height == codecs->vc->height) | |
390 { | |
391 if (is_mpeg_ps_es_audio_stream_extended_ac3 (ctx, codecs)) | |
392 return ntsc_xac3; | |
393 else if (is_mpeg_ps_es_audio_stream_lpcm (ctx, codecs) || | |
394 is_mpeg_ps_es_audio_stream_ac3 (ctx, codecs) || | |
395 is_mpeg_ps_es_audio_stream_mp2 (ctx, codecs)) | |
396 return ntsc; | |
397 | |
398 return NULL; | |
399 } | |
400 } | |
401 | |
402 /* invalid resolution */ | |
403 return NULL; | |
404 } | |
405 else if (codecs->vs->r_frame_rate.num == 25 && | |
406 codecs->vs->r_frame_rate.den == 1) /* PAL */ | |
407 { | |
408 for (i = 0; i < (int) (sizeof (mpeg_ps_es_valid_streams_pal) | |
409 / sizeof (mpeg_ps_es_stream_t)); i++) | |
410 { | |
411 if (mpeg_ps_es_valid_streams_pal[i].width == codecs->vc->width && | |
412 mpeg_ps_es_valid_streams_pal[i].height == codecs->vc->height) | |
413 { | |
414 if (is_mpeg_ps_es_audio_stream_extended_ac3 (ctx, codecs)) | |
415 return pal_xac3; | |
416 else if (is_mpeg_ps_es_audio_stream_lpcm (ctx, codecs) || | |
417 is_mpeg_ps_es_audio_stream_ac3 (ctx, codecs) || | |
418 is_mpeg_ps_es_audio_stream_mp2 (ctx, codecs)) | |
419 return pal; | |
420 | |
421 return NULL; | |
422 } | |
423 } | |
424 | |
425 /* invalid resolution */ | |
426 return NULL; | |
427 } | |
428 | |
429 return NULL; | |
430 } | |
431 | |
432 static dlna_profile_t * | |
433 probe_mpeg_ps (AVFormatContext *ctx, av_codecs_t *codecs) | |
434 { | |
435 return probe_mpeg_ps_es (ctx, codecs, | |
436 &mpeg_ps_pal, &mpeg_ps_pal_xac3, | |
437 &mpeg_ps_ntsc, &mpeg_ps_ntsc_xac3); | |
438 } | |
439 | |
440 static dlna_profile_t * | |
441 probe_mpeg_es (AVFormatContext *ctx, av_codecs_t *codecs) | |
442 { | |
443 return probe_mpeg_ps_es (ctx, codecs, | |
444 &mpeg_es_pal, &mpeg_es_pal_xac3, | |
445 &mpeg_es_ntsc, &mpeg_es_ntsc_xac3); | |
446 } | |
447 | |
448 static dlna_profile_t * | |
449 probe_mpeg_ts (AVFormatContext *ctx, | |
450 av_codecs_t *codecs, dlna_container_type_t st) | |
451 { | |
452 int xac3 = 0; /* extended AC3 audio */ | |
453 int i; | |
454 | |
455 /* check for MPEG-2 MP@LL profile */ | |
456 if (codecs->ac->codec_id == CODEC_ID_AAC) | |
457 { | |
458 /* 352x288 only */ | |
459 if (codecs->vc->width != 352 && codecs->vc->height != 288) | |
460 return NULL; | |
461 | |
462 /* 30 fps */ | |
463 if (codecs->vs->r_frame_rate.num != 30 && | |
464 codecs->vs->r_frame_rate.den != 1) | |
465 return NULL; | |
466 | |
467 /* video bitrate is less or equal to 4 Mbps */ | |
468 if (codecs->vc->bit_rate > 4000000) | |
469 return NULL; | |
470 | |
471 /* audio bitrate is less or equal to 256 Kbps */ | |
472 if (codecs->ac->bit_rate > 256000) | |
473 return NULL; | |
474 | |
475 switch (st) | |
476 { | |
477 case CT_MPEG_TRANSPORT_STREAM: | |
478 return &mpeg_ts_mp_ll_aac_iso; | |
479 case CT_MPEG_TRANSPORT_STREAM_DLNA: | |
480 return &mpeg_ts_mp_ll_aac_t; | |
481 case CT_MPEG_TRANSPORT_STREAM_DLNA_NO_TS: | |
482 return &mpeg_ts_mp_ll_aac; | |
483 default: | |
484 return NULL; | |
485 } | |
486 } | |
487 | |
488 /* check for Region: only Europe supports 25 fps (50i) */ | |
489 if (codecs->vs->r_frame_rate.num == 25 && | |
490 codecs->vs->r_frame_rate.den == 1) | |
491 { | |
492 for (i = 0; i < (int) (sizeof (mpeg_ts_valid_streams_eu_sd) | |
493 / sizeof (mpeg_ts_stream_t)); i++) | |
494 { | |
495 if (mpeg_ts_valid_streams_eu_sd[i].width == codecs->vc->width && | |
496 mpeg_ts_valid_streams_eu_sd[i].height == codecs->vc->height && | |
497 mpeg_ts_valid_streams_eu_sd[i].fps_num == 25 && | |
498 mpeg_ts_valid_streams_eu_sd[i].fps_den == 1) | |
499 { | |
500 if (is_mpeg_ts_audio_stream_ac3 (ctx, codecs) || | |
501 is_mpeg_ts_audio_stream_mp2 (ctx, codecs)) | |
502 { | |
503 switch (st) | |
504 { | |
505 case CT_MPEG_TRANSPORT_STREAM: | |
506 return &mpeg_ts_sd_eu_iso; | |
507 case CT_MPEG_TRANSPORT_STREAM_DLNA: | |
508 return &mpeg_ts_sd_eu_t; | |
509 case CT_MPEG_TRANSPORT_STREAM_DLNA_NO_TS: | |
510 return &mpeg_ts_sd_eu; | |
511 default: | |
512 return NULL; | |
513 } | |
514 } | |
515 | |
516 /* invalid audio stream */ | |
517 return NULL; | |
518 } | |
519 } | |
520 | |
521 /* invalid resolution */ | |
522 return NULL; | |
523 } | |
524 | |
525 /* now comes the stupid part: there's no way to differentiate region | |
526 codes between North America (NA) and Korea (KO) as both have exactly | |
527 the same requirements !! NA however supports additional stream formats | |
528 so all streams will be declared as NA ones (which shouldn't bother | |
529 the real KO ones). */ | |
530 | |
531 /* NA and KO streams can be either SD (Standard Definition) | |
532 or HD (High-Definition) and only support AC3 as audio stream codec */ | |
533 | |
534 /* maximum system bit rate is 19.3927 Mb/s */ | |
535 if (ctx->bit_rate > 19392700) | |
536 return NULL; | |
537 | |
538 if (codecs->ac->codec_id != CODEC_ID_AC3) | |
539 return NULL; | |
540 | |
541 /* 48 KHz only */ | |
542 if (codecs->ac->sample_rate != 48000) | |
543 return NULL; | |
544 | |
545 /* up to 5 audio channels */ | |
546 if (codecs->ac->channels > 5) | |
547 return NULL; | |
548 | |
549 /* audio bitrate up to 448 Kbps (or 640 for extended AC3) */ | |
550 if (codecs->ac->bit_rate > 448000) | |
551 xac3 = 1; | |
552 if (codecs->ac->bit_rate > 640000) | |
553 return NULL; | |
554 | |
555 /* look for compatible SD video stream */ | |
556 for (i = 0; i < (int) (sizeof (mpeg_ts_valid_streams_na_sd) | |
557 / sizeof (mpeg_ts_stream_t)); i++) | |
558 { | |
559 if (mpeg_ts_valid_streams_na_sd[i].width == codecs->vc->width && | |
560 mpeg_ts_valid_streams_na_sd[i].height == codecs->vc->height && | |
561 mpeg_ts_valid_streams_na_sd[i].fps_num | |
562 == codecs->vs->r_frame_rate.num && | |
563 mpeg_ts_valid_streams_na_sd[i].fps_den | |
564 == codecs->vs->r_frame_rate.num) | |
565 { | |
566 switch (st) | |
567 { | |
568 case CT_MPEG_TRANSPORT_STREAM: | |
569 return xac3 ? &mpeg_ts_sd_na_xac3_iso : &mpeg_ts_sd_na_iso; | |
570 case CT_MPEG_TRANSPORT_STREAM_DLNA: | |
571 return xac3 ? &mpeg_ts_sd_na_xac3_t : &mpeg_ts_sd_na_t; | |
572 case CT_MPEG_TRANSPORT_STREAM_DLNA_NO_TS: | |
573 return xac3 ? &mpeg_ts_sd_na_xac3 : &mpeg_ts_sd_na; | |
574 default: | |
575 return NULL; | |
576 } | |
577 } | |
578 } | |
579 | |
580 /* look for compatible HD video stream */ | |
581 for (i = 0; i < (int) (sizeof (mpeg_ts_valid_streams_na_hd) | |
582 / sizeof (mpeg_ts_stream_t)); i++) | |
583 { | |
584 if (mpeg_ts_valid_streams_na_hd[i].width == codecs->vc->width && | |
585 mpeg_ts_valid_streams_na_hd[i].height == codecs->vc->height && | |
586 mpeg_ts_valid_streams_na_hd[i].fps_num | |
587 == codecs->vs->r_frame_rate.num && | |
588 mpeg_ts_valid_streams_na_hd[i].fps_den | |
589 == codecs->vs->r_frame_rate.num) | |
590 { | |
591 switch (st) | |
592 { | |
593 case CT_MPEG_TRANSPORT_STREAM: | |
594 return xac3 ? &mpeg_ts_hd_na_xac3_iso : &mpeg_ts_hd_na_iso; | |
595 case CT_MPEG_TRANSPORT_STREAM_DLNA: | |
596 return xac3 ? &mpeg_ts_hd_na_xac3_t : &mpeg_ts_hd_na_t; | |
597 case CT_MPEG_TRANSPORT_STREAM_DLNA_NO_TS: | |
598 return xac3 ? &mpeg_ts_hd_na_xac3 : &mpeg_ts_hd_na; | |
599 default: | |
600 return NULL; | |
601 } | |
602 } | |
603 } | |
604 | |
605 /* no compliant resolution found */ | |
606 return NULL; | |
607 } | |
608 | |
609 static dlna_profile_t * | |
610 probe_mpeg2 (AVFormatContext *ctx, | |
611 dlna_container_type_t st, | |
612 av_codecs_t *codecs) | |
613 { | |
614 if (!stream_ctx_is_av (codecs)) | |
615 return NULL; | |
616 | |
617 /* check for MPEG-2 video codec */ | |
618 if (codecs->vc->codec_id != CODEC_ID_MPEG2VIDEO) | |
619 return NULL; | |
620 | |
621 switch (st) | |
622 { | |
623 case CT_MPEG_ELEMENTARY_STREAM: | |
624 return probe_mpeg_es (ctx, codecs); | |
625 case CT_MPEG_PROGRAM_STREAM: | |
626 return probe_mpeg_ps (ctx, codecs); | |
627 case CT_MPEG_TRANSPORT_STREAM: | |
628 case CT_MPEG_TRANSPORT_STREAM_DLNA: | |
629 case CT_MPEG_TRANSPORT_STREAM_DLNA_NO_TS: | |
630 return probe_mpeg_ts (ctx, codecs, st); | |
631 default: | |
632 break; | |
633 } | |
634 | |
635 return NULL; | |
636 } | |
637 | |
638 dlna_registered_profile_t dlna_profile_av_mpeg2 = { | |
639 .id = DLNA_PROFILE_AV_MPEG2, | |
640 .class = DLNA_CLASS_AV, | |
641 .extensions = "mpg,mpeg,mpe,m2v,mp2p,mp2t,ts,ps,pes", | |
642 .probe = probe_mpeg2, | |
643 .next = NULL | |
644 }; |