Revision 2e7973bb

View differences:

libavformat/asf.c
806 806
	    asf->packet_size = asf->hdr.max_pktsize;
807 807
            asf->nb_packets = asf->hdr.packets_count;
808 808
        } else if (!memcmp(&g, &stream_header, sizeof(GUID))) {
809
            int type, total_size;
809
            int type, total_size, type_specific_size;
810 810
            unsigned int tag1;
811 811
            int64_t pos1, pos2;
812 812

  
......
832 832
            }
833 833
            get_guid(pb, &g);
834 834
            total_size = get_le64(pb);
835
            get_le32(pb);
835
            type_specific_size = get_le32(pb);
836 836
            get_le32(pb);
837 837
	    st->id = get_le16(pb) & 0x7f; /* stream id */
838 838
            // mapping of asf ID to AV stream ID;
......
842 842
	    st->codec.codec_type = type;
843 843
            st->codec.frame_rate = 15 * s->pts_den / s->pts_num; // 15 fps default
844 844
            if (type == CODEC_TYPE_AUDIO) {
845
                get_wav_header(pb, &st->codec, 1);
845
                get_wav_header(pb, &st->codec, type_specific_size);
846 846
		/* We have to init the frame size at some point .... */
847 847
		pos2 = url_ftell(pb);
848 848
		if (gsize > (pos2 + 8 - pos1 + 24)) {
libavformat/avi.h
18 18
void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const CodecTag *tags, int for_asf);
19 19
int put_wav_header(ByteIOContext *pb, AVCodecContext *enc);
20 20
int wav_codec_get_id(unsigned int tag, int bps);
21
void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, 
22
                    int has_extra_data);
21
void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size); 
23 22

  
24 23
extern const CodecTag codec_bmp_tags[];
25 24
extern const CodecTag codec_wav_tags[];
libavformat/avidec.c
187 187
//                    url_fskip(pb, size - 5 * 4);
188 188
                    break;
189 189
                case CODEC_TYPE_AUDIO:
190
                    get_wav_header(pb, &st->codec, (size >= 18));
190
                    get_wav_header(pb, &st->codec, size);
191 191
                    if (size%2) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
192 192
                        url_fskip(pb, 1);
193 193
                    break;
libavformat/wav.c
103 103
    return hdrsize;
104 104
}
105 105

  
106
void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, 
107
                    int has_extra_data)
106
/* We could be given one of the three possible structures here:
107
 * WAVEFORMAT, PCMWAVEFORMAT or WAVEFORMATEX. Each structure
108
 * is an expansion of the previous one with the fields added
109
 * at the bottom. PCMWAVEFORMAT adds 'WORD wBitsPerSample' and
110
 * WAVEFORMATEX adds 'WORD  cbSize' and basically makes itself
111
 * an openended structure.
112
 */
113
void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size) 
108 114
{
109 115
    int id;
110 116

  
111 117
    id = get_le16(pb);
118
    codec->codec_id = wav_codec_get_id(id, codec->frame_bits);
112 119
    codec->codec_type = CODEC_TYPE_AUDIO;
113 120
    codec->codec_tag = id;
114 121
    codec->channels = get_le16(pb);
115 122
    codec->sample_rate = get_le32(pb);
116 123
    codec->bit_rate = get_le32(pb) * 8;
117 124
    codec->block_align = get_le16(pb);
118
    codec->bits_per_sample = get_le16(pb); /* bits per sample */
119
    codec->codec_id = wav_codec_get_id(id, codec->frame_bits);
120
    if (has_extra_data) {
125
    if (size == 14) {  /* We're dealing with plain vanilla WAVEFORMAT */
126
        codec->bits_per_sample = 8;
127
	return;
128
    }
129
    
130
    codec->bits_per_sample = get_le16(pb);
131
    if (size > 16) {  /* We're obviously dealing with WAVEFORMATEX */
121 132
	codec->extradata_size = get_le16(pb);
122 133
	if (codec->extradata_size > 0) {
134
	    if (codec->extradata_size > size - 18)
135
	        codec->extradata_size = size - 18;
123 136
            codec->extradata = av_mallocz(codec->extradata_size);
124 137
            get_buffer(pb, codec->extradata, codec->extradata_size);
125
        }
138
        } else
139
	    codec->extradata_size = 0;
140
	
141
	/* It is possible for the chunk to contain garbage at the end */
142
	if (size - codec->extradata_size - 18 > 0)
143
	    url_fskip(pb, size - codec->extradata_size - 18);
126 144
    }
127 145
}
128 146

  
......
259 277
    if (!st)
260 278
        return AVERROR_NOMEM;
261 279

  
262
    get_wav_header(pb, &st->codec, (size >= 18));
280
    get_wav_header(pb, &st->codec, size);
263 281
    
264 282
    size = find_tag(pb, MKTAG('d', 'a', 't', 'a'));
265 283
    if (size < 0)

Also available in: Unified diff