Quoting Alexandra Hájková (2015-03-05 16:33:29)
> +
> +static int asf_read_properties(AVFormatContext *s, const GUIDParseTable *g)
> +{
> + ASFContext *asf = s->priv_data;
> + AVIOContext *pb = s->pb;
> + uint64_t nb_packets, creation_date;
> + uint32_t max_packet_size;
> + struct tm tmbuf;
> + struct tm *tm;
> + char buf[100];
> +
> + avio_rl64(pb); // read object size
> + avio_skip(pb, 16); // skip File ID
> + avio_skip(pb, 8); // skip File size
> + creation_date = avio_rl64(pb);
> + if (!(asf->b_flags & IS_BROADCAST)) {
> + // creation date is in 100 ns units from 1 Jan 1601, conversion to s
> + creation_date /= 10000000;
> + // there are 11644473600 seconds between 1 Jan 1601 and 1 Jan 1970
> + creation_date -= 11644473600;
> + tm = gmtime_r(&creation_date, &tmbuf);
> + if (tm) {
> + if (!strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm))
> + buf[0] = '\0';
> + } else
> + buf[0] = '\0';
> + }
> + if (av_dict_set(&s->metadata, "creation date", buf, 0) < 0)
buf looks potentially uninitialized to me.
Also, other demuxers call this 'creation_time'.
> + av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");
> + nb_packets = avio_rl64(pb);
> + asf->duration = avio_rl64(pb) / 10000; // stream duration
> + avio_skip(pb, 8); // skip send duration
> + asf->preroll = avio_rl64(pb);
> + asf->b_flags = avio_rl32(pb);
> + avio_skip(pb, 4); // skip minimal packet size
> + max_packet_size = avio_rl32(pb);
> + avio_skip(pb, 4); // skip max_bitrate
> + asf->nb_packets = nb_packets;
> + asf->packet_size = max_packet_size;
Why are some context value assigned immediately and others at the end?
>
> return 0;
> }
>
> -static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
> +static int parse_video_info(AVIOContext *pb, AVStream *st)
> +{
> + uint16_t size;
> + unsigned int tag;
> +
> + st->codec->width = avio_rl32(pb);
> + st->codec->height = avio_rl32(pb);
> + avio_skip(pb, 1); // skip reserved flags
> + size = avio_rl16(pb); // size of the Format Data
> + tag = ff_get_bmp_header(pb, st);
> + st->codec->codec_tag = tag;
> + st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag);
> +
> + if (size > BMP_HEADER_SIZE) {
> + int ret;
> + st->codec->extradata_size = size - BMP_HEADER_SIZE;
> + if (!(st->codec->extradata = av_malloc(st->codec->extradata_size +
> +
> FF_INPUT_BUFFER_PADDING_SIZE)))
The padding must be zeroed.
> + return AVERROR(ENOMEM);
> + if ((ret = avio_read(pb, st->codec->extradata,
> + st->codec->extradata_size)) < 0)
> + return ret;
> + }
> + return 0;
> +}
> +
> +static int asf_read_stream_properties(AVFormatContext *s, const
> GUIDParseTable *g)
> {
> ASFContext *asf = s->priv_data;
> AVIOContext *pb = s->pb;
> + uint64_t size;
> + uint32_t err_data_len, ts_data_len; // time specific data length
type
> + uint16_t flags;
> + ff_asf_guid stream_type;
> + enum AVMediaType type;
> + int i, ret;
> + uint8_t stream_index, *ts_data;
> AVStream *st;
> ASFStream *asf_st;
> - ff_asf_guid g;
> - enum AVMediaType type;
> - int type_specific_size, sizeX;
> - unsigned int tag1;
> - int64_t pos1, pos2, start_time;
> - int test_for_ext_stream_audio, is_dvr_ms_audio = 0;
>
> - if (s->nb_streams == ASF_MAX_STREAMS) {
> - av_log(s, AV_LOG_ERROR, "too many streams\n");
> - return AVERROR(EINVAL);
> - }
> + // ASF file must not contain more than 128 streams according to the
> specification
> + if (asf->nb_streams >= ASF_MAX_STREAMS)
> + return AVERROR_INVALIDDATA;
> +
> + size = avio_rl64(pb);
> + ff_get_guid(pb, &stream_type);
> + if (!ff_guidcmp(&stream_type, &ff_asf_audio_stream))
> + type = AVMEDIA_TYPE_AUDIO;
> + else if (!ff_guidcmp(&stream_type, &ff_asf_video_stream))
> + type = AVMEDIA_TYPE_VIDEO;
> + else if (!ff_guidcmp(&stream_type, &ff_asf_jfif_media))
> + type = AVMEDIA_TYPE_VIDEO;
> + else if (!ff_guidcmp(&stream_type, &ff_asf_command_stream))
> + type = AVMEDIA_TYPE_DATA;
> + else if (!ff_guidcmp(&stream_type,
> + &ff_asf_ext_stream_embed_stream_header))
> + type = AVMEDIA_TYPE_UNKNOWN;
> + else
> + return AVERROR_INVALIDDATA;
>
> - pos1 = avio_tell(pb);
> + ff_get_guid(pb, &stream_type); // error correction type
> + asf->time_offset = avio_rl64(pb);
> + ts_data_len = avio_rl32(pb);
> + err_data_len = avio_rl32(pb);
> + flags = avio_rl16(pb); // bit 15 - Encrypted Content
> +
> + stream_index = flags & ASF_STREAM_NUM;
> + for (i = 0; i < asf->nb_streams; i++)
> + if (stream_index == asf->asf_st[i]->stream_index) {
> + av_log(s, AV_LOG_WARNING,
> + "Duplicate stream found, this stream will be ignored.\n");
> + align_position(pb, asf->offset, size);
> + return 0;
> + }
>
> st = avformat_new_stream(s, NULL);
> if (!st)
> return AVERROR(ENOMEM);
> - avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
> - asf_st = av_mallocz(sizeof(ASFStream));
> + avpriv_set_pts_info(st, 32, 1, 1000); // pts should be dword, in
> milliseconds
> + st->codec->codec_type = type;
> + asf->asf_st[asf->nb_streams] = av_mallocz(sizeof(*asf_st));
> + asf_st = asf->asf_st[asf->nb_streams];
The second assignment should be after the check.
> if (!asf_st)
> return AVERROR(ENOMEM);
> - st->priv_data = asf_st;
> - st->start_time = 0;
> - start_time = asf->hdr.preroll;
> -
> - asf_st->stream_language_index = 128; // invalid stream index means no
> language info
> -
> - if (!(asf->hdr.flags & 0x01)) { // if we aren't streaming...
> - st->duration = asf->hdr.play_time /
> - (10000000 / 1000) - start_time;
> + asf_st->stream_index = stream_index;
> + asf_st->index = st->index;
> + asf_st->indexed = 0;
> + st->id = flags & ASF_STREAM_NUM;
> + asf_st->pkt = av_mallocz(sizeof(*asf_st->pkt));
> + if (!asf_st->pkt)
> + return AVERROR(ENOMEM);
> + av_init_packet(&asf_st->pkt->avpkt);
> + asf_st->pkt->data_size = 0;
> + avio_skip(pb, 4); // skip reserved field
> + if (!ts_data_len) {
> + av_log(s, AV_LOG_WARNING, "Suspicious data found! Stream will be
> ignored.\n");
> + align_position(pb, asf->offset, size);
> + return 0;
> }
> - ff_get_guid(pb, &g);
>
> - test_for_ext_stream_audio = 0;
> - if (!ff_guidcmp(&g, &ff_asf_audio_stream)) {
> - type = AVMEDIA_TYPE_AUDIO;
> - } else if (!ff_guidcmp(&g, &ff_asf_video_stream)) {
> - type = AVMEDIA_TYPE_VIDEO;
> - } else if (!ff_guidcmp(&g, &ff_asf_jfif_media)) {
> - type = AVMEDIA_TYPE_VIDEO;
> - st->codec->codec_id = AV_CODEC_ID_MJPEG;
> - } else if (!ff_guidcmp(&g, &ff_asf_command_stream)) {
> - type = AVMEDIA_TYPE_DATA;
> - } else if (!ff_guidcmp(&g, &ff_asf_ext_stream_embed_stream_header)) {
> - test_for_ext_stream_audio = 1;
> - type = AVMEDIA_TYPE_UNKNOWN;
> - } else {
> - return -1;
> + ts_data = av_malloc(ts_data_len);
> + if (!ts_data)
> + return AVERROR(ENOMEM);
> + switch (type) {
> + case AVMEDIA_TYPE_AUDIO:
> + asf_st->type = AVMEDIA_TYPE_AUDIO;
> + if ((ret = ff_get_wav_header(pb, st->codec, ts_data_len)) < 0)
> + goto fail;
> + break;
> + case AVMEDIA_TYPE_VIDEO:
> + asf_st->type = AVMEDIA_TYPE_VIDEO;
> + if ((ret = parse_video_info(pb, st)) < 0)
> + goto fail;
> + break;
> + default:
> + if ((ret = avio_read(pb, ts_data, ts_data_len)) < 0)
> + goto fail;
> + break;
It does not seem to me that allocating ts_data is needed here.
> }
> - ff_get_guid(pb, &g);
> - avio_skip(pb, 8); /* total_size */
> - type_specific_size = avio_rl32(pb);
> - avio_rl32(pb);
> - st->id = avio_rl16(pb) & 0x7f; /* stream id */
> - // mapping of asf ID to AV stream ID;
> - asf->asfid2avid[st->id] = s->nb_streams - 1;
> -
> - avio_rl32(pb);
> -
> - if (test_for_ext_stream_audio) {
> - ff_get_guid(pb, &g);
> - if (!ff_guidcmp(&g, &ff_asf_ext_stream_audio_stream)) {
> - type = AVMEDIA_TYPE_AUDIO;
> - is_dvr_ms_audio = 1;
> - ff_get_guid(pb, &g);
> - avio_rl32(pb);
> - avio_rl32(pb);
> - avio_rl32(pb);
> - ff_get_guid(pb, &g);
> - avio_rl32(pb);
> - }
> + av_freep(&ts_data);
> +
> + if (err_data_len) {
> + if (type == AVMEDIA_TYPE_AUDIO) {
> + uint8_t span = avio_r8(pb);
> + if (span > 1) {
> + asf_st->span = span;
> + asf_st->virtual_pkt_len = avio_rl16(pb);
> + asf_st->virtual_chunk_len = avio_rl16(pb);
> + avio_skip(pb, err_data_len - 5);
> + } else
> + avio_skip(pb, err_data_len);
-1
> + } else
> + avio_skip(pb, err_data_len);
> }
>
> - st->codec->codec_type = type;
> - if (type == AVMEDIA_TYPE_AUDIO) {
> - int ret = ff_get_wav_header(pb, st->codec, type_specific_size);
> - if (ret < 0)
> - return ret;
> - if (is_dvr_ms_audio) {
> - // codec_id and codec_tag are unreliable in dvr_ms
> - // files. Set them later by probing stream.
> - st->codec->codec_id = AV_CODEC_ID_PROBE;
> - st->codec->codec_tag = 0;
> - }
> - if (st->codec->codec_id == AV_CODEC_ID_AAC)
> - st->need_parsing = AVSTREAM_PARSE_NONE;
> - else
> - st->need_parsing = AVSTREAM_PARSE_FULL;
> - /* We have to init the frame size at some point .... */
> - pos2 = avio_tell(pb);
> - if (size >= (pos2 + 8 - pos1 + 24)) {
> - asf_st->ds_span = avio_r8(pb);
> - asf_st->ds_packet_size = avio_rl16(pb);
> - asf_st->ds_chunk_size = avio_rl16(pb);
> - avio_rl16(pb); // ds_data_size
> - avio_r8(pb); // ds_silence_data
> - }
> - if (asf_st->ds_span > 1) {
> - if (!asf_st->ds_chunk_size ||
> - (asf_st->ds_packet_size / asf_st->ds_chunk_size <= 1) ||
> - asf_st->ds_packet_size % asf_st->ds_chunk_size)
> - asf_st->ds_span = 0; // disable descrambling
> - }
> - } else if (type == AVMEDIA_TYPE_VIDEO &&
> - size - (avio_tell(pb) - pos1 + 24) >= 51) {
> - avio_rl32(pb);
> - avio_rl32(pb);
> - avio_r8(pb);
> - avio_rl16(pb); /* size */
> - sizeX = avio_rl32(pb); /* size */
> - st->codec->width = avio_rl32(pb);
> - st->codec->height = avio_rl32(pb);
> - /* not available for asf */
> - avio_rl16(pb); /* panes */
> - st->codec->bits_per_coded_sample = avio_rl16(pb); /* depth */
> - tag1 = avio_rl32(pb);
> - avio_skip(pb, 20);
> - if (sizeX > 40) {
> - st->codec->extradata_size = sizeX - 40;
> - st->codec->extradata = av_mallocz(st->codec->extradata_size
> +
> -
> FF_INPUT_BUFFER_PADDING_SIZE);
> - avio_read(pb, st->codec->extradata, st->codec->extradata_size);
> - }
> -
> - /* Extract palette from extradata if bpp <= 8 */
> - /* This code assumes that extradata contains only palette */
> - /* This is true for all paletted codecs implemented in libavcodec */
> - if (st->codec->extradata_size && (st->codec->bits_per_coded_sample
> <= 8)) {
> -#if HAVE_BIGENDIAN
> - int i;
> - for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)
> / 4; i++)
> - asf_st->palette[i] = av_bswap32(((uint32_t
> *)st->codec->extradata)[i]);
> -#else
> - memcpy(asf_st->palette, st->codec->extradata,
> - FFMIN(st->codec->extradata_size, AVPALETTE_SIZE));
> -#endif
> - asf_st->palette_changed = 1;
> - }
> -
> - st->codec->codec_tag = tag1;
> - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1);
> - if (tag1 == MKTAG('D', 'V', 'R', ' ')) {
> - st->need_parsing = AVSTREAM_PARSE_FULL;
> - /* issue658 contains wrong w/h and MS even puts a fake seq header
> - * with wrong w/h in extradata while a correct one is in the
> stream.
> - * maximum lameness */
> - st->codec->width =
> - st->codec->height = 0;
> - av_freep(&st->codec->extradata);
> - st->codec->extradata_size = 0;
> - }
> - if (st->codec->codec_id == AV_CODEC_ID_H264)
> - st->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
> - }
> - pos2 = avio_tell(pb);
> - avio_skip(pb, size - (pos2 - pos1 + 24));
> + asf->nb_streams++;
> + align_position(pb, asf->offset, size);
>
> return 0;
> +
> +fail:
> + av_freep(&ts_data);
> + return ret;
> }
>
> -static int asf_read_ext_stream_properties(AVFormatContext *s, int64_t size)
> +static void set_language(AVFormatContext *s, const char *rfc1766,
> AVDictionary **met)
> {
> - ASFContext *asf = s->priv_data;
> - AVIOContext *pb = s->pb;
> - ff_asf_guid g;
> - int ext_len, payload_ext_ct, stream_ct, i;
> - uint32_t leak_rate, stream_num;
> - unsigned int stream_languageid_index;
> -
> - avio_rl64(pb); // starttime
> - avio_rl64(pb); // endtime
> - leak_rate = avio_rl32(pb); // leak-datarate
> - avio_rl32(pb); // bucket-datasize
> - avio_rl32(pb); // init-bucket-fullness
> - avio_rl32(pb); // alt-leak-datarate
> - avio_rl32(pb); // alt-bucket-datasize
> - avio_rl32(pb); // alt-init-bucket-fullness
> - avio_rl32(pb); // max-object-size
> - avio_rl32(pb); // flags
> (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits
> reserved)
> - stream_num = avio_rl16(pb); // stream-num
> -
> - stream_languageid_index = avio_rl16(pb); // stream-language-id-index
> - if (stream_num < 128)
> - asf->streams[stream_num].stream_language_index =
> stream_languageid_index;
> -
> - avio_rl64(pb); // avg frametime in 100ns units
> - stream_ct = avio_rl16(pb); // stream-name-count
> - payload_ext_ct = avio_rl16(pb); // payload-extension-system-count
> -
> - if (stream_num < 128)
> - asf->stream_bitrates[stream_num] = leak_rate;
> -
> - for (i = 0; i < stream_ct; i++) {
> - avio_rl16(pb);
> - ext_len = avio_rl16(pb);
> - avio_skip(pb, ext_len);
> + if (rfc1766 && strlen(rfc1766) > 1) {
Why 1?
> + const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' }; //
> ignore country code if any
> + const char *iso6392 = av_convert_lang_to(primary_tag,
> +
> AV_LANG_ISO639_2_BIBL);
> + if (iso6392)
> + if (av_dict_set(met, "language", iso6392, 0) < 0)
> + av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");
> }
> -
> - for (i = 0; i < payload_ext_ct; i++) {
> - ff_get_guid(pb, &g);
> - avio_skip(pb, 2);
> - ext_len = avio_rl32(pb);
> - avio_skip(pb, ext_len);
> - }
> -
> - return 0;
> }
>
> -static int asf_read_content_desc(AVFormatContext *s, int64_t size)
> +static int asf_read_ext_stream_properties(AVFormatContext *s, const
> GUIDParseTable *g)
> {
> + ASFContext *asf = s->priv_data;
> AVIOContext *pb = s->pb;
> - int len1, len2, len3, len4, len5;
> -
> - len1 = avio_rl16(pb);
> - len2 = avio_rl16(pb);
> - len3 = avio_rl16(pb);
> - len4 = avio_rl16(pb);
> - len5 = avio_rl16(pb);
> - get_tag(s, "title", 0, len1, 32);
> - get_tag(s, "author", 0, len2, 32);
> - get_tag(s, "copyright", 0, len3, 32);
> - get_tag(s, "comment", 0, len4, 32);
> - avio_skip(pb, len5);
> + ff_asf_guid guid;
> + uint64_t size = avio_rl64(pb);
> + uint16_t nb_st_name, nb_pay_exts, st_num, lang_idx;
> + int i, ret;
> +
> + avio_skip(pb, 48); // skip some unused values
This skips a whole lot of potentially useful information.
Specifically, start and end time (mapped to start+duration in our API)
and bitrate.
> + st_num = avio_rl16(pb);
> + st_num &= ASF_STREAM_NUM;
> + lang_idx = avio_rl16(pb); // Stream Language ID Index
> + for (i = 0; i < asf->nb_streams; i++)
> + if (st_num == asf->asf_st[i]->stream_index)
> + asf->asf_st[i]->lang_idx = lang_idx;
> +
> + avio_skip(pb, 8); // skip average time per frame
This should be exported as the inverse of the framerate.
> + nb_st_name = avio_rl16(pb);
> + nb_pay_exts = avio_rl16(pb);
> + for (i = 0; i < nb_st_name; i++) {
> + uint16_t len;
> +
> + avio_rl16(pb); // Language ID Index
> + len = avio_rl16(pb);
> + avio_skip(pb, len);
> + }
>
> - return 0;
> -}
> + for (i = 0; i < nb_pay_exts; i++) {
> + uint32_t len;
> + avio_skip(pb, 16); // Extension System ID
> + avio_skip(pb, 2); // Extension Data Size
> + len = avio_rl32(pb);
> + avio_skip(pb, len);
> + }
>
> -static int asf_read_ext_content_desc(AVFormatContext *s, int64_t size)
> -{
> - AVIOContext *pb = s->pb;
> - ASFContext *asf = s->priv_data;
> - int desc_count, i, ret;
> + if ((ret = ff_get_guid(pb, &guid)) < 0) {
> + align_position(pb, asf->offset, size);
>
> - desc_count = avio_rl16(pb);
> - for (i = 0; i < desc_count; i++) {
> - int name_len, value_type, value_len;
> - char name[1024];
> + return 0;
> + }
>
> - name_len = avio_rl16(pb);
> - if (name_len % 2) // must be even, broken lavf versions wrote len-1
> - name_len += 1;
> - if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) <
> name_len)
> - avio_skip(pb, name_len - ret);
> - value_type = avio_rl16(pb);
> - value_len = avio_rl16(pb);
> - if (!value_type && value_len % 2)
> - value_len += 1;
> - /* My sample has that stream set to 0 maybe that mean the container.
> - * ASF stream count starts at 1. I am using 0 to the container value
> - * since it's unused. */
> - if (!strcmp(name, "AspectRatioX"))
> - asf->dar[0].num = get_value(s->pb, value_type, 32);
> - else if (!strcmp(name, "AspectRatioY"))
> - asf->dar[0].den = get_value(s->pb, value_type, 32);
> - else
> - get_tag(s, name, value_type, value_len, 32);
> + g = find_guid(guid);
> + if (g && !(strcmp(g->name, "Extended Stream Properties"))) {
The spec says there should Stream Properties here.
> + if ((ret = g->read_object(s, g)) < 0)
> + return ret;
> }
>
> + align_position(pb, asf->offset, size);
> return 0;
> }
>
> -static int asf_read_language_list(AVFormatContext *s, int64_t size)
> +static int asf_read_language_list(AVFormatContext *s, const GUIDParseTable
> *g)
> {
> - AVIOContext *pb = s->pb;
> - ASFContext *asf = s->priv_data;
> - int j, ret;
> - int stream_count = avio_rl16(pb);
> - for (j = 0; j < stream_count; j++) {
> - char lang[6];
> - unsigned int lang_len = avio_r8(pb);
> - if ((ret = avio_get_str16le(pb, lang_len, lang,
> - sizeof(lang))) < lang_len)
> - avio_skip(pb, lang_len - ret);
> - if (j < 128)
> - av_strlcpy(asf->stream_languages[j], lang,
> - sizeof(*asf->stream_languages));
> + ASFContext *asf = s->priv_data;
> + AVIOContext *pb = s->pb;
> + int i, ret;
> + uint64_t size = avio_rl64(pb);
> + uint16_t nb_langs = avio_rl16(pb);
> +
> + for (i = 0; i < nb_langs; i++) {
> + size_t len;
> + int8_t *name;
This should be unsigned.
> + len = avio_r8(pb);
> + if (!len)
> + len = 6;
Why 6?
> + // len is number of unicode characters - 2 bytes for each char
> + name = av_malloc(2 * len);
Missing +1 for the terminator.
> + if (!name)
> + return AVERROR(ENOMEM);
> + if ((ret = get_asf_string(pb, len, name, 2 * len)) < 0)
> + return ret;
Leaking name here.
> + if (i < ASF_MAX_STREAMS)
> + av_strlcpy(asf->langs[i], name, sizeof(*name));
> + av_freep(&name);
Pointless copying, just store name.
> }
>
> + align_position(pb, asf->offset, size);
> return 0;
> }
>
> -static int asf_read_metadata(AVFormatContext *s, int64_t size)
> +// returns data object offset when reading this object for the first time
> +static int asf_read_data(AVFormatContext *s, const GUIDParseTable *g)
> {
> - AVIOContext *pb = s->pb;
> ASFContext *asf = s->priv_data;
> - int n, stream_num, name_len, value_len;
> - int ret, i;
> - n = avio_rl16(pb);
> -
> - for (i = 0; i < n; i++) {
> - char name[1024];
> - int value_type;
> -
> - avio_rl16(pb); // lang_list_index
> - stream_num = avio_rl16(pb);
> - name_len = avio_rl16(pb);
> - value_type = avio_rl16(pb); /* value_type */
> - value_len = avio_rl32(pb);
> -
> - if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) <
> name_len)
> - avio_skip(pb, name_len - ret);
> - av_dlog(s, "%d stream %d name_len %2d type %d len %4d <%s>\n",
> - i, stream_num, name_len, value_type, value_len, name);
> -
> - if (!strcmp(name, "AspectRatioX")){
> - int aspect_x = get_value(s->pb, value_type, 16);
> - if(stream_num < 128)
> - asf->dar[stream_num].num = aspect_x;
> - } else if(!strcmp(name, "AspectRatioY")){
> - int aspect_y = get_value(s->pb, value_type, 16);
> - if(stream_num < 128)
> - asf->dar[stream_num].den = aspect_y;
> - } else {
> - get_tag(s, name, value_type, value_len, 16);
> - }
> + AVIOContext *pb = s->pb;
> + uint64_t size = asf->data_size = avio_rl64(pb);
> + int i;
> +
> + if (!asf->data_reached && pb->seekable) {
> + asf->data_reached = 1;
> + asf->data_offset = asf->offset;
> }
>
> + for (i = 0; i < asf->nb_streams; i++)
> + s->streams[i]->duration = asf->duration;
> + asf->nb_mult_left = 0;
> + asf->sub_left = 0;
> + asf->state = PARSE_PACKET_HEADER;
> + asf->return_subpayload = 0;
> + asf->packet_size_internal = 0;
> + avio_skip(pb, 16); // skip File ID
> + size = avio_rl64(pb); // Total Data Packets
> + if (size != asf->nb_packets)
> + av_log(s, AV_LOG_WARNING,
> + "Number of Packets from File Properties Object is not equal
> to Total"
> + "Datapackets value! num of packets %"PRIu64" total num
> %"PRIu64".\n",
> + size, asf->nb_packets);
> + avio_skip(pb, 2); // skip reserved field
> + asf->first_packet_offset = avio_tell(pb);
> +
> +
Too many newlines.
> return 0;
> }
>
> -static int asf_read_marker(AVFormatContext *s, int64_t size)
> +static int asf_read_parameters(AVFormatContext *s, const GUIDParseTable *g)
> {
> - AVIOContext *pb = s->pb;
> ASFContext *asf = s->priv_data;
> - int i, count, name_len, ret;
> - char name[1024];
> -
> - avio_rl64(pb); // reserved 16 bytes
> - avio_rl64(pb); // ...
> - count = avio_rl32(pb); // markers count
> - avio_rl16(pb); // reserved 2 bytes
> - name_len = avio_rl16(pb); // name length
> - for (i = 0; i < name_len; i++)
> - avio_r8(pb); // skip the name
> -
> - for (i = 0; i < count; i++) {
> - int64_t pres_time;
> - int name_len;
> -
> - avio_rl64(pb); // offset, 8 bytes
> - pres_time = avio_rl64(pb); // presentation time
> - pres_time -= asf->hdr.preroll * 10000;
> - avio_rl16(pb); // entry length
> - avio_rl32(pb); // send time
> - avio_rl32(pb); // flags
> - name_len = avio_rl32(pb); // name length
> - if ((ret = avio_get_str16le(pb, name_len * 2, name,
> - sizeof(name))) < name_len)
> - avio_skip(pb, name_len - ret);
> - avpriv_new_chapter(s, i, (AVRational) { 1, 10000000 }, pres_time,
> - AV_NOPTS_VALUE, name);
> + AVIOContext *pb = s->pb;
> + uint64_t size = avio_rl64(pb);
> + uint16_t nb_idx_specs;
> + int i, j;
> +
> + avio_skip(pb, 4);
> + nb_idx_specs = avio_rl16(pb);
> + for (i = 0; i < nb_idx_specs; i++) {
> + uint16_t stream_index = avio_rl16(pb);
> + for (j = 0; j < asf->nb_streams; j++) {
> + if (asf->asf_st[j]->stream_index == stream_index)
> + asf->asf_st[j]->idx_type = avio_rl16(pb);
This seems to be unused. It also looks incorrect, since for each
specifier it will read 2 bytes for each stream.
--
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel