Mercurial > libavformat.hg
comparison ipmovie.c @ 4603:04f857454909 libavformat
Simplify ipmovie.c pts calculation by using an appropriate time_base.
author | reimar |
---|---|
date | Fri, 27 Feb 2009 10:07:12 +0000 |
parents | 06b665831f43 |
children | 6c50f319725d |
comparison
equal
deleted
inserted
replaced
4602:f1a4622fc4e1 | 4603:04f857454909 |
---|---|
91 typedef struct IPMVEContext { | 91 typedef struct IPMVEContext { |
92 | 92 |
93 unsigned char *buf; | 93 unsigned char *buf; |
94 int buf_size; | 94 int buf_size; |
95 | 95 |
96 float fps; | 96 uint64_t frame_pts_inc; |
97 int frame_pts_inc; | |
98 | 97 |
99 unsigned int video_width; | 98 unsigned int video_width; |
100 unsigned int video_height; | 99 unsigned int video_height; |
101 int64_t video_pts; | 100 int64_t video_pts; |
102 | 101 |
124 | 123 |
125 static int load_ipmovie_packet(IPMVEContext *s, ByteIOContext *pb, | 124 static int load_ipmovie_packet(IPMVEContext *s, ByteIOContext *pb, |
126 AVPacket *pkt) { | 125 AVPacket *pkt) { |
127 | 126 |
128 int chunk_type; | 127 int chunk_type; |
129 int64_t audio_pts = 0; | |
130 | 128 |
131 if (s->audio_chunk_offset) { | 129 if (s->audio_chunk_offset) { |
132 | 130 |
133 /* adjust for PCM audio by skipping chunk header */ | 131 /* adjust for PCM audio by skipping chunk header */ |
134 if (s->audio_type != CODEC_ID_INTERPLAY_DPCM) { | 132 if (s->audio_type != CODEC_ID_INTERPLAY_DPCM) { |
137 } | 135 } |
138 | 136 |
139 url_fseek(pb, s->audio_chunk_offset, SEEK_SET); | 137 url_fseek(pb, s->audio_chunk_offset, SEEK_SET); |
140 s->audio_chunk_offset = 0; | 138 s->audio_chunk_offset = 0; |
141 | 139 |
142 /* figure out the audio pts */ | |
143 audio_pts = 90000; | |
144 audio_pts *= s->audio_frame_count; | |
145 audio_pts /= s->audio_sample_rate; | |
146 | |
147 if (s->audio_chunk_size != av_get_packet(pb, pkt, s->audio_chunk_size)) | 140 if (s->audio_chunk_size != av_get_packet(pb, pkt, s->audio_chunk_size)) |
148 return CHUNK_EOF; | 141 return CHUNK_EOF; |
149 | 142 |
150 pkt->stream_index = s->audio_stream_index; | 143 pkt->stream_index = s->audio_stream_index; |
151 pkt->pts = audio_pts; | 144 pkt->pts = s->audio_frame_count; |
152 | 145 |
153 /* audio frame maintenance */ | 146 /* audio frame maintenance */ |
154 if (s->audio_type != CODEC_ID_INTERPLAY_DPCM) | 147 if (s->audio_type != CODEC_ID_INTERPLAY_DPCM) |
155 s->audio_frame_count += | 148 s->audio_frame_count += |
156 (s->audio_chunk_size / s->audio_channels / (s->audio_bits / 8)); | 149 (s->audio_chunk_size / s->audio_channels / (s->audio_bits / 8)); |
157 else | 150 else |
158 s->audio_frame_count += | 151 s->audio_frame_count += |
159 (s->audio_chunk_size - 6) / s->audio_channels; | 152 (s->audio_chunk_size - 6) / s->audio_channels; |
160 | 153 |
161 debug_ipmovie("sending audio frame with pts %"PRId64" (%d audio frames)\n", | 154 debug_ipmovie("sending audio frame with pts %"PRId64" (%d audio frames)\n", |
162 audio_pts, s->audio_frame_count); | 155 pkt->pts, s->audio_frame_count); |
163 | 156 |
164 chunk_type = CHUNK_VIDEO; | 157 chunk_type = CHUNK_VIDEO; |
165 | 158 |
166 } else if (s->decode_map_chunk_offset) { | 159 } else if (s->decode_map_chunk_offset) { |
167 | 160 |
325 if (get_buffer(pb, scratch, opcode_size) != | 318 if (get_buffer(pb, scratch, opcode_size) != |
326 opcode_size) { | 319 opcode_size) { |
327 chunk_type = CHUNK_BAD; | 320 chunk_type = CHUNK_BAD; |
328 break; | 321 break; |
329 } | 322 } |
330 s->fps = 1000000.0 / (AV_RL32(&scratch[0]) * AV_RL16(&scratch[4])); | 323 s->frame_pts_inc = ((uint64_t)AV_RL32(&scratch[0])) * AV_RL16(&scratch[4]); |
331 s->frame_pts_inc = 90000 / s->fps; | |
332 debug_ipmovie(" %.2f frames/second (timer div = %d, subdiv = %d)\n", | 324 debug_ipmovie(" %.2f frames/second (timer div = %d, subdiv = %d)\n", |
333 s->fps, AV_RL32(&scratch[0]), AV_RL16(&scratch[4])); | 325 1000000.0/s->frame_pts_inc, AV_RL32(&scratch[0]), AV_RL16(&scratch[4])); |
334 break; | 326 break; |
335 | 327 |
336 case OPCODE_INIT_AUDIO_BUFFERS: | 328 case OPCODE_INIT_AUDIO_BUFFERS: |
337 debug_ipmovie("initialize audio buffers\n"); | 329 debug_ipmovie("initialize audio buffers\n"); |
338 if ((opcode_version > 1) || (opcode_size > 10)) { | 330 if ((opcode_version > 1) || (opcode_size > 10)) { |
552 | 544 |
553 /* initialize the stream decoders */ | 545 /* initialize the stream decoders */ |
554 st = av_new_stream(s, 0); | 546 st = av_new_stream(s, 0); |
555 if (!st) | 547 if (!st) |
556 return AVERROR(ENOMEM); | 548 return AVERROR(ENOMEM); |
557 av_set_pts_info(st, 33, 1, 90000); | 549 av_set_pts_info(st, 63, 1, 1000000); |
558 ipmovie->video_stream_index = st->index; | 550 ipmovie->video_stream_index = st->index; |
559 st->codec->codec_type = CODEC_TYPE_VIDEO; | 551 st->codec->codec_type = CODEC_TYPE_VIDEO; |
560 st->codec->codec_id = CODEC_ID_INTERPLAY_VIDEO; | 552 st->codec->codec_id = CODEC_ID_INTERPLAY_VIDEO; |
561 st->codec->codec_tag = 0; /* no fourcc */ | 553 st->codec->codec_tag = 0; /* no fourcc */ |
562 st->codec->width = ipmovie->video_width; | 554 st->codec->width = ipmovie->video_width; |
567 | 559 |
568 if (ipmovie->audio_type) { | 560 if (ipmovie->audio_type) { |
569 st = av_new_stream(s, 0); | 561 st = av_new_stream(s, 0); |
570 if (!st) | 562 if (!st) |
571 return AVERROR(ENOMEM); | 563 return AVERROR(ENOMEM); |
572 av_set_pts_info(st, 33, 1, 90000); | 564 av_set_pts_info(st, 32, 1, ipmovie->audio_sample_rate); |
573 ipmovie->audio_stream_index = st->index; | 565 ipmovie->audio_stream_index = st->index; |
574 st->codec->codec_type = CODEC_TYPE_AUDIO; | 566 st->codec->codec_type = CODEC_TYPE_AUDIO; |
575 st->codec->codec_id = ipmovie->audio_type; | 567 st->codec->codec_id = ipmovie->audio_type; |
576 st->codec->codec_tag = 0; /* no tag */ | 568 st->codec->codec_tag = 0; /* no tag */ |
577 st->codec->channels = ipmovie->audio_channels; | 569 st->codec->channels = ipmovie->audio_channels; |