Skip to content

Commit f38b9de

Browse files
ram-mohanjzern
authored andcommitted
Use g_bit_depth during input validation
The libvpx encoder requires the input frames passed to it by the application for encoding have the same bit-depth as codec bit-depth. If the input bit-depth is less than codec bit-depth, then the application must upshift the frame before passing it. The application may communicate the actual input bit-depth via g_input_bit_depth so that quality metrics are computed with reference to actual input. As the input is expected to have same precision as codec bit-depth, this commit modifies the input validator to use codec bit-depth. Also updated API documentation to reflect these changes. Change-Id: I9d2fe17b61f141f0ed47cf78f2e1f717a695541c
1 parent 68ea923 commit f38b9de

4 files changed

Lines changed: 14 additions & 11 deletions

File tree

‎vp9/encoder/vp9_encoder.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ typedef struct VP9EncoderConfig {
156156
vpx_bit_depth_t bit_depth; // Codec bit-depth.
157157
int width; // width of data passed to the compressor
158158
int height; // height of data passed to the compressor
159-
unsigned int input_bit_depth; // Input bit depth.
159+
unsigned int input_bit_depth; // Actual bit-depth of the input source
160160
double init_framerate; // set to passed in framerate
161161
vpx_rational_t g_timebase; // equivalent to g_timebase in vpx_codec_enc_cfg_t
162162
vpx_rational64_t g_timebase_in_ts; // g_timebase * TICKS_PER_SEC

‎vp9/vp9_cx_iface.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
298298
RANGE_CHECK(extra_cfg, cq_level, 0, 63);
299299
RANGE_CHECK(cfg, g_bit_depth, VPX_BITS_8, VPX_BITS_12);
300300
RANGE_CHECK(cfg, g_input_bit_depth, 8, 12);
301+
if (cfg->g_input_bit_depth > cfg->g_bit_depth)
302+
ERROR("Input bit-depth must not exceed codec bit-depth");
301303
RANGE_CHECK(extra_cfg, content, VP9E_CONTENT_DEFAULT,
302304
VP9E_CONTENT_INVALID - 1);
303305

@@ -369,9 +371,6 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
369371
cfg->g_bit_depth > VPX_BITS_8) {
370372
ERROR("Codec high bit-depth not supported in profile < 2");
371373
}
372-
if (cfg->g_profile <= (unsigned int)PROFILE_1 && cfg->g_input_bit_depth > 8) {
373-
ERROR("Source high bit-depth not supported in profile < 2");
374-
}
375374
if (cfg->g_profile > (unsigned int)PROFILE_1 &&
376375
cfg->g_bit_depth == VPX_BITS_8) {
377376
ERROR("Codec bit-depth 8 not supported in profile > 1");
@@ -458,7 +457,7 @@ static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx,
458457
(img->fmt & VPX_IMG_FMT_HIGHBITDEPTH)) {
459458
const unsigned int h = img->d_h;
460459
const unsigned int w = img->d_w;
461-
const unsigned int bit_depth = ctx->oxcf.input_bit_depth;
460+
const unsigned int bit_depth = ctx->cfg.g_bit_depth;
462461
const int max_val = 1 << bit_depth;
463462
for (int plane = 0; plane < 3; ++plane) {
464463
const unsigned short *src = (const unsigned short *)img->planes[plane];

‎vpx/vpx_encoder.h‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,15 @@ typedef struct vpx_codec_enc_cfg {
331331
*/
332332
vpx_bit_depth_t g_bit_depth;
333333

334-
/*!\brief Bit-depth of the input frames
335-
*
336-
* This value identifies the bit_depth of the input frames in bits.
337-
* Note that the frames passed as input to the encoder must have
338-
* this bit-depth.
334+
/*!\brief Bit-depth of the input source
335+
*
336+
* This value identifies the actual bit-depth of the input source in bits. It
337+
* must not exceed codec bit-depth. Note that the frames passed as input to
338+
* the encoder must match codec bit-depth. So, if there is a mismatch between
339+
* source bit-depth and codec bit-depth, the application is required to
340+
* upshift the frame to the codec bit-depth before passing it for encoding.
341+
* This is only used for computing quality metrics relative to the actual
342+
* input source and has no effect on the encoder's output.
339343
*/
340344
unsigned int g_input_bit_depth;
341345

‎vpxenc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ static const arg_def_t bitdeptharg = ARG_DEF_ENUM(
497497
"Bit depth for codec (8 for version <=1, 10 or 12 for version 2)",
498498
bitdepth_enum);
499499
static const arg_def_t inbitdeptharg =
500-
ARG_DEF(NULL, "input-bit-depth", 1, "Bit depth of input");
500+
ARG_DEF(NULL, "input-bit-depth", 1, "Actual bit depth of input source");
501501
#endif
502502

503503
static const struct arg_enum_list tune_content_enum[] = {

0 commit comments

Comments
 (0)