diff options
author | Jean-Marc Valin <jmvalin@amazon.com> | 2023-08-10 01:17:06 +0300 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@amazon.com> | 2023-08-10 01:25:52 +0300 |
commit | 0886828eed7a293f556ad45a70d8d7ab04325c9d (patch) | |
tree | 7be20cfb60b2db1d26f2fa0836554823518ca9b9 | |
parent | 5160d7fdfada61e48d4c3df110cd773ec5e9ce7e (diff) |
Making it easier to remove DRED experimental ID
When ready, change DRED_EXTENSION_ID to the final ID, remove
DRED_EXPERIMENTAL_VERSION completely, and change DRED_EXPERIMENTAL_BYTES
to zero (eventually remove it).
-rw-r--r-- | silk/dred_config.h | 9 | ||||
-rw-r--r-- | src/opus_decoder.c | 11 | ||||
-rw-r--r-- | src/opus_encoder.c | 12 |
3 files changed, 24 insertions, 8 deletions
diff --git a/silk/dred_config.h b/silk/dred_config.h index c190b554..c7b9d51b 100644 --- a/silk/dred_config.h +++ b/silk/dred_config.h @@ -28,7 +28,14 @@ #ifndef DRED_CONFIG_H #define DRED_CONFIG_H -#define DRED_VERSION 1 +/* Change this once DRED gets an extension number assigned. */ +#define DRED_EXTENSION_ID 127 + +/* Remove these two completely once DRED gets an extension number assigned. */ +#define DRED_EXPERIMENTAL_VERSION 1 +#define DRED_EXPERIMENTAL_BYTES 2 + + #define DRED_MIN_BYTES 16 /* these are inpart duplicates to the values defined in dred_rdovae_constants.h */ diff --git a/src/opus_decoder.c b/src/opus_decoder.c index e430ce82..5c17c232 100644 --- a/src/opus_decoder.c +++ b/src/opus_decoder.c @@ -1280,18 +1280,25 @@ static int dred_find_payload(const unsigned char *data, opus_int32 len, const un } else { frame += data[1]; } - } else if (id == 127) + } else if (id == DRED_EXTENSION_ID) { const unsigned char *curr_payload; opus_int32 curr_payload_len; curr_payload = data0+header_size; curr_payload_len = (data-data0)-header_size; +#ifdef DRED_EXPERIMENTAL_VERSION /* Check that temporary extension type and version match. This check will be removed once extension is finalized. */ - if (curr_payload_len > 2 && curr_payload[0] == 'D' && curr_payload[1] == DRED_VERSION) { + if (curr_payload_len > DRED_EXPERIMENTAL_BYTES && curr_payload[0] == 'D' && curr_payload[1] == DRED_EXPERIMENTAL_VERSION) { *payload = curr_payload+2; return curr_payload_len-2; } +#else + if (curr_payload_len > 0) { + *payload = curr_payload; + return curr_payload_len; + } +#endif } } return 0; diff --git a/src/opus_encoder.c b/src/opus_encoder.c index 3933ab27..e8be50f4 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -2259,16 +2259,18 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ /* Remaining space for DRED, accounting for cost the 3 extra bytes for code 3, padding length, and extension number. */ dred_bytes_left = IMIN(DRED_MAX_DATA_SIZE, max_data_bytes-ret-3); /* Check whether we actually have something to encode. */ - if (dred_chunks >= 1 && dred_bytes_left >= DRED_MIN_BYTES+2) { + if (dred_chunks >= 1 && dred_bytes_left >= DRED_MIN_BYTES+DRED_EXPERIMENTAL_BYTES) { int dred_bytes; +#ifdef DRED_EXPERIMENTAL_VERSION /* Add temporary extension type and version. These bytes will be removed once extension is finalized. */ buf[0] = 'D'; - buf[1] = DRED_VERSION; - dred_bytes = dred_encode_silk_frame(&st->dred_encoder, buf+2, dred_chunks, dred_bytes_left-2); - dred_bytes += 2; + buf[1] = DRED_EXPERIMENTAL_VERSION; +#endif + dred_bytes = dred_encode_silk_frame(&st->dred_encoder, buf+DRED_EXPERIMENTAL_BYTES, dred_chunks, dred_bytes_left-DRED_EXPERIMENTAL_BYTES); + dred_bytes += DRED_EXPERIMENTAL_BYTES; celt_assert(dred_bytes <= dred_bytes_left); - extension.id = 127; + extension.id = DRED_EXTENSION_ID; extension.frame = 0; extension.data = buf; extension.len = dred_bytes; |