@@ -191,7 +191,7 @@ static void FillMediaFileProp(AVFormatContext *fmt_ctx,
191191{
192192 if (aud_dec_ctx != nullptr )
193193 {
194- out_prop.audio = media::AudioFormat (aud_dec_ctx->sample_rate , aud_dec_ctx->channels );
194+ out_prop.audio = media::AudioFormat (aud_dec_ctx->sample_rate , aud_dec_ctx->ch_layout . nb_channels );
195195 }
196196
197197 if ((vid_dec_ctx != nullptr ) && video_stream_index >= 0 )
@@ -635,7 +635,7 @@ int64_t FFmpegStreamer::ProcessAudioBuffer(AVFilterContext* aud_buffersink_ctx,
635635 frame_timestamp -= start_offset;
636636 }
637637
638- int const n_channels = av_get_channel_layout_nb_channels ( filt_frame->channel_layout ) ;
638+ int const n_channels = filt_frame->ch_layout . nb_channels ;
639639 auto * audio_data = reinterpret_cast <short *>(filt_frame->data [0 ]);
640640
641641 AudioFrame media_frame;
@@ -741,28 +741,27 @@ AVFilterGraph* CreateAudioFilterGraph(AVFormatContext *fmt_ctx,
741741
742742 const AVFilter *abuffersrc = avfilter_get_by_name (" abuffer" );
743743 const AVFilter *abuffersink = avfilter_get_by_name (" abuffersink" );
744- AVFilterInOut *outputs = avfilter_inout_alloc (); // TODO: Free??
745- AVFilterInOut *inputs = avfilter_inout_alloc (); // TODO: Free??
746- const enum AVSampleFormat OUT_SAMPLE_FMTS[] = { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE };
747- int64_t out_channel_layouts[] = { -1 , -1 };
748- int out_sample_rates[] = { out_samplerate, -1 };
744+ AVFilterInOut *outputs = avfilter_inout_alloc ();
745+ AVFilterInOut *inputs = avfilter_inout_alloc ();
749746 const AVFilterLink *outlink = nullptr ;
750747 char args[512 ];
751748 char filter_descr[100 ];
749+ char ch_layout_str[64 ];
752750 int ret = 0 ;
753751 AVRational const time_base = fmt_ctx->streams [audio_stream_index]->time_base ;
754- out_channel_layouts[0 ] = (out_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO);
752+ AVChannelLayout out_ch_layout = out_channels == 1 ?
753+ (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO : (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
755754
756755 filter_graph = avfilter_graph_alloc ();
757756
758- /* buffer audio source: the decoded frames from the decoder will be inserted here. */
759- if (aud_dec_ctx->channel_layout == 0u )
760- aud_dec_ctx->channel_layout = av_get_default_channel_layout (aud_dec_ctx->channels );
757+ if (aud_dec_ctx->ch_layout .order == AV_CHANNEL_ORDER_UNSPEC)
758+ av_channel_layout_default (&aud_dec_ctx->ch_layout , aud_dec_ctx->ch_layout .nb_channels );
761759
760+ av_channel_layout_describe (&aud_dec_ctx->ch_layout , ch_layout_str, sizeof (ch_layout_str));
762761 snprintf (args, sizeof (args),
763- " time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%x " ,
762+ " time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%s " ,
764763 time_base.num , time_base.den , aud_dec_ctx->sample_rate ,
765- av_get_sample_fmt_name (aud_dec_ctx->sample_fmt ), ( unsigned )aud_dec_ctx-> channel_layout );
764+ av_get_sample_fmt_name (aud_dec_ctx->sample_fmt ), ch_layout_str );
766765
767766 ret = avfilter_graph_create_filter (&aud_buffersrc_ctx, abuffersrc, " in" ,
768767 args, nullptr , filter_graph);
@@ -772,33 +771,52 @@ AVFilterGraph* CreateAudioFilterGraph(AVFormatContext *fmt_ctx,
772771 }
773772
774773 /* buffer audio sink: to terminate the filter chain. */
775- ret = avfilter_graph_create_filter (&aud_buffersink_ctx, abuffersink, " out" ,
776- nullptr , nullptr , filter_graph);
777- if (ret < 0 ) {
774+ aud_buffersink_ctx = avfilter_graph_alloc_filter (filter_graph, abuffersink, " out" );
775+ if (!aud_buffersink_ctx) {
778776 MYTRACE (ACE_TEXT (" Cannot create audio buffer sink\n " ));
777+ ret = AVERROR (ENOMEM);
779778 goto error;
780779 }
781780
782- ret = av_opt_set_int_list (aud_buffersink_ctx, " sample_fmts" , OUT_SAMPLE_FMTS, -1 ,
783- AV_OPT_SEARCH_CHILDREN);
781+ {
782+ const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16 };
783+ ret = av_opt_set_array (aud_buffersink_ctx, " sample_formats" ,
784+ AV_OPT_SEARCH_CHILDREN,
785+ 0 , 1 , AV_OPT_TYPE_SAMPLE_FMT, sample_fmts);
786+ }
784787 if (ret < 0 ) {
785788 MYTRACE (ACE_TEXT (" Failed to set output sample fmt\n " ));
786789 goto error;
787790 }
788791
789- ret = av_opt_set_int_list (aud_buffersink_ctx, " channel_layouts" , out_channel_layouts, -1 ,
790- AV_OPT_SEARCH_CHILDREN);
792+ {
793+ const AVChannelLayout channel_layouts[] = { out_ch_layout };
794+ ret = av_opt_set_array (aud_buffersink_ctx, " channel_layouts" ,
795+ AV_OPT_SEARCH_CHILDREN,
796+ 0 , 1 , AV_OPT_TYPE_CHLAYOUT, channel_layouts);
797+ }
791798 if (ret < 0 ) {
792799 MYTRACE (ACE_TEXT (" Cannot set output channel layout\n " ));
793800 goto error;
794801 }
795- ret = av_opt_set_int_list (aud_buffersink_ctx, " sample_rates" , out_sample_rates, -1 ,
796- AV_OPT_SEARCH_CHILDREN);
802+
803+ {
804+ const int samplerates[] = { out_samplerate };
805+ ret = av_opt_set_array (aud_buffersink_ctx, " samplerates" ,
806+ AV_OPT_SEARCH_CHILDREN,
807+ 0 , 1 , AV_OPT_TYPE_INT, samplerates);
808+ }
797809 if (ret < 0 ) {
798810 MYTRACE (ACE_TEXT (" Cannot set output sample rate\n " ));
799811 goto error;
800812 }
801813
814+ ret = avfilter_init_dict (aud_buffersink_ctx, nullptr );
815+ if (ret < 0 ) {
816+ MYTRACE (ACE_TEXT (" Cannot initialize audio buffer sink\n " ));
817+ goto error;
818+ }
819+
802820 /* Endpoints for the filter graph. */
803821 outputs->name = av_strdup (" in" );
804822 outputs->filter_ctx = aud_buffersrc_ctx;
@@ -863,7 +881,6 @@ AVFilterGraph* CreateVideoFilterGraph(AVFormatContext *fmt_ctx,
863881 AVFilterInOut *outputs = avfilter_inout_alloc ();
864882 AVFilterInOut *inputs = avfilter_inout_alloc ();
865883 AVRational const time_base = fmt_ctx->streams [video_stream_index]->time_base ;
866- const enum AVPixelFormat PIX_FMTS[] = { output_pixfmt, AV_PIX_FMT_NONE };
867884 char filters_descr[100 ];
868885
869886 snprintf (filters_descr, sizeof (filters_descr), " scale=%d:%d" ,
@@ -888,20 +905,30 @@ AVFilterGraph* CreateVideoFilterGraph(AVFormatContext *fmt_ctx,
888905 }
889906
890907 /* buffer video sink: to terminate the filter chain. */
891- ret = avfilter_graph_create_filter (&vid_buffersink_ctx, buffersink, " out" ,
892- nullptr , nullptr , filter_graph);
893- if (ret < 0 ) {
908+ vid_buffersink_ctx = avfilter_graph_alloc_filter (filter_graph, buffersink, " out" );
909+ if (!vid_buffersink_ctx) {
894910 MYTRACE (ACE_TEXT (" Cannot create buffer sink\n " ));
911+ ret = AVERROR (ENOMEM);
895912 goto error;
896913 }
897914
898- ret = av_opt_set_int_list (vid_buffersink_ctx, " pix_fmts" , PIX_FMTS,
899- AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
915+ {
916+ const enum AVPixelFormat pixel_formats[] = { output_pixfmt };
917+ ret = av_opt_set_array (vid_buffersink_ctx, " pixel_formats" ,
918+ AV_OPT_SEARCH_CHILDREN,
919+ 0 , 1 , AV_OPT_TYPE_PIXEL_FMT, pixel_formats);
920+ }
900921 if (ret < 0 ) {
901922 MYTRACE (ACE_TEXT (" Cannot set output pixel format\n " ));
902923 goto error;
903924 }
904925
926+ ret = avfilter_init_dict (vid_buffersink_ctx, nullptr );
927+ if (ret < 0 ) {
928+ MYTRACE (ACE_TEXT (" Cannot initialize video buffer sink\n " ));
929+ goto error;
930+ }
931+
905932 /* Endpoints for the filter graph. */
906933 outputs->name = av_strdup (" in" );
907934 outputs->filter_ctx = vid_buffersrc_ctx;
0 commit comments