]> git.sesse.net Git - nageru/blobdiff - nageru/audio_encoder.cpp
Update most code to the new FFmpeg channel layout API.
[nageru] / nageru / audio_encoder.cpp
index 0f7f9aac8c957e3d686c87daa863719d102982d1..4d42b4033c2a01052e41359005a897066c2fd426 100644 (file)
@@ -29,7 +29,7 @@ using namespace std;
 
 AudioEncoder::AudioEncoder(const string &codec_name, int bit_rate, const AVOutputFormat *oformat)
 {
-       AVCodec *codec = avcodec_find_encoder_by_name(codec_name.c_str());
+       const AVCodec *codec = avcodec_find_encoder_by_name(codec_name.c_str());
        if (codec == nullptr) {
                fprintf(stderr, "ERROR: Could not find codec '%s'\n", codec_name.c_str());
                abort();
@@ -39,8 +39,9 @@ AudioEncoder::AudioEncoder(const string &codec_name, int bit_rate, const AVOutpu
        ctx->bit_rate = bit_rate;
        ctx->sample_rate = OUTPUT_FREQUENCY;
        ctx->sample_fmt = codec->sample_fmts[0];
-       ctx->channels = 2;
-       ctx->channel_layout = AV_CH_LAYOUT_STEREO;
+       ctx->ch_layout.order = AV_CHANNEL_ORDER_NATIVE;
+       ctx->ch_layout.nb_channels = 2;
+       ctx->ch_layout.u.mask = AV_CH_LAYOUT_STEREO;
        ctx->time_base = AVRational{1, TIMEBASE};
        if (oformat->flags & AVFMT_GLOBALHEADER) {
                ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
@@ -110,7 +111,9 @@ void AudioEncoder::encode_audio_one_frame(const float *audio, size_t num_samples
 {
        audio_frame->pts = audio_pts;
        audio_frame->nb_samples = num_samples;
-       audio_frame->channel_layout = AV_CH_LAYOUT_STEREO;
+       audio_frame->ch_layout.order = AV_CHANNEL_ORDER_NATIVE;
+       audio_frame->ch_layout.nb_channels = 2;
+       audio_frame->ch_layout.u.mask = AV_CH_LAYOUT_STEREO;
        audio_frame->format = ctx->sample_fmt;
        audio_frame->sample_rate = OUTPUT_FREQUENCY;