[3/4] rtpdec: Interpret the different G726 names as bits_per_coded_sample

Message ID 1322735168-85431-1-git-send-email-martin@martin.st
State Committed
Commit fa6dce4c572fd52266201f1c9d83d26bc662bf56
Headers show

Commit Message

Martin Storsjö Dec. 1, 2011, 10:26 a.m.
For the standardized 8 kHz sample rate, this works exactly the same.
For nonstandard sample rates, the different predefined G726
names (G726-16, G726-24, G726-32, G726-40) are interpreted as an
indication of the bits per coded sample, even though their
actual bitrates aren't what the name specifies.

This feels more sane than using free-form names for nonstandard
sample rate/bitrate combinations, e.g like G726-22, G726-33
for 11025 Hz.
---
 libavformat/rtpdec_g726.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

Comments

Justin Ruggles Dec. 1, 2011, 2:41 p.m. | #1
On 12/01/2011 05:26 AM, Martin Storsjö wrote:

> For the standardized 8 kHz sample rate, this works exactly the same.
> For nonstandard sample rates, the different predefined G726
> names (G726-16, G726-24, G726-32, G726-40) are interpreted as an
> indication of the bits per coded sample, even though their
> actual bitrates aren't what the name specifies.
> 
> This feels more sane than using free-form names for nonstandard
> sample rate/bitrate combinations, e.g like G726-22, G726-33
> for 11025 Hz.
> ---
>  libavformat/rtpdec_g726.c |    6 ++----
>  1 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/rtpdec_g726.c b/libavformat/rtpdec_g726.c
> index 5735c2c..4a0b6ac 100644
> --- a/libavformat/rtpdec_g726.c
> +++ b/libavformat/rtpdec_g726.c
> @@ -27,10 +27,8 @@ static int g726_ ## bitrate ##_init(AVFormatContext *s, int st_index, PayloadCon
>      AVStream *stream = s->streams[st_index]; \
>      AVCodecContext *codec = stream->codec; \
>  \
> -    codec->bit_rate = bitrate*1000; \
> -    if (codec->sample_rate) \
> -        codec->bits_per_coded_sample = \
> -            av_clip((codec->bit_rate + codec->sample_rate/2) / codec->sample_rate, 2, 5); \
> +    codec->bits_per_coded_sample = bitrate/8; \
> +    codec->bit_rate = codec->bits_per_coded_sample * codec->sample_rate; \
>  \
>      return 0; \
>  } \


looks good.

-Justin

Patch

diff --git a/libavformat/rtpdec_g726.c b/libavformat/rtpdec_g726.c
index 5735c2c..4a0b6ac 100644
--- a/libavformat/rtpdec_g726.c
+++ b/libavformat/rtpdec_g726.c
@@ -27,10 +27,8 @@  static int g726_ ## bitrate ##_init(AVFormatContext *s, int st_index, PayloadCon
     AVStream *stream = s->streams[st_index]; \
     AVCodecContext *codec = stream->codec; \
 \
-    codec->bit_rate = bitrate*1000; \
-    if (codec->sample_rate) \
-        codec->bits_per_coded_sample = \
-            av_clip((codec->bit_rate + codec->sample_rate/2) / codec->sample_rate, 2, 5); \
+    codec->bits_per_coded_sample = bitrate/8; \
+    codec->bit_rate = codec->bits_per_coded_sample * codec->sample_rate; \
 \
     return 0; \
 } \