Mercurial > libavformat.hg
comparison raw.c @ 306:e7a8d4dd8e14 libavformat
seek support for PCM formats
author | bellard |
---|---|
date | Mon, 10 Nov 2003 18:41:45 +0000 |
parents | a313e1080322 |
children | e14fcd57ad2f |
comparison
equal
deleted
inserted
replaced
305:ef53bff8bf23 | 306:e7a8d4dd8e14 |
---|---|
105 static int raw_read_close(AVFormatContext *s) | 105 static int raw_read_close(AVFormatContext *s) |
106 { | 106 { |
107 return 0; | 107 return 0; |
108 } | 108 } |
109 | 109 |
110 int pcm_read_seek(AVFormatContext *s, | |
111 int stream_index, int64_t timestamp) | |
112 { | |
113 AVStream *st; | |
114 int block_align, byte_rate; | |
115 int64_t pos; | |
116 | |
117 st = s->streams[0]; | |
118 switch(st->codec.codec_id) { | |
119 case CODEC_ID_PCM_S16LE: | |
120 case CODEC_ID_PCM_S16BE: | |
121 case CODEC_ID_PCM_U16LE: | |
122 case CODEC_ID_PCM_U16BE: | |
123 block_align = 2 * st->codec.channels; | |
124 byte_rate = block_align * st->codec.sample_rate; | |
125 break; | |
126 case CODEC_ID_PCM_S8: | |
127 case CODEC_ID_PCM_U8: | |
128 case CODEC_ID_PCM_MULAW: | |
129 case CODEC_ID_PCM_ALAW: | |
130 block_align = st->codec.channels; | |
131 byte_rate = block_align * st->codec.sample_rate; | |
132 break; | |
133 default: | |
134 block_align = st->codec.block_align; | |
135 byte_rate = st->codec.bit_rate / 8; | |
136 break; | |
137 } | |
138 | |
139 if (block_align <= 0 || byte_rate <= 0) | |
140 return -1; | |
141 | |
142 /* compute the position by aligning it to block_align */ | |
143 pos = (timestamp * byte_rate) / AV_TIME_BASE; | |
144 pos = (pos / block_align) * block_align; | |
145 | |
146 /* recompute exact position */ | |
147 st->cur_dts = (pos * AV_TIME_BASE) / byte_rate; | |
148 url_fseek(&s->pb, pos + s->data_offset, SEEK_SET); | |
149 return 0; | |
150 } | |
151 | |
110 /* ac3 read */ | 152 /* ac3 read */ |
111 static int ac3_read_header(AVFormatContext *s, | 153 static int ac3_read_header(AVFormatContext *s, |
112 AVFormatParameters *ap) | 154 AVFormatParameters *ap) |
113 { | 155 { |
114 AVStream *st; | 156 AVStream *st; |
117 if (!st) | 159 if (!st) |
118 return AVERROR_NOMEM; | 160 return AVERROR_NOMEM; |
119 | 161 |
120 st->codec.codec_type = CODEC_TYPE_AUDIO; | 162 st->codec.codec_type = CODEC_TYPE_AUDIO; |
121 st->codec.codec_id = CODEC_ID_AC3; | 163 st->codec.codec_id = CODEC_ID_AC3; |
164 st->need_parsing = 1; | |
122 /* the parameters will be extracted from the compressed bitstream */ | 165 /* the parameters will be extracted from the compressed bitstream */ |
123 return 0; | 166 return 0; |
124 } | 167 } |
125 | 168 |
126 /* mpeg1/h263 input */ | 169 /* mpeg1/h263 input */ |
133 if (!st) | 176 if (!st) |
134 return AVERROR_NOMEM; | 177 return AVERROR_NOMEM; |
135 | 178 |
136 st->codec.codec_type = CODEC_TYPE_VIDEO; | 179 st->codec.codec_type = CODEC_TYPE_VIDEO; |
137 st->codec.codec_id = s->iformat->value; | 180 st->codec.codec_id = s->iformat->value; |
181 st->need_parsing = 1; | |
182 | |
138 /* for mjpeg, specify frame rate */ | 183 /* for mjpeg, specify frame rate */ |
139 /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/ | 184 /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/ |
140 if (st->codec.codec_id == CODEC_ID_MJPEG || st->codec.codec_id == CODEC_ID_MPEG4) { | 185 if (st->codec.codec_id == CODEC_ID_MJPEG || |
141 if (ap) { | 186 st->codec.codec_id == CODEC_ID_MPEG4) { |
187 if (ap && ap->frame_rate) { | |
142 st->codec.frame_rate = ap->frame_rate; | 188 st->codec.frame_rate = ap->frame_rate; |
143 st->codec.frame_rate_base = ap->frame_rate_base; | 189 st->codec.frame_rate_base = ap->frame_rate_base; |
144 } else { | 190 } else { |
145 st->codec.frame_rate = 25; | 191 st->codec.frame_rate = 25; |
146 st->codec.frame_rate_base = 1; | 192 st->codec.frame_rate_base = 1; |
354 raw_write_trailer, | 400 raw_write_trailer, |
355 }; | 401 }; |
356 #endif //CONFIG_ENCODERS | 402 #endif //CONFIG_ENCODERS |
357 | 403 |
358 /* pcm formats */ | 404 /* pcm formats */ |
359 #if !defined(CONFIG_ENCODERS) && defined(CONFIG_DECODERS) | 405 |
360 | 406 #define PCMINPUTDEF(name, long_name, ext, codec) \ |
361 #define PCMDEF(name, long_name, ext, codec) \ | |
362 AVInputFormat pcm_ ## name ## _iformat = {\ | 407 AVInputFormat pcm_ ## name ## _iformat = {\ |
363 #name,\ | 408 #name,\ |
364 long_name,\ | 409 long_name,\ |
365 0,\ | 410 0,\ |
366 NULL,\ | 411 NULL,\ |
367 raw_read_header,\ | 412 raw_read_header,\ |
368 raw_read_packet,\ | 413 raw_read_packet,\ |
369 raw_read_close,\ | 414 raw_read_close,\ |
415 pcm_read_seek,\ | |
370 .extensions = ext,\ | 416 .extensions = ext,\ |
371 .value = codec,\ | 417 .value = codec,\ |
372 }; | 418 }; |
373 | 419 |
420 #if !defined(CONFIG_ENCODERS) && defined(CONFIG_DECODERS) | |
421 | |
422 #define PCMDEF(name, long_name, ext, codec) \ | |
423 PCMINPUTDEF(name, long_name, ext, codec) | |
424 | |
374 #else | 425 #else |
375 | 426 |
376 #define PCMDEF(name, long_name, ext, codec) \ | 427 #define PCMDEF(name, long_name, ext, codec) \ |
377 AVInputFormat pcm_ ## name ## _iformat = {\ | 428 PCMINPUTDEF(name, long_name, ext, codec)\ |
378 #name,\ | |
379 long_name,\ | |
380 0,\ | |
381 NULL,\ | |
382 raw_read_header,\ | |
383 raw_read_packet,\ | |
384 raw_read_close,\ | |
385 .extensions = ext,\ | |
386 .value = codec,\ | |
387 };\ | |
388 \ | 429 \ |
389 AVOutputFormat pcm_ ## name ## _oformat = {\ | 430 AVOutputFormat pcm_ ## name ## _oformat = {\ |
390 #name,\ | 431 #name,\ |
391 long_name,\ | 432 long_name,\ |
392 NULL,\ | 433 NULL,\ |