@@ -876,6 +876,153 @@ int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
876
876
return ff_set_common_formats (ctx , ff_make_format_list (fmts ));
877
877
}
878
878
879
+ #define SET_COMMON_FORMATS2 (ctx , cfg_in , cfg_out , fmts , media_type , \
880
+ ref_fn , unref_fn ) \
881
+ if (!fmts) \
882
+ return AVERROR(ENOMEM); \
883
+ \
884
+ for (unsigned i = 0; i < ctx->nb_inputs; i++) { \
885
+ const AVFilterLink *const link = ctx->inputs[i]; \
886
+ if (!cfg_in[i]->fmts && \
887
+ (media_type == AVMEDIA_TYPE_UNKNOWN || \
888
+ link->type == media_type)) { \
889
+ int ret = ref_fn(fmts, &cfg_in[i]->fmts); \
890
+ if (ret < 0) { \
891
+ return ret; \
892
+ } \
893
+ } \
894
+ } \
895
+ for (unsigned i = 0; i < ctx->nb_outputs; i++) { \
896
+ const AVFilterLink *const link = ctx->outputs[i]; \
897
+ if (!cfg_out[i]->fmts && \
898
+ (media_type == AVMEDIA_TYPE_UNKNOWN || \
899
+ link->type == media_type)) { \
900
+ int ret = ref_fn(fmts, &cfg_out[i]->fmts); \
901
+ if (ret < 0) { \
902
+ return ret; \
903
+ } \
904
+ } \
905
+ } \
906
+ \
907
+ if (!fmts->refcount) \
908
+ unref_fn(&fmts); \
909
+ \
910
+ return 0;
911
+
912
+ int ff_set_common_channel_layouts2 (const AVFilterContext * ctx ,
913
+ AVFilterFormatsConfig * * cfg_in ,
914
+ AVFilterFormatsConfig * * cfg_out ,
915
+ AVFilterChannelLayouts * channel_layouts )
916
+ {
917
+ SET_COMMON_FORMATS2 (ctx , cfg_in , cfg_out , channel_layouts , AVMEDIA_TYPE_AUDIO ,
918
+ ff_channel_layouts_ref , ff_channel_layouts_unref );
919
+ }
920
+
921
+ int ff_set_common_channel_layouts_from_list2 (const AVFilterContext * ctx ,
922
+ AVFilterFormatsConfig * * cfg_in ,
923
+ AVFilterFormatsConfig * * cfg_out ,
924
+ const AVChannelLayout * fmts )
925
+ {
926
+ return ff_set_common_channel_layouts2 (ctx , cfg_in , cfg_out , ff_make_channel_layout_list (fmts ));
927
+ }
928
+
929
+ int ff_set_common_all_channel_counts2 (const AVFilterContext * ctx ,
930
+ AVFilterFormatsConfig * * cfg_in ,
931
+ AVFilterFormatsConfig * * cfg_out )
932
+ {
933
+ return ff_set_common_channel_layouts2 (ctx , cfg_in , cfg_out , ff_all_channel_counts ());
934
+ }
935
+
936
+ int ff_set_common_samplerates2 (const AVFilterContext * ctx ,
937
+ AVFilterFormatsConfig * * cfg_in ,
938
+ AVFilterFormatsConfig * * cfg_out ,
939
+ AVFilterFormats * samplerates )
940
+ {
941
+ SET_COMMON_FORMATS2 (ctx , cfg_in , cfg_out , samplerates , AVMEDIA_TYPE_AUDIO ,
942
+ ff_formats_ref , ff_formats_unref );
943
+ }
944
+
945
+ int ff_set_common_samplerates_from_list2 (const AVFilterContext * ctx ,
946
+ AVFilterFormatsConfig * * cfg_in ,
947
+ AVFilterFormatsConfig * * cfg_out ,
948
+ const int * samplerates )
949
+ {
950
+ return ff_set_common_samplerates2 (ctx , cfg_in , cfg_out , ff_make_format_list (samplerates ));
951
+ }
952
+
953
+ int ff_set_common_all_samplerates2 (const AVFilterContext * ctx ,
954
+ AVFilterFormatsConfig * * cfg_in ,
955
+ AVFilterFormatsConfig * * cfg_out )
956
+ {
957
+ return ff_set_common_samplerates2 (ctx , cfg_in , cfg_out , ff_all_samplerates ());
958
+ }
959
+
960
+ int ff_set_common_color_spaces2 (const AVFilterContext * ctx ,
961
+ AVFilterFormatsConfig * * cfg_in ,
962
+ AVFilterFormatsConfig * * cfg_out ,
963
+ AVFilterFormats * color_spaces )
964
+ {
965
+ SET_COMMON_FORMATS2 (ctx , cfg_in , cfg_out , color_spaces , AVMEDIA_TYPE_VIDEO ,
966
+ ff_formats_ref , ff_formats_unref );
967
+ }
968
+
969
+ int ff_set_common_color_spaces_from_list2 (const AVFilterContext * ctx ,
970
+ AVFilterFormatsConfig * * cfg_in ,
971
+ AVFilterFormatsConfig * * cfg_out ,
972
+ const int * color_ranges )
973
+ {
974
+ return ff_set_common_color_spaces2 (ctx , cfg_in , cfg_out , ff_make_format_list (color_ranges ));
975
+ }
976
+
977
+ int ff_set_common_all_color_spaces2 (const AVFilterContext * ctx ,
978
+ AVFilterFormatsConfig * * cfg_in ,
979
+ AVFilterFormatsConfig * * cfg_out )
980
+ {
981
+ return ff_set_common_color_spaces2 (ctx , cfg_in , cfg_out , ff_all_color_spaces ());
982
+ }
983
+
984
+ int ff_set_common_color_ranges2 (const AVFilterContext * ctx ,
985
+ AVFilterFormatsConfig * * cfg_in ,
986
+ AVFilterFormatsConfig * * cfg_out ,
987
+ AVFilterFormats * color_ranges )
988
+ {
989
+ SET_COMMON_FORMATS2 (ctx , cfg_in , cfg_out , color_ranges , AVMEDIA_TYPE_VIDEO ,
990
+ ff_formats_ref , ff_formats_unref );
991
+ }
992
+
993
+ int ff_set_common_color_ranges_from_list2 (const AVFilterContext * ctx ,
994
+ AVFilterFormatsConfig * * cfg_in ,
995
+ AVFilterFormatsConfig * * cfg_out ,
996
+ const int * color_ranges )
997
+ {
998
+ return ff_set_common_color_ranges2 (ctx , cfg_in , cfg_out , ff_make_format_list (color_ranges ));
999
+ }
1000
+
1001
+ int ff_set_common_all_color_ranges2 (const AVFilterContext * ctx ,
1002
+ AVFilterFormatsConfig * * cfg_in ,
1003
+ AVFilterFormatsConfig * * cfg_out )
1004
+ {
1005
+ return ff_set_common_color_ranges2 (ctx , cfg_in , cfg_out , ff_all_color_ranges ());
1006
+ }
1007
+
1008
+ int ff_set_common_formats2 (const AVFilterContext * ctx ,
1009
+ AVFilterFormatsConfig * * cfg_in ,
1010
+ AVFilterFormatsConfig * * cfg_out ,
1011
+ AVFilterFormats * formats )
1012
+ {
1013
+ SET_COMMON_FORMATS2 (ctx , cfg_in , cfg_out , formats , AVMEDIA_TYPE_UNKNOWN ,
1014
+ ff_formats_ref , ff_formats_unref );
1015
+ }
1016
+
1017
+ int ff_set_common_formats_from_list2 (const AVFilterContext * ctx ,
1018
+ AVFilterFormatsConfig * * cfg_in ,
1019
+ AVFilterFormatsConfig * * cfg_out ,
1020
+ const int * fmts )
1021
+ {
1022
+ return ff_set_common_formats2 (ctx , cfg_in , cfg_out , ff_make_format_list (fmts ));
1023
+ }
1024
+
1025
+
879
1026
int ff_default_query_formats (AVFilterContext * ctx )
880
1027
{
881
1028
const AVFilter * const f = ctx -> filter ;
@@ -905,6 +1052,7 @@ int ff_default_query_formats(AVFilterContext *ctx)
905
1052
/* Intended fallthrough */
906
1053
case FF_FILTER_FORMATS_PASSTHROUGH :
907
1054
case FF_FILTER_FORMATS_QUERY_FUNC :
1055
+ case FF_FILTER_FORMATS_QUERY_FUNC2 :
908
1056
type = AVMEDIA_TYPE_UNKNOWN ;
909
1057
formats = ff_all_formats (ctx -> nb_inputs ? ctx -> inputs [0 ]-> type :
910
1058
ctx -> nb_outputs ? ctx -> outputs [0 ]-> type :
0 commit comments