From e0b1599712f0ba38190cffead9bb8ab74ccfcd5c Mon Sep 17 00:00:00 2001 From: Rupert Swarbrick Date: Thu, 9 Nov 2017 15:04:32 +0000 Subject: [PATCH] Plumb in a "monochrome" flag This bit appears in the sequence header. At the moment, it does nothing, but it will mean that we don't encode (or read) chroma planes. This patch adds the flag to the sequence header, and also adds an encoder option (--monochrome) which enables it. At the moment, this doesn't do anything except cause the bit to be set correctly in the header. Change-Id: If5598412c1c75101553d7f8f9098f9ed1163514e --- aom/aom_encoder.h | 7 +++++++ aomenc.c | 11 +++++++++++ av1/av1_cx_iface.c | 7 +++++++ av1/av1_dx_iface.c | 7 ++----- av1/common/onyxc_int.h | 7 +++++++ av1/decoder/decodeframe.c | 4 ++++ av1/encoder/bitstream.c | 5 +++++ av1/encoder/encoder.c | 4 ++++ av1/encoder/encoder.h | 3 +++ 9 files changed, 50 insertions(+), 5 deletions(-) diff --git a/aom/aom_encoder.h b/aom/aom_encoder.h index 208ba011f..7a7f4e421 100644 --- a/aom/aom_encoder.h +++ b/aom/aom_encoder.h @@ -620,6 +620,13 @@ typedef struct aom_codec_enc_cfg { */ unsigned int large_scale_tile; + /*!\brief Monochrome mode + * + * If this is nonzero, the encoder will generate a monochrome stream + * with no chroma planes. + */ + unsigned int monochrome; + /*!\brief Number of explicit tile widths specified * * This value indicates the number of tile widths specified diff --git a/aomenc.c b/aomenc.c index 0ed471460..012849050 100644 --- a/aomenc.c +++ b/aomenc.c @@ -260,6 +260,10 @@ static const arg_def_t large_scale_tile = ARG_DEF(NULL, "large-scale-tile", 1, "Large scale tile coding (0: off (default), 1: on)"); #endif // CONFIG_EXT_TILE +#if CONFIG_MONO_VIDEO +static const arg_def_t monochrome = + ARG_DEF(NULL, "monochrome", 0, "Monochrome video (no chroma planes)"); +#endif // MONOCHROME static const arg_def_t *global_args[] = { &use_yv12, &use_i420, @@ -284,6 +288,9 @@ static const arg_def_t *global_args[] = { &use_yv12, #if CONFIG_EXT_TILE &large_scale_tile, #endif // CONFIG_EXT_TILE +#if CONFIG_MONO_VIDEO + &monochrome, +#endif // CONFIG_MONO_VIDEO NULL }; static const arg_def_t dropframe_thresh = @@ -1065,6 +1072,10 @@ static int parse_stream_params(struct AvxEncoderConfig *global, } else if (arg_match(&arg, &large_scale_tile, argi)) { config->cfg.large_scale_tile = arg_parse_uint(&arg); #endif // CONFIG_EXT_TILE +#if CONFIG_MONO_VIDEO + } else if (arg_match(&arg, &monochrome, argi)) { + config->cfg.monochrome = 1; +#endif // CONFIG_MONO_VIDEO } else if (arg_match(&arg, &dropframe_thresh, argi)) { config->cfg.rc_dropframe_thresh = arg_parse_uint(&arg); } else if (arg_match(&arg, &resize_mode, argi)) { diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c index 91e43dbdf..925077fa5 100644 --- a/av1/av1_cx_iface.c +++ b/av1/av1_cx_iface.c @@ -319,6 +319,9 @@ static aom_codec_err_t validate_config(aom_codec_alg_priv_t *ctx, #if CONFIG_EXT_TILE } #endif // CONFIG_EXT_TILE +#if CONFIG_MONO_VIDEO + RANGE_CHECK_HI(cfg, monochrome, 1); +#endif // CONFIG_MONO_VIDEO #if CONFIG_EXT_TILE if (cfg->large_scale_tile && extra_cfg->aq_mode) @@ -643,6 +646,9 @@ static aom_codec_err_t set_encoder_config( #if CONFIG_EXT_TILE } #endif // CONFIG_EXT_TILE +#if CONFIG_MONO_VIDEO + oxcf->monochrome = cfg->monochrome; +#endif // CONFIG_MONO_VIDEO #if CONFIG_MAX_TILE oxcf->tile_width_count = AOMMIN(cfg->tile_width_count, MAX_TILE_COLS); @@ -1711,6 +1717,7 @@ static aom_codec_enc_cfg_map_t encoder_usage_cfg_map[] = { 0, // kf_min_dist 9999, // kf_max_dist 0, // large_scale_tile + 0, // monochrome 0, // tile_width_count 0, // tile_height_count { 0 }, // tile_widths diff --git a/av1/av1_dx_iface.c b/av1/av1_dx_iface.c index ec896c2bc..3a02a8b6d 100644 --- a/av1/av1_dx_iface.c +++ b/av1/av1_dx_iface.c @@ -281,11 +281,8 @@ static aom_codec_err_t decoder_peek_si_internal( } error_resilient = aom_rb_read_bit(&rb); #if CONFIG_REFERENCE_BUFFER -#if CONFIG_FRAME_SIZE - SequenceHeader seq_params = { 0, 0, 0, 0, 0, 0, 0 }; -#else - SequenceHeader seq_params = { 0, 0, 0 }; -#endif + SequenceHeader seq_params; + memset(&seq_params, 0, sizeof(seq_params)); if (si->is_kf) { /* TODO: Move outside frame loop or inside key-frame branch */ read_sequence_header(&seq_params, &rb); diff --git a/av1/common/onyxc_int.h b/av1/common/onyxc_int.h index 1666ffcba..3f4c4d343 100644 --- a/av1/common/onyxc_int.h +++ b/av1/common/onyxc_int.h @@ -216,6 +216,9 @@ typedef struct SequenceHeader { int frame_id_numbers_present_flag; int frame_id_length; int delta_frame_id_length; +#if CONFIG_MONO_VIDEO + int monochrome; +#endif // CONFIG_MONO_VIDEO } SequenceHeader; #endif // CONFIG_REFERENCE_BUFFER @@ -480,6 +483,10 @@ typedef struct AV1Common { unsigned int single_tile_decoding; #endif // CONFIG_EXT_TILE +#if CONFIG_MONO_VIDEO + int monochrome; +#endif // CONFIG_MONO_VIDEO + #if CONFIG_DEPENDENT_HORZTILES int dependent_horz_tiles; int tile_group_start_row[MAX_TILE_ROWS][MAX_TILE_COLS]; diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c index d523cff76..ecc0baf4e 100644 --- a/av1/decoder/decodeframe.c +++ b/av1/decoder/decodeframe.c @@ -2573,6 +2573,10 @@ void read_sequence_header(SequenceHeader *seq_params, seq_params->frame_id_length = aom_rb_read_literal(rb, 3) + seq_params->delta_frame_id_length + 1; } + +#if CONFIG_MONO_VIDEO + seq_params->monochrome = aom_rb_read_bit(rb); +#endif // CONFIG_MONO_VIDEO } #endif // CONFIG_REFERENCE_BUFFER || CONFIG_OBU diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c index 04cb6e573..0798cfbb8 100644 --- a/av1/encoder/bitstream.c +++ b/av1/encoder/bitstream.c @@ -3658,6 +3658,11 @@ void write_sequence_header(AV1_COMP *cpi, struct aom_write_bit_buffer *wb) { wb, seq_params->frame_id_length - seq_params->delta_frame_id_length - 1, 3); } + +#if CONFIG_MONO_VIDEO + seq_params->monochrome = cm->monochrome; + aom_wb_write_bit(wb, seq_params->monochrome); +#endif // CONFIG_MONO_VIDEO } #endif // CONFIG_REFERENCE_BUFFER || CONFIG_OBU diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c index e3630b0b4..5b0e6ff13 100644 --- a/av1/encoder/encoder.c +++ b/av1/encoder/encoder.c @@ -5516,6 +5516,10 @@ static void encode_frame_to_data_rate(AV1_COMP *cpi, size_t *size, cm->single_tile_decoding = cpi->oxcf.single_tile_decoding; #endif // CONFIG_EXT_TILE +#if CONFIG_MONO_VIDEO + cm->monochrome = oxcf->monochrome; +#endif // CONFIG_MONO_VIDEO + #if CONFIG_XIPHRC if (drop_this_frame) { av1_rc_postencode_update_drop_frame(cpi); diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h index 358409839..d28870179 100644 --- a/av1/encoder/encoder.h +++ b/av1/encoder/encoder.h @@ -304,6 +304,9 @@ typedef struct AV1EncoderConfig { unsigned int large_scale_tile; unsigned int single_tile_decoding; #endif // CONFIG_EXT_TILE +#if CONFIG_MONO_VIDEO + int monochrome; +#endif // CONFIG_MONO_VIDEO unsigned int motion_vector_unit_test; } AV1EncoderConfig; -- GitLab