From 9250014c8716067517819351ad38b2485a2505e1 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 7 Feb 2016 22:52:55 +0100 Subject: [PATCH] opus: Use uint16_t for preskip and gain. These values are obtained by reading a 16 bit value from a buffer, so uint16_t is the right type for these fields. --- opus_common.c | 9 +++------ opus_common.h | 4 ++-- opusdec_filter.c | 7 ++++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/opus_common.c b/opus_common.c index 67a8841e..374df837 100644 --- a/opus_common.c +++ b/opus_common.c @@ -62,7 +62,7 @@ static int read_uint32(struct packet *p, ogg_uint32_t *val) return 1; } -static int read_uint16(struct packet *p, ogg_uint16_t *val) +static int read_uint16(struct packet *p, uint16_t *val) { if (p->pos > p->maxlen - 2) return 0; @@ -89,7 +89,6 @@ int opus_parse_header(const char *packet, int len, struct opus_header *h) char str[9]; struct packet p; unsigned char ch, channel_mapping; - ogg_uint16_t shortval; p.data = packet; p.maxlen = len; @@ -113,16 +112,14 @@ int opus_parse_header(const char *packet, int len, struct opus_header *h) if (h->channels == 0) return -E_OPUS_HEADER; - if (!read_uint16(&p, &shortval)) + if (!read_uint16(&p, &h->preskip)) return -E_OPUS_HEADER; - h->preskip = shortval; if (!read_uint32(&p, &h->input_sample_rate)) return -E_OPUS_HEADER; - if (!read_uint16(&p, &shortval)) + if (!read_uint16(&p, &h->gain)) return -E_OPUS_HEADER; - h->gain = (short)shortval; if (!read_chars(&p, &ch, 1)) return -E_OPUS_HEADER; diff --git a/opus_common.h b/opus_common.h index 2bcf5919..bdc67edd 100644 --- a/opus_common.h +++ b/opus_common.h @@ -16,11 +16,11 @@ struct opus_header { /** 1..255 */ int channels; /** Number of bytes to skip from the beginning. */ - int preskip; + uint16_t preskip; /** Sample rate of the input stream, used by the audio format handler. */ ogg_uint32_t input_sample_rate; /** In dB, should be zero whenever possible. */ - int gain; + uint16_t gain; /** Number of logical streams (usually 1). */ int nb_streams; /** Number of streams to decode as 2 channel streams. */ diff --git a/opusdec_filter.c b/opusdec_filter.c index 6a93f41f..28222985 100644 --- a/opusdec_filter.c +++ b/opusdec_filter.c @@ -70,7 +70,7 @@ struct opusdec_context { ogg_page ogg_page; bool eos; int channels; - int preskip; + uint16_t preskip; bool have_opus_stream; bool have_more; ogg_int32_t opus_serialno; @@ -142,9 +142,10 @@ static int opusdec_init(ogg_packet *op, struct opusdec_context *ctx) static void opusdec_add_output(short *pcm, int frames_available, struct btr_node *btrn, struct opusdec_context *ctx) { - int tmp_skip, num_frames, bytes; + int num_frames, bytes; + uint16_t tmp_skip; - tmp_skip = PARA_MIN(ctx->preskip, frames_available); + tmp_skip = PARA_MIN((int)ctx->preskip, frames_available); ctx->preskip -= tmp_skip; num_frames = frames_available - tmp_skip; if (num_frames <= 0) -- 2.39.5