Remove surprises from aom_codec_control The aom_codec_control API has surprising behavior: ---- aom_codec_control(&ctx, AOME_SET_CPUUSED, 8); // Fine int ctrl_id = AOME_SET_CPUUSED; aom_codec_control(&ctx, ctrl_id, 8); // Compiler error ---- aom_codec_control is a macro that expands to aom_codec_control_##ctrl_id for each control type. When users encounter the above problem, they must either call aom_codec_control_ (which is the underlying function without type-checking) or define AOM_DISABLE_CTRL_TYPECHECKS. Due to this behavior, both versions are used in the codebase. This patch: 1. Renames aom_codec_control_ to aom_codec_control 2. Creates the macro AOM_CODEC_CONTROL_TYPECHECKED to perform the same type-checking as before, with a simpler implementation Note that the macro-define AOM_DISABLE_CTRL_TYPECHECKS is no longer checked; when upgrading to libaom 2.0.0, it is advised to remove references to this macro-define. BUG=aomedia:2651 Change-Id: Ic2ec82ccc7a5b68f9a3fe6185f8fc297b4fcafd7 (cherry picked from commit 60dd0f988ec989c998a418dc8b9511c267248c0c)
diff --git a/aom/aom.h b/aom/aom.h index 6a5eee5..c591dc9 100644 --- a/aom/aom.h +++ b/aom/aom.h
@@ -77,16 +77,25 @@ /*!\cond */ /*!\brief aom decoder control function parameter type * - * defines the data type for each of AOM decoder control function requires + * Defines the data type for each of AOM decoder control function requires. + * + * \note For each control ID "X", a macro-define of + * AOM_CTRL_X is provided. It is used at compile time to determine + * if the control ID is supported by the libaom library available, + * when the libaom version cannot be controlled. */ AOM_CTRL_USE_TYPE(AV1_GET_REFERENCE, av1_ref_frame_t *) #define AOM_CTRL_AV1_GET_REFERENCE + AOM_CTRL_USE_TYPE(AV1_SET_REFERENCE, av1_ref_frame_t *) #define AOM_CTRL_AV1_SET_REFERENCE + AOM_CTRL_USE_TYPE(AV1_COPY_REFERENCE, av1_ref_frame_t *) #define AOM_CTRL_AV1_COPY_REFERENCE + AOM_CTRL_USE_TYPE(AV1_GET_NEW_FRAME_IMAGE, aom_image_t *) #define AOM_CTRL_AV1_GET_NEW_FRAME_IMAGE + AOM_CTRL_USE_TYPE(AV1_COPY_NEW_FRAME_IMAGE, aom_image_t *) #define AOM_CTRL_AV1_COPY_NEW_FRAME_IMAGE
diff --git a/aom/aom_codec.h b/aom/aom_codec.h index 9ac5619..75f6a1a 100644 --- a/aom/aom_codec.h +++ b/aom/aom_codec.h
@@ -95,7 +95,7 @@ * types, removing or reassigning enums, adding/removing/rearranging * fields to structures */ -#define AOM_CODEC_ABI_VERSION (4 + AOM_IMAGE_ABI_VERSION) /**<\hideinitializer*/ +#define AOM_CODEC_ABI_VERSION (5 + AOM_IMAGE_ABI_VERSION) /**<\hideinitializer*/ /*!\brief Algorithm return codes */ typedef enum { @@ -385,19 +385,24 @@ */ aom_codec_caps_t aom_codec_get_caps(aom_codec_iface_t *iface); -/*!\brief Control algorithm +/*!\name Codec Control * - * This function is used to exchange algorithm specific data with the codec - * instance. This can be used to implement features specific to a particular - * algorithm. + * The aom_codec_control function exchanges algorithm specific data with the + * codec instance. Additionally, the macro AOM_CODEC_CONTROL_TYPECHECKED is + * provided, which will type-check the parameter against the control ID before + * calling aom_codec_control - note that this macro requires the control ID + * to be directly encoded in it, e.g., + * AOM_CODEC_CONTROL_TYPECHECKED(&ctx, AOME_SET_CPUUSED, 8). * - * This wrapper function dispatches the request to the helper function - * associated with the given ctrl_id. It tries to call this function - * transparently, but will return #AOM_CODEC_ERROR if the request could not - * be dispatched. + * The codec control IDs can be found in aom.h, aomcx.h, and aomdx.h + * (defined as aom_com_control_id, aome_enc_control_id, and aom_dec_control_id). + * @{ + */ +/*!\brief Algorithm Control * - * Note that this function should not be used directly. Call the - * #aom_codec_control wrapper macro instead. + * aom_codec_control takes a context, a control ID, and a third parameter + * (with varying type). If the context is non-null and an error occurs, + * ctx->err will be set to the same value as the return value. * * \param[in] ctx Pointer to this instance's context * \param[in] ctrl_id Algorithm specific control identifier @@ -409,85 +414,33 @@ * \retval #AOM_CODEC_INVALID_PARAM * The data was not valid. */ -aom_codec_err_t aom_codec_control_(aom_codec_ctx_t *ctx, int ctrl_id, ...); -#if defined(AOM_DISABLE_CTRL_TYPECHECKS) && AOM_DISABLE_CTRL_TYPECHECKS -#define aom_codec_control(ctx, id, data) aom_codec_control_(ctx, id, data) -#define AOM_CTRL_USE_TYPE(id, typ) -#define AOM_CTRL_USE_TYPE_DEPRECATED(id, typ) -#define AOM_CTRL_VOID(id, typ) +aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id, ...); -#else -/*!\brief aom_codec_control wrapper macro +/*!\brief aom_codec_control wrapper macro (adds type-checking, less flexible) * * This macro allows for type safe conversions across the variadic parameter - * to aom_codec_control_(). - * - * \internal - * It works by dispatching the call to the control function through a wrapper - * function named with the id parameter. + * to aom_codec_control(). However, it requires the explicit control ID + * be passed in (it cannot be passed in via a variable) -- otherwise a compiler + * error will occur. After the type checking, it calls aom_codec_control. */ -#define aom_codec_control(ctx, id, data) \ - aom_codec_control_##id(ctx, id, data) /**<\hideinitializer*/ +#define AOM_CODEC_CONTROL_TYPECHECKED(ctx, id, data) \ + aom_codec_control_typechecked_##id(ctx, id, data) /**<\hideinitializer*/ -/*!\brief aom_codec_control type definition macro +/*!\brief Creates typechecking mechanisms for aom_codec_control * - * This macro allows for type safe conversions across the variadic parameter - * to aom_codec_control_(). It defines the type of the argument for a given - * control identifier. - * - * \internal - * It defines a static function with - * the correctly typed arguments as a wrapper to the type-unsafe internal - * function. + * It defines a static function with the correctly typed arguments as a wrapper + * to the type-unsafe aom_codec_control function. It also creates a typedef + * for each type. */ -#define AOM_CTRL_USE_TYPE(id, typ) \ - static aom_codec_err_t aom_codec_control_##id(aom_codec_ctx_t *, int, typ) \ - AOM_UNUSED; \ - \ - static aom_codec_err_t aom_codec_control_##id(aom_codec_ctx_t *ctx, \ - int ctrl_id, typ data) { \ - return aom_codec_control_(ctx, ctrl_id, data); \ - } /**<\hideinitializer*/ - -/*!\brief aom_codec_control deprecated type definition macro - * - * Like #AOM_CTRL_USE_TYPE, but indicates that the specified control is - * deprecated and should not be used. Consult the documentation for your - * codec for more information. - * - * \internal - * It defines a static function with the correctly typed arguments as a - * wrapper to the type-unsafe internal function. - */ -#define AOM_CTRL_USE_TYPE_DEPRECATED(id, typ) \ - AOM_DECLSPEC_DEPRECATED static aom_codec_err_t aom_codec_control_##id( \ - aom_codec_ctx_t *, int, typ) AOM_DEPRECATED AOM_UNUSED; \ - \ - AOM_DECLSPEC_DEPRECATED static aom_codec_err_t aom_codec_control_##id( \ - aom_codec_ctx_t *ctx, int ctrl_id, typ data) { \ - return aom_codec_control_(ctx, ctrl_id, data); \ - } /**<\hideinitializer*/ - -/*!\brief aom_codec_control void type definition macro - * - * This macro allows for type safe conversions across the variadic parameter - * to aom_codec_control_(). It indicates that a given control identifier takes - * no argument. - * - * \internal - * It defines a static function without a data argument as a wrapper to the - * type-unsafe internal function. - */ -#define AOM_CTRL_VOID(id) \ - static aom_codec_err_t aom_codec_control_##id(aom_codec_ctx_t *, int) \ - AOM_UNUSED; \ - \ - static aom_codec_err_t aom_codec_control_##id(aom_codec_ctx_t *ctx, \ - int ctrl_id) { \ - return aom_codec_control_(ctx, ctrl_id); \ - } /**<\hideinitializer*/ - -#endif +#define AOM_CTRL_USE_TYPE(id, typ) \ + static aom_codec_err_t aom_codec_control_typechecked_##id( \ + aom_codec_ctx_t *, int, typ) AOM_UNUSED; \ + static aom_codec_err_t aom_codec_control_typechecked_##id( \ + aom_codec_ctx_t *ctx, int ctrl, typ data) { \ + return aom_codec_control(ctx, ctrl, data); \ + } /**<\hideinitializer*/ \ + typedef typ aom_codec_control_type_##id; +/*!@} end Codec Control group */ /*!\brief OBU types. */ typedef enum ATTRIBUTE_PACKED {
diff --git a/aom/aomcx.h b/aom/aomcx.h index 7515ef9..051d33e 100644 --- a/aom/aomcx.h +++ b/aom/aomcx.h
@@ -148,7 +148,7 @@ * This set of macros define the control functions available for AVx * encoder interface. * - * \sa #aom_codec_control + * \sa #aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id, ...) */ enum aome_enc_control_id { /*!\brief Codec control function to set which reference frame encoder can use, @@ -1384,17 +1384,24 @@ /*!\cond */ /*!\brief Encoder control function parameter type * - * Defines the data types that AOME/AV1E control functions take. Note that - * additional common controls are defined in aom.h + * Defines the data types that AOME/AV1E control functions take. * + * \note Additional common controls are defined in aom.h. + * + * \note For each control ID "X", a macro-define of + * AOM_CTRL_X is provided. It is used at compile time to determine + * if the control ID is supported by the libaom library available, + * when the libaom version cannot be controlled. */ - AOM_CTRL_USE_TYPE(AOME_USE_REFERENCE, int) #define AOM_CTRL_AOME_USE_REFERENCE + AOM_CTRL_USE_TYPE(AOME_SET_ROI_MAP, aom_roi_map_t *) #define AOM_CTRL_AOME_SET_ROI_MAP + AOM_CTRL_USE_TYPE(AOME_SET_ACTIVEMAP, aom_active_map_t *) #define AOM_CTRL_AOME_SET_ACTIVEMAP + AOM_CTRL_USE_TYPE(AOME_SET_SCALEMODE, aom_scaling_mode_t *) #define AOM_CTRL_AOME_SET_SCALEMODE @@ -1403,6 +1410,7 @@ AOM_CTRL_USE_TYPE(AOME_SET_CPUUSED, int) #define AOM_CTRL_AOME_SET_CPUUSED + AOM_CTRL_USE_TYPE(AOME_SET_ENABLEAUTOALTREF, unsigned int) #define AOM_CTRL_AOME_SET_ENABLEAUTOALTREF @@ -1411,15 +1419,19 @@ AOM_CTRL_USE_TYPE(AOME_SET_SHARPNESS, unsigned int) #define AOM_CTRL_AOME_SET_SHARPNESS + AOM_CTRL_USE_TYPE(AOME_SET_STATIC_THRESHOLD, unsigned int) #define AOM_CTRL_AOME_SET_STATIC_THRESHOLD AOM_CTRL_USE_TYPE(AOME_SET_ARNR_MAXFRAMES, unsigned int) #define AOM_CTRL_AOME_SET_ARNR_MAXFRAMES + AOM_CTRL_USE_TYPE(AOME_SET_ARNR_STRENGTH, unsigned int) #define AOM_CTRL_AOME_SET_ARNR_STRENGTH + AOM_CTRL_USE_TYPE(AOME_SET_TUNING, int) /* aom_tune_metric */ #define AOM_CTRL_AOME_SET_TUNING + AOM_CTRL_USE_TYPE(AOME_SET_CQ_LEVEL, unsigned int) #define AOM_CTRL_AOME_SET_CQ_LEVEL @@ -1428,6 +1440,7 @@ AOM_CTRL_USE_TYPE(AV1E_SET_TILE_COLUMNS, unsigned int) #define AOM_CTRL_AV1E_SET_TILE_COLUMNS + AOM_CTRL_USE_TYPE(AV1E_SET_TILE_ROWS, unsigned int) #define AOM_CTRL_AV1E_SET_TILE_ROWS @@ -1439,11 +1452,13 @@ AOM_CTRL_USE_TYPE(AOME_GET_LAST_QUANTIZER, int *) #define AOM_CTRL_AOME_GET_LAST_QUANTIZER + AOM_CTRL_USE_TYPE(AOME_GET_LAST_QUANTIZER_64, int *) #define AOM_CTRL_AOME_GET_LAST_QUANTIZER_64 AOM_CTRL_USE_TYPE(AOME_SET_MAX_INTRA_BITRATE_PCT, unsigned int) #define AOM_CTRL_AOME_SET_MAX_INTRA_BITRATE_PCT + AOM_CTRL_USE_TYPE(AOME_SET_MAX_INTER_BITRATE_PCT, unsigned int) #define AOM_CTRL_AOME_SET_MAX_INTER_BITRATE_PCT @@ -1494,6 +1509,7 @@ AOM_CTRL_USE_TYPE(AV1E_SET_NUM_TG, unsigned int) #define AOM_CTRL_AV1E_SET_NUM_TG + AOM_CTRL_USE_TYPE(AV1E_SET_MTU, unsigned int) #define AOM_CTRL_AV1E_SET_MTU
diff --git a/aom/aomdx.h b/aom/aomdx.h index 1f0414b..8cd5de3 100644 --- a/aom/aomdx.h +++ b/aom/aomdx.h
@@ -106,7 +106,7 @@ * This set of macros define the control functions available for the AOM * decoder interface. * - * \sa #aom_codec_control + * \sa #aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id, ...) */ enum aom_dec_control_id { /*!\brief Codec control function to get info on which reference frames were @@ -304,59 +304,87 @@ /*!\cond */ /*!\brief AOM decoder control function parameter type * - * Defines the data types that AOMD control functions take. Note that - * additional common controls are defined in aom.h + * Defines the data types that AOMD control functions take. * + * \note Additional common controls are defined in aom.h. + * + * \note For each control ID "X", a macro-define of + * AOM_CTRL_X is provided. It is used at compile time to determine + * if the control ID is supported by the libaom library available, + * when the libaom version cannot be controlled. */ - AOM_CTRL_USE_TYPE(AOMD_GET_LAST_REF_UPDATES, int *) #define AOM_CTRL_AOMD_GET_LAST_REF_UPDATES + AOM_CTRL_USE_TYPE(AOMD_GET_FRAME_CORRUPTED, int *) #define AOM_CTRL_AOMD_GET_FRAME_CORRUPTED + AOM_CTRL_USE_TYPE(AOMD_GET_LAST_REF_USED, int *) #define AOM_CTRL_AOMD_GET_LAST_REF_USED + AOM_CTRL_USE_TYPE(AOMD_GET_LAST_QUANTIZER, int *) #define AOM_CTRL_AOMD_GET_LAST_QUANTIZER + AOM_CTRL_USE_TYPE(AV1D_GET_DISPLAY_SIZE, int *) #define AOM_CTRL_AV1D_GET_DISPLAY_SIZE + AOM_CTRL_USE_TYPE(AV1D_GET_BIT_DEPTH, unsigned int *) #define AOM_CTRL_AV1D_GET_BIT_DEPTH + AOM_CTRL_USE_TYPE(AV1D_GET_IMG_FORMAT, aom_img_fmt_t *) #define AOM_CTRL_AV1D_GET_IMG_FORMAT + AOM_CTRL_USE_TYPE(AV1D_GET_TILE_SIZE, unsigned int *) #define AOM_CTRL_AV1D_GET_TILE_SIZE + AOM_CTRL_USE_TYPE(AV1D_GET_TILE_COUNT, unsigned int *) #define AOM_CTRL_AV1D_GET_TILE_COUNT + AOM_CTRL_USE_TYPE(AV1D_GET_FRAME_SIZE, int *) #define AOM_CTRL_AV1D_GET_FRAME_SIZE + AOM_CTRL_USE_TYPE(AV1_INVERT_TILE_DECODE_ORDER, int) #define AOM_CTRL_AV1_INVERT_TILE_DECODE_ORDER + AOM_CTRL_USE_TYPE(AV1_GET_ACCOUNTING, Accounting **) #define AOM_CTRL_AV1_GET_ACCOUNTING + AOM_CTRL_USE_TYPE(AV1_SET_DECODE_TILE_ROW, int) #define AOM_CTRL_AV1_SET_DECODE_TILE_ROW + AOM_CTRL_USE_TYPE(AV1_SET_DECODE_TILE_COL, int) #define AOM_CTRL_AV1_SET_DECODE_TILE_COL + AOM_CTRL_USE_TYPE(AV1_SET_TILE_MODE, unsigned int) #define AOM_CTRL_AV1_SET_TILE_MODE + AOM_CTRL_USE_TYPE(AV1D_GET_FRAME_HEADER_INFO, aom_tile_data *) #define AOM_CTRL_AV1D_GET_FRAME_HEADER_INFO + AOM_CTRL_USE_TYPE(AV1D_GET_TILE_DATA, aom_tile_data *) #define AOM_CTRL_AV1D_GET_TILE_DATA + AOM_CTRL_USE_TYPE(AV1D_SET_EXT_REF_PTR, av1_ext_ref_frame_t *) #define AOM_CTRL_AV1D_SET_EXT_REF_PTR + AOM_CTRL_USE_TYPE(AV1D_EXT_TILE_DEBUG, unsigned int) #define AOM_CTRL_AV1D_EXT_TILE_DEBUG + AOM_CTRL_USE_TYPE(AV1D_SET_ROW_MT, unsigned int) #define AOM_CTRL_AV1D_SET_ROW_MT + AOM_CTRL_USE_TYPE(AV1D_SET_SKIP_FILM_GRAIN, int) #define AOM_CTRL_AV1D_SET_SKIP_FILM_GRAIN + AOM_CTRL_USE_TYPE(AV1D_SET_IS_ANNEXB, unsigned int) #define AOM_CTRL_AV1D_SET_IS_ANNEXB + AOM_CTRL_USE_TYPE(AV1D_SET_OPERATING_POINT, int) #define AOM_CTRL_AV1D_SET_OPERATING_POINT + AOM_CTRL_USE_TYPE(AV1D_SET_OUTPUT_ALL_LAYERS, int) #define AOM_CTRL_AV1D_SET_OUTPUT_ALL_LAYERS + AOM_CTRL_USE_TYPE(AV1_SET_INSPECTION_CALLBACK, aom_inspect_init *) #define AOM_CTRL_AV1_SET_INSPECTION_CALLBACK /*!\endcond */
diff --git a/aom/exports_com b/aom/exports_com index 68dbfe0..6f796f5 100644 --- a/aom/exports_com +++ b/aom/exports_com
@@ -1,5 +1,5 @@ text aom_codec_build_config -text aom_codec_control_ +text aom_codec_control text aom_codec_destroy text aom_codec_err_to_string text aom_codec_error
diff --git a/aom/internal/aom_codec_internal.h b/aom/internal/aom_codec_internal.h index c3afa10..efe09ac 100644 --- a/aom/internal/aom_codec_internal.h +++ b/aom/internal/aom_codec_internal.h
@@ -136,7 +136,7 @@ * function, so plugins implementing this interface may trust the input * parameters to be properly initialized. However, this interface does not * provide type safety for the exchanged data or assign meanings to the - * control codes. Those details should be specified in the algorithm's + * control IDs. Those details should be specified in the algorithm's * header file. In particular, the ctrl_id parameter is guaranteed to exist * in the algorithm's control mapping table, and the data parameter may be NULL. * @@ -305,15 +305,7 @@ } enc; }; -#undef AOM_CTRL_USE_TYPE -#define AOM_CTRL_USE_TYPE(id, typ) \ - static AOM_INLINE typ id##__value(va_list args) { return va_arg(args, typ); } - -#undef AOM_CTRL_USE_TYPE_DEPRECATED -#define AOM_CTRL_USE_TYPE_DEPRECATED(id, typ) \ - static AOM_INLINE typ id##__value(va_list args) { return va_arg(args, typ); } - -#define CAST(id, arg) id##__value(arg) +#define CAST(id, arg) va_arg((arg), aom_codec_control_type_##id) /* CODEC_INTERFACE convenience macro *
diff --git a/aom/src/aom_codec.c b/aom/src/aom_codec.c index 733bffb..196ab83 100644 --- a/aom/src/aom_codec.c +++ b/aom/src/aom_codec.c
@@ -89,7 +89,7 @@ return (iface) ? iface->caps : 0; } -aom_codec_err_t aom_codec_control_(aom_codec_ctx_t *ctx, int ctrl_id, ...) { +aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id, ...) { aom_codec_err_t res; if (!ctx || !ctrl_id)
diff --git a/apps/aomdec.c b/apps/aomdec.c index 86b0e00..2591d41 100644 --- a/apps/aomdec.c +++ b/apps/aomdec.c
@@ -680,25 +680,27 @@ if (!quiet) fprintf(stderr, "%s\n", decoder.name); - if (aom_codec_control(&decoder, AV1D_SET_IS_ANNEXB, is_annexb)) { + if (AOM_CODEC_CONTROL_TYPECHECKED(&decoder, AV1D_SET_IS_ANNEXB, is_annexb)) { fprintf(stderr, "Failed to set is_annexb: %s\n", aom_codec_error(&decoder)); goto fail; } - if (aom_codec_control(&decoder, AV1D_SET_OPERATING_POINT, operating_point)) { + if (AOM_CODEC_CONTROL_TYPECHECKED(&decoder, AV1D_SET_OPERATING_POINT, + operating_point)) { fprintf(stderr, "Failed to set operating_point: %s\n", aom_codec_error(&decoder)); goto fail; } - if (aom_codec_control(&decoder, AV1D_SET_OUTPUT_ALL_LAYERS, - output_all_layers)) { + if (AOM_CODEC_CONTROL_TYPECHECKED(&decoder, AV1D_SET_OUTPUT_ALL_LAYERS, + output_all_layers)) { fprintf(stderr, "Failed to set output_all_layers: %s\n", aom_codec_error(&decoder)); goto fail; } - if (aom_codec_control(&decoder, AV1D_SET_SKIP_FILM_GRAIN, skip_film_grain)) { + if (AOM_CODEC_CONTROL_TYPECHECKED(&decoder, AV1D_SET_SKIP_FILM_GRAIN, + skip_film_grain)) { fprintf(stderr, "Failed to set skip_film_grain: %s\n", aom_codec_error(&decoder)); goto fail; @@ -754,7 +756,8 @@ if (framestats_file) { int qp; - if (aom_codec_control(&decoder, AOMD_GET_LAST_QUANTIZER, &qp)) { + if (AOM_CODEC_CONTROL_TYPECHECKED(&decoder, AOMD_GET_LAST_QUANTIZER, + &qp)) { warn("Failed AOMD_GET_LAST_QUANTIZER: %s", aom_codec_error(&decoder)); if (!keep_going) goto fail; @@ -788,7 +791,8 @@ ++frame_out; got_data = 1; - if (aom_codec_control(&decoder, AOMD_GET_FRAME_CORRUPTED, &corrupted)) { + if (AOM_CODEC_CONTROL_TYPECHECKED(&decoder, AOMD_GET_FRAME_CORRUPTED, + &corrupted)) { warn("Failed AOM_GET_FRAME_CORRUPTED: %s", aom_codec_error(&decoder)); if (!keep_going) goto fail; } @@ -812,8 +816,8 @@ int render_height = aom_input_ctx.height; if (!render_width || !render_height) { int render_size[2]; - if (aom_codec_control(&decoder, AV1D_GET_DISPLAY_SIZE, - render_size)) { + if (AOM_CODEC_CONTROL_TYPECHECKED(&decoder, AV1D_GET_DISPLAY_SIZE, + render_size)) { // As last resort use size of first frame as display size. render_width = img->d_w; render_height = img->d_h;
diff --git a/apps/aomenc.c b/apps/aomenc.c index 4e15683..bb57726 100644 --- a/apps/aomenc.c +++ b/apps/aomenc.c
@@ -1896,14 +1896,10 @@ &stream->config.cfg, flags); ctx_exit_on_error(&stream->encoder, "Failed to initialize encoder"); - /* Note that we bypass the aom_codec_control wrapper macro because - * we're being clever to store the control IDs in an array. Real - * applications will want to make use of the enumerations directly - */ for (i = 0; i < stream->config.arg_ctrl_cnt; i++) { int ctrl = stream->config.arg_ctrls[i][0]; int value = stream->config.arg_ctrls[i][1]; - if (aom_codec_control_(&stream->encoder, ctrl, value)) + if (aom_codec_control(&stream->encoder, ctrl, value)) fprintf(stderr, "Error: Tried to set control %d = %d\n", ctrl, value); ctx_exit_on_error(&stream->encoder, "Failed to control codec"); @@ -1911,14 +1907,14 @@ #if CONFIG_TUNE_VMAF if (stream->config.vmaf_model_path) { - aom_codec_control_(&stream->encoder, AV1E_SET_VMAF_MODEL_PATH, - stream->config.vmaf_model_path); + AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, AV1E_SET_VMAF_MODEL_PATH, + stream->config.vmaf_model_path); } #endif if (stream->config.film_grain_filename) { - aom_codec_control_(&stream->encoder, AV1E_SET_FILM_GRAIN_TABLE, - stream->config.film_grain_filename); + AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, AV1E_SET_FILM_GRAIN_TABLE, + stream->config.film_grain_filename); } #if CONFIG_AV1_DECODER @@ -1928,18 +1924,20 @@ aom_codec_dec_init(&stream->decoder, decoder->codec_interface(), &cfg, 0); if (strcmp(global->codec->name, "av1") == 0) { - aom_codec_control(&stream->decoder, AV1_SET_TILE_MODE, - stream->config.cfg.large_scale_tile); + AOM_CODEC_CONTROL_TYPECHECKED(&stream->decoder, AV1_SET_TILE_MODE, + stream->config.cfg.large_scale_tile); ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_mode"); - aom_codec_control(&stream->decoder, AV1D_SET_IS_ANNEXB, - stream->config.cfg.save_as_annexb); + AOM_CODEC_CONTROL_TYPECHECKED(&stream->decoder, AV1D_SET_IS_ANNEXB, + stream->config.cfg.save_as_annexb); ctx_exit_on_error(&stream->decoder, "Failed to set is_annexb"); - aom_codec_control(&stream->decoder, AV1_SET_DECODE_TILE_ROW, -1); + AOM_CODEC_CONTROL_TYPECHECKED(&stream->decoder, AV1_SET_DECODE_TILE_ROW, + -1); ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_row"); - aom_codec_control(&stream->decoder, AV1_SET_DECODE_TILE_COL, -1); + AOM_CODEC_CONTROL_TYPECHECKED(&stream->decoder, AV1_SET_DECODE_TILE_COL, + -1); ctx_exit_on_error(&stream->decoder, "Failed to set decode_tile_col"); } } @@ -2038,7 +2036,8 @@ if (stream->config.cfg.g_pass != AOM_RC_FIRST_PASS) { int q; - aom_codec_control(&stream->encoder, AOME_GET_LAST_QUANTIZER_64, &q); + AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, AOME_GET_LAST_QUANTIZER_64, + &q); ctx_exit_on_error(&stream->encoder, "Failed to read quantizer"); stream->counts[q]++; } @@ -2165,8 +2164,10 @@ if (stream->mismatch_seen) return; /* Get the internal reference frame */ - aom_codec_control(&stream->encoder, AV1_GET_NEW_FRAME_IMAGE, &enc_img); - aom_codec_control(&stream->decoder, AV1_GET_NEW_FRAME_IMAGE, &dec_img); + AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, AV1_GET_NEW_FRAME_IMAGE, + &enc_img); + AOM_CODEC_CONTROL_TYPECHECKED(&stream->decoder, AV1_GET_NEW_FRAME_IMAGE, + &dec_img); if ((enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) != (dec_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH)) { @@ -2403,16 +2404,20 @@ input.file_type == FILE_TYPE_Y4M) { // Note that here the input file values for chroma subsampling // are used instead of those from the command line. - aom_codec_control(&stream->encoder, AV1E_SET_CHROMA_SUBSAMPLING_X, - input.y4m.dst_c_dec_h >> 1); - aom_codec_control(&stream->encoder, AV1E_SET_CHROMA_SUBSAMPLING_Y, - input.y4m.dst_c_dec_v >> 1); + AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, + AV1E_SET_CHROMA_SUBSAMPLING_X, + input.y4m.dst_c_dec_h >> 1); + AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, + AV1E_SET_CHROMA_SUBSAMPLING_Y, + input.y4m.dst_c_dec_v >> 1); } else if (input.bit_depth == 12 && input.file_type == FILE_TYPE_RAW) { - aom_codec_control(&stream->encoder, AV1E_SET_CHROMA_SUBSAMPLING_X, - stream->chroma_subsampling_x); - aom_codec_control(&stream->encoder, AV1E_SET_CHROMA_SUBSAMPLING_Y, - stream->chroma_subsampling_y); + AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, + AV1E_SET_CHROMA_SUBSAMPLING_X, + stream->chroma_subsampling_x); + AOM_CODEC_CONTROL_TYPECHECKED(&stream->encoder, + AV1E_SET_CHROMA_SUBSAMPLING_Y, + stream->chroma_subsampling_y); } break; default: break;
diff --git a/examples/lightfield_bitstream_parsing.c b/examples/lightfield_bitstream_parsing.c index afacf44..ffcbcb9 100644 --- a/examples/lightfield_bitstream_parsing.c +++ b/examples/lightfield_bitstream_parsing.c
@@ -148,14 +148,14 @@ size_t frame_size = frame_sizes[image_idx]; const unsigned char *frame = frames[image_idx]; - aom_codec_control_(codec, AV1_SET_DECODE_TILE_ROW, tr); - aom_codec_control_(codec, AV1_SET_DECODE_TILE_COL, tc); + AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1_SET_DECODE_TILE_ROW, tr); + AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1_SET_DECODE_TILE_COL, tc); aom_codec_err_t aom_status = aom_codec_decode(codec, frame, frame_size, NULL); if (aom_status) die_codec(codec, "Failed to decode tile."); - aom_codec_control_(codec, AV1D_GET_TILE_DATA, &tile_data); + AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1D_GET_TILE_DATA, &tile_data); // Copy over tile info. // uint8_t anchor_frame_idx; @@ -228,7 +228,7 @@ die_codec(&codec, "Failed to initialize decoder."); // Decode anchor frames. - aom_codec_control_(&codec, AV1_SET_TILE_MODE, 0); + AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_TILE_MODE, 0); printf("Reading %d reference images.\n", num_references); for (i = 0; i < num_references; ++i) { @@ -248,8 +248,8 @@ } // Decode camera frames. - aom_codec_control_(&codec, AV1_SET_TILE_MODE, 1); - aom_codec_control_(&codec, AV1D_EXT_TILE_DEBUG, 1); + AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_TILE_MODE, 1); + AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_EXT_TILE_DEBUG, 1); FILE *infile = aom_video_reader_get_file(reader); // Record the offset of the first camera image. @@ -291,14 +291,15 @@ // Need to decode frame header to get camera frame header info. So, here // decoding 1 tile is enough. - aom_codec_control_(&codec, AV1_SET_DECODE_TILE_ROW, 0); - aom_codec_control_(&codec, AV1_SET_DECODE_TILE_COL, 0); + AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_DECODE_TILE_ROW, 0); + AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_DECODE_TILE_COL, 0); aom_codec_err_t aom_status = aom_codec_decode(&codec, frame, frame_size, NULL); if (aom_status) die_codec(&codec, "Failed to decode tile."); - aom_codec_control_(&codec, AV1D_GET_FRAME_HEADER_INFO, &frame_header_info); + AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_GET_FRAME_HEADER_INFO, + &frame_header_info); size_t obu_size_offset = (uint8_t *)frame_header_info.coded_tile_data - frame; @@ -330,13 +331,13 @@ // Read out the image format. aom_img_fmt_t ref_fmt = 0; - if (aom_codec_control(&codec, AV1D_GET_IMG_FORMAT, &ref_fmt)) + if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_GET_IMG_FORMAT, &ref_fmt)) die_codec(&codec, "Failed to get the image format"); const int bps = get_image_bps(ref_fmt); if (!bps) die_codec(&codec, "Invalid image format."); // read out the tile size. unsigned int tile_size = 0; - if (aom_codec_control(&codec, AV1D_GET_TILE_SIZE, &tile_size)) + if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_GET_TILE_SIZE, &tile_size)) die_codec(&codec, "Failed to get the tile size"); const unsigned int tile_width = tile_size >> 16; const unsigned int tile_height = tile_size & 65535;
diff --git a/examples/lightfield_decoder.c b/examples/lightfield_decoder.c index c26af4d..a292e9c 100644 --- a/examples/lightfield_decoder.c +++ b/examples/lightfield_decoder.c
@@ -95,16 +95,16 @@ aom_image_t *reference_images, aom_image_t *output, int *tile_idx, unsigned int *output_bit_depth, aom_image_t **img_ptr, int output_format) { - aom_codec_control_(codec, AV1_SET_TILE_MODE, 1); - aom_codec_control_(codec, AV1D_EXT_TILE_DEBUG, 1); - aom_codec_control_(codec, AV1_SET_DECODE_TILE_ROW, tr); - aom_codec_control_(codec, AV1_SET_DECODE_TILE_COL, tc); + AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1_SET_TILE_MODE, 1); + AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1D_EXT_TILE_DEBUG, 1); + AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1_SET_DECODE_TILE_ROW, tr); + AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1_SET_DECODE_TILE_COL, tc); av1_ref_frame_t ref; ref.idx = 0; ref.use_external_ref = 1; ref.img = reference_images[ref_idx]; - if (aom_codec_control(codec, AV1_SET_REFERENCE, &ref)) { + if (AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1_SET_REFERENCE, &ref)) { die_codec(codec, "Failed to set reference frame."); } @@ -126,7 +126,7 @@ if (output_format != YUV1D) { // read out the tile size. unsigned int tile_size = 0; - if (aom_codec_control(codec, AV1D_GET_TILE_SIZE, &tile_size)) + if (AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1D_GET_TILE_SIZE, &tile_size)) die_codec(codec, "Failed to get the tile size"); const unsigned int tile_width = tile_size >> 16; const unsigned int tile_height = tile_size & 65535; @@ -198,12 +198,13 @@ if (aom_codec_dec_init(&codec, decoder->codec_interface(), NULL, 0)) die_codec(&codec, "Failed to initialize decoder."); - if (aom_codec_control(&codec, AV1D_SET_IS_ANNEXB, info->is_annexb)) { + if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_SET_IS_ANNEXB, + info->is_annexb)) { die("Failed to set annex b status"); } // Decode anchor frames. - aom_codec_control_(&codec, AV1_SET_TILE_MODE, 0); + AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_TILE_MODE, 0); for (i = 0; i < num_references; ++i) { aom_video_reader_read_frame(reader); frame = aom_video_reader_get_frame(reader, &frame_size); @@ -211,11 +212,11 @@ die_codec(&codec, "Failed to decode frame."); if (i == 0) { - if (aom_codec_control(&codec, AV1D_GET_IMG_FORMAT, &ref_fmt)) + if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_GET_IMG_FORMAT, &ref_fmt)) die_codec(&codec, "Failed to get the image format"); int frame_res[2]; - if (aom_codec_control(&codec, AV1D_GET_FRAME_SIZE, frame_res)) + if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_GET_FRAME_SIZE, frame_res)) die_codec(&codec, "Failed to get the image frame size"); // Allocate memory to store decoded references. Allocate memory with the @@ -230,8 +231,8 @@ } } - if (aom_codec_control(&codec, AV1_COPY_NEW_FRAME_IMAGE, - &reference_images[i])) + if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_COPY_NEW_FRAME_IMAGE, + &reference_images[i])) die_codec(&codec, "Failed to copy decoded reference frame"); aom_codec_iter_t iter = NULL;
diff --git a/examples/lightfield_tile_list_decoder.c b/examples/lightfield_tile_list_decoder.c index a5b8f73..3b928df 100644 --- a/examples/lightfield_tile_list_decoder.c +++ b/examples/lightfield_tile_list_decoder.c
@@ -51,14 +51,14 @@ FILE *file) { // read out the tile size. unsigned int tile_size = 0; - if (aom_codec_control(codec, AV1D_GET_TILE_SIZE, &tile_size)) + if (AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1D_GET_TILE_SIZE, &tile_size)) die_codec(codec, "Failed to get the tile size"); const unsigned int tile_width = tile_size >> 16; const unsigned int tile_height = tile_size & 65535; const uint32_t output_frame_width_in_tiles = img->d_w / tile_width; unsigned int tile_count = 0; - if (aom_codec_control(codec, AV1D_GET_TILE_COUNT, &tile_count)) + if (AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1D_GET_TILE_COUNT, &tile_count)) die_codec(codec, "Failed to get the tile size"); // Write tile to file. @@ -136,12 +136,13 @@ if (aom_codec_dec_init(&codec, decoder->codec_interface(), NULL, 0)) die_codec(&codec, "Failed to initialize decoder."); - if (aom_codec_control(&codec, AV1D_SET_IS_ANNEXB, info->is_annexb)) { + if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_SET_IS_ANNEXB, + info->is_annexb)) { die("Failed to set annex b status"); } // Decode anchor frames. - aom_codec_control_(&codec, AV1_SET_TILE_MODE, 0); + AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_TILE_MODE, 0); for (i = 0; i < num_references; ++i) { aom_video_reader_read_frame(reader); frame = aom_video_reader_get_frame(reader, &frame_size); @@ -150,11 +151,11 @@ if (i == 0) { aom_img_fmt_t ref_fmt = 0; - if (aom_codec_control(&codec, AV1D_GET_IMG_FORMAT, &ref_fmt)) + if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_GET_IMG_FORMAT, &ref_fmt)) die_codec(&codec, "Failed to get the image format"); int frame_res[2]; - if (aom_codec_control(&codec, AV1D_GET_FRAME_SIZE, frame_res)) + if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_GET_FRAME_SIZE, frame_res)) die_codec(&codec, "Failed to get the image frame size"); // Allocate memory to store decoded references. Allocate memory with the @@ -169,8 +170,8 @@ } } - if (aom_codec_control(&codec, AV1_COPY_NEW_FRAME_IMAGE, - &reference_images[i])) + if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_COPY_NEW_FRAME_IMAGE, + &reference_images[i])) die_codec(&codec, "Failed to copy decoded reference frame"); aom_codec_iter_t iter = NULL; @@ -186,11 +187,11 @@ } // Decode the lightfield. - aom_codec_control_(&codec, AV1_SET_TILE_MODE, 1); + AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_TILE_MODE, 1); // Set external references. av1_ext_ref_frame_t set_ext_ref = { &reference_images[0], num_references }; - aom_codec_control_(&codec, AV1D_SET_EXT_REF_PTR, &set_ext_ref); + AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_SET_EXT_REF_PTR, &set_ext_ref); // Must decode the camera frame header first. aom_video_reader_read_frame(reader); frame = aom_video_reader_get_frame(reader, &frame_size);
diff --git a/examples/lossless_encoder.c b/examples/lossless_encoder.c index 438ff21..e0253d2 100644 --- a/examples/lossless_encoder.c +++ b/examples/lossless_encoder.c
@@ -113,7 +113,7 @@ if (aom_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0)) die_codec(&codec, "Failed to initialize encoder"); - if (aom_codec_control_(&codec, AV1E_SET_LOSSLESS, 1)) + if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1E_SET_LOSSLESS, 1)) die_codec(&codec, "Failed to use lossless mode"); // Encode frames.
diff --git a/test/decode_test_driver.h b/test/decode_test_driver.h index d13e13e..64722f4 100644 --- a/test/decode_test_driver.h +++ b/test/decode_test_driver.h
@@ -67,13 +67,13 @@ void Control(int ctrl_id, const void *arg) { InitOnce(); - const aom_codec_err_t res = aom_codec_control_(&decoder_, ctrl_id, arg); + const aom_codec_err_t res = aom_codec_control(&decoder_, ctrl_id, arg); ASSERT_EQ(AOM_CODEC_OK, res) << DecodeError(); } void Control(int ctrl_id, int arg, aom_codec_err_t expected_value) { InitOnce(); - const aom_codec_err_t res = aom_codec_control_(&decoder_, ctrl_id, arg); + const aom_codec_err_t res = aom_codec_control(&decoder_, ctrl_id, arg); ASSERT_EQ(expected_value, res) << DecodeError(); }
diff --git a/test/encode_test_driver.h b/test/encode_test_driver.h index cce8653..6319a52 100644 --- a/test/encode_test_driver.h +++ b/test/encode_test_driver.h
@@ -105,38 +105,38 @@ void EncodeFrame(VideoSource *video) { EncodeFrame(video, 0); } void Control(int ctrl_id, int arg) { - const aom_codec_err_t res = aom_codec_control_(&encoder_, ctrl_id, arg); + const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg); ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError(); } void Control(int ctrl_id, int *arg) { - const aom_codec_err_t res = aom_codec_control_(&encoder_, ctrl_id, arg); + const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg); ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError(); } void Control(int ctrl_id, struct aom_scaling_mode *arg) { - const aom_codec_err_t res = aom_codec_control_(&encoder_, ctrl_id, arg); + const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg); ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError(); } void Control(int ctrl_id, struct aom_svc_layer_id *arg) { - const aom_codec_err_t res = aom_codec_control_(&encoder_, ctrl_id, arg); + const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg); ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError(); } void Control(int ctrl_id, struct aom_svc_ref_frame_config *arg) { - const aom_codec_err_t res = aom_codec_control_(&encoder_, ctrl_id, arg); + const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg); ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError(); } void Control(int ctrl_id, struct aom_svc_params *arg) { - const aom_codec_err_t res = aom_codec_control_(&encoder_, ctrl_id, arg); + const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg); ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError(); } #if CONFIG_AV1_ENCODER void Control(int ctrl_id, aom_active_map_t *arg) { - const aom_codec_err_t res = aom_codec_control_(&encoder_, ctrl_id, arg); + const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg); ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError(); } #endif
diff --git a/test/level_test.cc b/test/level_test.cc index 73e52e3..a9613c5 100644 --- a/test/level_test.cc +++ b/test/level_test.cc
@@ -93,12 +93,12 @@ level != 21 && level != 22 && level != 23) || level == 31 || operating_point > 31) { EXPECT_EQ(AOM_CODEC_OK, - aom_codec_control(&enc, AV1E_SET_TARGET_SEQ_LEVEL_IDX, - target_level)); + AOM_CODEC_CONTROL_TYPECHECKED( + &enc, AV1E_SET_TARGET_SEQ_LEVEL_IDX, target_level)); } else { EXPECT_EQ(AOM_CODEC_INVALID_PARAM, - aom_codec_control(&enc, AV1E_SET_TARGET_SEQ_LEVEL_IDX, - target_level)); + AOM_CODEC_CONTROL_TYPECHECKED( + &enc, AV1E_SET_TARGET_SEQ_LEVEL_IDX, target_level)); } } }