]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mxfenc.c
Merge commit '9765549f551ff40869aee1a6492b6a976c86cfe9'
[ffmpeg] / libavformat / mxfenc.c
index cd13f897873c7478000fb660aab74a1d4ef4c982..36a43e4a41473e997ce48311c95b97bf4575880c 100644 (file)
@@ -834,14 +834,14 @@ static void mxf_write_common_fields(AVFormatContext *s, AVStream *st)
     if (st == mxf->timecode_track)
         avio_write(pb, smpte_12m_timecode_track_data_ul, 16);
     else {
-        const MXFCodecUL *data_def_ul = mxf_get_data_definition_ul(st->codec->codec_type);
+        const MXFCodecUL *data_def_ul = mxf_get_data_definition_ul(st->codecpar->codec_type);
         avio_write(pb, data_def_ul->uid, 16);
     }
 
     // write duration
     mxf_write_local_tag(pb, 8, 0x0202);
 
-    if (st != mxf->timecode_track && s->oformat == &ff_mxf_opatom_muxer && st->codec->codec_type == AVMEDIA_TYPE_AUDIO){
+    if (st != mxf->timecode_track && s->oformat == &ff_mxf_opatom_muxer && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO){
         avio_wb64(pb, mxf->body_offset / mxf->edit_unit_byte_count);
     } else {
         avio_wb64(pb, mxf->duration);
@@ -1010,7 +1010,7 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke
 {
     MXFStreamContext *sc = st->priv_data;
     AVIOContext *pb = s->pb;
-    int stored_height = (st->codec->height+15)/16*16;
+    int stored_height = (st->codecpar->height+15)/16*16;
     int display_height;
     int f1, f2;
     unsigned desc_size = size+8+8+8+8+8+8+8+5+16+4+12+20+5;
@@ -1022,27 +1022,27 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke
     mxf_write_generic_desc(s, st, key, desc_size);
 
     mxf_write_local_tag(pb, 4, 0x3203);
-    avio_wb32(pb, st->codec->width);
+    avio_wb32(pb, st->codecpar->width);
 
     mxf_write_local_tag(pb, 4, 0x3202);
     avio_wb32(pb, stored_height>>sc->interlaced);
 
     mxf_write_local_tag(pb, 4, 0x3209);
-    avio_wb32(pb, st->codec->width);
+    avio_wb32(pb, st->codecpar->width);
 
-    if (st->codec->height == 608) // PAL + VBI
+    if (st->codecpar->height == 608) // PAL + VBI
         display_height = 576;
-    else if (st->codec->height == 512)  // NTSC + VBI
+    else if (st->codecpar->height == 512)  // NTSC + VBI
         display_height = 486;
     else
-        display_height = st->codec->height;
+        display_height = st->codecpar->height;
 
     mxf_write_local_tag(pb, 4, 0x3208);
     avio_wb32(pb, display_height>>sc->interlaced);
 
     // presentation Y offset
     mxf_write_local_tag(pb, 4, 0x320B);
-    avio_wb32(pb, (st->codec->height - display_height)>>sc->interlaced);
+    avio_wb32(pb, (st->codecpar->height - display_height)>>sc->interlaced);
 
     // component depth
     mxf_write_local_tag(pb, 4, 0x3301);
@@ -1066,10 +1066,10 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke
     avio_w8(pb, sc->interlaced);
 
     // video line map
-    switch (st->codec->height) {
-    case  576: f1 = 23; f2 = st->codec->codec_id == AV_CODEC_ID_DVVIDEO ? 335 : 336; break;
+    switch (st->codecpar->height) {
+    case  576: f1 = 23; f2 = st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO ? 335 : 336; break;
     case  608: f1 =  7; f2 = 320; break;
-    case  480: f1 = 20; f2 = st->codec->codec_id == AV_CODEC_ID_DVVIDEO ? 285 : 283; break;
+    case  480: f1 = 20; f2 = st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO ? 285 : 283; break;
     case  512: f1 =  7; f2 = 270; break;
     case  720: f1 = 26; f2 =   0; break; // progressive
     case 1080: f1 = 21; f2 = 584; break;
@@ -1111,9 +1111,9 @@ static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st)
 {
     AVIOContext *pb = s->pb;
     MXFStreamContext *sc = st->priv_data;
-    int profile_and_level = (st->codec->profile<<4) | st->codec->level;
+    int profile_and_level = (st->codecpar->profile<<4) | st->codecpar->level;
 
-    if (st->codec->codec_id != AV_CODEC_ID_H264) {
+    if (st->codecpar->codec_id != AV_CODEC_ID_H264) {
         mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8+5);
 
         // bit rate
@@ -1122,7 +1122,7 @@ static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st)
 
         // profile and level
         mxf_write_local_tag(pb, 1, 0x8007);
-        if (!st->codec->profile)
+        if (!st->codecpar->profile)
             profile_and_level |= 0x80; // escape bit
         avio_w8(pb, profile_and_level);
     } else {
@@ -1153,16 +1153,16 @@ static void mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, con
 
     // write audio sampling rate
     mxf_write_local_tag(pb, 8, 0x3D03);
-    avio_wb32(pb, st->codec->sample_rate);
+    avio_wb32(pb, st->codecpar->sample_rate);
     avio_wb32(pb, 1);
 
     mxf_write_local_tag(pb, 4, 0x3D07);
     if (mxf->channel_count == -1) {
-        if (show_warnings && (s->oformat == &ff_mxf_d10_muxer) && (st->codec->channels != 4) && (st->codec->channels != 8))
+        if (show_warnings && (s->oformat == &ff_mxf_d10_muxer) && (st->codecpar->channels != 4) && (st->codecpar->channels != 8))
             av_log(s, AV_LOG_WARNING, "the number of audio channels shall be 4 or 8 : the output will not comply to MXF D-10 specs, use -d10_channelcount to fix this\n");
-        avio_wb32(pb, st->codec->channels);
+        avio_wb32(pb, st->codecpar->channels);
     } else if (s->oformat == &ff_mxf_d10_muxer) {
-        if (show_warnings && (mxf->channel_count < st->codec->channels))
+        if (show_warnings && (mxf->channel_count < st->codecpar->channels))
             av_log(s, AV_LOG_WARNING, "d10_channelcount < actual number of audio channels : some channels will be discarded\n");
         if (show_warnings && (mxf->channel_count != 4) && (mxf->channel_count != 8))
             av_log(s, AV_LOG_WARNING, "d10_channelcount shall be set to 4 or 8 : the output will not comply to MXF D-10 specs\n");
@@ -1170,11 +1170,11 @@ static void mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, con
     } else {
         if (show_warnings && mxf->channel_count != -1 && s->oformat != &ff_mxf_opatom_muxer)
             av_log(s, AV_LOG_ERROR, "-d10_channelcount requires MXF D-10 and will be ignored\n");
-        avio_wb32(pb, st->codec->channels);
+        avio_wb32(pb, st->codecpar->channels);
     }
 
     mxf_write_local_tag(pb, 4, 0x3D01);
-    avio_wb32(pb, av_get_bits_per_sample(st->codec->codec_id));
+    avio_wb32(pb, av_get_bits_per_sample(st->codecpar->codec_id));
 }
 
 static void mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size)
@@ -1184,11 +1184,11 @@ static void mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key
     mxf_write_generic_sound_common(s, st, key, size+6+8);
 
     mxf_write_local_tag(pb, 2, 0x3D0A);
-    avio_wb16(pb, st->codec->block_align);
+    avio_wb16(pb, st->codecpar->block_align);
 
     // avg bytes per sec
     mxf_write_local_tag(pb, 4, 0x3D09);
-    avio_wb32(pb, st->codec->block_align*st->codec->sample_rate);
+    avio_wb32(pb, st->codecpar->block_align*st->codecpar->sample_rate);
 }
 
 static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st)
@@ -1729,10 +1729,10 @@ AVPacket *pkt)
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
         MXFStreamContext *sc = st->priv_data;
-        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+        if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
             mxf->edit_unit_byte_count += 16 + 4 + sc->aic.samples[0]*sc->aic.sample_size;
             mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count);
-        } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+        } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
             mxf->edit_unit_byte_count += 16 + 4 + frame_size;
             mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count);
         }
@@ -1804,10 +1804,10 @@ static int mxf_parse_dv_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt)
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
         MXFStreamContext *sc = st->priv_data;
-        if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+        if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
             mxf->edit_unit_byte_count += 16 + 4 + sc->aic.samples[0]*sc->aic.sample_size;
             mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count);
-        } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+        } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
             mxf->edit_unit_byte_count += 16 + 4 + frame_size;
             mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count);
         }
@@ -1861,7 +1861,7 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st,
         --buf;
         switch (state & 0x1f) {
         case NAL_SPS:
-            st->codec->profile = buf[1];
+            st->codecpar->profile = buf[1];
             e->flags |= 0x40;
             break;
         case NAL_PPS:
@@ -1881,7 +1881,7 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st,
 
     sc->aspect_ratio = (AVRational){ 16, 9 }; // 16:9 is mandatory for broadcast HD
     sc->component_depth = 10; // AVC Intra is always 10 Bit
-    sc->interlaced = st->codec->field_order != AV_FIELD_PROGRESSIVE ? 1 : 0;
+    sc->interlaced = st->codecpar->field_order != AV_FIELD_PROGRESSIVE ? 1 : 0;
     if (sc->interlaced)
         sc->field_dominance = 1; // top field first is mandatory for AVC Intra
 
@@ -1891,7 +1891,7 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st,
         if (frame_size == mxf_h264_codec_uls[i].frame_size && sc->interlaced == mxf_h264_codec_uls[i].interlaced) {
             sc->codec_ul = &mxf_h264_codec_uls[i].uid;
             return 1;
-        } else if (st->codec->profile == mxf_h264_codec_uls[i].profile) {
+        } else if (st->codecpar->profile == mxf_h264_codec_uls[i].profile) {
             sc->codec_ul = &mxf_h264_codec_uls[i].uid;
             uid_found = 1;
         }
@@ -1918,21 +1918,21 @@ static const UID mxf_mpeg2_codec_uls[] = {
     { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x03,0x00 }, // MP@H-14 Long GOP
 };
 
-static const UID *mxf_get_mpeg2_codec_ul(AVCodecContext *avctx)
+static const UID *mxf_get_mpeg2_codec_ul(AVCodecParameters *par)
 {
     int long_gop = 1;
 
-    if (avctx->profile == 4) { // Main
-        if (avctx->level == 8) // Main
+    if (par->profile == 4) { // Main
+        if (par->level == 8) // Main
             return &mxf_mpeg2_codec_uls[0+long_gop];
-        else if (avctx->level == 4) // High
+        else if (par->level == 4) // High
             return &mxf_mpeg2_codec_uls[4+long_gop];
-        else if (avctx->level == 6) // High 14
+        else if (par->level == 6) // High 14
             return &mxf_mpeg2_codec_uls[8+long_gop];
-    } else if (avctx->profile == 0) { // 422
-        if (avctx->level == 5) // Main
+    } else if (par->profile == 0) { // 422
+        if (par->level == 5) // Main
             return &mxf_mpeg2_codec_uls[2+long_gop];
-        else if (avctx->level == 2) // High
+        else if (par->level == 2) // High
             return &mxf_mpeg2_codec_uls[6+long_gop];
     }
     return NULL;
@@ -1949,8 +1949,8 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st,
         c = (c<<8) + pkt->data[i];
         if (c == 0x1b5) {
             if ((pkt->data[i+1] & 0xf0) == 0x10) { // seq ext
-                st->codec->profile = pkt->data[i+1] & 0x07;
-                st->codec->level   = pkt->data[i+2] >> 4;
+                st->codecpar->profile = pkt->data[i+1] & 0x07;
+                st->codecpar->level   = pkt->data[i+2] >> 4;
             } else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext
                 sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame
                 if (sc->interlaced)
@@ -1971,7 +1971,7 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st,
             case 4:  sc->aspect_ratio = (AVRational){221,100}; break;
             default:
                 av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den,
-                          st->codec->width, st->codec->height, 1024*1024);
+                          st->codecpar->width, st->codecpar->height, 1024*1024);
             }
         } else if (c == 0x100) { // pic
             int pict_type = (pkt->data[i+2]>>3) & 0x07;
@@ -1992,7 +1992,7 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st,
         }
     }
     if (s->oformat != &ff_mxf_d10_muxer)
-        sc->codec_ul = mxf_get_mpeg2_codec_ul(st->codec);
+        sc->codec_ul = mxf_get_mpeg2_codec_ul(st->codecpar);
     return !!sc->codec_ul;
 }
 
@@ -2061,13 +2061,13 @@ static int mxf_write_header(AVFormatContext *s)
             return AVERROR(ENOMEM);
         st->priv_data = sc;
 
-        if (((i == 0) ^ (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)) && s->oformat != &ff_mxf_opatom_muxer) {
+        if (((i == 0) ^ (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)) && s->oformat != &ff_mxf_opatom_muxer) {
             av_log(s, AV_LOG_ERROR, "there must be exactly one video stream and it must be the first one\n");
             return -1;
         }
 
-        if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
-            const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codec->pix_fmt);
+        if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+            const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format);
             // TODO: should be avg_frame_rate
             AVRational rate, tbc = st->time_base;
             // Default component depth to 8
@@ -2099,7 +2099,7 @@ static int mxf_write_header(AVFormatContext *s)
             if((ret = mxf_init_timecode(s, st, rate)) < 0)
                 return ret;
 
-            sc->video_bit_rate = st->codec->bit_rate ? st->codec->bit_rate : st->codec->rc_max_rate;
+            sc->video_bit_rate = st->codecpar->bit_rate;
             if (s->oformat == &ff_mxf_d10_muxer) {
                 if ((sc->video_bit_rate == 50000000) && (mxf->time_base.den == 25)) {
                     sc->index = 3;
@@ -2127,31 +2127,31 @@ static int mxf_write_header(AVFormatContext *s)
             }
             if (mxf->signal_standard >= 0)
                 sc->signal_standard = mxf->signal_standard;
-        } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
-            if (st->codec->sample_rate != 48000) {
+        } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
+            if (st->codecpar->sample_rate != 48000) {
                 av_log(s, AV_LOG_ERROR, "only 48khz is implemented\n");
                 return -1;
             }
-            avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+            avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
             if (s->oformat == &ff_mxf_d10_muxer) {
                 if (st->index != 1) {
                     av_log(s, AV_LOG_ERROR, "MXF D-10 only support one audio track\n");
                     return -1;
                 }
-                if (st->codec->codec_id != AV_CODEC_ID_PCM_S16LE &&
-                    st->codec->codec_id != AV_CODEC_ID_PCM_S24LE) {
+                if (st->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE &&
+                    st->codecpar->codec_id != AV_CODEC_ID_PCM_S24LE) {
                     av_log(s, AV_LOG_ERROR, "MXF D-10 only support 16 or 24 bits le audio\n");
                 }
                 sc->index = ((MXFStreamContext*)s->streams[0]->priv_data)->index + 1;
             } else if (s->oformat == &ff_mxf_opatom_muxer) {
                 AVRational tbc = av_inv_q(mxf->audio_edit_rate);
 
-                if (st->codec->codec_id != AV_CODEC_ID_PCM_S16LE &&
-                    st->codec->codec_id != AV_CODEC_ID_PCM_S24LE) {
+                if (st->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE &&
+                    st->codecpar->codec_id != AV_CODEC_ID_PCM_S24LE) {
                     av_log(s, AV_LOG_ERROR, "Only pcm_s16le and pcm_s24le audio codecs are implemented\n");
                     return AVERROR_PATCHWELCOME;
                 }
-                if (st->codec->channels != 1) {
+                if (st->codecpar->channels != 1) {
                     av_log(s, AV_LOG_ERROR, "MXF OPAtom only supports single channel audio\n");
                     return AVERROR(EINVAL);
                 }
@@ -2167,7 +2167,7 @@ static int mxf_write_header(AVFormatContext *s)
                     return ret;
 
                 mxf->timecode_base = (tbc.den + tbc.num/2) / tbc.num;
-                mxf->edit_unit_byte_count = (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
+                mxf->edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3;
                 sc->index = 2;
             } else {
                 mxf->slice_count = 1;
@@ -2175,7 +2175,7 @@ static int mxf_write_header(AVFormatContext *s)
         }
 
         if (!sc->index) {
-            sc->index = mxf_get_essence_container_ul_index(st->codec->codec_id);
+            sc->index = mxf_get_essence_container_ul_index(st->codecpar->codec_id);
             if (sc->index == -1) {
                 av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, "
                        "codec not currently supported in container\n", i);
@@ -2309,7 +2309,7 @@ static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacke
 {
     MXFContext *mxf = s->priv_data;
     AVIOContext *pb = s->pb;
-    int frame_size = pkt->size / st->codec->block_align;
+    int frame_size = pkt->size / st->codecpar->block_align;
     uint8_t *samples = pkt->data;
     uint8_t *end = pkt->data + pkt->size;
     int i;
@@ -2318,12 +2318,12 @@ static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacke
 
     avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));
     avio_wl16(pb, frame_size);
-    avio_w8(pb, (1<<st->codec->channels)-1);
+    avio_w8(pb, (1<<st->codecpar->channels)-1);
 
     while (samples < end) {
-        for (i = 0; i < st->codec->channels; i++) {
+        for (i = 0; i < st->codecpar->channels; i++) {
             uint32_t sample;
-            if (st->codec->codec_id == AV_CODEC_ID_PCM_S24LE) {
+            if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE) {
                 sample = AV_RL24(samples)<< 4;
                 samples += 3;
             } else {
@@ -2406,22 +2406,22 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
         }
     }
 
-    if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
+    if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
         if (!mxf_parse_mpeg2_frame(s, st, pkt, &ie)) {
             av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\n");
             return -1;
         }
-    } else if (st->codec->codec_id == AV_CODEC_ID_DNXHD) {
+    } else if (st->codecpar->codec_id == AV_CODEC_ID_DNXHD) {
         if (!mxf_parse_dnxhd_frame(s, st, pkt)) {
             av_log(s, AV_LOG_ERROR, "could not get dnxhd profile\n");
             return -1;
         }
-    } else if (st->codec->codec_id == AV_CODEC_ID_DVVIDEO) {
+    } else if (st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO) {
         if (!mxf_parse_dv_frame(s, st, pkt)) {
             av_log(s, AV_LOG_ERROR, "could not get dv profile\n");
             return -1;
         }
-    } else if (st->codec->codec_id == AV_CODEC_ID_H264) {
+    } else if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
         if (!mxf_parse_h264_frame(s, st, pkt, &ie)) {
             av_log(s, AV_LOG_ERROR, "could not get h264 profile\n");
             return -1;
@@ -2477,7 +2477,7 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
     mxf_write_klv_fill(s);
     avio_write(pb, sc->track_essence_element_key, 16); // write key
     if (s->oformat == &ff_mxf_d10_muxer) {
-        if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
+        if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
             mxf_write_d10_video_packet(s, st, pkt);
         else
             mxf_write_d10_audio_packet(s, st, pkt);