Index: apps/metadata/metadata_parsers.h =================================================================== --- apps/metadata/metadata_parsers.h (revision 21477) +++ apps/metadata/metadata_parsers.h (working copy) @@ -39,3 +39,4 @@ bool get_a52_metadata(int fd, struct mp3entry* id3); bool get_asf_metadata(int fd, struct mp3entry* id3); bool get_asap_metadata(int fd, struct mp3entry* id3); +bool get_rm_metadata(int fd, struct mp3entry* id3); Index: apps/metadata.c =================================================================== --- apps/metadata.c (revision 21477) +++ apps/metadata.c (working copy) @@ -115,6 +115,9 @@ /* Amiga SAP File */ [AFMT_SAP] = AFMT_ENTRY("SAP", "asap", NULL, "sap\0" ), + /* Cook in RM/RA */ + [AFMT_COOK] = + AFMT_ENTRY("Cook", "cook", NULL, "rm\0ra\0" ), #endif }; @@ -372,6 +375,14 @@ id3->filesize = filesize(fd); id3->genre_string = id3_get_num_genre(36); break; + + case AFMT_COOK: + if (!get_rm_metadata(fd, id3)) + { + DEBUGF("get_rm_metadata error\n"); + return false; + } + break; #endif /* CONFIG_CODEC == SWCODEC */ Index: apps/metadata.h =================================================================== --- apps/metadata.h (revision 21477) +++ apps/metadata.h (working copy) @@ -61,6 +61,7 @@ AFMT_WMA, /* WMAV1/V2 in ASF */ AFMT_MOD, /* Amiga MOD File Format */ AFMT_SAP, /* Amiga 8Bit SAP Format */ + AFMT_COOK, /* Cook in RM/RA */ #endif /* add new formats at any index above this line to have a sensible order - Index: apps/SOURCES =================================================================== --- apps/SOURCES (revision 21477) +++ apps/SOURCES (working copy) @@ -166,6 +166,7 @@ metadata/wavpack.c metadata/a52.c metadata/asap.c +metadata/rm.c #endif #ifdef HAVE_TAGCACHE tagcache.c Index: apps/filetypes.c =================================================================== --- apps/filetypes.c (revision 21477) +++ apps/filetypes.c (working copy) @@ -83,6 +83,8 @@ { "ape", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, { "mac", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, { "sap" ,FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, + { "rm", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, + { "ra", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, #endif { "m3u", FILE_ATTR_M3U, Icon_Playlist, LANG_PLAYLIST }, { "m3u8",FILE_ATTR_M3U, Icon_Playlist, LANG_PLAYLIST }, Index: apps/codecs/libcook/bitstream.h =================================================================== --- apps/codecs/libcook/bitstream.h (revision 21477) +++ apps/codecs/libcook/bitstream.h (working copy) @@ -23,14 +23,15 @@ * bitstream api header. */ -#ifndef AVCODEC_BITSTREAM_H -#define AVCODEC_BITSTREAM_H +#ifndef BITSTREAM_H +#define BITSTREAM_H -#include -#include -#include -#include -#include +#define av_always_inline inline +#define attribute_deprecated + +#include +#include "ffmpeg_config.h" +//#include #include "bswap.h" /* The following 2 defines are taken from libavutil/intreadwrite.h */ @@ -51,7 +52,7 @@ //#define ALT_BITSTREAM_WRITER //#define ALIGNED_BITSTREAM_WRITER #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) -# if ARCH_ARM +# if defined(ARCH_ARM) # define A32_BITSTREAM_READER # else # define ALT_BITSTREAM_READER @@ -62,7 +63,7 @@ extern const uint8_t ff_reverse[256]; -#if ARCH_X86 +#if defined(ARCH_X86) // avoid +32 for shift optimization (gcc should do that ...) static inline int32_t NEG_SSR32( int32_t a, int8_t s){ __asm__ ("sarl %1, %0\n\t" @@ -197,18 +198,18 @@ unsigned int bit_buf; int bit_left; - // printf("put_bits=%d %x\n", n, value); - assert(n == 32 || value < (1U << n)); + // DEBUGF("put_bits=%d %x\n", n, value); + //assert(n == 32 || value < (1U << n)); bit_buf = s->bit_buf; bit_left = s->bit_left; - // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf); + // DEBUGF("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf); /* XXX: optimize */ #ifdef BITSTREAM_WRITER_LE bit_buf |= value << (32 - bit_left); if (n >= bit_left) { -#if !HAVE_FAST_UNALIGNED +#if !defined(HAVE_FAST_UNALIGNED) if (3 & (intptr_t) s->buf_ptr) { AV_WL32(s->buf_ptr, bit_buf); } else @@ -226,13 +227,13 @@ } else { bit_buf<<=bit_left; bit_buf |= value >> (n - bit_left); -#if !HAVE_FAST_UNALIGNED +#if !defined(HAVE_FAST_UNALIGNED) if (3 & (intptr_t) s->buf_ptr) { AV_WB32(s->buf_ptr, bit_buf); } else #endif *(uint32_t *)s->buf_ptr = be2me_32(bit_buf); - //printf("bitbuf = %08x\n", bit_buf); + //DEBUGF("bitbuf = %08x\n", bit_buf); s->buf_ptr+=4; bit_left+=32 - n; bit_buf = value; @@ -275,7 +276,7 @@ ptr[0] |= be2me_32(value>>(index&31)); ptr[1] = be2me_32(value<<(32-(index&31))); -//if(n>24) printf("%d %d\n", n, value); +//if(n>24) DEBUGF("%d %d\n", n, value); index+= n; s->index= index; # endif @@ -303,7 +304,7 @@ ptr[0] |= be2me_32(value<<(32-n-(index&7) )); ptr[1] = 0; -//if(n>24) printf("%d %d\n", n, value); +//if(n>24) DEBUGF("%d %d\n", n, value); index+= n; s->index= index; # endif @@ -313,7 +314,7 @@ static inline void put_sbits(PutBitContext *pb, int bits, int32_t val) { - assert(bits >= 0 && bits <= 31); + //assert(bits >= 0 && bits <= 31); put_bits(pb, bits, val & ((1<index += n<<3; #else - assert(s->bit_left==32); + //assert(s->bit_left==32); s->buf_ptr += n; #endif } @@ -739,9 +740,9 @@ static inline int check_marker(GetBitContext *s, const char *msg) { int bit= get_bits1(s); - if(!bit) - printf("Marker bit missing %s\n", msg); - + if(!bit){ + DEBUGF("Marker bit missing %s\n", msg); + } return bit; } @@ -901,17 +902,17 @@ int i; for(i=n-1; i>=0; i--){ - printf("%d", (bits>>i)&1); + DEBUGF("%d", (bits>>i)&1); } for(i=n; i<24; i++) - printf(" "); + DEBUGF(" "); } static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ int r= get_bits(s, n); print_bin(r, n); - printf("%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line); + DEBUGF("%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line); return r; } static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){ @@ -923,7 +924,7 @@ print_bin(bits2, len); - printf("%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); + DEBUGF("%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); return r; } static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ @@ -931,7 +932,7 @@ int r= get_xbits(s, n); print_bin(show, n); - printf("%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line); + DEBUGF("%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line); return r; } @@ -941,10 +942,10 @@ #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) -#define tprintf(p, ...) printf +#define tDEBUGF(p, ...) DEBUGF #else //TRACE -#define tprintf(p, ...) {} +#define tDEBUGF(p, ...) {} #endif static inline int decode012(GetBitContext *gb){ Index: apps/codecs/libcook/cook.h =================================================================== --- apps/codecs/libcook/cook.h (revision 21477) +++ apps/codecs/libcook/cook.h (working copy) @@ -22,7 +22,7 @@ #ifndef _COOK_H #define _COOK_H -#include +#include #include "bitstream.h" #include "../librm/rm.h" #include "cookdata_fixpoint.h" Index: apps/codecs/libcook/cook_fixpoint.h =================================================================== --- apps/codecs/libcook/cook_fixpoint.h (revision 21477) +++ apps/codecs/libcook/cook_fixpoint.h (working copy) @@ -54,29 +54,6 @@ }; /** - * Initialise fixed point implementation. - * Nothing to do for fixed point. - * - * @param q pointer to the COOKContext - */ -static inline int init_cook_math(COOKContext *q) -{ - return 0; -} - -/** - * Free resources used by floating point implementation. - * Nothing to do for fixed point. - * - * @param q pointer to the COOKContext - */ -static inline void free_cook_math(COOKContext *q) -{ - return; -} - - -/** * Fixed point multiply by power of two. * * @param x fix point value @@ -167,7 +144,7 @@ } } - +#ifdef TEST /** * The modulated lapped transform, this takes transform coefficients * and transforms them into timedomain samples. @@ -205,8 +182,36 @@ q->mono_mdct_output[n + i] = fixp_mult_su(tmp, sincos_lookup[j]); } while (++i < n); } +#else +#include +static inline void imlt_math(COOKContext *q, FIXP *in) +{ + const int n = q->samples_per_channel; + const int step = 4 << (10 - av_log2(n)); + int i = 0, j = step>>1; + mdct_backward(2 * n, in, q->mono_mdct_output); + + do { + FIXP tmp = q->mono_mdct_output[i]; + + q->mono_mdct_output[i] = + fixp_mult_su(-q->mono_mdct_output[n + i], sincos_lookup[j]); + q->mono_mdct_output[n + i] = fixp_mult_su(tmp, sincos_lookup[j+1]); + j += step; + } while (++i < n/2); + do { + FIXP tmp = q->mono_mdct_output[i]; + + j -= step; + q->mono_mdct_output[i] = + fixp_mult_su(-q->mono_mdct_output[n + i], sincos_lookup[j+1]); + q->mono_mdct_output[n + i] = fixp_mult_su(tmp, sincos_lookup[j]); + } while (++i < n); +} +#endif + /** * Perform buffer overlapping. * Index: apps/codecs/libcook/bswap.h =================================================================== --- apps/codecs/libcook/bswap.h (revision 21477) +++ apps/codecs/libcook/bswap.h (working copy) @@ -1,85 +1,136 @@ -/* - * copyright (c) 2006 Michael Niedermayer - * - * This file is part of FFmpeg. - * - * FFmpeg 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, - * 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 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - /** - * @file libavutil/bswap.h - * byte swapping routines + * @file bswap.h + * byte swap. */ -#ifndef AVUTIL_BSWAP_H -#define AVUTIL_BSWAP_H +#ifndef __BSWAP_H__ +#define __BSWAP_H__ -#include -//#include "ffmpeg_config.h" -//#include "common.h" +#ifdef HAVE_BYTESWAP_H +#include +#else -#if ARCH_ARM -# include "arm/bswap.h" -#elif ARCH_BFIN -# include "bfin/bswap.h" -#elif ARCH_SH4 -# include "sh4/bswap.h" -#elif ARCH_X86 -# include "x86/bswap.h" -#endif +#ifdef ROCKBOX +#include "codecs.h" -#ifndef bswap_16 -static inline uint16_t bswap_16(uint16_t x) +/* rockbox' optimised inline functions */ +#define bswap_16(x) swap16(x) +#define bswap_32(x) swap32(x) + +static inline uint64_t ByteSwap64(uint64_t x) { - x= (x>>8) | (x<<8); - return x; + union { + uint64_t ll; + struct { + uint32_t l,h; + } l; + } r; + r.l.l = bswap_32 (x); + r.l.h = bswap_32 (x>>32); + return r.ll; } -#endif +#define bswap_64(x) ByteSwap64(x) -#ifndef bswap_32 -static inline uint32_t bswap_32(uint32_t x) +#elif defined(ARCH_X86) +static inline unsigned short ByteSwap16(unsigned short x) { - x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); - x= (x>>16) | (x<<16); + __asm("xchgb %b0,%h0" : + "=q" (x) : + "0" (x)); return x; } +#define bswap_16(x) ByteSwap16(x) + +static inline unsigned int ByteSwap32(unsigned int x) +{ +#if __CPU__ > 386 + __asm("bswap %0": + "=r" (x) : +#else + __asm("xchgb %b0,%h0\n" + " rorl $16,%0\n" + " xchgb %b0,%h0": + "=q" (x) : #endif + "0" (x)); + return x; +} +#define bswap_32(x) ByteSwap32(x) -#ifndef bswap_64 -static inline uint64_t bswap_64(uint64_t x) +static inline unsigned long long int ByteSwap64(unsigned long long int x) { -#if 0 - x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); - x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); - return (x>>32) | (x<<32); + register union { __extension__ uint64_t __ll; + uint32_t __l[2]; } __x; + asm("xchgl %0,%1": + "=r"(__x.__l[0]),"=r"(__x.__l[1]): + "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); + return __x.__ll; +} +#define bswap_64(x) ByteSwap64(x) + +#elif defined(ARCH_SH4) + +static inline uint16_t ByteSwap16(uint16_t x) { + __asm__("swap.b %0,%0":"=r"(x):"0"(x)); + return x; +} + +static inline uint32_t ByteSwap32(uint32_t x) { + __asm__( + "swap.b %0,%0\n" + "swap.w %0,%0\n" + "swap.b %0,%0\n" + :"=r"(x):"0"(x)); + return x; +} + +#define bswap_16(x) ByteSwap16(x) +#define bswap_32(x) ByteSwap32(x) + +static inline uint64_t ByteSwap64(uint64_t x) +{ + union { + uint64_t ll; + struct { + uint32_t l,h; + } l; + } r; + r.l.l = bswap_32 (x); + r.l.h = bswap_32 (x>>32); + return r.ll; +} +#define bswap_64(x) ByteSwap64(x) + #else - union { + +#define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8) + + +// code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc. +#define bswap_32(x) \ + ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ + (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) + +static inline uint64_t ByteSwap64(uint64_t x) +{ + union { uint64_t ll; - uint32_t l[2]; + uint32_t l[2]; } w, r; w.ll = x; r.l[0] = bswap_32 (w.l[1]); r.l[1] = bswap_32 (w.l[0]); return r.ll; -#endif } -#endif +#define bswap_64(x) ByteSwap64(x) -// be2me ... big-endian to machine-endian -// le2me ... little-endian to machine-endian +#endif /* !ARCH_X86 */ +#endif /* !HAVE_BYTESWAP_H */ + +// be2me ... BigEndian to MachineEndian +// le2me ... LittleEndian to MachineEndian + #ifdef WORDS_BIGENDIAN #define be2me_16(x) (x) #define be2me_32(x) (x) @@ -96,4 +147,4 @@ #define le2me_64(x) (x) #endif -#endif /* AVUTIL_BSWAP_H */ +#endif /* __BSWAP_H__ */ Index: apps/codecs/libcook/Makefile.test =================================================================== --- apps/codecs/libcook/Makefile.test (revision 21477) +++ apps/codecs/libcook/Makefile.test (working copy) @@ -1,4 +1,4 @@ -CFLAGS = -Wall -O3 +CFLAGS = -Wall -O3 -DTEST OBJS = main.o bitstream.o cook.o ../librm/rm.o cooktest: $(OBJS) gcc -o cooktest $(OBJS) Index: apps/codecs/libcook/cookdata_fixpoint.h =================================================================== --- apps/codecs/libcook/cookdata_fixpoint.h (revision 21477) +++ apps/codecs/libcook/cookdata_fixpoint.h (working copy) @@ -26,7 +26,7 @@ * fixed point data types and constants */ -#include +#include typedef int32_t FIXP; /* Fixed point variable type */ typedef uint16_t FIXPU; /* Fixed point fraction 0<=x<1 */ @@ -39,11 +39,11 @@ typedef struct { } realvars_t; - +#ifdef TEST #define cPI1_8 0xec83 /* 1pi/8 2^16 */ #define cPI2_8 0xb505 /* 2pi/8 2^16 */ #define cPI3_8 0x61f8 /* 3pi/8 2^16 */ - +#endif static const FIXPU sincos_lookup[2050] = { /* x_i = 2^16 sin(i 2pi/8192), 2^16 cos(i 2pi/8192); i=0..1024 */ 0x0000, 0xffff, 0x0032, 0xffff, 0x0065, 0xffff, 0x0097, 0xffff, Index: apps/codecs/libcook/bitstream.c =================================================================== --- apps/codecs/libcook/bitstream.c (revision 21477) +++ apps/codecs/libcook/bitstream.c (working copy) @@ -27,8 +27,10 @@ * bitstream api. */ +#include #include "bitstream.h" + const uint8_t ff_log2_run[32]={ 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, @@ -127,8 +129,8 @@ 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"); + //abort(); //cant do anything, init_vlc() is used with too little memory } if (!vlc->table) @@ -151,7 +153,7 @@ 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,7 +177,7 @@ 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; @@ -192,11 +194,11 @@ if(flags & INIT_VLC_LE) j = (code >> n_prefix) + (k<> ((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 +284,7 @@ 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 + //abort(); // fatal error, we are called on a partially initialized table } }else if(!(flags & INIT_VLC_USE_STATIC)) { vlc->table = NULL; @@ -296,7 +298,7 @@ } #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, @@ -310,8 +312,9 @@ /* 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. */ - 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); + if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size > vlc->table_allocated){ + DEBUGF("needed %d had %d\n", vlc->table_size, vlc->table_allocated); + } return 0; } Index: apps/codecs/libcook/cook.c =================================================================== --- apps/codecs/libcook/cook.c (revision 21477) +++ apps/codecs/libcook/cook.c (working copy) @@ -42,12 +42,15 @@ * available. */ -#include -#include -#include -#include -#include +#include +#include +//#include +//#include +//#include +//#include +//#include + #include "cook.h" #include "cookdata.h" @@ -61,15 +64,15 @@ #define MAX_SUBPACKETS 5 //#define COOKDEBUG #if 0 -#define DEBUGF(message,args ...) printf +#define DEBUGF printf #else -#define DEBUGF(...) +//#define DEBUGF(...) #endif /** * Random bit stream generator. */ -static int inline cook_random(COOKContext *q) +static inline int cook_random(COOKContext *q) { q->random_state = q->random_state * 214013 + 2531011; /* typical RNG numbers */ @@ -200,7 +203,7 @@ i = 0; while (n--) { int index = get_bits(gb, 3); - int gain = get_bits1(gb) ? get_bits(gb, 4) - 7 : -1; + int gain = get_bits1(gb) ? (int)get_bits(gb, 4) - 7 : -1; while (i <= index) gaininfo[i++] = gain; } @@ -789,7 +792,7 @@ return -1; - if(q->block_align >= UINT_MAX/2) + if(rmctx->block_align >= UINT16_MAX/2) return -1; q->gains1.now = q->gain_1; Index: apps/codecs/codecs.make =================================================================== --- apps/codecs/codecs.make (revision 21477) +++ apps/codecs/codecs.make (working copy) @@ -33,6 +33,8 @@ include $(APPSDIR)/codecs/libtremor/libtremor.make include $(APPSDIR)/codecs/libwavpack/libwavpack.make include $(APPSDIR)/codecs/libwma/libwma.make +include $(APPSDIR)/codecs/libcook/libcook.make +include $(APPSDIR)/codecs/librm/librm.make # compile flags for codecs CODECFLAGS = $(CFLAGS) -I$(APPSDIR)/codecs -I$(APPSDIR)/codecs/lib \ @@ -47,7 +49,7 @@ CODECLIBS := $(DEMACLIB) $(A52LIB) $(ALACLIB) $(ASAPLIB) \ $(FAADLIB) $(FFMPEGFLACLIB) $(M4ALIB) $(MADLIB) $(MUSEPACKLIB) \ - $(SPCLIB) $(SPEEXLIB) $(TREMORLIB) $(WAVPACKLIB) $(WMALIB) \ + $(SPCLIB) $(SPEEXLIB) $(TREMORLIB) $(WAVPACKLIB) $(WMALIB) $(COOKLIB) $(RMLIB)\ $(CODECLIB) $(CODECS): $(CODEC_CRT0) $(CODECLINK_LDS) @@ -73,6 +75,7 @@ $(CODECDIR)/wma.codec : $(CODECDIR)/libwma.a $(CODECDIR)/wavpack_enc.codec: $(CODECDIR)/libwavpack.a $(CODECDIR)/asap.codec : $(CODECDIR)/libasap.a +$(CODECDIR)/cook.codec : $(CODECDIR)/libcook.a $(CODECS): $(CODECLIB) # this must be last in codec dependency list Index: apps/codecs/SOURCES =================================================================== --- apps/codecs/SOURCES (revision 21477) +++ apps/codecs/SOURCES (working copy) @@ -22,6 +22,7 @@ aiff.c speex.c adx.c +cook.c #if defined(HAVE_RECORDING) && !defined(SIMULATOR) /* encoders */ aiff_enc.c Index: apps/codecs/librm/rm.c =================================================================== --- apps/codecs/librm/rm.c (revision 21477) +++ apps/codecs/librm/rm.c (working copy) @@ -19,13 +19,8 @@ * KIND, either express or implied. * ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include +//#include +//#include #include "rm.h" @@ -52,7 +47,26 @@ { return (uint32_t)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]); } +void advance_buffer(uint8_t **buf, int val) +{ + *buf += val; +} +#ifdef TEST +#include +#include +#include +int filesize(int fd) +{ + struct stat buf; + + if (fstat(fd,&buf) == -1) { + return -1; + } else { + return (int)buf.st_size; + } +} + static int read_uint8(int fd, uint8_t* buf) { unsigned char tmp[1]; @@ -83,22 +97,8 @@ return res; } -off_t filesize(int fd) -{ - struct stat buf; - if (fstat(fd,&buf) == -1) { - return -1; - } else { - return buf.st_size; - } -} -void advance_buffer(uint8_t **buf, int val) -{ - *buf += val; -} - int read_cook_extradata(int fd, RMContext *rmctx) { read_uint32be(fd, &rmctx->cook_version); read_uint16be(fd, &rmctx->samples_pf_pc); @@ -113,12 +113,12 @@ void print_cook_extradata(RMContext *rmctx) { - printf(" cook_version = 0x%08x\n", rmctx->cook_version); - printf(" samples_per_frame_per_channel = %d\n", rmctx->samples_pf_pc); - printf(" number_of_subbands_in_freq_domain = %d\n", rmctx->nb_subbands); + DEBUGF(" cook_version = 0x%08x\n", rmctx->cook_version); + DEBUGF(" samples_per_frame_per_channel = %d\n", rmctx->samples_pf_pc); + DEBUGF(" number_of_subbands_in_freq_domain = %d\n", rmctx->nb_subbands); if(rmctx->extradata_size == 16) { - printf(" joint_stereo_subband_start = %d\n",rmctx->js_subband_start); - printf(" joint_stereo_vlc_bits = %d\n", rmctx->js_vlc_bits); + DEBUGF(" joint_stereo_subband_start = %d\n",rmctx->js_subband_start); + DEBUGF(" joint_stereo_vlc_bits = %d\n", rmctx->js_vlc_bits); } } @@ -196,7 +196,7 @@ read_uint32be(fd, &version); skipped += 4; - printf(" version=0x%04x\n",((version >> 16) & 0xff)); + DEBUGF(" version=0x%04x\n",((version >> 16) & 0xff)); if (((version >> 16) & 0xff) == 3) { /* Very old version */ } else { @@ -205,7 +205,7 @@ read_uint32be(fd, &header_size); skipped += 4; /* obj.size will be filled with an unknown value, replaced with header_size */ - printf(" Object: %s, size: %d bytes, version: 0x%04x\n",fourcc2str(obj.fourcc),header_size,obj.version); + DEBUGF(" Object: %s, size: %d bytes, version: 0x%04x\n",fourcc2str(obj.fourcc),header_size,obj.version); read_uint16be(fd, &flavor); read_uint32be(fd, &coded_framesize); @@ -253,20 +253,22 @@ read_uint32be(fd, &rmctx->extradata_size); skipped += 4; - if(!strncmp(fourcc2str(fourcc),"cook",4)) + if(!strncmp(fourcc2str(fourcc),"cook",4)){ skipped += read_cook_extradata(fd, rmctx); + rmctx->codec_type = cook; + } - printf(" flavor = %d\n",flavor); - printf(" coded_frame_size = %d\n",coded_framesize); - printf(" sub_packet_h = %d\n",rmctx->sub_packet_h); - printf(" frame_size = %d\n",rmctx->block_align); - printf(" sub_packet_size = %d\n",rmctx->sub_packet_size); - printf(" sample_rate= %d\n",rmctx->sample_rate); - printf(" channels= %d\n",rmctx->nb_channels); - printf(" fourcc = %s\n",fourcc2str(fourcc)); - printf(" codec_extra_data_length = %d\n",rmctx->extradata_size); - printf(" codec_extradata :\n"); + DEBUGF(" flavor = %d\n",flavor); + DEBUGF(" coded_frame_size = %d\n",coded_framesize); + DEBUGF(" sub_packet_h = %d\n",rmctx->sub_packet_h); + DEBUGF(" frame_size = %d\n",rmctx->block_align); + DEBUGF(" sub_packet_size = %d\n",rmctx->sub_packet_size); + DEBUGF(" sample_rate= %d\n",rmctx->sample_rate); + DEBUGF(" channels= %d\n",rmctx->nb_channels); + DEBUGF(" fourcc = %s\n",fourcc2str(fourcc)); + DEBUGF(" codec_extra_data_length = %d\n",rmctx->extradata_size); + DEBUGF(" codec_extradata :\n"); print_cook_extradata(rmctx); } @@ -290,8 +292,8 @@ uint32_t max_packet_size; uint32_t avg_packet_size; uint32_t packet_count; + uint32_t preroll; uint32_t duration; - uint32_t preroll; uint32_t index_offset; uint16_t num_streams; uint16_t flags = 0; @@ -303,11 +305,6 @@ uint32_t codec_data_size; uint32_t v; - char title[256]; - char author[256]; - char copyright[256]; - char comment[256]; - uint32_t next_data_off; uint8_t header_end; @@ -327,18 +324,18 @@ read_uint32be(fd, &unknown1); read_uint32be(fd, &unknown2); - printf("Object: %s, size: %d bytes, version: 0x%04x, pos: %d\n",fourcc2str(obj.fourcc),(int)obj.size,obj.version,(int)curpos); - printf(" unknown1=%d (0x%08x)\n",unknown1,unknown1); - printf(" unknown2=%d (0x%08x)\n",unknown2,unknown2); + DEBUGF("Object: %s, size: %d bytes, version: 0x%04x, pos: %d\n",fourcc2str(obj.fourcc),(int)obj.size,obj.version,(int)curpos); + DEBUGF(" unknown1=%d (0x%08x)\n",unknown1,unknown1); + DEBUGF(" unknown2=%d (0x%08x)\n",unknown2,unknown2); res = real_read_object_header(fd, &obj); header_end = 0; while(res) { - printf("Object: %s, size: %d bytes, version: 0x%04x, pos: %d\n",fourcc2str(obj.fourcc),(int)obj.size,obj.version,(int)curpos); + DEBUGF("Object: %s, size: %d bytes, version: 0x%04x, pos: %d\n",fourcc2str(obj.fourcc),(int)obj.size,obj.version,(int)curpos); skipped = 10; - if(obj.fourcc == FOURCC('I','N','D','X')) - break; + if(obj.fourcc == FOURCC('I','N','D','X')) + break; switch (obj.fourcc) { case FOURCC('P','R','O','P'): /* File properties */ @@ -347,7 +344,7 @@ read_uint32be(fd, &max_packet_size); read_uint32be(fd, &avg_packet_size); read_uint32be(fd, &packet_count); - read_uint32be(fd, &duration); + read_uint32be(fd, &rmctx->duration); read_uint32be(fd, &preroll); read_uint32be(fd, &index_offset); read_uint32be(fd, &rmctx->data_offset); @@ -355,30 +352,30 @@ read_uint16be(fd, &rmctx->flags); skipped += 40; - printf(" max_bitrate = %d\n",max_bitrate); - printf(" avg_bitrate = %d\n",avg_bitrate); - printf(" max_packet_size = %d\n",max_packet_size); - printf(" avg_packet_size = %d\n",avg_packet_size); - printf(" packet_count = %d\n",packet_count); - printf(" duration = %d\n",duration); - printf(" preroll = %d\n",preroll); - printf(" index_offset = %d\n",index_offset); - printf(" data_offset = %d\n",rmctx->data_offset); - printf(" num_streams = %d\n",num_streams); - printf(" flags=0x%04x\n",flags); + DEBUGF(" max_bitrate = %d\n",max_bitrate); + DEBUGF(" avg_bitrate = %d\n",avg_bitrate); + DEBUGF(" max_packet_size = %d\n",max_packet_size); + DEBUGF(" avg_packet_size = %d\n",avg_packet_size); + DEBUGF(" packet_count = %d\n",packet_count); + DEBUGF(" duration = %d\n",rmctx->duration); + DEBUGF(" preroll = %d\n",preroll); + DEBUGF(" index_offset = %d\n",index_offset); + DEBUGF(" data_offset = %d\n",rmctx->data_offset); + DEBUGF(" num_streams = %d\n",num_streams); + DEBUGF(" flags=0x%04x\n",flags); break; case FOURCC('C','O','N','T'): /* Four strings - Title, Author, Copyright, Comment */ - skipped += read_str(fd,title); - skipped += read_str(fd,author); - skipped += read_str(fd,copyright); - skipped += read_str(fd,comment); + skipped += read_str(fd,rmctx->title); + skipped += read_str(fd,rmctx->author); + skipped += read_str(fd,rmctx->copyright); + skipped += read_str(fd,rmctx->comment); - printf(" title=\"%s\"\n",title); - printf(" author=\"%s\"\n",author); - printf(" copyright=\"%s\"\n",copyright); - printf(" comment=\"%s\"\n",comment); + DEBUGF(" title=\"%s\"\n",rmctx->title); + DEBUGF(" author=\"%s\"\n",rmctx->author); + DEBUGF(" copyright=\"%s\"\n",rmctx->copyright); + DEBUGF(" comment=\"%s\"\n",rmctx->comment); break; case FOURCC('M','D','P','R'): /* Media properties */ @@ -406,18 +403,18 @@ read_uint32be(fd,&v); skipped += 4; - printf(" stream_id = 0x%04x\n",stream_id); - printf(" max_bitrate = %d\n",max_bitrate); - printf(" avg_bitrate = %d\n",avg_bitrate); - printf(" max_packet_size = %d\n",max_packet_size); - printf(" avg_packet_size = %d\n",avg_packet_size); - printf(" start_time = %d\n",start_time); - printf(" preroll = %d\n",preroll); - printf(" duration = %d\n",duration); - printf(" desc=\"%s\"\n",desc); - printf(" mimetype=\"%s\"\n",mimetype); - printf(" codec_data_size = %d\n",codec_data_size); - printf(" v=\"%s\"\n", fourcc2str(v)); + DEBUGF(" stream_id = 0x%04x\n",stream_id); + DEBUGF(" max_bitrate = %d\n",max_bitrate); + DEBUGF(" avg_bitrate = %d\n",avg_bitrate); + DEBUGF(" max_packet_size = %d\n",max_packet_size); + DEBUGF(" avg_packet_size = %d\n",avg_packet_size); + DEBUGF(" start_time = %d\n",start_time); + DEBUGF(" preroll = %d\n",preroll); + DEBUGF(" duration = %d\n",duration); + DEBUGF(" desc=\"%s\"\n",desc); + DEBUGF(" mimetype=\"%s\"\n",mimetype); + DEBUGF(" codec_data_size = %d\n",codec_data_size); + DEBUGF(" v=\"%s\"\n", fourcc2str(v)); if (v == FOURCC('.','r','a',0xfd)) { @@ -428,12 +425,12 @@ case FOURCC('D','A','T','A'): - read_uint32be(fd,&rmctx->nb_packets); - skipped += 4; - read_uint32be(fd,&next_data_off); - skipped += 4; + read_uint32be(fd,&rmctx->nb_packets); + skipped += 4; + read_uint32be(fd,&next_data_off); + skipped += 4; if (!rmctx->nb_packets && (rmctx->flags & 4)) - rmctx->nb_packets = 3600 * 25; + rmctx->nb_packets = 3600 * 25; /*** * nb_packets correction : @@ -445,9 +442,9 @@ if(rmctx->nb_packets % rmctx->sub_packet_h) rmctx->nb_packets += rmctx->sub_packet_h - (rmctx->nb_packets % rmctx->sub_packet_h); - printf(" data_nb_packets = %d\n",rmctx->nb_packets); - printf(" next DATA offset = %d\n",next_data_off); - header_end = 1; + DEBUGF(" data_nb_packets = %d\n",rmctx->nb_packets); + DEBUGF(" next DATA offset = %d\n",next_data_off); + header_end = 1; break; } if(header_end) break; @@ -504,13 +501,15 @@ //return pkt->data; } +#endif /*TEST*/ /** * Another version of rm_get_packet which reads from a memory buffer - * instead of readind from a file descriptor. + * instead of reading from a file descriptor. **/ -void rm_get_packet_membuf(uint8_t **filebuf,RMContext *rmctx, RMPacket *pkt) +int rm_get_packet_membuf(uint8_t **filebuf,RMContext *rmctx, RMPacket *pkt) { + int consumed = 0; uint8_t unknown; uint16_t x, place; uint16_t sps = rmctx->sub_packet_size; @@ -524,11 +523,10 @@ pkt->length = get_uint16be(*filebuf+2); pkt->stream_number = get_uint16be(*filebuf+4); pkt->timestamp = get_uint32be(*filebuf+6); - DEBUGF(" version = %d\n" + /*DEBUGF(" version = %d\n" " length = %d\n" " stream = %d\n" - " timestamp= %d\n",pkt->version,pkt->length,pkt->stream_number,pkt->timestamp); - + " timestamp= %d\n\n",pkt->version,pkt->length,pkt->stream_number,pkt->timestamp);*/ unknown = get_uint8(*filebuf+10); pkt->flags = get_uint8(*filebuf+11); @@ -541,15 +539,19 @@ rmctx->audiotimestamp = pkt->timestamp; advance_buffer(filebuf,12); - + consumed += 12; for(x = 0 ; x < w/sps; x++) { place = sps*(h*x+((h+1)/2)*(y&1)+(y>>1)); + //DEBUGF(" Place = %p\n",place); pkt->frames[place/sps] = *filebuf; advance_buffer(filebuf,sps); + consumed += sps; } rmctx->audio_pkt_cnt++; }while(++(rmctx->sub_packet_cnt) < h); + +return consumed; } #ifdef DEBUG Index: apps/codecs/librm/rm.h =================================================================== --- apps/codecs/librm/rm.h (revision 21477) +++ apps/codecs/librm/rm.h (working copy) @@ -21,9 +21,10 @@ #ifndef _RM_H #define _RM_H -#include -#include +//#include +#include +enum codecs{cook}; typedef struct rm_packet { uint8_t data[30000]; /* Reordered data. No malloc, hence the size */ @@ -46,6 +47,7 @@ /* Stream Variables */ uint32_t data_offset; + uint32_t duration; uint32_t audiotimestamp; /* Audio packet timestamp*/ uint16_t sub_packet_cnt; /* Subpacket counter, used while reading */ uint16_t sub_packet_size, sub_packet_h, coded_framesize; /* Descrambling parameters from container */ @@ -53,6 +55,7 @@ uint16_t sub_packet_lengths[16]; /* Length of each subpacket */ /* Codec Context */ + enum codecs codec_type; uint16_t block_align; uint32_t nb_packets; int frame_number; @@ -71,13 +74,15 @@ uint16_t js_subband_start; /* joint stereo subband start */ uint16_t js_vlc_bits; + /* Metadata */ + char title[256]; + char author[256]; + char copyright[256]; + char comment[256]; + } RMContext; -int open_wav(char* filename); -void close_wav(int fd, RMContext *rmctx); int real_parse_header(int fd, RMContext *rmctx); void rm_get_packet(int fd,RMContext *rmctx, RMPacket *pkt); -void rm_get_packet_membuf(uint8_t **filebuf,RMContext *rmctx, RMPacket *pkt); -off_t filesize(int fd); -void advance_buffer(uint8_t **buf, int val); +int rm_get_packet_membuf(uint8_t **filebuf,RMContext *rmctx, RMPacket *pkt); #endif