| @@ -51,56 +51,6 @@ · 50 unmodified lines |
| 51 | * muxing functions for use within Libav | 51 | * muxing functions for use within Libav |
| 52 | */ | 52 | */ |
| 53 | | 53 | |
| 54 | /* fraction handling */ | | |
| 55 | | | |
| 56 | /** | | |
| 57 | * f = val + (num / den) + 0.5. | | |
| 58 | * | | |
| 59 | * 'num' is normalized so that it is such as 0 <= num < den. | | |
| 60 | * | | |
| 61 | * @param f fractional number | | |
| 62 | * @param val integer value | | |
| 63 | * @param num must be >= 0 | | |
| 64 | * @param den must be >= 1 | | |
| 65 | */ | | |
| 66 | static void frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den) | | |
| 67 | { | | |
| 68 | num += (den >> 1); | | |
| 69 | if (num >= den) { | | |
| 70 | val += num / den; | | |
| 71 | num = num % den; | | |
| 72 | } | | |
| 73 | f->val = val; | | |
| 74 | f->num = num; | | |
| 75 | f->den = den; | | |
| 76 | } | | |
| 77 | | | |
| 78 | /** | | |
| 79 | * Fractional addition to f: f = f + (incr / f->den). | | |
| 80 | * | | |
| 81 | * @param f fractional number | | |
| 82 | * @param incr increment, can be positive or negative | | |
| 83 | */ | | |
| 84 | static void frac_add(AVFrac *f, int64_t incr) | | |
| 85 | { | | |
| 86 | int64_t num, den; | | |
| 87 | | | |
| 88 | num = f->num + incr; | | |
| 89 | den = f->den; | | |
| 90 | if (num < 0) { | | |
| 91 | f->val += num / den; | | |
| 92 | num = num % den; | | |
| 93 | if (num < 0) { | | |
| 94 | num += den; | | |
| 95 | f->val--; | | |
| 96 | } | | |
| 97 | } else if (num >= den) { | | |
| 98 | f->val += num / den; | | |
| 99 | num = num % den; | | |
| 100 | } | | |
| 101 | f->num = num; | | |
| 102 | } | | |
| 103 | | | |
| 104 | static int validate_codec_tag(AVFormatContext *s, AVStream *st) | 54 | static int validate_codec_tag(AVFormatContext *s, AVStream *st) |
| 105 | { | 55 | { |
| 106 | const AVCodecTag *avctag; | 56 | const AVCodecTag *avctag; |
| @@ -273,37 +223,6 @@ fail: · 166 unmodified lines |
| 273 | return ret; | 223 | return ret; |
| 274 | } | 224 | } |
| 275 | | 225 | |
| 276 | static int init_pts(AVFormatContext *s) | | |
| 277 | { | | |
| 278 | int i; | | |
| 279 | AVStream *st; | | |
| 280 | | | |
| 281 | /* init PTS generation */ | | |
| 282 | for (i = 0; i < s->nb_streams; i++) { | | |
| 283 | int64_t den = AV_NOPTS_VALUE; | | |
| 284 | st = s->streams[i]; | | |
| 285 | | | |
| 286 | switch (st->codec->codec_type) { | | |
| 287 | case AVMEDIA_TYPE_AUDIO: | | |
| 288 | den = (int64_t)st->time_base.num * st->codec->sample_rate; | | |
| 289 | break; | | |
| 290 | case AVMEDIA_TYPE_VIDEO: | | |
| 291 | den = (int64_t)st->time_base.num * st->codec->time_base.den; | | |
| 292 | break; | | |
| 293 | default: | | |
| 294 | break; | | |
| 295 | } | | |
| 296 | if (den != AV_NOPTS_VALUE) { | | |
| 297 | if (den <= 0) | | |
| 298 | return AVERROR_INVALIDDATA; | | |
| 299 | | | |
| 300 | frac_init(&st->pts, 0, 0, den); | | |
| 301 | } | | |
| 302 | } | | |
| 303 | | | |
| 304 | return 0; | | |
| 305 | } | | |
| 306 | | | |
| 307 | int avformat_write_header(AVFormatContext *s, AVDictionary **options) | 226 | int avformat_write_header(AVFormatContext *s, AVDictionary **options) |
| 308 | { | 227 | { |
| 309 | int ret = 0; | 228 | int ret = 0; |
| @@ -317,9 +236,6 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) · 7 unmodified lines |
| 317 | return ret; | 236 | return ret; |
| 318 | } | 237 | } |
| 319 | | 238 | |
| 320 | if ((ret = init_pts(s)) < 0) | | |
| 321 | return ret; | | |
| 322 | | | |
| 323 | return 0; | 239 | return 0; |
| 324 | } | 240 | } |
| 325 | | 241 | |
| @@ -327,7 +243,7 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) · 1 unmodified line |
| 327 | static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt) | 243 | static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt) |
| 328 | { | 244 | { |
| 329 | int delay = FFMAX(st->codec->has_b_frames, !!st->codec->max_b_frames); | 245 | int delay = FFMAX(st->codec->has_b_frames, !!st->codec->max_b_frames); |
| 330 | int num, den, frame_size, i; | 246 | int num, den, i; |
| 331 | | 247 | |
| 332 | av_dlog(s, "compute_pkt_fields2: pts:%" PRId64 " dts:%" PRId64 " cur_dts:%" PRId64 " b:%d size:%d st:%d\n", | 248 | av_dlog(s, "compute_pkt_fields2: pts:%" PRId64 " dts:%" PRId64 " cur_dts:%" PRId64 " b:%d size:%d st:%d\n", |
| 333 | pkt->pts, pkt->dts, st->cur_dts, delay, pkt->size, pkt->stream_index); | 249 | pkt->pts, pkt->dts, st->cur_dts, delay, pkt->size, pkt->stream_index); |
| @@ -373,26 +289,7 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt) · 39 unmodified lines |
| 373 | av_dlog(s, "av_write_frame: pts2:%"PRId64" dts2:%"PRId64"\n", | 289 | av_dlog(s, "av_write_frame: pts2:%"PRId64" dts2:%"PRId64"\n", |
| 374 | pkt->pts, pkt->dts); | 290 | pkt->pts, pkt->dts); |
| 375 | st->cur_dts = pkt->dts; | 291 | st->cur_dts = pkt->dts; |
| 376 | st->pts.val = pkt->dts; | 292 | |
| 377 | | | |
| 378 | /* update pts */ | | |
| 379 | switch (st->codec->codec_type) { | | |
| 380 | case AVMEDIA_TYPE_AUDIO: | | |
| 381 | frame_size = ff_get_audio_frame_size(st->codec, pkt->size, 1); | | |
| 382 | | | |
| 383 | /* HACK/FIXME, we skip the initial 0 size packets as they are most | | |
| 384 | * likely equal to the encoder delay, but it would be better if we | | |
| 385 | * had the real timestamps from the encoder */ | | |
| 386 | if (frame_size >= 0 && (pkt->size || st->pts.num != st->pts.den >> 1 || st->pts.val)) { | | |
| 387 | frac_add(&st->pts, (int64_t)st->time_base.den * frame_size); | | |
| 388 | } | | |
| 389 | break; | | |
| 390 | case AVMEDIA_TYPE_VIDEO: | | |
| 391 | frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num); | | |
| 392 | break; | | |
| 393 | default: | | |
| 394 | break; | | |
| 395 | } | | |
| 396 | return 0; | 293 | return 0; |
| 397 | } | 294 | } |
| 398 | | 295 | |