Adding support for rm playback. Only cook codec is supported for now and no seeking.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21695 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Mohamed Tarek 2009-07-06 22:40:45 +00:00
parent 03fe562a95
commit e184ef1027
22 changed files with 967 additions and 327 deletions

View file

@ -22,13 +22,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file libavcodec/bitstream.c
* bitstream api.
*/
#include "bitstream.h"
#ifdef ROCKBOX
#undef DEBUGF
#define DEBUGF(...)
#endif
const uint8_t ff_log2_run[32]={
0, 0, 0, 0, 1, 1, 1, 1,
2, 2, 2, 2, 3, 3, 3, 3,
@ -46,24 +46,6 @@ const uint8_t ff_log2_run[32]={
* and should correctly use static arrays
*/
#if 0
attribute_deprecated av_alloc_size(2)
static void *ff_realloc_static(void *ptr, unsigned int size);
static void *ff_realloc_static(void *ptr, unsigned int size)
{
return av_realloc(ptr, size);
}
void align_put_bits(PutBitContext *s)
{
#ifdef ALT_BITSTREAM_WRITER
put_bits(s,( - s->index) & 7,0);
#else
put_bits(s,s->bit_left & 7,0);
#endif
}
#endif
void ff_put_string(PutBitContext * pbc, const char *s, int put_zero)
{
@ -75,30 +57,6 @@ void ff_put_string(PutBitContext * pbc, const char *s, int put_zero)
put_bits(pbc, 8, 0);
}
#if 0
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
{
const uint16_t *srcw= (const uint16_t*)src;
int words= length>>4;
int bits= length&15;
int i;
if(length==0) return;
if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){
for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(&srcw[i]));
}else{
for(i=0; put_bits_count(pb)&31; i++)
put_bits(pb, 8, src[i]);
flush_put_bits(pb);
memcpy(pbBufPtr(pb), src+i, 2*words-i);
skip_put_bytes(pb, 2*words-i);
}
put_bits(pb, bits, AV_RB16(&srcw[words])>>(16-bits));
}
#endif
/* VLC decoding */
//#define DEBUG_VLC
@ -127,8 +85,7 @@ static int alloc_table(VLC *vlc, int size, int use_static)
vlc->table_size += size;
if (vlc->table_size > vlc->table_allocated) {
if(use_static>1){
printf("init_vlc() used with too little memory : table_size > allocated_memory\n");
abort(); //cant do anything, init_vlc() is used with too little memory
DEBUGF("init_vlc() used with too little memory : table_size > allocated_memory\n");
}
if (!vlc->table)
@ -151,7 +108,7 @@ static int build_table(VLC *vlc, int table_nb_bits,
table_size = 1 << table_nb_bits;
table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC));
#ifdef DEBUG_VLC
printf("new table index=%d size=%d code_prefix=%x n=%d\n",
DEBUGF("new table index=%d size=%d code_prefix=%x n=%d\n",
table_index, table_size, code_prefix, n_prefix);
#endif
if (table_index < 0)
@ -175,15 +132,15 @@ static int build_table(VLC *vlc, int table_nb_bits,
else
GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size);
#if defined(DEBUG_VLC) && 0
printf("i=%d n=%d code=0x%x\n", i, n, code);
DEBUGF("i=%d n=%d code=0x%x\n", i, n, code);
#endif
/* if code matches the prefix, it is in the table */
n -= n_prefix;
if(flags & INIT_VLC_LE)
code_prefix2= code & (n_prefix>=32 ? 0xffffffff : (1 << n_prefix)-1);
code_prefix2= code & (n_prefix>=32 ? (int)0xffffffff : (1 << n_prefix)-1);
else
code_prefix2= code >> n;
if (n > 0 && code_prefix2 == code_prefix) {
if (n > 0 && code_prefix2 == (int)code_prefix) {
if (n <= table_nb_bits) {
/* no need to add another table */
j = (code << (table_nb_bits - n)) & (table_size - 1);
@ -192,11 +149,11 @@ static int build_table(VLC *vlc, int table_nb_bits,
if(flags & INIT_VLC_LE)
j = (code >> n_prefix) + (k<<n);
#ifdef DEBUG_VLC
printf("%4x: code=%d n=%d\n",
DEBUGF("%4x: code=%d n=%d\n",
j, i, n);
#endif
if (table[j][1] /*bits*/ != 0) {
printf("incorrect codes\n");
DEBUGF("incorrect codes\n");
return -1;
}
table[j][1] = n; //bits
@ -207,7 +164,7 @@ static int build_table(VLC *vlc, int table_nb_bits,
n -= table_nb_bits;
j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1);
#ifdef DEBUG_VLC
printf("%4x: n=%d (subtable)\n",
DEBUGF("%4x: n=%d (subtable)\n",
j, n);
#endif
/* compute table size */
@ -282,7 +239,7 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
if(vlc->table_size && vlc->table_size == vlc->table_allocated){
return 0;
}else if(vlc->table_size){
abort(); // fatal error, we are called on a partially initialized table
return -1; // fatal error, we are called on a partially initialized table
}
}else if(!(flags & INIT_VLC_USE_STATIC)) {
vlc->table = NULL;
@ -296,7 +253,7 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
}
#ifdef DEBUG_VLC
printf("build table nb_codes=%d\n", nb_codes);
DEBUGF("build table nb_codes=%d\n", nb_codes);
#endif
if (build_table(vlc, nb_bits, nb_codes,
@ -304,20 +261,16 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
codes, codes_wrap, codes_size,
symbols, symbols_wrap, symbols_size,
0, 0, flags) < 0) {
free(&vlc->table);
//free(&vlc->table);
return -1;
}
/* Changed the following condition to be true if table_size > table_allocated. *
* This would be more sensible for static tables since we want warnings for *
* memory shortages only. */
#ifdef TEST
if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size > vlc->table_allocated)
printf("needed %d had %d\n", vlc->table_size, vlc->table_allocated);
DEBUGF("needed %d had %d\n", vlc->table_size, vlc->table_allocated);
#endif
return 0;
}
void free_vlc(VLC *vlc)
{
free(&vlc->table);
}