[FFmpeg-devel] [PATCH] avcodec: Add bits_per_raw_sample to AVCodecParameters

Michael Niedermayer michael at niedermayer.cc
Tue Apr 12 13:10:09 CEST 2016


On Mon, Apr 11, 2016 at 01:32:07AM +0200, Michael Niedermayer wrote:
> The bits_per_raw_sample represents the number of bits of precission per sample.
> 
> The field is added at the logical place, not at the end as the code was just
> recently added
> 
> This fixes the regression about loosing the audio sample precission information
> 
> The change in the fate test checksum un-does the change from the merge
> 
> Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> ---
>  libavcodec/avcodec.h |   17 +++++++++++++++++
>  libavcodec/utils.c   |    2 ++
>  tests/ref/lavf/ffm   |    2 +-
>  3 files changed, 20 insertions(+), 1 deletion(-)

new version of this with improved documentation
I intend to apply this soon if noone is against


From e500d2222d31368b760144b1e2b5b094f73b571b Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michael at niedermayer.cc>
Date: Mon, 11 Apr 2016 00:52:21 +0200
Subject: [PATCH] avcodec: Add bits_per_raw_sample to AVCodecParameters

The bits_per_raw_sample represents the number of bits of precission per sample.

The field is added at the logical place, not at the end as the code was just
recently added

This fixes the regression about loosing the audio sample precission information

The change in the fate test checksum un-does the change from the merge

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 libavcodec/avcodec.h |   21 +++++++++++++++++++++
 libavcodec/utils.c   |    2 ++
 tests/ref/lavf/ffm   |    2 +-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index b3655c5..99cbf88 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3832,9 +3832,30 @@ typedef struct AVCodecParameters {
      */
     int64_t bit_rate;

+    /**
+     * The number of bits per sample in the codedwords.
+     *
+     * This is basically the bitrate per sample, it is mandatory for a bunch of
+     * formats to actually decode them, its the number of bits for one sample in
+     * the actual coded bitstream.
+     *
+     * This could be for example 4 for ADPCM
+     * For PCM formats this matches bits_per_raw_sample
+     * Can be 0
+     */
     int bits_per_coded_sample;

     /**
+     * The number of bits of precission in the samples.
+     *
+     * These are the bits in a decoded (raw) sample.
+     *
+     * For ADPCM this might be 12 or 16 or similar
+     * Can be 0
+     */
+    int bits_per_raw_sample;
+
+    /**
      * Codec-specific bitstream restrictions that the stream conforms to.
      */
     int profile;
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index c1f8e22..e0edce3 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -3771,6 +3771,7 @@ int avcodec_parameters_from_context(AVCodecParameters *par,

     par->bit_rate              = codec->bit_rate;
     par->bits_per_coded_sample = codec->bits_per_coded_sample;
+    par->bits_per_raw_sample   = codec->bits_per_raw_sample;
     par->profile               = codec->profile;
     par->level                 = codec->level;

@@ -3824,6 +3825,7 @@ int avcodec_parameters_to_context(AVCodecContext *codec,

     codec->bit_rate              = par->bit_rate;
     codec->bits_per_coded_sample = par->bits_per_coded_sample;
+    codec->bits_per_raw_sample   = par->bits_per_raw_sample;
     codec->profile               = par->profile;
     codec->level                 = par->level;

diff --git a/tests/ref/lavf/ffm b/tests/ref/lavf/ffm
index e45ef08..c4d7e1f 100644
--- a/tests/ref/lavf/ffm
+++ b/tests/ref/lavf/ffm
@@ -1,3 +1,3 @@
-79674a5219d00e1d2221a29157b35eb4 *./tests/data/lavf/lavf.ffm
+e63c16b5f0ad5015304fc4009fdb33ca *./tests/data/lavf/lavf.ffm
 376832 ./tests/data/lavf/lavf.ffm
 ./tests/data/lavf/lavf.ffm CRC=0x000e23ae
--
1.7.9.5

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
then the original author, trying to rewrite it will not make it better.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160412/7417d35b/attachment.sig>


More information about the ffmpeg-devel mailing list