[SCM] libav/experimental: av_get_bits_per_sample and due simplifications

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 15:48:50 UTC 2013


The following commit has been merged in the experimental branch:
commit ac3e183403ecc246520fd8882eb8ff5e58473413
Author: Baptiste Coudurier <baptiste.coudurier at gmail.com>
Date:   Fri Jul 7 17:50:09 2006 +0000

    av_get_bits_per_sample and due simplifications
    
    Originally committed as revision 5661 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 5509621..a829fd6 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2499,6 +2499,10 @@ void avcodec_default_free_buffers(AVCodecContext *s);
  */
 char av_get_pict_type_char(int pict_type);
 
+/**
+ * returns codec bits per sample
+ */
+int av_get_bits_per_sample(enum CodecID codec_id);
 
 /* frame parsing */
 typedef struct AVCodecParserContext {
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 641c680..b343ba0 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1304,6 +1304,34 @@ char av_get_pict_type_char(int pict_type){
     }
 }
 
+int av_get_bits_per_sample(enum CodecID codec_id){
+    switch(codec_id){
+    case CODEC_ID_PCM_ALAW:
+    case CODEC_ID_PCM_MULAW:
+    case CODEC_ID_PCM_S8:
+    case CODEC_ID_PCM_U8:
+        return 8;
+    case CODEC_ID_PCM_S16BE:
+    case CODEC_ID_PCM_S16LE:
+    case CODEC_ID_PCM_U16BE:
+    case CODEC_ID_PCM_U16LE:
+        return 16;
+    case CODEC_ID_PCM_S24DAUD:
+    case CODEC_ID_PCM_S24BE:
+    case CODEC_ID_PCM_S24LE:
+    case CODEC_ID_PCM_U24BE:
+    case CODEC_ID_PCM_U24LE:
+        return 24;
+    case CODEC_ID_PCM_S32BE:
+    case CODEC_ID_PCM_S32LE:
+    case CODEC_ID_PCM_U32BE:
+    case CODEC_ID_PCM_U32LE:
+        return 32;
+    default:
+        return 0;
+    }
+}
+
 /* av_log API */
 
 static int av_log_level = AV_LOG_INFO;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index e51fda1..30e3b00 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1463,27 +1463,7 @@ static int mov_write_header(AVFormatContext *s)
         }else if(st->codec->codec_type == CODEC_TYPE_AUDIO){
             track->tag = mov_find_audio_codec_tag(s, track);
             av_set_pts_info(st, 64, 1, st->codec->sample_rate);
-
-            switch (st->codec->codec_id) {
-            case CODEC_ID_PCM_MULAW:
-            case CODEC_ID_PCM_ALAW:
-                track->sampleSize = 1 * st->codec->channels;
-                break;
-            case CODEC_ID_PCM_S16BE:
-            case CODEC_ID_PCM_S16LE:
-                track->sampleSize = 2 * st->codec->channels;
-                break;
-            case CODEC_ID_PCM_S24BE:
-            case CODEC_ID_PCM_S24LE:
-                track->sampleSize = 3 * st->codec->channels;
-                break;
-            case CODEC_ID_PCM_S32BE:
-            case CODEC_ID_PCM_S32LE:
-                track->sampleSize = 4 * st->codec->channels;
-                break;
-            default:
-                track->sampleSize = 0;
-            }
+            track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels;
         }
         track->language = ff_mov_iso639_to_lang(st->language, mov->mode != MODE_MOV);
         track->mode = mov->mode;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 42f54d6..d51e64a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -653,48 +653,17 @@ static int get_audio_frame_size(AVCodecContext *enc, int size)
     int frame_size;
 
     if (enc->frame_size <= 1) {
-        /* specific hack for pcm codecs because no frame size is
-           provided */
-        switch(enc->codec_id) {
-        case CODEC_ID_PCM_S32LE:
-        case CODEC_ID_PCM_S32BE:
-        case CODEC_ID_PCM_U32LE:
-        case CODEC_ID_PCM_U32BE:
-            if (enc->channels == 0)
-                return -1;
-            frame_size = size / (4 * enc->channels);
-            break;
-        case CODEC_ID_PCM_S24LE:
-        case CODEC_ID_PCM_S24BE:
-        case CODEC_ID_PCM_U24LE:
-        case CODEC_ID_PCM_U24BE:
-        case CODEC_ID_PCM_S24DAUD:
-            if (enc->channels == 0)
-                return -1;
-            frame_size = size / (3 * enc->channels);
-            break;
-        case CODEC_ID_PCM_S16LE:
-        case CODEC_ID_PCM_S16BE:
-        case CODEC_ID_PCM_U16LE:
-        case CODEC_ID_PCM_U16BE:
-            if (enc->channels == 0)
-                return -1;
-            frame_size = size / (2 * enc->channels);
-            break;
-        case CODEC_ID_PCM_S8:
-        case CODEC_ID_PCM_U8:
-        case CODEC_ID_PCM_MULAW:
-        case CODEC_ID_PCM_ALAW:
+        int bits_per_sample = av_get_bits_per_sample(enc->codec_id);
+
+        if (bits_per_sample) {
             if (enc->channels == 0)
                 return -1;
-            frame_size = size / (enc->channels);
-            break;
-        default:
+            frame_size = size / ((bits_per_sample >> 3) * enc->channels);
+        } else {
             /* used for example by ADPCM codecs */
             if (enc->bit_rate == 0)
                 return -1;
             frame_size = (size * 8 * enc->sample_rate) / enc->bit_rate;
-            break;
         }
     } else {
         frame_size = enc->frame_size;

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list