| 1208 | } |
| 1209 | |
| 1210 | int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt) |
| 1211 | { |
| 1212 | const AVPixFmtDescriptor *desc; |
| 1213 | enum AVPixelFormat *choices; |
| 1214 | enum AVPixelFormat ret, user_choice; |
| 1215 | const AVCodecHWConfigInternal *hw_config; |
| 1216 | const AVCodecHWConfig *config; |
| 1217 | int i, n, err; |
| 1218 | |
| 1219 | // Find end of list. |
| 1220 | for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++); |
| 1221 | // Must contain at least one entry. |
| 1222 | av_assert0(n >= 1); |
| 1223 | // If a software format is available, it must be the last entry. |
| 1224 | desc = av_pix_fmt_desc_get(fmt[n - 1]); |
| 1225 | if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) { |
| 1226 | // No software format is available. |
| 1227 | } else { |
| 1228 | avctx->sw_pix_fmt = fmt[n - 1]; |
| 1229 | } |
| 1230 | |
| 1231 | choices = av_memdup(fmt, (n + 1) * sizeof(*choices)); |
| 1232 | if (!choices) |
| 1233 | return AV_PIX_FMT_NONE; |
| 1234 | |
| 1235 | for (;;) { |
| 1236 | // Remove the previous hwaccel, if there was one. |
| 1237 | ff_hwaccel_uninit(avctx); |
| 1238 | |
| 1239 | user_choice = avctx->get_format(avctx, choices); |
| 1240 | if (user_choice == AV_PIX_FMT_NONE) { |
| 1241 | // Explicitly chose nothing, give up. |
| 1242 | ret = AV_PIX_FMT_NONE; |
| 1243 | break; |
| 1244 | } |
| 1245 | |
| 1246 | desc = av_pix_fmt_desc_get(user_choice); |
| 1247 | if (!desc) { |
| 1248 | av_log(avctx, AV_LOG_ERROR, "Invalid format returned by " |
| 1249 | "get_format() callback.\n"); |
| 1250 | ret = AV_PIX_FMT_NONE; |
| 1251 | break; |
| 1252 | } |
| 1253 | av_log(avctx, AV_LOG_DEBUG, "Format %s chosen by get_format().\n", |
| 1254 | desc->name); |
| 1255 | |
| 1256 | for (i = 0; i < n; i++) { |
| 1257 | if (choices[i] == user_choice) |
| 1258 | break; |
| 1259 | } |
| 1260 | if (i == n) { |
| 1261 | av_log(avctx, AV_LOG_ERROR, "Invalid return from get_format(): " |
| 1262 | "%s not in possible list.\n", desc->name); |
| 1263 | ret = AV_PIX_FMT_NONE; |
| 1264 | break; |
| 1265 | } |
| 1266 | |
| 1267 | if (ffcodec(avctx->codec)->hw_configs) { |
no test coverage detected