MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / avcodec_default_get_format

Function avcodec_default_get_format

libavcodec/decode.c:987–1048  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

985}
986
987enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *avctx,
988 const enum AVPixelFormat *fmt)
989{
990 const AVPixFmtDescriptor *desc;
991 const AVCodecHWConfig *config;
992 int i, n;
993
994 // If a device was supplied when the codec was opened, assume that the
995 // user wants to use it.
996 if (avctx->hw_device_ctx && ffcodec(avctx->codec)->hw_configs) {
997 AVHWDeviceContext *device_ctx =
998 (AVHWDeviceContext*)avctx->hw_device_ctx->data;
999 for (i = 0;; i++) {
1000 config = &ffcodec(avctx->codec)->hw_configs[i]->public;
1001 if (!config)
1002 break;
1003 if (!(config->methods &
1004 AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX))
1005 continue;
1006 if (device_ctx->type != config->device_type)
1007 continue;
1008 for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1009 if (config->pix_fmt == fmt[n])
1010 return fmt[n];
1011 }
1012 }
1013 }
1014 // No device or other setup, so we have to choose from things which
1015 // don't any other external information.
1016
1017 // If the last element of the list is a software format, choose it
1018 // (this should be best software format if any exist).
1019 for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
1020 desc = av_pix_fmt_desc_get(fmt[n - 1]);
1021 if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
1022 return fmt[n - 1];
1023
1024 // Finally, traverse the list in order and choose the first entry
1025 // with no external dependencies (if there is no hardware configuration
1026 // information available then this just picks the first entry).
1027 for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1028 for (i = 0;; i++) {
1029 config = avcodec_get_hw_config(avctx->codec, i);
1030 if (!config)
1031 break;
1032 if (config->pix_fmt == fmt[n])
1033 break;
1034 }
1035 if (!config) {
1036 // No specific config available, so the decoder must be able
1037 // to handle this format without any additional setup.
1038 return fmt[n];
1039 }
1040 if (config->methods & AV_CODEC_HW_CONFIG_METHOD_INTERNAL) {
1041 // Usable with only internal setup.
1042 return fmt[n];
1043 }
1044 }

Callers

nothing calls this directly

Calls 3

ffcodecFunction · 0.85
av_pix_fmt_desc_getFunction · 0.85
avcodec_get_hw_configFunction · 0.85

Tested by

no test coverage detected