[FFmpeg-soc] [soc]: r4029 - in wmapro: wma3.h wma3dec.c

faust3 subversion at mplayerhq.hu
Sun Feb 8 21:52:48 CET 2009


Author: faust3
Date: Sun Feb  8 21:52:47 2009
New Revision: 4029

Log:
Only store the GetBitContext that is used for
decoding the frame inside the decoder context

Modified:
   wmapro/wma3.h
   wmapro/wma3dec.c

Modified: wmapro/wma3.h
==============================================================================
--- wmapro/wma3.h	Sun Feb  8 21:21:25 2009	(r4028)
+++ wmapro/wma3.h	Sun Feb  8 21:52:47 2009	(r4029)
@@ -131,7 +131,6 @@ typedef struct WMA3DecodeContext {
     /** frame decode state */
     unsigned int     frame_num;                     //< current frame number
     GetBitContext*   getbit;
-    GetBitContext    gb;                            //< getbitcontext for the packet
     int              buf_bit_size;                  //< buffer size in bits
     int16_t*         samples;                       //< current samplebuffer pointer
     int16_t*         samples_end;                   //< maximum samplebuffer pointer

Modified: wmapro/wma3dec.c
==============================================================================
--- wmapro/wma3dec.c	Sun Feb  8 21:21:25 2009	(r4028)
+++ wmapro/wma3dec.c	Sun Feb  8 21:52:47 2009	(r4029)
@@ -411,10 +411,9 @@ static av_cold int wma3_decode_init(AVCo
  *       between the individual channels.
  *
  *@param s context
- *@param gb current get bit context
  *@return 0 on success, < 0 in case of an error
  */
-static int wma_decode_tilehdr(WMA3DecodeContext *s, GetBitContext* gb)
+static int wma_decode_tilehdr(WMA3DecodeContext *s)
 {
     int c;
     int missing_samples = s->num_channels * s->samples_per_frame;
@@ -462,7 +461,7 @@ static int wma_decode_tilehdr(WMA3Decode
 
             /** check if this is the start of a new frame */
             if(missing_samples == s->num_channels * s->samples_per_frame){
-                s->no_tiling = get_bits1(gb);
+                s->no_tiling = get_bits1(s->getbit);
             }
 
             if(s->no_tiling){
@@ -495,7 +494,7 @@ static int wma_decode_tilehdr(WMA3Decode
                 int num_bits = total_num_bits;
                 if(num_bits > 32)
                     num_bits = 32;
-                tileinfo |= get_bits_long(gb,num_bits);
+                tileinfo |= get_bits_long(s->getbit,num_bits);
                 total_num_bits -= num_bits;
                 num_bits = total_num_bits;
                 tileinfo <<= (num_bits > 32)? 32 : num_bits;
@@ -508,12 +507,13 @@ static int wma_decode_tilehdr(WMA3Decode
                 int log2_subframe_len = 0;
                 /* 1 bit indicates if the subframe length is zero */
                 if(subframe_len_zero_bit){
-                    if(get_bits1(gb)){
-                        log2_subframe_len = get_bits(gb,subframe_len_bits-1);
+                    if(get_bits1(s->getbit)){
+                        log2_subframe_len =
+                            get_bits(s->getbit,subframe_len_bits-1);
                         ++log2_subframe_len;
                     }
                 }else
-                    log2_subframe_len = get_bits(gb,subframe_len_bits);
+                    log2_subframe_len = get_bits(s->getbit,subframe_len_bits);
 
                 if(s->lossless){
                     subframe_len =
@@ -579,7 +579,7 @@ static int wma_decode_tilehdr(WMA3Decode
     return 0;
 }
 
-static int wma_decode_channel_transform(WMA3DecodeContext* s, GetBitContext* gb)
+static int wma_decode_channel_transform(WMA3DecodeContext* s)
 {
     int i;
     for(i=0;i< s->num_channels;i++){
@@ -600,7 +600,7 @@ static int wma_decode_channel_transform(
     }else{
         int remaining_channels = s->channels_for_cur_subframe;
 
-        if(get_bits(gb,1)){
+        if(get_bits(s->getbit,1)){
             av_log(s->avctx,AV_LOG_ERROR,"unsupported channel transform bit\n");
             return 0;
         }
@@ -617,7 +617,8 @@ static int wma_decode_channel_transform(
             if(remaining_channels > 2){
                 for(i=0;i<s->channels_for_cur_subframe;i++){
                     int channel_idx = s->channel_indexes_for_cur_subframe[i];
-                    if(!s->channel[channel_idx].grouped && get_bits(gb,1)){
+                    if(!s->channel[channel_idx].grouped
+                       && get_bits(s->getbit,1)){
                         ++chgroup->num_channels;
                         s->channel[channel_idx].grouped = 1;
                         chgroup->use_channel[channel_idx] = 1;
@@ -642,8 +643,8 @@ static int wma_decode_channel_transform(
                 chgroup->decorrelation_matrix[0] = 1.0;
 
             }else if(chgroup->num_channels == 2){
-                if(get_bits(gb,1)){
-                    if(!get_bits(gb,1)){
+                if(get_bits(s->getbit,1)){
+                    if(!get_bits(s->getbit,1)){
                         chgroup->no_rotation = 1;
                         chgroup->transform = 2;
                         chgroup->decorrelation_matrix[0] = 1.0;
@@ -660,8 +661,8 @@ static int wma_decode_channel_transform(
                     chgroup->decorrelation_matrix[3] = 0.70703125;
                 }
             }else{
-                if(get_bits(gb,1)){
-                    if(get_bits(gb,1)){
+                if(get_bits(s->getbit,1)){
+                    if(get_bits(s->getbit,1)){
                         chgroup->no_rotation = 0;
                         chgroup->transform = 0;
                     }else{
@@ -691,10 +692,10 @@ static int wma_decode_channel_transform(
                 int n_offset = chgroup->num_channels  * (chgroup->num_channels - 1) / 2;
                 int i;
                 for(i=0;i<n_offset;i++){
-                    chgroup->rotation_offset[i] = get_bits(gb,6);
+                    chgroup->rotation_offset[i] = get_bits(s->getbit,6);
                 }
                 for(i=0;i<chgroup->num_channels;i++)
-                    chgroup->positive[i] = get_bits(gb,1);
+                    chgroup->positive[i] = get_bits(s->getbit,1);
             }
 
             /* decode transform on / off */
@@ -704,11 +705,11 @@ static int wma_decode_channel_transform(
                 for(i=0;i<s->num_bands;i++)
                     chgroup->transform_band[i] = 1;
             }else{
-                if(get_bits(gb,1) == 0){
+                if(get_bits(s->getbit,1) == 0){
                     int i;
                     // transform works on individual scale factor bands
                     for(i=0;i< s->num_bands;i++){
-                        chgroup->transform_band[i] = get_bits(gb,1);
+                        chgroup->transform_band[i] = get_bits(s->getbit,1);
                     }
                 }else{
                     int i;
@@ -782,7 +783,7 @@ static inline void wma_get_vec4(WMA3Deco
             masks[3] = get_bits(s->getbit,1);
 }
 
-static int decode_coeffs(WMA3DecodeContext *s,GetBitContext* gb,int c)
+static int decode_coeffs(WMA3DecodeContext *s, int c)
 {
     int vlctable;
     VLC* vlc;
@@ -796,7 +797,6 @@ static int decode_coeffs(WMA3DecodeConte
 
     av_log(s->avctx,AV_LOG_DEBUG,"decode coefficients for channel %i\n",c);
 
-    s->getbit = gb;
     s->esc_len = av_log2(s->subframe_len -1) +1;
     vlctable = get_bits(s->getbit, 1);
     vlc = &s->coef_vlc[vlctable];
@@ -869,7 +869,7 @@ static int decode_coeffs(WMA3DecodeConte
     return 0;
 }
 
-static int wma_decode_scale_factors(WMA3DecodeContext* s,GetBitContext* gb)
+static int wma_decode_scale_factors(WMA3DecodeContext* s)
 {
     int i;
     for(i=0;i<s->channels_for_cur_subframe;i++){
@@ -893,7 +893,7 @@ static int wma_decode_scale_factors(WMA3
         }
 
         if(s->channel[c].cur_subframe > 0){
-            s->channel[c].transmit_sf = get_bits(gb,1);
+            s->channel[c].transmit_sf = get_bits(s->getbit,1);
         }else
             s->channel[c].transmit_sf = 1;
 
@@ -902,9 +902,9 @@ static int wma_decode_scale_factors(WMA3
 
             if(!s->channel[c].reuse_sf){
                 int i;
-                s->channel[c].scale_factor_step = get_bits(gb,2) + 1;
+                s->channel[c].scale_factor_step = get_bits(s->getbit,2) + 1;
                 for(i=0;i<s->num_bands;i++){
-                    int val = get_vlc2(gb, s->sf_vlc.table, SCALEVLCBITS, ((FF_WMA3_HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)); // DPCM-coded
+                    int val = get_vlc2(s->getbit, s->sf_vlc.table, SCALEVLCBITS, ((FF_WMA3_HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)); // DPCM-coded
                     if(!i)
                         s->channel[c].scale_factors[i] = 45 / s->channel[c].scale_factor_step + val - 60;
                     else
@@ -921,10 +921,10 @@ static int wma_decode_scale_factors(WMA3
                     short level_mask;
                     short val;
 
-                    idx = get_vlc2(gb, s->sf_rl_vlc.table, VLCBITS, ((FF_WMA3_HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS));
+                    idx = get_vlc2(s->getbit, s->sf_rl_vlc.table, VLCBITS, ((FF_WMA3_HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS));
 
                     if( !idx ){
-                        uint32_t mask = get_bits(gb,14);
+                        uint32_t mask = get_bits(s->getbit,14);
                         level_mask = mask >> 6;
                         val = (mask & 1) - 1;
                         skip = (0x3f & mask)>>1;
@@ -933,7 +933,7 @@ static int wma_decode_scale_factors(WMA3
                     }else{
                         skip = ff_wma3_scale_rl_run[idx];
                         level_mask = ff_wma3_scale_rl_level[idx];
-                        val = get_bits(gb,1)-1;
+                        val = get_bits(s->getbit,1)-1;
                     }
 
                     i += skip;
@@ -1097,7 +1097,7 @@ static void wma_window(WMA3DecodeContext
     }
 }
 
-static int wma_decode_subframe(WMA3DecodeContext *s,GetBitContext* gb)
+static int wma_decode_subframe(WMA3DecodeContext *s)
 {
     int offset = s->samples_per_frame;
     int subframe_len = s->samples_per_frame;
@@ -1105,7 +1105,7 @@ static int wma_decode_subframe(WMA3Decod
     int total_samples = s->samples_per_frame * s->num_channels;
     int transmit_coeffs = 0;
 
-    bitstreamcounter = get_bits_count(gb);
+    bitstreamcounter = get_bits_count(s->getbit);
 
 
     /** reset channel context and find the next block offset and size
@@ -1177,32 +1177,32 @@ static int wma_decode_subframe(WMA3Decod
     s->subframe_len = subframe_len;
 
     /** skip extended header if any */
-    if(get_bits(gb,1)){
+    if(get_bits(s->getbit,1)){
         int num_fill_bits;
-        if(!(num_fill_bits = get_bits(gb,2))){
-            num_fill_bits = get_bits(gb,4);
-            num_fill_bits = get_bits(gb,num_fill_bits) + 1;
+        if(!(num_fill_bits = get_bits(s->getbit,2))){
+            num_fill_bits = get_bits(s->getbit,4);
+            num_fill_bits = get_bits(s->getbit,num_fill_bits) + 1;
         }
 
         if(num_fill_bits >= 0){
-            skip_bits(gb,num_fill_bits);
+            skip_bits(s->getbit,num_fill_bits);
         }
     }
 
     /** no idea for what the following bit is used */
-    if(get_bits(gb,1)){
+    if(get_bits(s->getbit,1)){
         av_log(s->avctx,AV_LOG_ERROR,"reserved bit set\n");
         return 0;
     }
 
 
-    if(!wma_decode_channel_transform(s,gb))
+    if(!wma_decode_channel_transform(s))
         return 0;
 
 
     for(i=0;i<s->channels_for_cur_subframe;i++){
         int c = s->channel_indexes_for_cur_subframe[i];
-        if((s->channel[c].transmit_coefs = get_bits(gb,1)))
+        if((s->channel[c].transmit_coefs = get_bits(s->getbit,1)))
             transmit_coeffs = 1;
     }
 
@@ -1212,12 +1212,12 @@ static int wma_decode_subframe(WMA3Decod
         int quant;
         int sign = 1;
         int large_quant = 0;
-        if((get_bits(gb,1))){ /** FIXME: might influence how often getvec4 may be called */
+        if((get_bits(s->getbit,1))){ /** FIXME: might influence how often getvec4 may be called */
             av_log(s->avctx,AV_LOG_ERROR,"unsupported quant step coding\n");
             return 0;
         }
         /** decode quantization step */
-        quant = get_bits(gb,6);
+        quant = get_bits(s->getbit,6);
         if(quant & 0x20){
             quant |= 0xFFFFFFC0u;
             sign = -1;
@@ -1226,7 +1226,7 @@ static int wma_decode_subframe(WMA3Decod
         if(quant <= -32 || quant > 30)
             large_quant = 1;
         while(large_quant){
-            quant = get_bits(gb,5);
+            quant = get_bits(s->getbit,5);
             if(quant != 31){
                 s->quant_step += quant * sign;
                 break;
@@ -1244,13 +1244,13 @@ static int wma_decode_subframe(WMA3Decod
         if(s->channels_for_cur_subframe == 1)
             s->channel[s->channel_indexes_for_cur_subframe[0]].quant_step_modifier = 0;
         else{
-            int modifier_len = get_bits(gb,3);
+            int modifier_len = get_bits(s->getbit,3);
             for(i=0;i<s->channels_for_cur_subframe;i++){
                 int c = s->channel_indexes_for_cur_subframe[i];
                 s->channel[c].quant_step_modifier = 0;
-                if(get_bits(gb,1)){
+                if(get_bits(s->getbit,1)){
                     if(modifier_len)
-                        s->channel[c].quant_step_modifier = get_bits(gb,modifier_len) + 1;
+                        s->channel[c].quant_step_modifier = get_bits(s->getbit,modifier_len) + 1;
                     else
                         s->channel[c].quant_step_modifier = 1;
                 }else
@@ -1260,20 +1260,20 @@ static int wma_decode_subframe(WMA3Decod
         }
 
         /** decode scale factors */
-        if(!wma_decode_scale_factors(s,gb))
+        if(!wma_decode_scale_factors(s))
             return 0;
     }
 
-    av_log(s->avctx,AV_LOG_DEBUG,"BITSTREAM: subframe header length was %i\n",get_bits_count(gb) - bitstreamcounter);
+    av_log(s->avctx,AV_LOG_DEBUG,"BITSTREAM: subframe header length was %i\n",get_bits_count(s->getbit) - bitstreamcounter);
 
     /** parse coefficients */
     for(i=0;i<s->channels_for_cur_subframe;i++){
         int c = s->channel_indexes_for_cur_subframe[i];
         if(s->channel[c].transmit_coefs)
-                decode_coeffs(s,gb,c);
+                decode_coeffs(s,c);
     }
 
-    av_log(s->avctx,AV_LOG_DEBUG,"BITSTREAM: subframe length was %i\n",get_bits_count(gb) - bitstreamcounter);
+    av_log(s->avctx,AV_LOG_DEBUG,"BITSTREAM: subframe length was %i\n",get_bits_count(s->getbit) - bitstreamcounter);
 
     if(transmit_coeffs){
         wma_inverse_channel_transform(s);
@@ -1347,6 +1347,8 @@ static int wma_decode_frame(WMA3DecodeCo
     int len = 0;
     int i;
 
+    s->getbit = gb;
+
     /** check for potential output buffer overflow */
     if(s->samples + s->num_channels * s->samples_per_frame > s->samples_end){
         av_log(s->avctx,AV_LOG_ERROR,"not enough space for the output samples\n");
@@ -1364,7 +1366,7 @@ static int wma_decode_frame(WMA3DecodeCo
     av_log(s->avctx,AV_LOG_DEBUG,"decoding frame with length %x\n",len);
 
     /** decode tile information */
-    if(wma_decode_tilehdr(s,gb)){
+    if(wma_decode_tilehdr(s)){
         s->packet_loss = 1;
         return 0;
     }
@@ -1413,7 +1415,7 @@ static int wma_decode_frame(WMA3DecodeCo
 
     /** parse all subframes */
     while(!s->parsed_all_subframes){
-        if(!wma_decode_subframe(s,gb)){
+        if(!wma_decode_subframe(s)){
             s->packet_loss = 1;
             return 0;
         }
@@ -1470,19 +1472,21 @@ static int wma_decode_frame(WMA3DecodeCo
 /**
  *@brief Calculate remaining input buffer length.
  *@param s codec context
+ *@param gb bitstream reader context
  *@return remaining size in bits
  */
-static int remaining_bits(WMA3DecodeContext *s)
+static int remaining_bits(WMA3DecodeContext *s, GetBitContext* gb)
 {
-    return s->buf_bit_size - get_bits_count(&s->gb);
+    return s->buf_bit_size - get_bits_count(gb);
 }
 
 /**
  *@brief Fill the bit reservoir with a partial frame.
  *@param s codec context
+ *@param gb bitstream reader context
  *@param len length of the partial frame
  */
-static void save_bits(WMA3DecodeContext *s,int len)
+static void save_bits(WMA3DecodeContext *s, GetBitContext* gb, int len)
 {
     int buflen = (s->prev_packet_bit_size + len + 8) / 8;
     int bit_offset = s->prev_packet_bit_size % 8;
@@ -1502,19 +1506,19 @@ static void save_bits(WMA3DecodeContext 
         if(len < missing)
             missing = len;
         s->prev_packet_data[pos++] |=
-            get_bits(&s->gb, missing) << (8 - bit_offset - missing);
+            get_bits(gb, missing) << (8 - bit_offset - missing);
         len -= missing;
     }
 
     /** copy full bytes */
     while(len > 7){
-        s->prev_packet_data[pos++] = get_bits(&s->gb,8);
+        s->prev_packet_data[pos++] = get_bits(gb,8);
         len -= 8;
     }
 
     /** copy remaining bits */
     if(len > 0)
-        s->prev_packet_data[pos++] = get_bits(&s->gb,len) << (8 - len);
+        s->prev_packet_data[pos++] = get_bits(gb,len) << (8 - len);
 }
 
 /**
@@ -1530,6 +1534,7 @@ static int wma3_decode_packet(AVCodecCon
                              void *data, int *data_size,
                              const uint8_t *buf, int buf_size)
 {
+    GetBitContext gb;
     WMA3DecodeContext *s = avctx->priv_data;
     int more_frames=1;
     int num_bits_prev_frame;
@@ -1546,13 +1551,13 @@ static int wma3_decode_packet(AVCodecCon
         return 0;
 
     /** parse packet header */
-    init_get_bits(&s->gb, buf, s->buf_bit_size);
-    s->packet_sequence_number = get_bits(&s->gb, 4);
-    s->bit5                   = get_bits1(&s->gb);
-    s->bit6                   = get_bits1(&s->gb);
+    init_get_bits(&gb, buf, s->buf_bit_size);
+    s->packet_sequence_number = get_bits(&gb, 4);
+    s->bit5                   = get_bits1(&gb);
+    s->bit6                   = get_bits1(&gb);
 
     /** get number of bits that need to be added to the previous frame */
-    num_bits_prev_frame = get_bits(&s->gb, s->log2_frame_size);
+    num_bits_prev_frame = get_bits(&gb, s->log2_frame_size);
     av_log(avctx, AV_LOG_DEBUG, "packet[%d]: nbpf %x\n", avctx->frame_number,
                   num_bits_prev_frame);
 
@@ -1566,7 +1571,7 @@ static int wma3_decode_packet(AVCodecCon
     if (num_bits_prev_frame > 0) {
         /** append the previous frame data to the remaining data from the
             previous packet to create a full frame */
-        save_bits(s,num_bits_prev_frame);
+        save_bits(s,&gb,num_bits_prev_frame);
         av_log(avctx, AV_LOG_DEBUG, "accumulated %x bits of frame data\n",
                       s->prev_packet_bit_size);
 
@@ -1586,14 +1591,14 @@ static int wma3_decode_packet(AVCodecCon
     s->prev_packet_bit_size = 0;
     s->packet_loss = 0;
     /** decode the rest of the packet */
-    while(more_frames && remaining_bits(s) > s->log2_frame_size){
-        int frame_size = show_bits(&s->gb, s->log2_frame_size);
+    while(more_frames && remaining_bits(s,&gb) > s->log2_frame_size){
+        int frame_size = show_bits(&gb, s->log2_frame_size);
 
         /** there is enough data for a full frame */
-        if(remaining_bits(s) >= frame_size){
+        if(remaining_bits(s,&gb) >= frame_size){
 
             /** decode the frame */
-            more_frames = wma_decode_frame(s,&s->gb);
+            more_frames = wma_decode_frame(s,&gb);
 
             if(!more_frames){
                 av_log(avctx, AV_LOG_ERROR, "no more frames\n");
@@ -1607,7 +1612,7 @@ static int wma3_decode_packet(AVCodecCon
 
     /** save the rest of the data so that it can be decoded
        with the next packet */
-    save_bits(s,remaining_bits(s));
+    save_bits(s,&gb,remaining_bits(s,&gb));
 
     *data_size = (int8_t *)s->samples - (int8_t *)data;
 



More information about the FFmpeg-soc mailing list