comparison bink.c @ 5736:9a98bc214731 libavformat

Support demuxing of streamed Bink files
author pross
date Wed, 03 Mar 2010 09:44:30 +0000
parents 1481fbffd30b
children ee8f29f3f9f7
comparison
equal deleted inserted replaced
5735:0f6f55a8e878 5736:9a98bc214731
209 return AVERROR(EIO); 209 return AVERROR(EIO);
210 } 210 }
211 bink->remain_packet_size -= 4 + audio_size; 211 bink->remain_packet_size -= 4 + audio_size;
212 bink->current_track++; 212 bink->current_track++;
213 if (audio_size > 0) { 213 if (audio_size > 0) {
214 /* Each audio packet reports the number of decompressed samples
215 (in bytes). We use this value to calcuate the audio PTS */
216 int reported_size = get_le32(pb) / (2 * s->streams[bink->current_track]->codec->channels);
217 url_fseek(pb, -4, SEEK_CUR);
218
219 /* get one audio packet per track */ 214 /* get one audio packet per track */
220 if ((ret = av_get_packet(pb, pkt, audio_size)) 215 if ((ret = av_get_packet(pb, pkt, audio_size))
221 != audio_size) 216 != audio_size)
222 return ret; 217 return ret;
223 pkt->stream_index = bink->current_track; 218 pkt->stream_index = bink->current_track;
224 pkt->pts = bink->audio_pts[bink->current_track - 1]; 219 pkt->pts = bink->audio_pts[bink->current_track - 1];
225 bink->audio_pts[bink->current_track -1] += reported_size; 220
221 /* Each audio packet reports the number of decompressed samples
222 (in bytes). We use this value to calcuate the audio PTS */
223 bink->audio_pts[bink->current_track -1] +=
224 AV_RL32(pkt->data) / (2 * s->streams[bink->current_track]->codec->channels);
226 return 0; 225 return 0;
227 } 226 }
228 } 227 }
229 228
230 /* get video packet */ 229 /* get video packet */
243 242
244 static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) 243 static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
245 { 244 {
246 BinkDemuxContext *bink = s->priv_data; 245 BinkDemuxContext *bink = s->priv_data;
247 AVStream *vst = s->streams[0]; 246 AVStream *vst = s->streams[0];
247
248 if (url_is_streamed(s->pb))
249 return -1;
248 250
249 /* seek to the first frame */ 251 /* seek to the first frame */
250 url_fseek(s->pb, vst->index_entries[0].pos, SEEK_SET); 252 url_fseek(s->pb, vst->index_entries[0].pos, SEEK_SET);
251 bink->video_pts = 0; 253 bink->video_pts = 0;
252 memset(bink->audio_pts, 0, sizeof(bink->audio_pts)); 254 memset(bink->audio_pts, 0, sizeof(bink->audio_pts));