~ubuntu-branches/ubuntu/utopic/ffmpeg-debian/utopic

« back to all changes in this revision

Viewing changes to libavformat/matroskaenc.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-01-20 09:20:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120092053-izz63p40hc98qfgp
Tags: 3:0.svn20090119-1ubuntu1
* merge from debian. LP: #318501
* new version fixes CVE-2008-3230, LP: #253767

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "isom.h"
25
25
#include "matroska.h"
26
26
#include "avc.h"
 
27
#include "libavutil/intreadwrite.h"
27
28
#include "libavutil/md5.h"
28
29
#include "libavcodec/xiph.h"
29
30
#include "libavcodec/mpeg4audio.h"
559
560
        else
560
561
            put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, "und");
561
562
 
562
 
        put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGDEFAULT, !!(st->disposition & AV_DISPOSITION_DEFAULT));
 
563
        if (st->disposition)
 
564
            put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGDEFAULT, !!(st->disposition & AV_DISPOSITION_DEFAULT));
563
565
 
564
566
        // look for a codec ID string specific to mkv to use,
565
567
        // if none are found, use AVI codes
707
709
    if (mkv->cues == NULL)
708
710
        return AVERROR(ENOMEM);
709
711
 
 
712
    put_flush_packet(pb);
710
713
    return 0;
711
714
}
712
715
 
784
787
{
785
788
    MatroskaMuxContext *mkv = s->priv_data;
786
789
    ByteIOContext *pb = s->pb;
 
790
    AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
787
791
 
788
792
    av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, "
789
793
           "pts %" PRId64 ", dts %" PRId64 ", duration %d, flags %d\n",
793
797
    put_byte(pb, 0x80 | (pkt->stream_index + 1));     // this assumes stream_index is less than 126
794
798
    put_be16(pb, pkt->pts - mkv->cluster_pts);
795
799
    put_byte(pb, flags);
796
 
    put_buffer(pb, pkt->data, pkt->size);
 
800
    if (codec->codec_id == CODEC_ID_H264 &&
 
801
        codec->extradata_size > 0 && AV_RB32(codec->extradata) == 0x00000001) {
 
802
        /* from x264 or from bytestream h264 */
 
803
        /* nal reformating needed */
 
804
        ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
 
805
    } else {
 
806
        put_buffer(pb, pkt->data, pkt->size);
 
807
    }
797
808
}
798
809
 
799
810
static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
821
832
        av_md5_update(mkv->md5_ctx, pkt->data, FFMIN(200, pkt->size));
822
833
    }
823
834
 
824
 
    if (codec->codec_id == CODEC_ID_H264 &&
825
 
        codec->extradata_size > 0 && AV_RB32(codec->extradata) == 0x00000001) {
826
 
        /* from x264 or from bytestream h264 */
827
 
        /* nal reformating needed */
828
 
        int ret = ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size);
829
 
        if (ret < 0)
830
 
            return ret;
831
 
        assert(pkt->size);
832
 
    }
833
 
 
834
835
    if (codec->codec_type != CODEC_TYPE_SUBTITLE) {
835
836
        mkv_write_block(s, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe << 7);
836
837
    } else if (codec->codec_id == CODEC_ID_SSA) {
889
890
 
890
891
    end_ebml_master(pb, mkv->segment);
891
892
    av_free(mkv->md5_ctx);
 
893
    put_flush_packet(pb);
892
894
    return 0;
893
895
}
894
896