comparison mpegaudiodec.c @ 520:19a5e2a81e1a libavcodec

new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler) minor optimizations to get_vlc
author michaelni
date Tue, 09 Jul 2002 10:35:10 +0000
parents 1e23eae32087
children d8d23aae4ac3
comparison
equal deleted inserted replaced
519:55b4e2248a45 520:19a5e2a81e1a
1455 static void seek_to_maindata(MPADecodeContext *s, long backstep) 1455 static void seek_to_maindata(MPADecodeContext *s, long backstep)
1456 { 1456 {
1457 UINT8 *ptr; 1457 UINT8 *ptr;
1458 1458
1459 /* compute current position in stream */ 1459 /* compute current position in stream */
1460 #ifdef ALT_BITSTREAM_READER 1460 ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3);
1461 ptr = s->gb.buffer + (s->gb.index>>3); 1461
1462 #else
1463 ptr = s->gb.buf_ptr - (s->gb.bit_cnt >> 3);
1464 #endif
1465 /* copy old data before current one */ 1462 /* copy old data before current one */
1466 ptr -= backstep; 1463 ptr -= backstep;
1467 memcpy(ptr, s->inbuf1[s->inbuf_index ^ 1] + 1464 memcpy(ptr, s->inbuf1[s->inbuf_index ^ 1] +
1468 BACKSTEP_SIZE + s->old_frame_size - backstep, backstep); 1465 BACKSTEP_SIZE + s->old_frame_size - backstep, backstep);
1469 /* init get bits again */ 1466 /* init get bits again */
1545 static int huffman_decode(MPADecodeContext *s, GranuleDef *g, 1542 static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
1546 INT16 *exponents, int end_pos) 1543 INT16 *exponents, int end_pos)
1547 { 1544 {
1548 int s_index; 1545 int s_index;
1549 int linbits, code, x, y, l, v, i, j, k, pos; 1546 int linbits, code, x, y, l, v, i, j, k, pos;
1550 UINT8 *last_buf_ptr; 1547 GetBitContext last_gb;
1551 UINT32 last_bit_buf;
1552 int last_bit_cnt;
1553 VLC *vlc; 1548 VLC *vlc;
1554 UINT8 *code_table; 1549 UINT8 *code_table;
1555 1550
1556 /* low frequencies (called big values) */ 1551 /* low frequencies (called big values) */
1557 s_index = 0; 1552 s_index = 0;
1606 } 1601 }
1607 } 1602 }
1608 1603
1609 /* high frequencies */ 1604 /* high frequencies */
1610 vlc = &huff_quad_vlc[g->count1table_select]; 1605 vlc = &huff_quad_vlc[g->count1table_select];
1611 last_buf_ptr = NULL; 1606 last_gb.buffer = NULL;
1612 last_bit_buf = 0;
1613 last_bit_cnt = 0;
1614 while (s_index <= 572) { 1607 while (s_index <= 572) {
1615 pos = get_bits_count(&s->gb); 1608 pos = get_bits_count(&s->gb);
1616 if (pos >= end_pos) { 1609 if (pos >= end_pos) {
1617 if (pos > end_pos && last_buf_ptr != NULL) { 1610 if (pos > end_pos && last_gb.buffer != NULL) {
1618 /* some encoders generate an incorrect size for this 1611 /* some encoders generate an incorrect size for this
1619 part. We must go back into the data */ 1612 part. We must go back into the data */
1620 s_index -= 4; 1613 s_index -= 4;
1621 #ifdef ALT_BITSTREAM_READER 1614 s->gb = last_gb;
1622 s->gb.buffer = last_buf_ptr;
1623 s->gb.index = last_bit_cnt;
1624 #else
1625 s->gb.buf_ptr = last_buf_ptr;
1626 s->gb.bit_buf = last_bit_buf;
1627 s->gb.bit_cnt = last_bit_cnt;
1628 #endif
1629 } 1615 }
1630 break; 1616 break;
1631 } 1617 }
1632 #ifdef ALT_BITSTREAM_READER 1618 last_gb= s->gb;
1633 last_buf_ptr = s->gb.buffer; 1619
1634 last_bit_cnt = s->gb.index;
1635 #else
1636 last_buf_ptr = s->gb.buf_ptr;
1637 last_bit_buf = s->gb.bit_buf;
1638 last_bit_cnt = s->gb.bit_cnt;
1639 #endif
1640
1641 code = get_vlc(&s->gb, vlc); 1620 code = get_vlc(&s->gb, vlc);
1642 dprintf("t=%d code=%d\n", g->count1table_select, code); 1621 dprintf("t=%d code=%d\n", g->count1table_select, code);
1643 if (code < 0) 1622 if (code < 0)
1644 return -1; 1623 return -1;
1645 for(i=0;i<4;i++) { 1624 for(i=0;i<4;i++) {