~ubuntu-branches/debian/experimental/libav/experimental

« back to all changes in this revision

Viewing changes to libavformat/mux.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2014-02-17 22:07:03 UTC
  • mfrom: (1.1.25)
  • Revision ID: package-import@ubuntu.com-20140217220703-51bpzx0ln1d961vs
Tags: 6:10~beta1-2
* New Upstream release 10_beta1. This upstream git snapshot has too many
  changes to list here, cf. to the upstream Changelog:
  http://git.libav.org/?p=libav.git;a=blob;f=Changelog;hb=refs/tags/v10_beta1
  - works with H.264 that has different bit depth between chroma and luma,
    Closes: #738599
* Bump shlibs

Show diffs side-by-side

added added

removed removed

Lines of Context:
232
232
            av_log(s, AV_LOG_WARNING,
233
233
                   "Codec for stream %d does not use global headers "
234
234
                   "but container format requires global headers\n", i);
 
235
 
 
236
        if (codec->codec_type != AVMEDIA_TYPE_ATTACHMENT)
 
237
            s->internal->nb_interleaved_streams++;
235
238
    }
236
239
 
237
240
    if (!s->priv_data && of->priv_data_size > 0) {
429
432
    return ret;
430
433
}
431
434
 
 
435
static int check_packet(AVFormatContext *s, AVPacket *pkt)
 
436
{
 
437
    if (!pkt)
 
438
        return 0;
 
439
 
 
440
    if (pkt->stream_index < 0 || pkt->stream_index >= s->nb_streams) {
 
441
        av_log(s, AV_LOG_ERROR, "Invalid packet stream index: %d\n",
 
442
               pkt->stream_index);
 
443
        return AVERROR(EINVAL);
 
444
    }
 
445
 
 
446
    if (s->streams[pkt->stream_index]->codec->codec_type == AVMEDIA_TYPE_ATTACHMENT) {
 
447
        av_log(s, AV_LOG_ERROR, "Received a packet for an attachment stream.\n");
 
448
        return AVERROR(EINVAL);
 
449
    }
 
450
 
 
451
    return 0;
 
452
}
 
453
 
432
454
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
433
455
{
434
456
    int ret;
435
457
 
 
458
    ret = check_packet(s, pkt);
 
459
    if (ret < 0)
 
460
        return ret;
 
461
 
436
462
    if (!pkt) {
437
463
        if (s->oformat->flags & AVFMT_ALLOW_FLUSH)
438
464
            return s->oformat->write_packet(s, pkt);
515
541
        ff_interleave_add_packet(s, pkt, interleave_compare_dts);
516
542
    }
517
543
 
518
 
    for (i = 0; i < s->nb_streams; i++)
519
 
        stream_count += !!s->streams[i]->last_in_packet_buffer;
520
 
 
521
 
    if (stream_count && (s->nb_streams == stream_count || flush)) {
 
544
    if (s->max_interleave_delta > 0 && s->packet_buffer && !flush) {
 
545
        AVPacket *top_pkt = &s->packet_buffer->pkt;
 
546
        int64_t delta_dts = INT64_MIN;
 
547
        int64_t top_dts = av_rescale_q(top_pkt->dts,
 
548
                                       s->streams[top_pkt->stream_index]->time_base,
 
549
                                       AV_TIME_BASE_Q);
 
550
 
 
551
        for (i = 0; i < s->nb_streams; i++) {
 
552
            int64_t last_dts;
 
553
            const AVPacketList *last = s->streams[i]->last_in_packet_buffer;
 
554
 
 
555
            if (!last)
 
556
                continue;
 
557
 
 
558
            last_dts = av_rescale_q(last->pkt.dts,
 
559
                                    s->streams[i]->time_base,
 
560
                                    AV_TIME_BASE_Q);
 
561
            delta_dts = FFMAX(delta_dts, last_dts - top_dts);
 
562
            stream_count++;
 
563
        }
 
564
 
 
565
        if (delta_dts > s->max_interleave_delta) {
 
566
            av_log(s, AV_LOG_DEBUG,
 
567
                   "Delay between the first packet and last packet in the "
 
568
                   "muxing queue is %"PRId64" > %"PRId64": forcing output\n",
 
569
                   delta_dts, s->max_interleave_delta);
 
570
            flush = 1;
 
571
        }
 
572
    } else {
 
573
        for (i = 0; i < s->nb_streams; i++)
 
574
            stream_count += !!s->streams[i]->last_in_packet_buffer;
 
575
    }
 
576
 
 
577
 
 
578
    if (stream_count && (s->internal->nb_interleaved_streams == stream_count || flush)) {
522
579
        pktl = s->packet_buffer;
523
580
        *out = pktl->pkt;
524
581
 
560
617
{
561
618
    int ret, flush = 0;
562
619
 
 
620
    ret = check_packet(s, pkt);
 
621
    if (ret < 0)
 
622
        goto fail;
 
623
 
563
624
    if (pkt) {
564
625
        AVStream *st = s->streams[pkt->stream_index];
565
626
 
566
627
        //FIXME/XXX/HACK drop zero sized packets
567
 
        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size == 0)
568
 
            return 0;
 
628
        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size == 0) {
 
629
            ret = 0;
 
630
            goto fail;
 
631
        }
569
632
 
570
633
        av_dlog(s, "av_interleaved_write_frame size:%d dts:%" PRId64 " pts:%" PRId64 "\n",
571
634
                pkt->size, pkt->dts, pkt->pts);
572
635
        if ((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
573
 
            return ret;
 
636
            goto fail;
574
637
 
575
 
        if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
576
 
            return AVERROR(EINVAL);
 
638
        if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
 
639
            ret = AVERROR(EINVAL);
 
640
            goto fail;
 
641
        }
577
642
    } else {
578
643
        av_dlog(s, "av_interleaved_write_frame FLUSH\n");
579
644
        flush = 1;
582
647
    for (;; ) {
583
648
        AVPacket opkt;
584
649
        int ret = interleave_packet(s, &opkt, pkt, flush);
 
650
        if (pkt) {
 
651
            memset(pkt, 0, sizeof(*pkt));
 
652
            av_init_packet(pkt);
 
653
            pkt = NULL;
 
654
        }
585
655
        if (ret <= 0) //FIXME cleanup needed for ret<0 ?
586
656
            return ret;
587
657
 
590
660
            s->streams[opkt.stream_index]->nb_frames++;
591
661
 
592
662
        av_free_packet(&opkt);
593
 
        pkt = NULL;
594
663
 
595
664
        if (ret < 0)
596
665
            return ret;
597
666
    }
 
667
fail:
 
668
    av_packet_unref(pkt);
 
669
    return ret;
598
670
}
599
671
 
600
672
int av_write_trailer(AVFormatContext *s)