FFmpeg
Loading...
Searching...
No Matches
asfdec_f.c
Go to the documentation of this file.
1/*
2 * ASF compatible demuxer
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <inttypes.h>
23
25#include "libavutil/avassert.h"
26#include "libavutil/avstring.h"
27#include "libavutil/bswap.h"
28#include "libavutil/common.h"
29#include "libavutil/dict.h"
30#include "libavutil/internal.h"
32#include "libavutil/mem.h"
33#include "libavutil/opt.h"
34#include "avformat.h"
35#include "avio_internal.h"
36#include "avlanguage.h"
37#include "demux.h"
38#include "internal.h"
39#include "riff.h"
40#include "asf.h"
41#include "asfcrypt.h"
42
43typedef struct ASFPayload {
44 uint8_t type;
45 uint16_t size;
47
48typedef struct ASFStream {
49 int num;
50 unsigned char seq;
51 /* use for reading */
59
60 int ds_span; /* descrambling */
63
65
67
69 uint32_t palette[256];
70
73
75} ASFStream;
76
77typedef struct ASFContext {
78 const AVClass *class;
79 int asfid2avid[128]; ///< conversion table from asf ID 2 AVStream ID
80 ASFStream streams[128]; ///< it's max number and it's not that big
81 uint32_t stream_bitrates[128]; ///< max number of streams, bitrate for each (for streaming)
83 char stream_languages[128][6]; ///< max number of streams, language for each (RFC1766, e.g. en-US)
84 /* non streamed additonnal info */
85 /* packet filling */
87 /* only for reading */
88 uint64_t data_offset; ///< beginning of the first data packet
89 uint64_t data_object_offset; ///< data object offset (excl. GUID & size)
90 uint64_t data_object_size; ///< size of the data object
92
94
104 unsigned int packet_frag_offset;
105 unsigned int packet_frag_size;
112
114
115 ASFStream *asf_st; ///< currently decoded stream
116
119
121} ASFContext;
122
123static const AVOption options[] = {
124 { "no_resync_search", "Don't try to resynchronize by looking for a certain optional start code", offsetof(ASFContext, no_resync_search), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
125 { "export_xmp", "Export full XMP metadata", offsetof(ASFContext, export_xmp), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
126 { NULL },
127};
128
129static const AVClass asf_class = {
130 .class_name = "asf demuxer",
131 .item_name = av_default_item_name,
132 .option = options,
133 .version = LIBAVUTIL_VERSION_INT,
134};
135
136#undef NDEBUG
137#include <assert.h>
138
139#define FRAME_HEADER_SIZE 6
140// Fix Me! FRAME_HEADER_SIZE may be different.
141// (7 is known to be too large for GipsyGuitar.wmv)
142
143#ifdef DEBUG
144static const ff_asf_guid stream_bitrate_guid = { /* (http://get.to/sdp) */
145 0xce, 0x75, 0xf8, 0x7b, 0x8d, 0x46, 0xd1, 0x11, 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2
146};
147
148static const ff_asf_guid asf_audio_conceal_none = {
149 // 0x40, 0xa4, 0xf1, 0x49, 0x4ece, 0x11d0, 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6
150 // New value lifted from avifile
151 0x00, 0x57, 0xfb, 0x20, 0x55, 0x5B, 0xCF, 0x11, 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b
152};
153
154#define PRINT_IF_GUID(g, cmp) \
155 if (!ff_guidcmp(g, &(cmp))) \
156 av_log(NULL, AV_LOG_TRACE, "(GUID: %s) ", # cmp)
157
158static void print_guid(ff_asf_guid *g)
159{
160 int i;
161 PRINT_IF_GUID(g, ff_asf_header);
162 else PRINT_IF_GUID(g, ff_asf_file_header);
163 else PRINT_IF_GUID(g, ff_asf_stream_header);
164 else PRINT_IF_GUID(g, ff_asf_audio_stream);
165 else PRINT_IF_GUID(g, asf_audio_conceal_none);
166 else PRINT_IF_GUID(g, ff_asf_video_stream);
167 else PRINT_IF_GUID(g, ff_asf_video_conceal_none);
168 else PRINT_IF_GUID(g, ff_asf_command_stream);
169 else PRINT_IF_GUID(g, ff_asf_comment_header);
170 else PRINT_IF_GUID(g, ff_asf_codec_comment_header);
171 else PRINT_IF_GUID(g, ff_asf_codec_comment1_header);
172 else PRINT_IF_GUID(g, ff_asf_data_header);
173 else PRINT_IF_GUID(g, ff_asf_simple_index_header);
174 else PRINT_IF_GUID(g, ff_asf_head1_guid);
175 else PRINT_IF_GUID(g, ff_asf_head2_guid);
176 else PRINT_IF_GUID(g, ff_asf_my_guid);
177 else PRINT_IF_GUID(g, ff_asf_ext_stream_header);
178 else PRINT_IF_GUID(g, ff_asf_extended_content_header);
179 else PRINT_IF_GUID(g, ff_asf_ext_stream_embed_stream_header);
180 else PRINT_IF_GUID(g, ff_asf_ext_stream_audio_stream);
181 else PRINT_IF_GUID(g, ff_asf_metadata_header);
182 else PRINT_IF_GUID(g, ff_asf_metadata_library_header);
183 else PRINT_IF_GUID(g, ff_asf_marker_header);
184 else PRINT_IF_GUID(g, stream_bitrate_guid);
185 else PRINT_IF_GUID(g, ff_asf_language_guid);
186 else
187 av_log(NULL, AV_LOG_TRACE, "(GUID: unknown) ");
188 for (i = 0; i < 16; i++)
189 av_log(NULL, AV_LOG_TRACE, " 0x%02x,", (*g)[i]);
190 av_log(NULL, AV_LOG_TRACE, "}\n");
191}
192#undef PRINT_IF_GUID
193#else
194#define print_guid(g) while(0)
195#endif
196
197static int asf_probe(const AVProbeData *pd)
198{
199 /* check file header */
200 if (!ff_guidcmp(pd->buf, &ff_asf_header))
201 return AVPROBE_SCORE_MAX;
202 else
203 return 0;
204}
205
206static uint64_t get_value(AVIOContext *pb, int type)
207{
208 switch (type) {
209 case ASF_BOOL:
210 return avio_rl16(pb);
211 case ASF_DWORD:
212 return avio_rl32(pb);
213 case ASF_QWORD:
214 return avio_rl64(pb);
215 case ASF_WORD:
216 return avio_rl16(pb);
217 default:
218 return 0;
219 }
220}
221
223 const char *key, int type, int len)
224{
225 ASFContext *asf = s->priv_data;
226 char *value = NULL;
227 int64_t off = avio_tell(s->pb);
228#define LEN 22
229
230 av_assert0((unsigned)len < (INT_MAX - LEN) / 2);
231
232 if (!asf->export_xmp && !strncmp(key, "xmp", 3))
233 goto finish;
234
235 value = av_malloc(2 * len + LEN);
236 if (!value)
237 goto finish;
238
239 switch (type) {
240 case ASF_UNICODE:
241 avio_get_str16le(s->pb, len, value, 2 * len + 1);
242 break;
243 case -1:; // ASCII
244 int ret = ffio_read_size(s->pb, value, len);
245 if (ret < 0)
246 goto finish;
247 value[len]=0;
248 break;
249 case ASF_BYTE_ARRAY:
251 av_log(s, AV_LOG_VERBOSE, "Unsupported byte array in tag %s.\n", key);
252 goto finish;
253 case ASF_BOOL:
254 case ASF_DWORD:
255 case ASF_QWORD:
256 case ASF_WORD: {
257 uint64_t num = get_value(s->pb, type);
258 snprintf(value, LEN, "%"PRIu64, num);
259 break;
260 }
261 case ASF_GUID:
262 av_log(s, AV_LOG_DEBUG, "Unsupported GUID value in tag %s.\n", key);
263 goto finish;
264 default:
266 "Unsupported value type %d in tag %s.\n", type, key);
267 goto finish;
268 }
269 if (*value)
271
272finish:
273 av_freep(&value);
274 avio_seek(s->pb, off + len, SEEK_SET);
275}
276
278{
279 ASFContext *asf = s->priv_data;
280 AVIOContext *pb = s->pb;
281
282 ff_get_guid(pb, &asf->hdr.guid);
283 asf->hdr.file_size = avio_rl64(pb);
284 asf->hdr.create_time = avio_rl64(pb);
285 avio_rl64(pb); /* number of packets */
286 asf->hdr.play_time = avio_rl64(pb);
287 asf->hdr.send_time = avio_rl64(pb);
288 asf->hdr.preroll = avio_rl32(pb);
289 asf->hdr.ignore = avio_rl32(pb);
290 asf->hdr.flags = avio_rl32(pb);
291 asf->hdr.min_pktsize = avio_rl32(pb);
292 asf->hdr.max_pktsize = avio_rl32(pb);
293 if (asf->hdr.min_pktsize >= (1U << 29))
294 return AVERROR_INVALIDDATA;
295 asf->hdr.max_bitrate = avio_rl32(pb);
296 s->packet_size = asf->hdr.max_pktsize;
297
298 ff_dict_set_timestamp(&s->metadata, "creation_time", ff_asf_filetime_to_avtime(asf->hdr.create_time));
299 return 0;
300}
301
303{
304 ASFContext *asf = s->priv_data;
305 AVIOContext *pb = s->pb;
306 AVStream *st;
307 FFStream *sti;
308 ASFStream *asf_st;
310 enum AVMediaType type;
311 int type_specific_size, sizeX;
312 unsigned int tag1;
313 int64_t pos1, pos2, start_time;
314 int test_for_ext_stream_audio, is_dvr_ms_audio = 0;
315
316 pos1 = avio_tell(pb);
317
319 if (!st)
320 return AVERROR(ENOMEM);
321 sti = ffstream(st);
322 avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
323 start_time = asf->hdr.preroll;
324
325 if (!(asf->hdr.flags & 0x01)) { // if we aren't streaming...
326 int64_t fsize = avio_size(pb);
327 if (fsize <= 0 || (int64_t)asf->hdr.file_size <= 0 ||
328 FFABS(fsize - (int64_t)asf->hdr.file_size) < FFMIN(fsize, asf->hdr.file_size)/20)
329 st->duration = asf->hdr.play_time /
330 (10000000 / 1000) - start_time;
331 }
332 ff_get_guid(pb, &g);
333
334 test_for_ext_stream_audio = 0;
337 } else if (!ff_guidcmp(&g, &ff_asf_video_stream)) {
339 } else if (!ff_guidcmp(&g, &ff_asf_jfif_media)) {
342 } else if (!ff_guidcmp(&g, &ff_asf_command_stream)) {
345 test_for_ext_stream_audio = 1;
347 } else {
348 return -1;
349 }
350 ff_get_guid(pb, &g);
351 avio_skip(pb, 8); /* total_size */
352 type_specific_size = avio_rl32(pb);
353 avio_rl32(pb);
354 st->id = avio_rl16(pb) & 0x7f; /* stream id */
355 // mapping of asf ID to AV stream ID;
356 asf->asfid2avid[st->id] = s->nb_streams - 1;
357 asf_st = &asf->streams[st->id];
358
359 avio_rl32(pb);
360
361 if (test_for_ext_stream_audio) {
362 ff_get_guid(pb, &g);
365 is_dvr_ms_audio = 1;
366 ff_get_guid(pb, &g);
367 avio_rl32(pb);
368 avio_rl32(pb);
369 avio_rl32(pb);
370 ff_get_guid(pb, &g);
371 avio_rl32(pb);
372 }
373 }
374
375 st->codecpar->codec_type = type;
376 if (type == AVMEDIA_TYPE_AUDIO) {
377 int ret = ff_get_wav_header(s, pb, st->codecpar, type_specific_size, 0);
378 if (ret < 0)
379 return ret;
380 if (is_dvr_ms_audio) {
381 // codec_id and codec_tag are unreliable in dvr_ms
382 // files. Set them later by probing stream.
383 sti->request_probe = 1;
384 st->codecpar->codec_tag = 0;
385 }
388 else
390 /* We have to init the frame size at some point .... */
391 pos2 = avio_tell(pb);
392 if (size >= (pos2 + 8 - pos1 + 24)) {
393 asf_st->ds_span = avio_r8(pb);
394 asf_st->ds_packet_size = avio_rl16(pb);
395 asf_st->ds_chunk_size = avio_rl16(pb);
396 avio_rl16(pb); // ds_data_size
397 avio_r8(pb); // ds_silence_data
398 }
399 if (asf_st->ds_span > 1) {
400 if (!asf_st->ds_chunk_size ||
401 (asf_st->ds_packet_size / asf_st->ds_chunk_size <= 1) ||
402 asf_st->ds_packet_size % asf_st->ds_chunk_size)
403 asf_st->ds_span = 0; // disable descrambling
404 }
405 } else if (type == AVMEDIA_TYPE_VIDEO &&
406 size - (avio_tell(pb) - pos1 + 24) >= 51) {
407 avio_rl32(pb);
408 avio_rl32(pb);
409 avio_r8(pb);
410 avio_rl16(pb); /* size */
411 sizeX = avio_rl32(pb); /* size */
412 st->codecpar->width = avio_rl32(pb);
413 st->codecpar->height = avio_rl32(pb);
414 /* not available for asf */
415 avio_rl16(pb); /* panes */
416 st->codecpar->bits_per_coded_sample = avio_rl16(pb); /* depth */
417 tag1 = avio_rl32(pb);
418 avio_skip(pb, 20);
419 if (sizeX > 40) {
421 return AVERROR_INVALIDDATA;
422 st->codecpar->extradata_size = ffio_limit(pb, sizeX - 40);
425 if (!st->codecpar->extradata)
426 return AVERROR(ENOMEM);
428 }
429
430 /* Extract palette from extradata if bpp <= 8 */
431 /* This code assumes that extradata contains only palette */
432 /* This is true for all paletted codecs implemented in libavcodec */
433 if (st->codecpar->extradata_size && (st->codecpar->bits_per_coded_sample <= 8)) {
434#if HAVE_BIGENDIAN
435 int i;
436 for (i = 0; i < FFMIN(st->codecpar->extradata_size, AVPALETTE_SIZE) / 4; i++)
437 asf_st->palette[i] = av_bswap32(((uint32_t *)st->codecpar->extradata)[i]);
438#else
439 memcpy(asf_st->palette, st->codecpar->extradata,
441#endif
442 asf_st->palette_changed = 1;
443 }
444
445 st->codecpar->codec_tag = tag1;
447 if (!st->codecpar->codec_id)
449 if (tag1 == MKTAG('D', 'V', 'R', ' ')) {
451 /* issue658 contains wrong w/h and MS even puts a fake seq header
452 * with wrong w/h in extradata while a correct one is in the stream.
453 * maximum lameness */
454 st->codecpar->width =
455 st->codecpar->height = 0;
457 st->codecpar->extradata_size = 0;
458 }
465 }
466 pos2 = avio_tell(pb);
467 avio_skip(pb, size - (pos2 - pos1 + 24));
468
469 return 0;
470}
471
473{
474 ASFContext *asf = s->priv_data;
475 AVIOContext *pb = s->pb;
477 int ext_len, payload_ext_ct, stream_ct, i;
478 uint32_t leak_rate, stream_num;
479 unsigned int stream_languageid_index;
480
481 avio_rl64(pb); // starttime
482 avio_rl64(pb); // endtime
483 leak_rate = avio_rl32(pb); // leak-datarate
484 avio_rl32(pb); // bucket-datasize
485 avio_rl32(pb); // init-bucket-fullness
486 avio_rl32(pb); // alt-leak-datarate
487 avio_rl32(pb); // alt-bucket-datasize
488 avio_rl32(pb); // alt-init-bucket-fullness
489 avio_rl32(pb); // max-object-size
490 avio_rl32(pb); // flags (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits reserved)
491 stream_num = avio_rl16(pb); // stream-num
492
493 stream_languageid_index = avio_rl16(pb); // stream-language-id-index
494 if (stream_num < 128)
495 asf->streams[stream_num].stream_language_index = stream_languageid_index;
496
497 avio_rl64(pb); // avg frametime in 100ns units
498 stream_ct = avio_rl16(pb); // stream-name-count
499 payload_ext_ct = avio_rl16(pb); // payload-extension-system-count
500
501 if (stream_num < 128) {
502 asf->stream_bitrates[stream_num] = leak_rate;
503 asf->streams[stream_num].payload_ext_ct = 0;
504 }
505
506 for (i = 0; i < stream_ct; i++) {
507 avio_rl16(pb);
508 ext_len = avio_rl16(pb);
509 avio_skip(pb, ext_len);
510 }
511
512 for (i = 0; i < payload_ext_ct; i++) {
513 int size;
514 ff_get_guid(pb, &g);
515 size = avio_rl16(pb);
516 ext_len = avio_rl32(pb);
517 if (ext_len < 0)
518 return AVERROR_INVALIDDATA;
519 avio_skip(pb, ext_len);
520 if (stream_num < 128 && i < FF_ARRAY_ELEMS(asf->streams[stream_num].payload)) {
521 ASFPayload *p = &asf->streams[stream_num].payload[i];
522 p->type = g[0];
523 p->size = size;
524 av_log(s, AV_LOG_DEBUG, "Payload extension %x %d\n", g[0], p->size );
525 asf->streams[stream_num].payload_ext_ct ++;
526 }
527 }
528
529 return 0;
530}
531
533{
534 AVIOContext *pb = s->pb;
535 int len1, len2, len3, len4, len5;
536
537 len1 = avio_rl16(pb);
538 len2 = avio_rl16(pb);
539 len3 = avio_rl16(pb);
540 len4 = avio_rl16(pb);
541 len5 = avio_rl16(pb);
542 get_tag(s, &s->metadata, "title", 0, len1);
543 get_tag(s, &s->metadata, "author", 0, len2);
544 get_tag(s, &s->metadata, "copyright", 0, len3);
545 get_tag(s, &s->metadata, "comment", 0, len4);
546 avio_skip(pb, len5);
547
548 return 0;
549}
550
552{
553 AVIOContext *pb = s->pb;
554 ASFContext *asf = s->priv_data;
555 int desc_count, i, ret;
556
557 desc_count = avio_rl16(pb);
558 for (i = 0; i < desc_count; i++) {
559 int name_len, value_type, value_len;
560 char name[1024];
561
562 name_len = avio_rl16(pb);
563 if (name_len % 2) // must be even, broken lavf versions wrote len-1
564 name_len += 1;
565 if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) < name_len)
566 avio_skip(pb, name_len - ret);
567 value_type = avio_rl16(pb);
568 value_len = avio_rl16(pb);
569 if (!value_type && value_len % 2)
570 value_len += 1;
571 /* size of type 2 (BOOL) is 32bit for "Extended Content Description Object"
572 * but 16 bit for "Metadata Object" and "Metadata Library Object" */
573 if (value_type == ASF_BOOL)
574 value_type = ASF_DWORD;
575 /* My sample has that stream set to 0 maybe that mean the container.
576 * ASF stream count starts at 1. I am using 0 to the container value
577 * since it's unused. */
578 if (!strcmp(name, "AspectRatioX"))
579 asf->dar[0].num = get_value(s->pb, value_type);
580 else if (!strcmp(name, "AspectRatioY"))
581 asf->dar[0].den = get_value(s->pb, value_type);
582 else
583 get_tag(s, &s->metadata, name, value_type, value_len);
584 }
585
586 return 0;
587}
588
590{
591 AVIOContext *pb = s->pb;
592 ASFContext *asf = s->priv_data;
593 int j, ret;
594 int stream_count = avio_rl16(pb);
595 for (j = 0; j < stream_count; j++) {
596 char lang[6];
597 unsigned int lang_len = avio_r8(pb);
598 if ((ret = avio_get_str16le(pb, lang_len, lang,
599 sizeof(lang))) < lang_len)
600 avio_skip(pb, lang_len - ret);
601 if (j < 128)
602 av_strlcpy(asf->stream_languages[j], lang,
603 sizeof(*asf->stream_languages));
604 }
605
606 return 0;
607}
608
610{
611 AVIOContext *pb = s->pb;
612 ASFContext *asf = s->priv_data;
613 int n, stream_num, name_len_utf16, name_len_utf8;
614 unsigned int value_len;
615 int ret, i;
616 n = avio_rl16(pb);
617
618 for (i = 0; i < n; i++) {
619 uint8_t *name;
620 int value_type;
621
622 avio_rl16(pb); // lang_list_index
623 stream_num = avio_rl16(pb);
624 name_len_utf16 = avio_rl16(pb);
625 value_type = avio_rl16(pb); /* value_type */
626 value_len = avio_rl32(pb);
627
628 if (value_len >= (INT_MAX - LEN) / 2)
629 return AVERROR_INVALIDDATA;
630
631 name_len_utf8 = 2*name_len_utf16 + 1;
632 name = av_malloc(name_len_utf8);
633 if (!name)
634 return AVERROR(ENOMEM);
635
636 if ((ret = avio_get_str16le(pb, name_len_utf16, name, name_len_utf8)) < name_len_utf16)
637 avio_skip(pb, name_len_utf16 - ret);
638 av_log(s, AV_LOG_TRACE, "%d stream %d name_len %2d type %d len %4d <%s>\n",
639 i, stream_num, name_len_utf16, value_type, value_len, name);
640
641 if (!strcmp(name, "AspectRatioX")){
642 int aspect_x = get_value(s->pb, value_type);
643 if(stream_num < 128)
644 asf->dar[stream_num].num = aspect_x;
645 } else if(!strcmp(name, "AspectRatioY")){
646 int aspect_y = get_value(s->pb, value_type);
647 if(stream_num < 128)
648 asf->dar[stream_num].den = aspect_y;
649 } else {
650 get_tag(s, stream_num > 0 && stream_num < 128 ? &asf->streams[stream_num].metadata
651 : &s->metadata,
652 name, value_type, value_len);
653 }
654 av_freep(&name);
655 }
656
657 return 0;
658}
659
661{
662 AVIOContext *pb = s->pb;
663 ASFContext *asf = s->priv_data;
664 int i, count, name_len, ret;
665 char name[1024];
666
667 avio_rl64(pb); // reserved 16 bytes
668 avio_rl64(pb); // ...
669 count = avio_rl32(pb); // markers count
670 avio_rl16(pb); // reserved 2 bytes
671 name_len = avio_rl16(pb); // name length
672 avio_skip(pb, name_len);
673
674 for (i = 0; i < count; i++) {
675 int64_t pres_time;
676
677 if (avio_feof(pb))
678 return AVERROR_INVALIDDATA;
679
680 avio_rl64(pb); // offset, 8 bytes
681 pres_time = avio_rl64(pb); // presentation time
682 pres_time = av_sat_sub64(pres_time, asf->hdr.preroll * 10000LL);
683 avio_rl16(pb); // entry length
684 avio_rl32(pb); // send time
685 avio_rl32(pb); // flags
686 name_len = avio_rl32(pb); // name length
687 if ((unsigned)name_len > INT_MAX / 2)
688 return AVERROR_INVALIDDATA;
689 if ((ret = avio_get_str16le(pb, name_len * 2, name,
690 sizeof(name))) < name_len)
691 avio_skip(pb, name_len - ret);
692 avpriv_new_chapter(s, i, (AVRational) { 1, 10000000 }, pres_time,
694 }
695
696 return 0;
697}
698
700{
701 ASFContext *asf = s->priv_data;
703 AVIOContext *pb = s->pb;
704 int i;
705 int64_t gsize;
706
707 ff_get_guid(pb, &g);
708 if (ff_guidcmp(&g, &ff_asf_header))
709 return AVERROR_INVALIDDATA;
710 avio_rl64(pb);
711 avio_rl32(pb);
712 avio_r8(pb);
713 avio_r8(pb);
714 memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
715
716 for (i = 0; i<128; i++)
717 asf->streams[i].stream_language_index = 128; // invalid stream index means no language info
718
719 for (;;) {
720 uint64_t gpos = avio_tell(pb);
721 int ret = 0;
722 ff_get_guid(pb, &g);
723 gsize = avio_rl64(pb);
724 print_guid(&g);
726 asf->data_object_offset = avio_tell(pb);
727 /* If not streaming, gsize is not unlimited (how?),
728 * and there is enough space in the file.. */
729 if (!(asf->hdr.flags & 0x01) && gsize >= 100)
730 asf->data_object_size = gsize - 24;
731 else
732 asf->data_object_size = (uint64_t)-1;
733 break;
734 }
735 if (gsize < 24)
736 return AVERROR_INVALIDDATA;
739 } else if (!ff_guidcmp(&g, &ff_asf_stream_header)) {
741 } else if (!ff_guidcmp(&g, &ff_asf_comment_header)) {
743 } else if (!ff_guidcmp(&g, &ff_asf_language_guid)) {
747 } else if (!ff_guidcmp(&g, &ff_asf_metadata_header)) {
751 } else if (!ff_guidcmp(&g, &ff_asf_ext_stream_header)) {
753
754 // there could be an optional stream properties object to follow
755 // if so the next iteration will pick it up
756 continue;
757 } else if (!ff_guidcmp(&g, &ff_asf_head1_guid)) {
758 ff_get_guid(pb, &g);
759 avio_skip(pb, 6);
760 continue;
761 } else if (!ff_guidcmp(&g, &ff_asf_marker_header)) {
763 } else if (avio_feof(pb)) {
764 return AVERROR_EOF;
765 } else {
766 if (!s->keylen) {
769 unsigned int len;
771 "DRM protected stream detected, decoding will likely fail!\n");
772 len= avio_rl32(pb);
773 av_log(s, AV_LOG_DEBUG, "Secret data:\n");
774
775 if ((ret = av_get_packet(pb, pkt, len)) < 0)
776 return ret;
777 av_hex_dump_log(s, AV_LOG_DEBUG, pkt->data, pkt->size);
779
780 len= avio_rl32(pb);
781 if (len > UINT16_MAX)
782 return AVERROR_INVALIDDATA;
783 get_tag(s, &s->metadata, "ASF_Protection_Type", -1, len);
784
785 len= avio_rl32(pb);
786 if (len > UINT16_MAX)
787 return AVERROR_INVALIDDATA;
788 get_tag(s, &s->metadata, "ASF_Key_ID", -1, len);
789
790 len= avio_rl32(pb);
791 if (len > UINT16_MAX)
792 return AVERROR_INVALIDDATA;
793 get_tag(s, &s->metadata, "ASF_License_URL", -1, len);
796 "Ext DRM protected stream detected, decoding will likely fail!\n");
797 av_dict_set(&s->metadata, "encryption", "ASF Extended Content Encryption", 0);
798 } else if (!ff_guidcmp(&g, &ff_asf_digital_signature)) {
799 av_log(s, AV_LOG_INFO, "Digital signature detected!\n");
800 }
801 }
802 }
803 if (ret < 0)
804 return ret;
805
806 if (avio_tell(pb) != gpos + gsize)
808 "gpos mismatch our pos=%"PRIu64", end=%"PRId64"\n",
809 avio_tell(pb) - gpos, gsize);
810 avio_seek(pb, gpos + gsize, SEEK_SET);
811 }
812 ff_get_guid(pb, &g);
813 avio_rl64(pb);
814 avio_r8(pb);
815 avio_r8(pb);
816 if (avio_feof(pb))
817 return AVERROR_EOF;
818 asf->data_offset = avio_tell(pb);
819 asf->packet_size_left = 0;
820
821 for (i = 0; i < 128; i++) {
822 int stream_num = asf->asfid2avid[i];
823 if (stream_num >= 0) {
824 AVStream *st = s->streams[stream_num];
825 int ret = av_dict_copy(&st->metadata, asf->streams[i].metadata, 0);
826 if (ret < 0)
827 return ret;
829 if (!st->codecpar->bit_rate)
830 st->codecpar->bit_rate = asf->stream_bitrates[i];
831 if (asf->dar[i].num > 0 && asf->dar[i].den > 0) {
834 asf->dar[i].num, asf->dar[i].den, INT_MAX);
835 } else if ((asf->dar[0].num > 0) && (asf->dar[0].den > 0) &&
836 // Use ASF container value if the stream doesn't set AR.
840 asf->dar[0].num, asf->dar[0].den, INT_MAX);
841
842 av_log(s, AV_LOG_TRACE, "i=%d, st->codecpar->codec_type:%d, asf->dar %d:%d sar=%d:%d\n",
843 i, st->codecpar->codec_type, asf->dar[i].num, asf->dar[i].den,
845
846 // copy and convert language codes to the frontend
847 if (asf->streams[i].stream_language_index < 128) {
848 const char *rfc1766 = asf->stream_languages[asf->streams[i].stream_language_index];
849 if (rfc1766 && strlen(rfc1766) > 1) {
850 const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' }; // ignore country code if any
851 const char *iso6392 = ff_convert_lang_to(primary_tag,
853 if (iso6392)
854 av_dict_set(&st->metadata, "language", iso6392, 0);
855 }
856 }
857 }
858 }
859
861
862 return 0;
863}
864
865#define DO_2BITS(bits, var, defval) \
866 switch (bits & 3) { \
867 case 3: \
868 var = avio_rl32(pb); \
869 rsize += 4; \
870 break; \
871 case 2: \
872 var = avio_rl16(pb); \
873 rsize += 2; \
874 break; \
875 case 1: \
876 var = avio_r8(pb); \
877 rsize++; \
878 break; \
879 default: \
880 var = defval; \
881 break; \
882 }
883
884/**
885 * Load a single ASF packet into the demuxer.
886 * @param s demux context
887 * @param pb context to read data from
888 * @return 0 on success, <0 on error
889 */
891{
892 ASFContext *asf = s->priv_data;
893 uint32_t packet_length, padsize;
894 int rsize = 8;
895 int c, d, e, off;
896
897 if (asf->uses_std_ecc > 0) {
898 // if we do not know packet size, allow skipping up to 32 kB
899 off = 32768;
900 if (asf->no_resync_search)
901 off = 3;
902// else if (s->packet_size > 0 && !asf->uses_std_ecc)
903// off = (avio_tell(pb) - ffformatcontext(s)->data_offset) % s->packet_size + 3;
904
905 c = d = e = -1;
906 while (off-- > 0) {
907 c = d;
908 d = e;
909 e = avio_r8(pb);
910 if (c == 0x82 && !d && !e)
911 break;
912 }
913
914 if (c != 0x82) {
915 /* This code allows handling of -EAGAIN at packet boundaries (i.e.
916 * if the packet sync code above triggers -EAGAIN). This does not
917 * imply complete -EAGAIN handling support at random positions in
918 * the stream. */
919 if (pb->error == AVERROR(EAGAIN))
920 return AVERROR(EAGAIN);
921 if (!avio_feof(pb))
923 "ff asf bad header %x at:%"PRId64"\n", c, avio_tell(pb));
924 }
925 if ((c & 0x8f) == 0x82) {
926 if (d || e) {
927 if (!avio_feof(pb))
928 av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n");
929 return AVERROR_INVALIDDATA;
930 }
931 c = avio_r8(pb);
932 d = avio_r8(pb);
933 rsize += 3;
934 } else if(!avio_feof(pb)) {
935 avio_seek(pb, -1, SEEK_CUR); // FIXME
936 }
937 } else {
938 c = avio_r8(pb);
939 if (c & 0x80) {
940 rsize ++;
941 if (!(c & 0x60)) {
942 d = avio_r8(pb);
943 e = avio_r8(pb);
944 avio_seek(pb, (c & 0xF) - 2, SEEK_CUR);
945 rsize += c & 0xF;
946 }
947
948 if (c != 0x82)
949 avpriv_request_sample(s, "Invalid ECC byte");
950
951 if (!asf->uses_std_ecc)
952 asf->uses_std_ecc = (c == 0x82 && !d && !e) ? 1 : -1;
953
954 c = avio_r8(pb);
955 } else
956 asf->uses_std_ecc = -1;
957 d = avio_r8(pb);
958 }
959
960 asf->packet_flags = c;
961 asf->packet_property = d;
962
963 DO_2BITS(asf->packet_flags >> 5, packet_length, s->packet_size);
964 DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
965 DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length
966
967 // the following checks prevent overflows and infinite loops
968 if (!packet_length || packet_length >= (1U << 29)) {
970 "invalid packet_length %"PRIu32" at:%"PRId64"\n",
971 packet_length, avio_tell(pb));
972 return AVERROR_INVALIDDATA;
973 }
974 if (padsize >= packet_length) {
976 "invalid padsize %"PRIu32" at:%"PRId64"\n", padsize, avio_tell(pb));
977 return AVERROR_INVALIDDATA;
978 }
979
980 asf->packet_timestamp = avio_rl32(pb);
981 avio_rl16(pb); /* duration */
982 // rsize has at least 11 bytes which have to be present
983
984 if (asf->packet_flags & 0x01) {
985 asf->packet_segsizetype = avio_r8(pb);
986 rsize++;
987 asf->packet_segments = asf->packet_segsizetype & 0x3f;
988 } else {
989 asf->packet_segments = 1;
990 asf->packet_segsizetype = 0x80;
991 }
992 if (rsize > packet_length - padsize) {
993 asf->packet_size_left = 0;
995 "invalid packet header length %d for pktlen %"PRIu32"-%"PRIu32" at %"PRId64"\n",
996 rsize, packet_length, padsize, avio_tell(pb));
997 return AVERROR_INVALIDDATA;
998 }
999 asf->packet_size_left = packet_length - padsize - rsize;
1000 if (packet_length < asf->hdr.min_pktsize)
1001 padsize += asf->hdr.min_pktsize - packet_length;
1002 asf->packet_padsize = padsize;
1003 av_log(s, AV_LOG_TRACE, "packet: size=%d padsize=%d left=%d\n",
1004 s->packet_size, asf->packet_padsize, asf->packet_size_left);
1005 return 0;
1006}
1007
1008/**
1009 *
1010 * @return <0 if error
1011 */
1013{
1014 ASFContext *asf = s->priv_data;
1015 ASFStream *asfst;
1016 int rsize = 1;
1017 int num = avio_r8(pb);
1018 int i;
1019 int64_t ts0, ts1 av_unused;
1020
1021 asf->packet_segments--;
1022 asf->packet_key_frame = num >> 7;
1023 asf->stream_index = asf->asfid2avid[num & 0x7f];
1024 asfst = &asf->streams[num & 0x7f];
1025 // sequence should be ignored!
1026 DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
1027 DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
1029 av_log(asf, AV_LOG_TRACE, "key:%d stream:%d seq:%d offset:%d replic_size:%d num:%X packet_property %X\n",
1030 asf->packet_key_frame, asf->stream_index, asf->packet_seq,
1032 if (rsize+(int64_t)asf->packet_replic_size > asf->packet_size_left) {
1033 av_log(s, AV_LOG_ERROR, "packet_replic_size %d is invalid\n", asf->packet_replic_size);
1034 return AVERROR_INVALIDDATA;
1035 }
1036 if (asf->packet_replic_size >= 8) {
1037 int64_t end = avio_tell(pb) + asf->packet_replic_size;
1038 AVRational aspect;
1039 asfst->packet_obj_size = avio_rl32(pb);
1040 if (asfst->packet_obj_size >= (1 << 24) || asfst->packet_obj_size < 0) {
1041 av_log(s, AV_LOG_ERROR, "packet_obj_size %d invalid\n", asfst->packet_obj_size);
1042 asfst->packet_obj_size = 0;
1043 return AVERROR_INVALIDDATA;
1044 }
1045 asf->packet_frag_timestamp = avio_rl32(pb); // timestamp
1046
1047 for (i = 0; i < asfst->payload_ext_ct; i++) {
1048 ASFPayload *p = &asfst->payload[i];
1049 int size = p->size;
1050 int64_t payend;
1051 if (size == 0xFFFF)
1052 size = avio_rl16(pb);
1053 payend = avio_tell(pb) + size;
1054 if (payend > end) {
1055 av_log(s, AV_LOG_ERROR, "too long payload\n");
1056 break;
1057 }
1058 switch (p->type) {
1059 case 0x50:
1060// duration = avio_rl16(pb);
1061 break;
1062 case 0x54:
1063 aspect.num = avio_r8(pb);
1064 aspect.den = avio_r8(pb);
1065 if (aspect.num > 0 && aspect.den > 0 && asf->stream_index >= 0) {
1066 s->streams[asf->stream_index]->sample_aspect_ratio = aspect;
1067 }
1068 break;
1069 case 0x2A:
1070 avio_skip(pb, 8);
1071 ts0 = avio_rl64(pb);
1072 ts1 = avio_rl64(pb);
1073 if (ts0!= -1) asf->packet_frag_timestamp = ts0/10000;
1075 asf->ts_is_pts = 1;
1076 break;
1077 case 0x5B:
1078 case 0xB7:
1079 case 0xCC:
1080 case 0xC0:
1081 case 0xA0:
1082 //unknown
1083 break;
1084 }
1085 avio_seek(pb, payend, SEEK_SET);
1086 }
1087
1088 avio_seek(pb, end, SEEK_SET);
1089 rsize += asf->packet_replic_size; // FIXME - check validity
1090 } else if (asf->packet_replic_size == 1) {
1091 // multipacket - frag_offset is beginning timestamp
1093 asf->packet_frag_offset = 0;
1095
1096 asf->packet_time_delta = avio_r8(pb);
1097 rsize++;
1098 } else if (asf->packet_replic_size != 0) {
1099 av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n",
1100 asf->packet_replic_size);
1101 return AVERROR_INVALIDDATA;
1102 }
1103 if (asf->packet_flags & 0x01) {
1104 DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
1105 if (rsize > asf->packet_size_left) {
1106 av_log(s, AV_LOG_ERROR, "packet_replic_size is invalid\n");
1107 return AVERROR_INVALIDDATA;
1108 } else if (asf->packet_frag_size > asf->packet_size_left - rsize) {
1109 if (asf->packet_frag_size > asf->packet_size_left - rsize + asf->packet_padsize) {
1110 av_log(s, AV_LOG_ERROR, "packet_frag_size is invalid (%d>%d-%d+%d)\n",
1111 asf->packet_frag_size, asf->packet_size_left, rsize, asf->packet_padsize);
1112 return AVERROR_INVALIDDATA;
1113 } else {
1114 int diff = asf->packet_frag_size - (asf->packet_size_left - rsize);
1115 asf->packet_size_left += diff;
1116 asf->packet_padsize -= diff;
1117 }
1118 }
1119 } else {
1120 asf->packet_frag_size = asf->packet_size_left - rsize;
1121 }
1122 if (asf->packet_replic_size == 1) {
1124 if (asf->packet_multi_size > asf->packet_size_left)
1125 return AVERROR_INVALIDDATA;
1126 }
1127 asf->packet_size_left -= rsize;
1128
1129 return 0;
1130}
1131
1132/**
1133 * Parse data from individual ASF packets (which were previously loaded
1134 * with asf_get_packet()).
1135 * @param s demux context
1136 * @param pb context to read data from
1137 * @param pkt pointer to store packet data into
1138 * @return 0 if data was stored in pkt, <0 on error or 1 if more ASF
1139 * packets need to be loaded (through asf_get_packet())
1140 */
1142{
1143 ASFContext *asf = s->priv_data;
1144 ASFStream *asf_st = 0;
1145 for (;;) {
1146 int read;
1147 if (avio_feof(pb))
1148 return AVERROR_EOF;
1150 asf->packet_segments < 1 && asf->packet_time_start == 0) {
1151 int ret = asf->packet_size_left + asf->packet_padsize;
1152
1154 av_log(s, AV_LOG_WARNING, "Skip due to FRAME_HEADER_SIZE\n");
1155
1156 assert(ret >= 0);
1157 /* fail safe */
1158 avio_skip(pb, ret);
1159
1160 asf->packet_pos = avio_tell(pb);
1161 if (asf->data_object_size != (uint64_t)-1 &&
1162 (asf->packet_pos - asf->data_object_offset >= asf->data_object_size))
1163 return AVERROR_EOF; /* Do not exceed the size of the data object */
1164 return 1;
1165 }
1166 if (asf->packet_time_start == 0) {
1167 if (asf_read_frame_header(s, pb) < 0) {
1168 asf->packet_time_start = asf->packet_segments = 0;
1169 continue;
1170 }
1171 if (asf->stream_index < 0 ||
1172 s->streams[asf->stream_index]->discard >= AVDISCARD_ALL ||
1173 (!asf->packet_key_frame &&
1174 (s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY || asf->streams[s->streams[asf->stream_index]->id].skip_to_key))) {
1175 asf->packet_time_start = 0;
1176 /* unhandled packet (should not happen) */
1177 avio_skip(pb, asf->packet_frag_size);
1179 if (asf->stream_index < 0)
1180 av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n",
1181 asf->packet_frag_size);
1182 continue;
1183 }
1184 asf->asf_st = &asf->streams[s->streams[asf->stream_index]->id];
1185 if (!asf->packet_frag_offset)
1186 asf->asf_st->skip_to_key = 0;
1187 }
1188 asf_st = asf->asf_st;
1189 av_assert0(asf_st);
1190
1191 if (!asf_st->frag_offset && asf->packet_frag_offset) {
1192 av_log(s, AV_LOG_TRACE, "skipping asf data pkt with fragment offset for "
1193 "stream:%d, expected:%d but got %d from pkt)\n",
1194 asf->stream_index, asf_st->frag_offset,
1195 asf->packet_frag_offset);
1196 avio_skip(pb, asf->packet_frag_size);
1198 continue;
1199 }
1200
1201 if (asf->packet_replic_size == 1) {
1202 // frag_offset is here used as the beginning timestamp
1205 asf_st->packet_obj_size = asf->packet_frag_size = avio_r8(pb);
1206 asf->packet_size_left--;
1207 asf->packet_multi_size--;
1208 if (asf->packet_multi_size < asf_st->packet_obj_size) {
1209 asf->packet_time_start = 0;
1210 avio_skip(pb, asf->packet_multi_size);
1212 continue;
1213 }
1214 asf->packet_multi_size -= asf_st->packet_obj_size;
1215 }
1216
1217 if (asf_st->pkt.size != asf_st->packet_obj_size ||
1218 // FIXME is this condition sufficient?
1219 asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) {
1220 int ret;
1221
1222 if (asf_st->pkt.data) {
1224 "freeing incomplete packet size %d, new %d\n",
1225 asf_st->pkt.size, asf_st->packet_obj_size);
1226 asf_st->frag_offset = 0;
1227 av_packet_unref(&asf_st->pkt);
1228 }
1229 /* new packet */
1230 if ((ret = av_new_packet(&asf_st->pkt, asf_st->packet_obj_size)) < 0)
1231 return ret;
1232 asf_st->seq = asf->packet_seq;
1234 if (asf->ts_is_pts) {
1235 asf_st->pkt.pts = asf->packet_frag_timestamp - asf->hdr.preroll;
1236 } else
1237 asf_st->pkt.dts = asf->packet_frag_timestamp - asf->hdr.preroll;
1238 }
1239 asf_st->pkt.stream_index = asf->stream_index;
1240 asf_st->pkt.pos = asf_st->packet_pos = asf->packet_pos;
1241 asf_st->pkt_clean = 0;
1242
1243 if (asf_st->pkt.data && asf_st->palette_changed) {
1244 uint8_t *pal;
1247 if (!pal) {
1248 av_log(s, AV_LOG_ERROR, "Cannot append palette to packet\n");
1249 } else {
1250 memcpy(pal, asf_st->palette, AVPALETTE_SIZE);
1251 asf_st->palette_changed = 0;
1252 }
1253 }
1254 av_log(asf, AV_LOG_TRACE, "new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n",
1255 asf->stream_index, asf->packet_key_frame,
1256 asf_st->pkt.flags & AV_PKT_FLAG_KEY,
1257 s->streams[asf->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO,
1258 asf_st->packet_obj_size);
1259 if (s->streams[asf->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
1260 asf->packet_key_frame = 1;
1261 if (asf->packet_key_frame)
1262 asf_st->pkt.flags |= AV_PKT_FLAG_KEY;
1263 }
1264
1265 /* read data */
1266 av_log(asf, AV_LOG_TRACE, "READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
1267 s->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
1268 asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
1270 if (asf->packet_size_left < 0)
1271 continue;
1272
1273 if (asf->packet_frag_offset >= asf_st->pkt.size ||
1274 asf->packet_frag_size > asf_st->pkt.size - asf->packet_frag_offset) {
1276 "packet fragment position invalid %u,%u not in %u\n",
1278 asf_st->pkt.size);
1279 continue;
1280 }
1281
1282 if (asf->packet_frag_offset != asf_st->frag_offset && !asf_st->pkt_clean) {
1283 memset(asf_st->pkt.data + asf_st->frag_offset, 0, asf_st->pkt.size - asf_st->frag_offset);
1284 asf_st->pkt_clean = 1;
1285 }
1286
1287 read = avio_read(pb, asf_st->pkt.data + asf->packet_frag_offset,
1288 asf->packet_frag_size);
1289 if (read != asf->packet_frag_size) {
1290 if (read < 0 || asf->packet_frag_offset + read == 0)
1291 return read < 0 ? read : AVERROR_EOF;
1292
1293 if (asf_st->ds_span > 1) {
1294 // scrambling, we can either drop it completely or fill the remainder
1295 // TODO: should we fill the whole packet instead of just the current
1296 // fragment?
1297 memset(asf_st->pkt.data + asf->packet_frag_offset + read, 0,
1298 asf->packet_frag_size - read);
1299 read = asf->packet_frag_size;
1300 } else {
1301 // no scrambling, so we can return partial packets
1302 av_shrink_packet(&asf_st->pkt, asf->packet_frag_offset + read);
1303 }
1304 }
1305 if (s->key && s->keylen == 20)
1306 ff_asfcrypt_dec(s->key, asf_st->pkt.data + asf->packet_frag_offset,
1307 read);
1308 asf_st->frag_offset += read;
1309 /* test if whole packet is read */
1310 if (asf_st->frag_offset == asf_st->pkt.size) {
1311 // workaround for macroshit radio DVR-MS files
1312 if (s->streams[asf->stream_index]->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO &&
1313 asf_st->pkt.size > 100) {
1314 int i;
1315 for (i = 0; i < asf_st->pkt.size && !asf_st->pkt.data[i]; i++)
1316 ;
1317 if (i == asf_st->pkt.size) {
1318 av_log(s, AV_LOG_DEBUG, "discarding ms fart\n");
1319 asf_st->frag_offset = 0;
1320 av_packet_unref(&asf_st->pkt);
1321 continue;
1322 }
1323 }
1324
1325 /* return packet */
1326 if (asf_st->ds_span > 1) {
1327 if (asf_st->pkt.size != asf_st->ds_packet_size * asf_st->ds_span) {
1329 "pkt.size != ds_packet_size * ds_span (%d %d %d)\n",
1330 asf_st->pkt.size, asf_st->ds_packet_size,
1331 asf_st->ds_span);
1332 } else {
1333 /* packet descrambling */
1334 AVBufferRef *buf = av_buffer_alloc(asf_st->pkt.size +
1336 if (buf) {
1337 uint8_t *newdata = buf->data;
1338 int offset = 0;
1339 memset(newdata + asf_st->pkt.size, 0,
1341 while (offset < asf_st->pkt.size) {
1342 int off = offset / asf_st->ds_chunk_size;
1343 int row = off / asf_st->ds_span;
1344 int col = off % asf_st->ds_span;
1345 int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
1346 assert(offset + asf_st->ds_chunk_size <= asf_st->pkt.size);
1347 assert(idx + 1 <= asf_st->pkt.size / asf_st->ds_chunk_size);
1348 memcpy(newdata + offset,
1349 asf_st->pkt.data + idx * asf_st->ds_chunk_size,
1350 asf_st->ds_chunk_size);
1351 offset += asf_st->ds_chunk_size;
1352 }
1353 av_buffer_unref(&asf_st->pkt.buf);
1354 asf_st->pkt.buf = buf;
1355 asf_st->pkt.data = buf->data;
1356 }
1357 }
1358 }
1359 asf_st->frag_offset = 0;
1360 *pkt = asf_st->pkt;
1361 asf_st->pkt.buf = 0;
1362 asf_st->pkt.size = 0;
1363 asf_st->pkt.data = 0;
1364 asf_st->pkt.side_data_elems = 0;
1365 asf_st->pkt.side_data = NULL;
1366 break; // packet completed
1367 }
1368 }
1369 return 0;
1370}
1371
1373{
1374 ASFContext *asf = s->priv_data;
1375
1376 for (;;) {
1377 int ret;
1378
1379 /* parse cached packets, if any */
1380 if ((ret = asf_parse_packet(s, s->pb, pkt)) <= 0)
1381 return ret;
1382 if ((ret = asf_get_packet(s, s->pb)) < 0)
1383 assert(asf->packet_size_left < FRAME_HEADER_SIZE ||
1384 asf->packet_segments < 1);
1385 asf->packet_time_start = 0;
1386 }
1387}
1388
1389// Added to support seeking after packets have been read
1390// If information is not reset, read_packet fails due to
1391// leftover information from previous reads
1393{
1394 ASFContext *asf = s->priv_data;
1395 ASFStream *asf_st;
1396 int i;
1397
1398 asf->packet_size_left = 0;
1399 asf->packet_flags = 0;
1400 asf->packet_property = 0;
1401 asf->packet_timestamp = 0;
1402 asf->packet_segsizetype = 0;
1403 asf->packet_segments = 0;
1404 asf->packet_seq = 0;
1405 asf->packet_replic_size = 0;
1406 asf->packet_key_frame = 0;
1407 asf->packet_padsize = 0;
1408 asf->packet_frag_offset = 0;
1409 asf->packet_frag_size = 0;
1410 asf->packet_frag_timestamp = 0;
1411 asf->packet_multi_size = 0;
1412 asf->packet_time_delta = 0;
1413 asf->packet_time_start = 0;
1414
1415 for (i = 0; i < 128; i++) {
1416 asf_st = &asf->streams[i];
1417 av_packet_unref(&asf_st->pkt);
1418 asf_st->packet_obj_size = 0;
1419 asf_st->frag_offset = 0;
1420 asf_st->seq = 0;
1421 }
1422 asf->asf_st = NULL;
1423}
1424
1426{
1427 ASFContext *asf = s->priv_data;
1428 int i;
1429
1430 for (i = 0; i < 128; i++) {
1431 int j = asf->asfid2avid[i];
1432 ASFStream *asf_st = &asf->streams[i];
1433 if (j < 0 || s->streams[j]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
1434 continue;
1435
1436 asf_st->skip_to_key = 1;
1437 }
1438}
1439
1441{
1442 ASFContext *asf = s->priv_data;
1443
1445 for (int i = 0; i < 128; i++)
1447
1448 return 0;
1449}
1450
1451static int64_t asf_read_pts(AVFormatContext *s, int stream_index,
1452 int64_t *ppos, int64_t pos_limit)
1453{
1454 FFFormatContext *const si = ffformatcontext(s);
1455 ASFContext *asf = s->priv_data;
1456 AVPacket pkt1, *pkt = &pkt1;
1457 int64_t pts;
1458 int64_t pos = *ppos;
1459 int i;
1460 int64_t start_pos[FF_ARRAY_ELEMS(asf->streams)];
1461
1462 for (i = 0; i < FF_ARRAY_ELEMS(start_pos); i++)
1463 start_pos[i] = pos;
1464
1465 if (s->packet_size > 0)
1466 pos = (pos + s->packet_size - 1 - si->data_offset) /
1467 s->packet_size * s->packet_size +
1468 si->data_offset;
1469 *ppos = pos;
1470 if (avio_seek(s->pb, pos, SEEK_SET) < 0)
1471 return AV_NOPTS_VALUE;
1472
1475 for (;;) {
1476 if (av_read_frame(s, pkt) < 0) {
1477 av_log(s, AV_LOG_INFO, "asf_read_pts failed\n");
1478 return AV_NOPTS_VALUE;
1479 }
1480
1481 pts = pkt->dts;
1482
1483 if (pkt->flags & AV_PKT_FLAG_KEY) {
1484 AVStream *st = s->streams[pkt->stream_index];
1485
1486 pos = pkt->pos;
1487 av_add_index_entry(st, pos, pts, pkt->size,
1488 pos - start_pos[st->id] + 1, AVINDEX_KEYFRAME);
1489 start_pos[st->id] = pos + 1;
1490
1491 if (pkt->stream_index == stream_index) {
1493 break;
1494 }
1495 }
1497 }
1498
1499 *ppos = pos;
1500 return pts;
1501}
1502
1503static int asf_build_simple_index(AVFormatContext *s, int stream_index)
1504{
1505 ff_asf_guid g;
1506 ASFContext *asf = s->priv_data;
1507 int64_t current_pos = avio_tell(s->pb);
1508 int64_t ret;
1509
1510 if((ret = avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET)) < 0) {
1511 return ret;
1512 }
1513
1514 if ((ret = ff_get_guid(s->pb, &g)) < 0)
1515 goto end;
1516
1517 /* the data object can be followed by other top-level objects,
1518 * skip them until the simple index object is reached */
1520 int64_t gsize = avio_rl64(s->pb);
1521 if (gsize < 24 || avio_feof(s->pb)) {
1522 goto end;
1523 }
1524 avio_skip(s->pb, gsize - 24);
1525 if ((ret = ff_get_guid(s->pb, &g)) < 0)
1526 goto end;
1527 }
1528
1529 {
1530 int64_t itime, last_pos = -1;
1531 int pct, ict;
1532 int i;
1533 av_unused int64_t gsize = avio_rl64(s->pb);
1534 if ((ret = ff_get_guid(s->pb, &g)) < 0)
1535 goto end;
1536 itime = avio_rl64(s->pb);
1537 pct = avio_rl32(s->pb);
1538 ict = avio_rl32(s->pb);
1540 "itime:0x%"PRIx64", pct:%d, ict:%d\n", itime, pct, ict);
1541
1542 for (i = 0; i < ict; i++) {
1543 int pktnum = avio_rl32(s->pb);
1544 int pktct = avio_rl16(s->pb);
1545 int64_t pos = ffformatcontext(s)->data_offset + s->packet_size * (int64_t)pktnum;
1546 int64_t index_pts = FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
1547
1548 if (avio_feof(s->pb)) {
1550 goto end;
1551 }
1552
1553 if (pos != last_pos) {
1554 av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d pts: %"PRId64"\n",
1555 pktnum, pktct, index_pts);
1556 av_add_index_entry(s->streams[stream_index], pos, index_pts,
1557 s->packet_size, 0, AVINDEX_KEYFRAME);
1558 last_pos = pos;
1559 }
1560 }
1561 asf->index_read = ict > 1;
1562 }
1563end:
1564// if (avio_feof(s->pb)) {
1565// ret = 0;
1566// }
1567 avio_seek(s->pb, current_pos, SEEK_SET);
1568 return ret;
1569}
1570
1571static int asf_read_seek(AVFormatContext *s, int stream_index,
1572 int64_t pts, int flags)
1573{
1574 ASFContext *asf = s->priv_data;
1575 AVStream *st = s->streams[stream_index];
1576 FFStream *const sti = ffstream(st);
1577 int ret = 0;
1578
1579 if (s->packet_size <= 0)
1580 return -1;
1581
1582 /* Try using the protocol's read_seek if available */
1583 if (s->pb) {
1584 int64_t ret64 = avio_seek_time(s->pb, stream_index, pts, flags);
1585 if (ret64 >= 0)
1587 if (ret64 != AVERROR(ENOSYS))
1588 return ret64;
1589 }
1590
1591 /* explicitly handle the case of seeking to 0 */
1592 if (!pts) {
1594 avio_seek(s->pb, ffformatcontext(s)->data_offset, SEEK_SET);
1595 return 0;
1596 }
1597
1598 if (!asf->index_read) {
1599 ret = asf_build_simple_index(s, stream_index);
1600 if (ret < 0)
1601 asf->index_read = -1;
1602 }
1603
1604 if (asf->index_read > 0 && sti->index_entries) {
1606 if (index >= 0) {
1607 /* find the position */
1608 uint64_t pos = sti->index_entries[index].pos;
1609
1610 /* do the seek */
1611 av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos);
1612 if(avio_seek(s->pb, pos, SEEK_SET) < 0)
1613 return -1;
1615 skip_to_key(s);
1616 return 0;
1617 }
1618 }
1619 /* no index or seeking by index failed */
1620 if (ff_seek_frame_binary(s, stream_index, pts, flags) < 0)
1621 return -1;
1623 skip_to_key(s);
1624 return 0;
1625}
1626
1628 .p.name = "asf",
1629 .p.long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
1631 .p.priv_class = &asf_class,
1632 .priv_data_size = sizeof(ASFContext),
1633 .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
1640};
const FFInputFormat ff_asf_demuxer
Definition asfdec_f.c:1627
static void finish(void)
const AVMetadataConv ff_asf_metadata_conv[]
Definition asf.c:28
int ff_asf_handle_byte_array(AVFormatContext *s, const char *name, int val_len)
Handles both attached pictures as well as id3 tags.
Definition asf.c:145
const ff_asf_guid ff_asf_video_conceal_none
Definition asf_tags.c:55
const ff_asf_guid ff_asf_codec_comment1_header
Definition asf_tags.c:70
const ff_asf_guid ff_asf_video_stream
Definition asf_tags.c:47
const ff_asf_guid ff_asf_ext_stream_header
Definition asf_tags.c:35
const ff_asf_guid ff_asf_stream_header
Definition asf_tags.c:31
const ff_asf_guid ff_asf_command_stream
Definition asf_tags.c:59
const ff_asf_guid ff_asf_ext_stream_audio_stream
Definition asf_tags.c:98
const ff_asf_guid ff_asf_language_guid
Definition asf_tags.c:124
const ff_asf_guid ff_asf_header
Definition asf_tags.c:23
const ff_asf_guid ff_asf_audio_stream
Definition asf_tags.c:39
const ff_asf_guid ff_asf_simple_index_header
Definition asf_tags.c:90
const ff_asf_guid ff_asf_ext_stream_embed_stream_header
Definition asf_tags.c:94
const ff_asf_guid ff_asf_content_encryption
Definition asf_tags.c:128
const ff_asf_guid ff_asf_extended_content_header
Definition asf_tags.c:86
const ff_asf_guid ff_asf_head1_guid
Definition asf_tags.c:78
const ff_asf_guid ff_asf_head2_guid
Definition asf_tags.c:82
const ff_asf_guid ff_asf_marker_header
Definition asf_tags.c:110
const ff_asf_guid ff_asf_metadata_library_header
Definition asf_tags.c:106
static int64_t ff_asf_filetime_to_avtime(int64_t filetime)
Definition asf.h:123
const ff_asf_guid ff_asf_data_header
Definition asf_tags.c:74
const ff_asf_guid ff_asf_jfif_media
Definition asf_tags.c:51
const ff_asf_guid ff_asf_digital_signature
Definition asf_tags.c:136
const ff_asf_guid ff_asf_ext_content_encryption
Definition asf_tags.c:132
const ff_asf_guid ff_asf_codec_comment_header
Definition asf_tags.c:67
const ff_asf_guid ff_asf_my_guid
Definition asf_tags.c:120
const ff_asf_guid ff_asf_file_header
Definition asf_tags.c:27
const ff_asf_guid ff_asf_comment_header
Definition asf_tags.c:63
@ ASF_UNICODE
Definition asf.h:30
@ ASF_BOOL
Definition asf.h:32
@ ASF_QWORD
Definition asf.h:34
@ ASF_BYTE_ARRAY
Definition asf.h:31
@ ASF_DWORD
Definition asf.h:33
@ ASF_WORD
Definition asf.h:35
@ ASF_GUID
Definition asf.h:36
const ff_asf_guid ff_asf_metadata_header
Definition asf_tags.c:102
void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len)
Definition asfcrypt.c:148
#define LEN
static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
Definition asfdec_f.c:302
static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb)
Definition asfdec_f.c:1012
static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
Definition asfdec_f.c:1451
static int asf_read_marker(AVFormatContext *s)
Definition asfdec_f.c:660
static void asf_reset_header(AVFormatContext *s)
Definition asfdec_f.c:1392
static int asf_read_header(AVFormatContext *s)
Definition asfdec_f.c:699
static int asf_read_file_properties(AVFormatContext *s)
Definition asfdec_f.c:277
static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition asfdec_f.c:1372
#define print_guid(g)
Definition asfdec_f.c:194
static const AVClass asf_class
Definition asfdec_f.c:129
#define DO_2BITS(bits, var, defval)
Definition asfdec_f.c:865
static int asf_build_simple_index(AVFormatContext *s, int stream_index)
Definition asfdec_f.c:1503
static int asf_read_content_desc(AVFormatContext *s)
Definition asfdec_f.c:532
static int asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt)
Parse data from individual ASF packets (which were previously loaded with asf_get_packet()).
Definition asfdec_f.c:1141
static void get_tag(AVFormatContext *s, AVDictionary **metadata, const char *key, int type, int len)
Definition asfdec_f.c:222
static void skip_to_key(AVFormatContext *s)
Definition asfdec_f.c:1425
static int asf_get_packet(AVFormatContext *s, AVIOContext *pb)
Load a single ASF packet into the demuxer.
Definition asfdec_f.c:890
static int asf_probe(const AVProbeData *pd)
Definition asfdec_f.c:197
static uint64_t get_value(AVIOContext *pb, int type)
Definition asfdec_f.c:206
static int asf_read_ext_stream_properties(AVFormatContext *s)
Definition asfdec_f.c:472
static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
Definition asfdec_f.c:1571
static int asf_read_language_list(AVFormatContext *s)
Definition asfdec_f.c:589
static int asf_read_close(AVFormatContext *s)
Definition asfdec_f.c:1440
static int asf_read_ext_content_desc(AVFormatContext *s)
Definition asfdec_f.c:551
static int asf_read_metadata(AVFormatContext *s)
Definition asfdec_f.c:609
static int64_t fsize(FILE *f)
Definition audiomatch.c:29
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:865
Main libavformat public API header.
#define AVINDEX_KEYFRAME
Definition avformat.h:630
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:485
#define AVFMT_NOGENSEARCH
Format does not allow to fall back on generic search.
Definition avformat.h:507
#define AVFMT_NOBINSEARCH
Format does not allow to fall back on binary search via read_timestamp.
Definition avformat.h:506
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition utils.c:98
@ AVSTREAM_PARSE_FULL_ONCE
full parsing and repack of the first frame only, only implemented for H.264 currently
Definition avformat.h:616
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition avformat.h:613
@ AVSTREAM_PARSE_NONE
Definition avformat.h:612
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition aviobuf.c:326
int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a UTF-16 string from pb and convert it to UTF-8.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:507
unsigned int avio_rl16(AVIOContext *s)
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:620
unsigned int avio_rl32(AVIOContext *s)
int64_t avio_seek_time(AVIOContext *h, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp relative to some component stream.
Definition aviobuf.c:1203
int avio_r8(AVIOContext *s)
Definition aviobuf.c:611
uint64_t avio_rl64(AVIOContext *s)
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:674
int ffio_limit(AVIOContext *s, int size)
Definition aviobuf.c:1032
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
const char * ff_convert_lang_to(const char *lang, enum AVLangCodespace target_codespace)
Convert a language code to a target codespace.
Definition avlanguage.c:741
@ AV_LANG_ISO639_2_BIBL
Definition avlanguage.h:28
static uint32_t BS_FUNC read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
byte swapping routines
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
static int read_probe(const AVProbeData *p)
Definition cdg.c:30
common internal and external API header
#define av_sat_sub64
Definition common.h:142
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
#define FRAME_HEADER_SIZE
Definition cpia.c:31
AVChapter * avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
Definition demux_utils.c:46
int ff_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags)
Perform a binary search using av_index_search_timestamp() and FFInputFormat.read_timestamp().
Definition seek.c:290
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
Definition demux.h:35
void ff_read_frame_flush(AVFormatContext *s)
Flush the frame reader.
Definition seek.c:801
static AVPacket * pkt
Public dictionary API.
double value
Definition eval.c:102
const char * key
int ret
Definition ffplay.c:391
static int64_t start_time
Definition ffplay.c:358
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition opt.h:355
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_CODEC_ID_H264
Definition codec_id.h:77
@ AV_CODEC_ID_HEVC
Definition codec_id.h:223
@ AV_CODEC_ID_AAC
Definition codec_id.h:460
@ AV_CODEC_ID_MPEG4
Definition codec_id.h:62
@ AV_CODEC_ID_MJPEG
Definition codec_id.h:57
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition codec_id.h:52
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
@ AVDISCARD_ALL
discard all
Definition defs.h:246
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition defs.h:245
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
Definition packet.h:47
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:435
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
Definition packet.c:231
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:657
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition packet.c:113
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition packet.c:98
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition demux.c:1645
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
Definition seek.c:122
void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size)
Send a nice hexadecimal dump of a buffer to the log.
Definition dump.c:89
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition seek.c:245
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:140
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition buffer.c:78
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition dict.c:236
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition dict.c:250
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:87
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition log.h:236
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:247
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition rational.c:35
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
AVMediaType
Definition avutil.h:198
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition avutil.h:202
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition avutil.h:199
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition avstring.c:85
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int index
Definition gxfenc.c:90
enum MPFType type
Definition jpegmpfenc.c:55
unsigned offset
Definition libaomenc.c:763
int ff_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t timestamp)
Set a dictionary value to an ISO-8601 compliant timestamp string.
Definition utils.c:626
static av_always_inline FFStream * ffstream(AVStream *st)
Definition internal.h:384
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition internal.h:135
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition utils.c:143
Macro definitions for various function/variable attributes.
#define av_unused
Definition attributes.h:164
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
static av_cold int read_close(AVFormatContext *ctx)
Definition libcdio.c:143
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition libcdio.c:151
#define FFMIN(a, b)
Definition macros.h:49
#define MKTAG(a, b, c, d)
Definition macros.h:55
#define FFMAX(a, b)
Definition macros.h:47
Memory handling functions.
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition metadata.c:26
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
#define AVPALETTE_SIZE
Definition pixfmt.h:32
const char * name
Definition qsvenc.c:142
const AVCodecTag ff_codec_bmp_tags_unofficial[]
Definition riff.c:520
const AVCodecTag ff_codec_bmp_tags[]
Definition riff.c:36
internal header for RIFF based (de)muxers do NOT include this in end user applications
static av_always_inline int ff_guidcmp(const void *g1, const void *g2)
Definition riff.h:122
int ff_get_guid(AVIOContext *s, ff_asf_guid *g)
Definition riffdec.c:33
int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int size, int big_endian)
Definition riffdec.c:141
uint8_t ff_asf_guid[16]
Definition riff.h:96
#define av_bswap32
Definition bswap.h:47
static int64_t read_timestamp(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit, int64_t(*read_timestamp)(struct AVFormatContext *, int, int64_t *, int64_t))
Definition seek.c:281
#define FF_ARRAY_ELEMS(a)
unsigned int pos
Definition spdifenc.c:431
char stream_languages[128][6]
max number of streams, language for each (RFC1766, e.g. en-US)
Definition asfdec_f.c:83
unsigned int packet_frag_size
Definition asfdec_f.c:105
int packet_padsize
Definition asfdec_f.c:103
int packet_multi_size
Definition asfdec_f.c:108
ASFStream streams[128]
it's max number and it's not that big
Definition asfdec_f.c:80
int export_xmp
Definition asfdec_f.c:118
int packet_replic_size
Definition asfdec_f.c:101
AVRational dar[128]
Definition asfdec_f.c:82
int packet_key_frame
Definition asfdec_f.c:102
int64_t packet_frag_timestamp
Definition asfdec_f.c:106
int packet_property
Definition asfdec_f.c:96
uint64_t data_offset
beginning of the first data packet
Definition asfdec_f.c:88
int packet_flags
Definition asfdec_f.c:95
ASFStream * asf_st
currently decoded stream
Definition asfdec_f.c:115
ASFMainHeader hdr
Definition asfdec_f.c:93
uint64_t data_object_offset
data object offset (excl. GUID & size)
Definition asfdec_f.c:89
int asfid2avid[128]
conversion table from asf ID 2 AVStream ID
Definition asfdec_f.c:79
int packet_size_left
Definition asfdec_f.c:86
int packet_timestamp
Definition asfdec_f.c:97
int index_read
Definition asfdec_f.c:91
int packet_seq
Definition asfdec_f.c:100
int stream_index
Definition asfdec_f.c:113
int64_t packet_time_start
Definition asfdec_f.c:110
int no_resync_search
Definition asfdec_f.c:117
uint32_t stream_bitrates[128]
max number of streams, bitrate for each (for streaming)
Definition asfdec_f.c:81
int ts_is_pts
Definition asfdec_f.c:107
int packet_segsizetype
Definition asfdec_f.c:98
unsigned int packet_frag_offset
Definition asfdec_f.c:104
uint64_t data_object_size
size of the data object
Definition asfdec_f.c:90
int64_t packet_pos
Definition asfdec_f.c:111
int uses_std_ecc
Definition asfdec_f.c:120
int packet_time_delta
Definition asfdec_f.c:109
int packet_segments
Definition asfdec_f.c:99
uint64_t create_time
time of creation, in 100-nanosecond units since 1.1.1601 invalid if broadcasting
Definition asf.h:43
uint32_t min_pktsize
size of a data packet invalid if broadcasting
Definition asf.h:55
uint32_t ignore
preroll is 64 bits - but let's just ignore it
Definition asf.h:51
ff_asf_guid guid
generated by client computer
Definition asf.h:40
uint32_t max_pktsize
shall be the same as for min_pktsize invalid if broadcasting
Definition asf.h:57
uint64_t send_time
time to send file, in 100-nanosecond units invalid if broadcasting (could be ignored)
Definition asf.h:47
uint32_t max_bitrate
bandwidth of stream in bps should be the sum of bitrates of the individual media streams
Definition asf.h:59
uint32_t flags
0x01 - broadcast 0x02 - seekable rest is reserved should be 0
Definition asf.h:52
uint64_t file_size
in bytes invalid if broadcasting
Definition asf.h:41
uint64_t play_time
play time, in 100-nanosecond units invalid if broadcasting
Definition asf.h:45
uint32_t preroll
timestamp of the first packet, in milliseconds if nonzero - subtract from time
Definition asf.h:49
uint8_t type
Definition asfdec_f.c:44
uint16_t size
Definition asfdec_f.c:45
int payload_ext_ct
Definition asfdec_f.c:71
unsigned char seq
Definition asfdec_f.c:50
AVPacket pkt
Definition asfdec_f.c:52
int ds_packet_size
Definition asfdec_f.c:61
uint16_t stream_language_index
Definition asfdec_f.c:66
int skip_to_key
Definition asfdec_f.c:57
int frag_offset
Definition asfdec_f.c:53
int ds_span
Definition asfdec_f.c:60
AVDictionary * metadata
Definition asfdec_f.c:74
int64_t packet_pos
Definition asfdec_f.c:64
int ds_chunk_size
Definition asfdec_f.c:62
int64_t duration
Definition asfdec_f.c:56
int num
Definition asfdec_f.c:49
int pkt_clean
Definition asfdec_f.c:58
int palette_changed
Definition asfdec_f.c:68
uint32_t palette[256]
Definition asfdec_f.c:69
int packet_obj_size
Definition asfdec_f.c:54
ASFPayload payload[8]
Definition asfdec_f.c:72
int timestamp
Definition asfdec_f.c:55
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
Describe the class of an AVClass context structure.
Definition log.h:76
int extradata_size
Size of the extradata content in bytes.
Definition codec_par.h:75
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition codec_par.h:113
int width
The width of the video frame in pixels.
Definition codec_par.h:143
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition codec_par.h:99
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition codec_par.h:61
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
Format I/O context.
Definition avformat.h:1401
Bytestream IO Context.
Definition avio.h:160
int error
contains the error code or 0 if no error happened
Definition avio.h:239
int64_t pos
Definition avformat.h:623
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:587
int stream_index
Definition packet.h:612
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition packet.h:593
int flags
A combination of AV_PKT_FLAG values.
Definition packet.h:616
int size
Definition packet.h:611
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition packet.h:603
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition packet.h:609
uint8_t * data
Definition packet.h:610
int64_t pos
byte position in stream, -1 if unknown
Definition packet.h:630
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Definition packet.h:621
int side_data_elems
Definition packet.h:622
This structure contains the data a format has to probe a file.
Definition avformat.h:473
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition avformat.h:475
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
Stream structure.
Definition avformat.h:768
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:791
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition avformat.h:846
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition avformat.h:827
AVDictionary * metadata
Definition avformat.h:848
int id
Format-specific stream ID.
Definition avformat.h:780
int64_t data_offset
offset of the first packet
Definition internal.h:89
AVPacket * parse_pkt
The generic code uses this as a temporary packet to parse packets or for muxing, especially flushing.
Definition internal.h:104
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
Definition internal.h:210
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition internal.h:196
enum AVStreamParseType need_parsing
Definition internal.h:340
#define av_mallocz(s)
#define avpriv_request_sample(...)
#define av_freep(p)
#define av_log(a,...)
int num
Definition error.c:23
static int64_t pts
int size
const char * g
Definition vf_curves.c:128
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
int len
static double c[64]