[FFmpeg-cvslog] swr: change sample format representation so as to maintain the planer/ packed distinction.

Michael Niedermayer git at videolan.org
Sat Apr 28 13:20:35 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat Apr 28 11:19:22 2012 +0200| [edbde5222688c18eecd7a589779aa8696b64a6ab] | committer: Michael Niedermayer

swr: change sample format representation so as to maintain the planer/packed distinction.

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=edbde5222688c18eecd7a589779aa8696b64a6ab
---

 libswresample/audioconvert.c        |    2 +-
 libswresample/dither.c              |    3 +++
 libswresample/rematrix.c            |   12 ++++++------
 libswresample/resample.c            |   24 ++++++++++++------------
 libswresample/swresample.c          |   24 +++++++++++-------------
 libswresample/swresample_internal.h |    2 +-
 6 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/libswresample/audioconvert.c b/libswresample/audioconvert.c
index 7598bba..26cf471 100644
--- a/libswresample/audioconvert.c
+++ b/libswresample/audioconvert.c
@@ -122,7 +122,7 @@ AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt,
                                        int flags)
 {
     AudioConvert *ctx;
-    conv_func_type *f = fmt_pair_to_conv_functions[out_fmt + AV_SAMPLE_FMT_NB*in_fmt];
+    conv_func_type *f = fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt) + AV_SAMPLE_FMT_NB*av_get_packed_sample_fmt(in_fmt)];
 
     if (!f)
         return NULL;
diff --git a/libswresample/dither.c b/libswresample/dither.c
index a340733..79113f4 100644
--- a/libswresample/dither.c
+++ b/libswresample/dither.c
@@ -27,6 +27,9 @@ void swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSa
     double *tmp = av_malloc((len + TMP_EXTRA) * sizeof(double));
     int i;
 
+    out_fmt = av_get_packed_sample_fmt(out_fmt);
+    in_fmt  = av_get_packed_sample_fmt( in_fmt);
+
     if(in_fmt == AV_SAMPLE_FMT_FLT || in_fmt == AV_SAMPLE_FMT_DBL){
         if(out_fmt == AV_SAMPLE_FMT_S32) scale = 1.0/(1L<<31);
         if(out_fmt == AV_SAMPLE_FMT_S16) scale = 1.0/(1L<<15);
diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
index 4431979..415fb1e 100644
--- a/libswresample/rematrix.c
+++ b/libswresample/rematrix.c
@@ -227,8 +227,8 @@ static int auto_matrix(SwrContext *s)
     if(s->rematrix_volume  < 0)
         maxcoef = -s->rematrix_volume;
 
-    if((   s->out_sample_fmt < AV_SAMPLE_FMT_FLT
-        || s->int_sample_fmt < AV_SAMPLE_FMT_FLT) && maxcoef > 1.0){
+    if((   av_get_packed_sample_fmt(s->out_sample_fmt) < AV_SAMPLE_FMT_FLT
+        || av_get_packed_sample_fmt(s->int_sample_fmt) < AV_SAMPLE_FMT_FLT) && maxcoef > 1.0){
         for(i=0; i<SWR_CH_MAX; i++)
             for(j=0; j<SWR_CH_MAX; j++){
                 s->matrix[i][j] /= maxcoef;
@@ -273,10 +273,10 @@ int swri_rematrix_init(SwrContext *s){
 }
 
 void swri_sum2(enum AVSampleFormat format, void *dst, const void *src0, const void *src1, float coef0, float coef1, int len){
-    if(format == AV_SAMPLE_FMT_FLT){
+    if(format == AV_SAMPLE_FMT_FLTP){
         sum2_float((float  *)dst, (const float  *)src0, (const float  *)src1, coef0, coef1, len);
     }else{
-        av_assert1(format == AV_SAMPLE_FMT_S16);
+        av_assert1(format == AV_SAMPLE_FMT_S16P);
         sum2_s16  ((int16_t*)dst, (const int16_t*)src0, (const int16_t*)src1, lrintf(coef0 * 32768), lrintf(coef1 * 32768), len);
     }
 }
@@ -295,7 +295,7 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
         case 1:
             in_i= s->matrix_ch[out_i][1];
             if(mustcopy || s->matrix[out_i][in_i]!=1.0){
-                if(s->int_sample_fmt == AV_SAMPLE_FMT_FLT){
+                if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){
                     copy_float((float  *)out->ch[out_i], (const float  *)in->ch[in_i], s->matrix  [out_i][in_i], len);
                 }else
                     copy_s16  ((int16_t*)out->ch[out_i], (const int16_t*)in->ch[in_i], s->matrix32[out_i][in_i], len);
@@ -308,7 +308,7 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
                         s->matrix[out_i][ s->matrix_ch[out_i][1] ], s->matrix[out_i][ s->matrix_ch[out_i][2] ], len);
             break;
         default:
-            if(s->int_sample_fmt == AV_SAMPLE_FMT_FLT){
+            if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){
                 for(i=0; i<len; i++){
                     float v=0;
                     for(j=0; j<s->matrix_ch[out_i][0]; j++){
diff --git a/libswresample/resample.c b/libswresample/resample.c
index 806aba8..868f3eb 100644
--- a/libswresample/resample.c
+++ b/libswresample/resample.c
@@ -131,19 +131,19 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap
 
         /* normalize so that an uniform color remains the same */
         switch(c->format){
-        case AV_SAMPLE_FMT_S16:
+        case AV_SAMPLE_FMT_S16P:
             for(i=0;i<tap_count;i++)
                 ((int16_t*)filter)[ph * tap_count + i] = av_clip(lrintf(tab[i] * scale / norm), INT16_MIN, INT16_MAX);
             break;
-        case AV_SAMPLE_FMT_S32:
+        case AV_SAMPLE_FMT_S32P:
             for(i=0;i<tap_count;i++)
                 ((int32_t*)filter)[ph * tap_count + i] = av_clip(lrintf(tab[i] * scale / norm), INT32_MIN, INT32_MAX);
             break;
-        case AV_SAMPLE_FMT_FLT:
+        case AV_SAMPLE_FMT_FLTP:
             for(i=0;i<tap_count;i++)
                 ((float*)filter)[ph * tap_count + i] = tab[i] * scale / norm;
             break;
-        case AV_SAMPLE_FMT_DBL:
+        case AV_SAMPLE_FMT_DBLP:
             for(i=0;i<tap_count;i++)
                 ((double*)filter)[ph * tap_count + i] = tab[i] * scale / norm;
             break;
@@ -205,14 +205,14 @@ ResampleContext *swri_resample_init(ResampleContext *c, int out_rate, int in_rat
         c->felem_size= av_get_bytes_per_sample(c->format);
 
         switch(c->format){
-        case AV_SAMPLE_FMT_S16:
+        case AV_SAMPLE_FMT_S16P:
             c->filter_shift = 15;
             break;
-        case AV_SAMPLE_FMT_S32:
+        case AV_SAMPLE_FMT_S32P:
             c->filter_shift = 30;
             break;
-        case AV_SAMPLE_FMT_FLT:
-        case AV_SAMPLE_FMT_DBL:
+        case AV_SAMPLE_FMT_FLTP:
+        case AV_SAMPLE_FMT_DBLP:
             c->filter_shift = 0;
             break;
         default:
@@ -359,10 +359,10 @@ int swri_multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, Aud
     int i, ret= -1;
 
     for(i=0; i<dst->ch_count; i++){
-        if(c->format == AV_SAMPLE_FMT_S16) ret= swri_resample_int16(c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
-        if(c->format == AV_SAMPLE_FMT_S32) ret= swri_resample_int32(c, (int32_t*)dst->ch[i], (const int32_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
-        if(c->format == AV_SAMPLE_FMT_FLT) ret= swri_resample_float(c, (float  *)dst->ch[i], (const float  *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
-        if(c->format == AV_SAMPLE_FMT_DBL) ret= swri_resample_double(c,(double *)dst->ch[i], (const double *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
+        if(c->format == AV_SAMPLE_FMT_S16P) ret= swri_resample_int16(c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
+        if(c->format == AV_SAMPLE_FMT_S32P) ret= swri_resample_int32(c, (int32_t*)dst->ch[i], (const int32_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
+        if(c->format == AV_SAMPLE_FMT_FLTP) ret= swri_resample_float(c, (float  *)dst->ch[i], (const float  *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
+        if(c->format == AV_SAMPLE_FMT_DBLP) ret= swri_resample_double(c,(double *)dst->ch[i], (const double *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);
     }
 
     return ret;
diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 414d84c..8e3d3f5 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -52,8 +52,8 @@ static const AVOption options[]={
 {"in_sample_fmt"        ,    "Input Sample Format"      , OFFSET( in_sample_fmt ), AV_OPT_TYPE_INT  , {.dbl=AV_SAMPLE_FMT_S16     }, 0      , AV_SAMPLE_FMT_NB-1+256, PARAM},
 {"osf"                  ,   "Output Sample Format"      , OFFSET(out_sample_fmt ), AV_OPT_TYPE_INT  , {.dbl=AV_SAMPLE_FMT_S16     }, 0      , AV_SAMPLE_FMT_NB-1+256, PARAM},
 {"out_sample_fmt"       ,   "Output Sample Format"      , OFFSET(out_sample_fmt ), AV_OPT_TYPE_INT  , {.dbl=AV_SAMPLE_FMT_S16     }, 0      , AV_SAMPLE_FMT_NB-1+256, PARAM},
-{"tsf"                  , "Internal Sample Format"      , OFFSET(int_sample_fmt ), AV_OPT_TYPE_INT  , {.dbl=AV_SAMPLE_FMT_NONE    }, -1     , AV_SAMPLE_FMT_FLT, PARAM},
-{"internal_sample_fmt"  , "Internal Sample Format"      , OFFSET(int_sample_fmt ), AV_OPT_TYPE_INT  , {.dbl=AV_SAMPLE_FMT_NONE    }, -1     , AV_SAMPLE_FMT_FLT, PARAM},
+{"tsf"                  , "Internal Sample Format"      , OFFSET(int_sample_fmt ), AV_OPT_TYPE_INT  , {.dbl=AV_SAMPLE_FMT_NONE    }, -1     , AV_SAMPLE_FMT_FLTP, PARAM},
+{"internal_sample_fmt"  , "Internal Sample Format"      , OFFSET(int_sample_fmt ), AV_OPT_TYPE_INT  , {.dbl=AV_SAMPLE_FMT_NONE    }, -1     , AV_SAMPLE_FMT_FLTP, PARAM},
 {"icl"                  ,   "Input Channel Layout"      , OFFSET( in_ch_layout  ), AV_OPT_TYPE_INT64, {.dbl=0                     }, 0      , INT64_MAX , PARAM, "channel_layout"},
 {"in_channel_layout"    ,   "Input Channel Layout"      , OFFSET( in_ch_layout  ), AV_OPT_TYPE_INT64, {.dbl=0                     }, 0      , INT64_MAX , PARAM, "channel_layout"},
 {"ocl"                  ,  "Output Channel Layout"      , OFFSET(out_ch_layout  ), AV_OPT_TYPE_INT64, {.dbl=0                     }, 0      , INT64_MAX , PARAM, "channel_layout"},
@@ -193,8 +193,6 @@ int swr_init(struct SwrContext *s){
 
     s-> in.planar= av_sample_fmt_is_planar(s-> in_sample_fmt);
     s->out.planar= av_sample_fmt_is_planar(s->out_sample_fmt);
-    s-> in_sample_fmt= av_get_alt_sample_fmt(s-> in_sample_fmt, 0);
-    s->out_sample_fmt= av_get_alt_sample_fmt(s->out_sample_fmt, 0);
 
     if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
         av_log(s, AV_LOG_ERROR, "Requested input sample format %d is invalid\n", s->in_sample_fmt);
@@ -206,14 +204,14 @@ int swr_init(struct SwrContext *s){
     }
 
     //FIXME should we allow/support using FLT on material that doesnt need it ?
-    if(s->in_sample_fmt <= AV_SAMPLE_FMT_S16 || s->int_sample_fmt==AV_SAMPLE_FMT_S16){
-        s->int_sample_fmt= AV_SAMPLE_FMT_S16;
+    if(av_get_planar_sample_fmt(s->in_sample_fmt) <= AV_SAMPLE_FMT_S16P || s->int_sample_fmt==AV_SAMPLE_FMT_S16P){
+        s->int_sample_fmt= AV_SAMPLE_FMT_S16P;
     }else
-        s->int_sample_fmt= AV_SAMPLE_FMT_FLT;
+        s->int_sample_fmt= AV_SAMPLE_FMT_FLTP;
 
-    if(   s->int_sample_fmt != AV_SAMPLE_FMT_S16
-        &&s->int_sample_fmt != AV_SAMPLE_FMT_S32
-        &&s->int_sample_fmt != AV_SAMPLE_FMT_FLT){
+    if(   s->int_sample_fmt != AV_SAMPLE_FMT_S16P
+        &&s->int_sample_fmt != AV_SAMPLE_FMT_S32P
+        &&s->int_sample_fmt != AV_SAMPLE_FMT_FLTP){
         av_log(s, AV_LOG_ERROR, "Requested sample format %s is not supported internally, S16/S32/FLT is supported\n", av_get_sample_fmt_name(s->int_sample_fmt));
         return AVERROR(EINVAL);
     }
@@ -222,9 +220,9 @@ int swr_init(struct SwrContext *s){
         s->resample = swri_resample_init(s->resample, s->out_sample_rate, s->in_sample_rate, s->filter_size, s->phase_shift, s->linear_interp, s->cutoff, s->int_sample_fmt);
     }else
         swri_resample_free(&s->resample);
-    if(    s->int_sample_fmt != AV_SAMPLE_FMT_S16
-        && s->int_sample_fmt != AV_SAMPLE_FMT_S32
-        && s->int_sample_fmt != AV_SAMPLE_FMT_FLT
+    if(    s->int_sample_fmt != AV_SAMPLE_FMT_S16P
+        && s->int_sample_fmt != AV_SAMPLE_FMT_S32P
+        && s->int_sample_fmt != AV_SAMPLE_FMT_FLTP
         && s->resample){
         av_log(s, AV_LOG_ERROR, "Resampling only supported with internal s16/s32/flt\n");
         return -1;
diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
index 06578b8..70db5ae 100644
--- a/libswresample/swresample_internal.h
+++ b/libswresample/swresample_internal.h
@@ -37,7 +37,7 @@ struct SwrContext {
     int log_level_offset;                           ///< logging level offset
     void *log_ctx;                                  ///< parent logging context
     enum AVSampleFormat  in_sample_fmt;             ///< input sample format
-    enum AVSampleFormat int_sample_fmt;             ///< internal sample format (AV_SAMPLE_FMT_FLT or AV_SAMPLE_FMT_S16)
+    enum AVSampleFormat int_sample_fmt;             ///< internal sample format (AV_SAMPLE_FMT_FLTP or AV_SAMPLE_FMT_S16P)
     enum AVSampleFormat out_sample_fmt;             ///< output sample format
     int64_t  in_ch_layout;                          ///< input channel layout
     int64_t out_ch_layout;                          ///< output channel layout



More information about the ffmpeg-cvslog mailing list