]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/intrax8.c
libilbc: set channel layout
[ffmpeg] / libavcodec / intrax8.c
index 413966b98aef749014d01cb821beab8bfce45daf..fad7ffec054fb0b68feb0c2f9fc3bbb8aa8467d1 100644 (file)
@@ -1,32 +1,33 @@
 /*
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /**
- * @file intrax8.c
- * @brief IntraX8 (J-Frame) sub-decoder, used by wmv2 and vc1
+ * @file
+ * @brief IntraX8 (J-Frame) subdecoder, used by WMV2 and VC-1
  */
 
 #include "avcodec.h"
-#include "bitstream.h"
+#include "get_bits.h"
 #include "mpegvideo.h"
 #include "msmpeg4data.h"
 #include "intrax8huf.h"
 #include "intrax8.h"
+#include "intrax8dsp.h"
 
 #define MAX_TABLE_DEPTH(table_bits, max_bits) ((max_bits+table_bits-1)/table_bits)
 
@@ -42,54 +43,79 @@ static VLC j_ac_vlc[2][2][8];  //[quant<13],[intra/inter],[select]
 static VLC j_dc_vlc[2][8];     //[quant], [select]
 static VLC j_orient_vlc[2][4]; //[quant], [select]
 
-static void x8_vlc_init(){
+static av_cold void x8_vlc_init(void){
     int i;
+    int offset = 0;
+    int sizeidx = 0;
+    static const uint16_t sizes[8*4 + 8*2 + 2 + 4] = {
+        576, 548, 582, 618, 546, 616, 560, 642,
+        584, 582, 704, 664, 512, 544, 656, 640,
+        512, 648, 582, 566, 532, 614, 596, 648,
+        586, 552, 584, 590, 544, 578, 584, 624,
+
+        528, 528, 526, 528, 536, 528, 526, 544,
+        544, 512, 512, 528, 528, 544, 512, 544,
+
+        128, 128, 128, 128, 128, 128};
+
+    static VLC_TYPE table[28150][2];
 
 #define  init_ac_vlc(dst,src) \
+    dst.table = &table[offset]; \
+    dst.table_allocated = sizes[sizeidx]; \
+    offset += sizes[sizeidx++]; \
        init_vlc(&dst, \
               AC_VLC_BITS,77, \
               &src[1],4,2, \
               &src[0],4,2, \
-              1)
+              INIT_VLC_USE_NEW_STATIC)
 //set ac tables
     for(i=0;i<8;i++){
-        init_ac_vlc( j_ac_vlc[0][0][i], ff_x8_ac0_highquant_table[i][0] );
-        init_ac_vlc( j_ac_vlc[0][1][i], ff_x8_ac1_highquant_table[i][0] );
-        init_ac_vlc( j_ac_vlc[1][0][i], ff_x8_ac0_lowquant_table [i][0] );
-        init_ac_vlc( j_ac_vlc[1][1][i], ff_x8_ac1_lowquant_table [i][0] );
+        init_ac_vlc( j_ac_vlc[0][0][i], x8_ac0_highquant_table[i][0] );
+        init_ac_vlc( j_ac_vlc[0][1][i], x8_ac1_highquant_table[i][0] );
+        init_ac_vlc( j_ac_vlc[1][0][i], x8_ac0_lowquant_table [i][0] );
+        init_ac_vlc( j_ac_vlc[1][1][i], x8_ac1_lowquant_table [i][0] );
     }
 #undef init_ac_vlc
 
 //set dc tables
 #define init_dc_vlc(dst,src) \
+    dst.table = &table[offset]; \
+    dst.table_allocated = sizes[sizeidx]; \
+    offset += sizes[sizeidx++]; \
         init_vlc(&dst, \
         DC_VLC_BITS,34, \
         &src[1],4,2, \
         &src[0],4,2, \
-        1);
+        INIT_VLC_USE_NEW_STATIC);
     for(i=0;i<8;i++){
-        init_dc_vlc( j_dc_vlc[0][i], ff_x8_dc_highquant_table[i][0]);
-        init_dc_vlc( j_dc_vlc[1][i], ff_x8_dc_lowquant_table [i][0]);
+        init_dc_vlc( j_dc_vlc[0][i], x8_dc_highquant_table[i][0]);
+        init_dc_vlc( j_dc_vlc[1][i], x8_dc_lowquant_table [i][0]);
     }
 #undef init_dc_vlc
 
 //set orient tables
 #define init_or_vlc(dst,src) \
+    dst.table = &table[offset]; \
+    dst.table_allocated = sizes[sizeidx]; \
+    offset += sizes[sizeidx++]; \
     init_vlc(&dst, \
     OR_VLC_BITS,12, \
     &src[1],4,2, \
     &src[0],4,2, \
-    1);
+    INIT_VLC_USE_NEW_STATIC);
     for(i=0;i<2;i++){
-        init_or_vlc( j_orient_vlc[0][i], ff_x8_orient_highquant_table[i][0]);
+        init_or_vlc( j_orient_vlc[0][i], x8_orient_highquant_table[i][0]);
     }
     for(i=0;i<4;i++){
-        init_or_vlc( j_orient_vlc[1][i], ff_x8_orient_lowquant_table [i][0])
+        init_or_vlc( j_orient_vlc[1][i], x8_orient_lowquant_table [i][0])
     }
+    if (offset != sizeof(table)/sizeof(VLC_TYPE)/2)
+        av_log(NULL, AV_LOG_ERROR, "table size %i does not match needed %i\n", (int)(sizeof(table)/sizeof(VLC_TYPE)/2), offset);
 }
 #undef init_or_vlc
 
-static inline void x8_reset_vlc_tables(IntraX8Context * w){
+static void x8_reset_vlc_tables(IntraX8Context * w){
     memset(w->j_dc_vlc,0,sizeof(w->j_dc_vlc));
     memset(w->j_ac_vlc,0,sizeof(w->j_ac_vlc));
     w->j_orient_vlc=NULL;
@@ -194,7 +220,7 @@ static void x8_get_ac_rlf(IntraX8Context * const w, const int mode,
   i==20-21 r=0-1  l=2 ;r=i& %00001
   i==22    r=0    l=3 ;r=i& %00000
 l=lut_l[i/2]={0,0,0,0,0,0,0,0,1,1,2,3}[i>>1];// 11 10'01 01'00 00'00 00'00 00'00 00 => 0xE50000
-t=lut_mask[l]={0x0f,0x03,0x01,0x00}[l]; as i<256 the higher bits doesn't matter */
+t=lut_mask[l]={0x0f,0x03,0x01,0x00}[l]; as i<256 the higher bits do not matter */
         l=(0xE50000>>(i&(0x1E)))&3;/*0x1E or (~1) or ((i>>1)<<1)*/
         t=(0x01030F>>(l<<3));
 
@@ -278,9 +304,9 @@ static int x8_setup_spatial_predictor(IntraX8Context * const w, const int chroma
     int sum;
     int quant;
 
-    s->dsp.x8_setup_spacial_compensation(s->dest[chroma], s->edge_emu_buffer,
-                                          s->current_picture.linesize[chroma>0],
-                                          &range, &sum, w->edges);
+    w->dsp.setup_spatial_compensation(s->dest[chroma], s->edge_emu_buffer,
+                                      s->current_picture.f.linesize[chroma>0],
+                                      &range, &sum, w->edges);
     if(chroma){
         w->orient=w->chroma_orient;
         quant=w->quant_dc_chroma;
@@ -291,7 +317,7 @@ static int x8_setup_spatial_predictor(IntraX8Context * const w, const int chroma
     w->flat_dc=0;
     if(range < quant || range < 3){
         w->orient=0;
-        if(range < 3){//yep you read right, idct error of +-1 may break decoding!
+        if(range < 3){//yep you read right, a +-1 idct error may break decoding!
             w->flat_dc=1;
             sum+=9;
             w->predicted_dc = (sum*6899)>>17;//((1<<17)+9)/(8+8+1+2)=6899
@@ -374,15 +400,15 @@ static void x8_get_prediction(IntraX8Context * const w){
             w->orient  = 0;
             return;
     }
-    //no edge cases.
+    //no edge cases
     b= w->prediction_table[2*s->mb_x   + !(s->mb_y&1) ];//block[x  ][y-1]
     a= w->prediction_table[2*s->mb_x-2 +  (s->mb_y&1) ];//block[x-1][y  ]
     c= w->prediction_table[2*s->mb_x-2 + !(s->mb_y&1) ];//block[x-1][y-1]
 
     w->est_run = FFMIN(b,a);
-    /*this condition have nothing to do with w->edges, even if it looks similar
-      it would triger if e.g. x=3;y=2;
-      I guess somebody wrote something wrong and it became standard */
+    /* This condition has nothing to do with w->edges, even if it looks
+       similar it would trigger if e.g. x=3;y=2;
+       I guess somebody wrote something wrong and it became standard. */
     if( (s->mb_x & s->mb_y) != 0 ) w->est_run=FFMIN(c,w->est_run);
     w->est_run>>=2;
 
@@ -500,7 +526,7 @@ static const int16_t quant_table[64] = {
 };
 
 static int x8_decode_intra_mb(IntraX8Context* const w, const int chroma){
-MpegEncContext * const s= w->s;
+    MpegEncContext * const s= w->s;
 
     uint8_t * scantable;
     int final,run,level;
@@ -511,7 +537,7 @@ MpegEncContext * const s= w->s;
     int sign;
 
     assert(w->orient<12);
-    memset(s->block[0],0x00,64*sizeof(DCTELEM));
+    s->dsp.clear_block(s->block[0]);
 
     if(chroma){
         dc_mode=2;
@@ -588,7 +614,7 @@ MpegEncContext * const s= w->s;
             dc_level+= (w->predicted_dc*divide_quant + (1<<12) )>>13;
 
             dsp_x8_put_solidcolor( av_clip_uint8((dc_level*dc_quant+4)>>3),
-                                   s->dest[chroma], s->current_picture.linesize[!!chroma]);
+                                   s->dest[chroma], s->current_picture.f.linesize[!!chroma]);
 
             goto block_placed;
         }
@@ -612,15 +638,15 @@ MpegEncContext * const s= w->s;
     }
 
     if(w->flat_dc){
-        dsp_x8_put_solidcolor(w->predicted_dc, s->dest[chroma], s->current_picture.linesize[!!chroma]);
+        dsp_x8_put_solidcolor(w->predicted_dc, s->dest[chroma], s->current_picture.f.linesize[!!chroma]);
     }else{
-        s->dsp.x8_spacial_compensation[w->orient]( s->edge_emu_buffer,
+        w->dsp.spatial_compensation[w->orient]( s->edge_emu_buffer,
                                             s->dest[chroma],
-                                            s->current_picture.linesize[!!chroma] );
+                                            s->current_picture.f.linesize[!!chroma] );
     }
     if(!zeros_only)
         s->dsp.idct_add ( s->dest[chroma],
-                          s->current_picture.linesize[!!chroma],
+                          s->current_picture.f.linesize[!!chroma],
                           s->block[0] );
 
 block_placed:
@@ -631,31 +657,31 @@ block_placed:
 
     if(s->loop_filter){
         uint8_t* ptr = s->dest[chroma];
-        int linesize = s->current_picture.linesize[!!chroma];
+        int linesize = s->current_picture.f.linesize[!!chroma];
 
         if(!( (w->edges&2) || ( zeros_only && (w->orient|4)==4 ) )){
-            s->dsp.x8_h_loop_filter(ptr, linesize, w->quant);
+            w->dsp.h_loop_filter(ptr, linesize, w->quant);
         }
         if(!( (w->edges&1) || ( zeros_only && (w->orient|8)==8 ) )){
-            s->dsp.x8_v_loop_filter(ptr, linesize, w->quant);
+            w->dsp.v_loop_filter(ptr, linesize, w->quant);
         }
     }
     return 0;
 }
 
-static inline void x8_init_block_index(MpegEncContext *s){ //FIXME maybe merge with ff_*
+static void x8_init_block_index(MpegEncContext *s){ //FIXME maybe merge with ff_*
 //not s->linesize as this would be wrong for field pics
-//not that IntraX8 have interlace support ;)
-    const int linesize  = s->current_picture.linesize[0];
-    const int uvlinesize= s->current_picture.linesize[1];
+//not that IntraX8 has interlacing support ;)
+    const int linesize   = s->current_picture.f.linesize[0];
+    const int uvlinesize = s->current_picture.f.linesize[1];
 
-    s->dest[0] = s->current_picture.data[0];
-    s->dest[1] = s->current_picture.data[1];
-    s->dest[2] = s->current_picture.data[2];
+    s->dest[0] = s->current_picture.f.data[0];
+    s->dest[1] = s->current_picture.f.data[1];
+    s->dest[2] = s->current_picture.f.data[2];
 
-        s->dest[0] += s->mb_y *   linesize << 3;
-        s->dest[1] += ( s->mb_y&(~1) ) * uvlinesize << 2;//chroma blocks are on add rows
-        s->dest[2] += ( s->mb_y&(~1) ) * uvlinesize << 2;
+    s->dest[0] +=   s->mb_y        *   linesize << 3;
+    s->dest[1] += ( s->mb_y&(~1) ) * uvlinesize << 2;//chroma blocks are on add rows
+    s->dest[2] += ( s->mb_y&(~1) ) * uvlinesize << 2;
 }
 
 /**
@@ -664,30 +690,40 @@ static inline void x8_init_block_index(MpegEncContext *s){ //FIXME maybe merge w
  * @param w pointer to IntraX8Context
  * @param s pointer to MpegEncContext of the parent codec
  */
-void ff_intrax8_common_init(IntraX8Context * w, MpegEncContext * const s){
+av_cold void ff_intrax8_common_init(IntraX8Context * w, MpegEncContext * const s){
 
     w->s=s;
     x8_vlc_init();
     assert(s->mb_width>0);
     w->prediction_table=av_mallocz(s->mb_width*2*2);//two rows, 2 blocks per cannon mb
 
-    ff_init_scantable(s->dsp.idct_permutation, &w->scantable[0], wmv1_scantable[0]);
-    ff_init_scantable(s->dsp.idct_permutation, &w->scantable[1], wmv1_scantable[2]);
-    ff_init_scantable(s->dsp.idct_permutation, &w->scantable[2], wmv1_scantable[3]);
+    ff_init_scantable(s->dsp.idct_permutation, &w->scantable[0], ff_wmv1_scantable[0]);
+    ff_init_scantable(s->dsp.idct_permutation, &w->scantable[1], ff_wmv1_scantable[2]);
+    ff_init_scantable(s->dsp.idct_permutation, &w->scantable[2], ff_wmv1_scantable[3]);
+
+    ff_intrax8dsp_init(&w->dsp);
+}
+
+/**
+ * Destroy IntraX8 frame structure.
+ * @param w pointer to IntraX8Context
+ */
+av_cold void ff_intrax8_common_end(IntraX8Context * w)
+{
+    av_freep(&w->prediction_table);
 }
 
 /**
  * Decode single IntraX8 frame.
  * The parent codec must fill s->loopfilter and s->gb (bitstream).
- * The parent codec must call MPV_frame_start(), ff_er_frame_start() before calling this function
+ * The parent codec must call MPV_frame_start(), ff_er_frame_start() before calling this function.
  * The parent codec must call ff_er_frame_end(), MPV_frame_end() after calling this function.
  * This function does not use MPV_decode_mb().
- * lowres decoding is theoretically impossible.
  * @param w pointer to IntraX8Context
- * @param dquant doubled quantizer, it would be odd in case of vc1 halfpq==1
- * @param quant_offset offset away from zero.
+ * @param dquant doubled quantizer, it would be odd in case of VC-1 halfpq==1.
+ * @param quant_offset offset away from zero
  */
-//FIXME extern uint8_t wmv3_dc_scale_table[32];
+//FIXME extern uint8_t ff_wmv3_dc_scale_table[32];
 int ff_intrax8_decode_picture(IntraX8Context * const w, int dquant, int quant_offset){
     MpegEncContext * const s= w->s;
     int mb_xy;
@@ -724,7 +760,7 @@ int ff_intrax8_decode_picture(IntraX8Context * const w, int dquant, int quant_of
                 x8_get_prediction_chroma(w);
 
                 /*when setting up chroma, no vlc is read,
-                so no error condition could be reached*/
+                so no error condition can be reached*/
                 x8_setup_spatial_predictor(w,1);
                 if(x8_decode_intra_mb(w,1)) goto error;
 
@@ -737,7 +773,7 @@ int ff_intrax8_decode_picture(IntraX8Context * const w, int dquant, int quant_of
                 /*emulate MB info in the relevant tables*/
                 s->mbskip_table [mb_xy]=0;
                 s->mbintra_table[mb_xy]=1;
-                s->current_picture.qscale_table[mb_xy]=w->quant;
+                s->current_picture.f.qscale_table[mb_xy] = w->quant;
                 mb_xy++;
             }
             s->dest[0]+= 8;
@@ -750,6 +786,6 @@ int ff_intrax8_decode_picture(IntraX8Context * const w, int dquant, int quant_of
 error:
     ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y,
                         (s->mb_x>>1)-1, (s->mb_y>>1)-1,
-                        (AC_END|DC_END|MV_END) );
+                        ER_MB_END );
     return 0;
 }