diff --git a/silk/dred_config.h b/silk/dred_config.h index c190b5545e5c57ba691c5ae5c3183660af041f5b..c7b9d51b6834bff3355717f962c3bfdbaf00c1a2 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 e430ce82ad9cf3563a3c4ff1543b91f7b26db7e9..5c17c232a33bf575b6a8a3a911c630a2767101a4 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 3933ab27775f24ae99d9262d30df933ed9238e17..e8be50f4fa15d34b1d1b3bb475085340bf382c99 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;