@@ -139,19 +139,22 @@ static void hwdevice_ctx_free(void *opaque, uint8_t *data)
av_freep(&ctx);
}
+static const HWContextType *hwcontext_find_type(enum AVHWDeviceType type)
+{
+ for (int i = 0; hw_table[i]; i++) {
+ if (hw_table[i]->type == type)
+ return hw_table[i];
+ }
+ return NULL;
+}
+
AVBufferRef *av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
{
AVHWDeviceContext *ctx;
AVBufferRef *buf;
- const HWContextType *hw_type = NULL;
- int i;
+ const HWContextType *hw_type;
- for (i = 0; hw_table[i]; i++) {
- if (hw_table[i]->type == type) {
- hw_type = hw_table[i];
- break;
- }
- }
+ hw_type = hwcontext_find_type(type);
if (!hw_type)
return NULL;
@@ -652,6 +655,11 @@ int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr,
AVHWDeviceContext *dst_ctx, *tmp_ctx;
int ret = 0;
+ if (!hwcontext_find_type(type)) {
+ // The type we want to derive is not supported in this build.
+ return AVERROR(ENOSYS);
+ }
+
tmp_ref = src_ref;
while (tmp_ref) {
tmp_ctx = (AVHWDeviceContext*)tmp_ref->data;