]> git.sesse.net Git - nageru/commitdiff
Remove some use of the AVStream::codec parameter (not all). Fixes some deprecation...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 27 Jul 2016 11:58:19 +0000 (13:58 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 27 Jul 2016 15:29:21 +0000 (17:29 +0200)
audio_encoder.cpp
audio_encoder.h
image_input.cpp
mux.cpp
mux.h
quicksync_encoder.cpp
video_encoder.cpp

index ac1c8f509f9aae5057335e3234dd2c2b123e6aa4..4ba56ad49905024150f44731cd9d93965eea95f7 100644 (file)
@@ -167,3 +167,10 @@ void AudioEncoder::encode_last_audio()
                }
        }
 }
+
+AVCodecParametersWithDeleter AudioEncoder::get_codec_parameters()
+{
+       AVCodecParameters *codecpar = avcodec_parameters_alloc();
+       avcodec_parameters_from_context(codecpar, ctx);
+       return AVCodecParametersWithDeleter(codecpar, avcodec_parameters_free_unique);
+}
index 786d36498bec525def5786e702f200bf79f189fb..8a08af5a1df25b91d967be86a6884dd3b1a3f680 100644 (file)
@@ -3,6 +3,7 @@
 #ifndef _AUDIO_ENCODER_H
 #define _AUDIO_ENCODER_H 1
 
+#include <memory>
 #include <string>
 #include <vector>
 
@@ -14,6 +15,14 @@ extern "C" {
 
 #include "mux.h"
 
+static inline void avcodec_parameters_free_unique(AVCodecParameters *codec_par)
+{
+       avcodec_parameters_free(&codec_par);
+}
+
+typedef std::unique_ptr<AVCodecParameters, decltype(avcodec_parameters_free_unique)*>
+AVCodecParametersWithDeleter;
+
 class AudioEncoder {
 public:
        AudioEncoder(const std::string &codec_name, int bit_rate, const AVOutputFormat *oformat);
@@ -25,7 +34,7 @@ public:
        void encode_audio(const std::vector<float> &audio, int64_t audio_pts);
        void encode_last_audio();
 
-       const AVCodecContext *get_ctx() { return ctx; }
+       AVCodecParametersWithDeleter get_codec_parameters();
 
 private:
        void encode_audio_one_frame(const float *audio, size_t num_samples, int64_t audio_pts);
index 49c2f62d8aef7837417baab77002e3f261f2461d..121fa7bf3c6872c04e8b72e332e01486d5704aed 100644 (file)
@@ -163,7 +163,7 @@ shared_ptr<const ImageInput::Image> ImageInput::load_image_raw(const string &pat
 
        int stream_index = -1;
        for (unsigned i = 0; i < format_ctx->nb_streams; ++i) {
-               if (format_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+               if (format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
                        stream_index = i;
                        break;
                }
diff --git a/mux.cpp b/mux.cpp
index cc67eb616b466b4a4e42f89fe511eeba8c081e11..8dd969a3ec8a95b4a21d21a4e7eae906ce584f6d 100644 (file)
--- a/mux.cpp
+++ b/mux.cpp
@@ -29,44 +29,41 @@ struct PacketBefore {
        const AVFormatContext * const ctx;
 };
 
-Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const string &video_extradata, const AVCodecContext *audio_ctx, int time_base)
+Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const string &video_extradata, const AVCodecParameters *audio_codecpar, int time_base)
        : avctx(avctx)
 {
-       AVCodec *codec_video = avcodec_find_encoder((video_codec == CODEC_H264) ? AV_CODEC_ID_H264 : AV_CODEC_ID_RAWVIDEO);
-       avstream_video = avformat_new_stream(avctx, codec_video);
+       avstream_video = avformat_new_stream(avctx, nullptr);
        if (avstream_video == nullptr) {
                fprintf(stderr, "avformat_new_stream() failed\n");
                exit(1);
        }
        avstream_video->time_base = AVRational{1, time_base};
-       avstream_video->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+       avstream_video->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
        if (video_codec == CODEC_H264) {
-               avstream_video->codec->codec_id = AV_CODEC_ID_H264;
+               avstream_video->codecpar->codec_id = AV_CODEC_ID_H264;
        } else {
                assert(video_codec == CODEC_NV12);
-               avstream_video->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
-               avstream_video->codec->codec_tag = avcodec_pix_fmt_to_codec_tag(AV_PIX_FMT_NV12);
+               avstream_video->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
+               avstream_video->codecpar->codec_tag = avcodec_pix_fmt_to_codec_tag(AV_PIX_FMT_NV12);
        }
-       avstream_video->codec->width = width;
-       avstream_video->codec->height = height;
-       avstream_video->codec->time_base = AVRational{1, time_base};
-       avstream_video->codec->ticks_per_frame = 1;  // or 2?
+       avstream_video->codecpar->width = width;
+       avstream_video->codecpar->height = height;
 
        // Colorspace details. Closely correspond to settings in EffectChain_finalize,
        // as noted in each comment.
        // Note that the H.264 stream also contains this information and depending on the
        // mux, this might simply get ignored. See sps_rbsp().
-       avstream_video->codec->color_primaries = AVCOL_PRI_BT709;  // RGB colorspace (inout_format.color_space).
-       avstream_video->codec->color_trc = AVCOL_TRC_UNSPECIFIED;  // Gamma curve (inout_format.gamma_curve).
-       avstream_video->codec->colorspace = AVCOL_SPC_SMPTE170M;  // YUV colorspace (output_ycbcr_format.luma_coefficients).
-       avstream_video->codec->color_range = AVCOL_RANGE_MPEG;  // Full vs. limited range (output_ycbcr_format.full_range).
-       avstream_video->codec->chroma_sample_location = AVCHROMA_LOC_LEFT;  // Chroma sample location. See chroma_offset_0[] in Mixer::subsample_chroma().
-       avstream_video->codec->field_order = AV_FIELD_PROGRESSIVE;
+       avstream_video->codecpar->color_primaries = AVCOL_PRI_BT709;  // RGB colorspace (inout_format.color_space).
+       avstream_video->codecpar->color_trc = AVCOL_TRC_UNSPECIFIED;  // Gamma curve (inout_format.gamma_curve).
+       avstream_video->codecpar->color_space = AVCOL_SPC_SMPTE170M;  // YUV colorspace (output_ycbcr_format.luma_coefficients).
+       avstream_video->codecpar->color_range = AVCOL_RANGE_MPEG;  // Full vs. limited range (output_ycbcr_format.full_range).
+       avstream_video->codecpar->chroma_location = AVCHROMA_LOC_LEFT;  // Chroma sample location. See chroma_offset_0[] in Mixer::subsample_chroma().
+       avstream_video->codecpar->field_order = AV_FIELD_PROGRESSIVE;
 
        if (!video_extradata.empty()) {
-               avstream_video->codec->extradata = (uint8_t *)av_malloc(video_extradata.size());
-               avstream_video->codec->extradata_size = video_extradata.size();
-               memcpy(avstream_video->codec->extradata, video_extradata.data(), video_extradata.size());
+               avstream_video->codecpar->extradata = (uint8_t *)av_malloc(video_extradata.size());
+               avstream_video->codecpar->extradata_size = video_extradata.size();
+               memcpy(avstream_video->codecpar->extradata, video_extradata.data(), video_extradata.size());
        }
 
        avstream_audio = avformat_new_stream(avctx, nullptr);
@@ -75,7 +72,10 @@ Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const
                exit(1);
        }
        avstream_audio->time_base = AVRational{1, time_base};
-       avcodec_copy_context(avstream_audio->codec, audio_ctx);
+       if (avcodec_parameters_copy(avstream_audio->codecpar, audio_codecpar) < 0) {
+               fprintf(stderr, "avcodec_parameters_copy() failed\n");
+               exit(1);
+       }
 
        AVDictionary *options = NULL;
        vector<pair<string, string>> opts = MUX_OPTS;
diff --git a/mux.h b/mux.h
index 83030215e86df4d3b5ae0a8adc581fdfd9d35e97..b3ea0120736e13c8cecd2daad5dc0975cd584df3 100644 (file)
--- a/mux.h
+++ b/mux.h
@@ -21,7 +21,7 @@ public:
        };
 
        // Takes ownership of avctx. <keyframe_signal_receiver> can be nullptr.
-       Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const std::string &video_extradata, const AVCodecContext *audio_ctx, int time_base);
+       Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const std::string &video_extradata, const AVCodecParameters *audio_codecpar, int time_base);
        ~Mux();
        void add_packet(const AVPacket &pkt, int64_t pts, int64_t dts);
 
index 11d1c0de6e36b988bf4b6c32d51a3085f5e73d7a..5bba54632907216d79fcc6801f1c8299e85eb56f 100644 (file)
@@ -1942,7 +1942,8 @@ void QuickSyncEncoderImpl::open_output_file(const std::string &filename)
        }
 
        string video_extradata = "";  // FIXME: See other comment about global headers.
-       file_mux.reset(new Mux(avctx, frame_width, frame_height, Mux::CODEC_H264, video_extradata, file_audio_encoder->get_ctx(), TIMEBASE));
+       AVCodecParametersWithDeleter audio_codecpar = file_audio_encoder->get_codec_parameters();
+       file_mux.reset(new Mux(avctx, frame_width, frame_height, Mux::CODEC_H264, video_extradata, audio_codecpar.get(), TIMEBASE));
 }
 
 void QuickSyncEncoderImpl::encode_thread_func()
index dbb2aa774502f67fb4469a8b7b462594aef5908a..0f3785f198279bcd1580c7e66d98738e1f295add 100644 (file)
@@ -146,7 +146,7 @@ void VideoEncoder::open_output_stream()
        }
 
        int time_base = global_flags.stream_coarse_timebase ? COARSE_TIMEBASE : TIMEBASE;
-       stream_mux.reset(new Mux(avctx, width, height, video_codec, video_extradata, stream_audio_encoder->get_ctx(), time_base));
+       stream_mux.reset(new Mux(avctx, width, height, video_codec, video_extradata, stream_audio_encoder->get_codec_parameters().get(), time_base));
 }
 
 int VideoEncoder::write_packet2_thunk(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time)