summaryrefslogtreecommitdiff
path: root/apps/codecs/libcook
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libcook')
-rw-r--r--apps/codecs/libcook/Makefile.test2
-rw-r--r--apps/codecs/libcook/bitstream.c14
-rw-r--r--apps/codecs/libcook/bitstream.h28
-rw-r--r--apps/codecs/libcook/cook.c62
-rw-r--r--apps/codecs/libcook/libavutil/avutil.h63
-rw-r--r--apps/codecs/libcook/libavutil/internal.h4
-rw-r--r--apps/codecs/libcook/libavutil/intreadwrite.h192
-rw-r--r--apps/codecs/libcook/libavutil/log.c89
-rw-r--r--apps/codecs/libcook/libavutil/log.h116
-rw-r--r--apps/codecs/libcook/main.c11
10 files changed, 71 insertions, 510 deletions
diff --git a/apps/codecs/libcook/Makefile.test b/apps/codecs/libcook/Makefile.test
index cb8630d180..d90cda2543 100644
--- a/apps/codecs/libcook/Makefile.test
+++ b/apps/codecs/libcook/Makefile.test
@@ -1,5 +1,5 @@
1CFLAGS = -Wall -O3 1CFLAGS = -Wall -O3
2OBJS = main.o bitstream.o cook.o libavutil/log.o libavutil/mem.o rm2wav.o 2OBJS = main.o bitstream.o cook.o libavutil/mem.o rm2wav.o
3cooktest: $(OBJS) 3cooktest: $(OBJS)
4 gcc -o cooktest $(OBJS) 4 gcc -o cooktest $(OBJS)
5 5
diff --git a/apps/codecs/libcook/bitstream.c b/apps/codecs/libcook/bitstream.c
index 6c8915d12f..3b0c0a7b55 100644
--- a/apps/codecs/libcook/bitstream.c
+++ b/apps/codecs/libcook/bitstream.c
@@ -152,7 +152,7 @@ static int build_table(VLC *vlc, int table_nb_bits,
152 table_size = 1 << table_nb_bits; 152 table_size = 1 << table_nb_bits;
153 table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC)); 153 table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC));
154#ifdef DEBUG_VLC 154#ifdef DEBUG_VLC
155 av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d code_prefix=%x n=%d\n", 155 printf("new table index=%d size=%d code_prefix=%x n=%d\n",
156 table_index, table_size, code_prefix, n_prefix); 156 table_index, table_size, code_prefix, n_prefix);
157#endif 157#endif
158 if (table_index < 0) 158 if (table_index < 0)
@@ -176,7 +176,7 @@ static int build_table(VLC *vlc, int table_nb_bits,
176 else 176 else
177 GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size); 177 GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size);
178#if defined(DEBUG_VLC) && 0 178#if defined(DEBUG_VLC) && 0
179 av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code); 179 printf("i=%d n=%d code=0x%x\n", i, n, code);
180#endif 180#endif
181 /* if code matches the prefix, it is in the table */ 181 /* if code matches the prefix, it is in the table */
182 n -= n_prefix; 182 n -= n_prefix;
@@ -193,11 +193,11 @@ static int build_table(VLC *vlc, int table_nb_bits,
193 if(flags & INIT_VLC_LE) 193 if(flags & INIT_VLC_LE)
194 j = (code >> n_prefix) + (k<<n); 194 j = (code >> n_prefix) + (k<<n);
195#ifdef DEBUG_VLC 195#ifdef DEBUG_VLC
196 av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n", 196 printf("%4x: code=%d n=%d\n",
197 j, i, n); 197 j, i, n);
198#endif 198#endif
199 if (table[j][1] /*bits*/ != 0) { 199 if (table[j][1] /*bits*/ != 0) {
200 av_log(NULL, AV_LOG_ERROR, "incorrect codes\n"); 200 printf("incorrect codes\n");
201 return -1; 201 return -1;
202 } 202 }
203 table[j][1] = n; //bits 203 table[j][1] = n; //bits
@@ -208,7 +208,7 @@ static int build_table(VLC *vlc, int table_nb_bits,
208 n -= table_nb_bits; 208 n -= table_nb_bits;
209 j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1); 209 j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1);
210#ifdef DEBUG_VLC 210#ifdef DEBUG_VLC
211 av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n", 211 printf("%4x: n=%d (subtable)\n",
212 j, n); 212 j, n);
213#endif 213#endif
214 /* compute table size */ 214 /* compute table size */
@@ -297,7 +297,7 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
297 } 297 }
298 298
299#ifdef DEBUG_VLC 299#ifdef DEBUG_VLC
300 av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes); 300 printf("build table nb_codes=%d\n", nb_codes);
301#endif 301#endif
302 302
303 if (build_table(vlc, nb_bits, nb_codes, 303 if (build_table(vlc, nb_bits, nb_codes,
@@ -309,7 +309,7 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
309 return -1; 309 return -1;
310 } 310 }
311 if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size != vlc->table_allocated) 311 if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size != vlc->table_allocated)
312 av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated); 312 printf("needed %d had %d\n", vlc->table_size, vlc->table_allocated);
313 return 0; 313 return 0;
314} 314}
315 315
diff --git a/apps/codecs/libcook/bitstream.h b/apps/codecs/libcook/bitstream.h
index e3e3d77595..2319a4d672 100644
--- a/apps/codecs/libcook/bitstream.h
+++ b/apps/codecs/libcook/bitstream.h
@@ -31,10 +31,20 @@
31#include <assert.h> 31#include <assert.h>
32#include "libavutil/bswap.h" 32#include "libavutil/bswap.h"
33#include "libavutil/common.h" 33#include "libavutil/common.h"
34#include "libavutil/intreadwrite.h" 34//#include "libavutil/log.h"
35#include "libavutil/log.h"
36//#include "mathops.h" 35//#include "mathops.h"
37 36
37/* The following 2 defines are taken from libavutil/intreadwrite.h */
38#define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \
39 (((const uint8_t*)(x))[1] << 16) | \
40 (((const uint8_t*)(x))[2] << 8) | \
41 ((const uint8_t*)(x))[3])
42#define AV_WB32(p, d) do { \
43 ((uint8_t*)(p))[3] = (d); \
44 ((uint8_t*)(p))[2] = (d)>>8; \
45 ((uint8_t*)(p))[1] = (d)>>16; \
46 ((uint8_t*)(p))[0] = (d)>>24; } while(0)
47
38#if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER) 48#if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER)
39# define ALT_BITSTREAM_READER 49# define ALT_BITSTREAM_READER
40#endif 50#endif
@@ -731,7 +741,7 @@ static inline int check_marker(GetBitContext *s, const char *msg)
731{ 741{
732 int bit= get_bits1(s); 742 int bit= get_bits1(s);
733 if(!bit) 743 if(!bit)
734 av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg); 744 printf("Marker bit missing %s\n", msg);
735 745
736 return bit; 746 return bit;
737} 747}
@@ -892,17 +902,17 @@ static inline void print_bin(int bits, int n){
892 int i; 902 int i;
893 903
894 for(i=n-1; i>=0; i--){ 904 for(i=n-1; i>=0; i--){
895 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1); 905 printf("%d", (bits>>i)&1);
896 } 906 }
897 for(i=n; i<24; i++) 907 for(i=n; i<24; i++)
898 av_log(NULL, AV_LOG_DEBUG, " "); 908 printf(" ");
899} 909}
900 910
901static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ 911static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
902 int r= get_bits(s, n); 912 int r= get_bits(s, n);
903 913
904 print_bin(r, n); 914 print_bin(r, n);
905 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line); 915 printf("%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line);
906 return r; 916 return r;
907} 917}
908static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){ 918static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){
@@ -914,7 +924,7 @@ static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits
914 924
915 print_bin(bits2, len); 925 print_bin(bits2, len);
916 926
917 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); 927 printf("%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
918 return r; 928 return r;
919} 929}
920static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ 930static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
@@ -922,7 +932,7 @@ static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const cha
922 int r= get_xbits(s, n); 932 int r= get_xbits(s, n);
923 933
924 print_bin(show, n); 934 print_bin(show, n);
925 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line); 935 printf("%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line);
926 return r; 936 return r;
927} 937}
928 938
@@ -932,7 +942,7 @@ static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const cha
932#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) 942#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
933#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) 943#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
934 944
935#define tprintf(p, ...) av_log(p, AV_LOG_DEBUG, __VA_ARGS__) 945#define tprintf(p, ...) printf
936 946
937#else //TRACE 947#else //TRACE
938#define tprintf(p, ...) {} 948#define tprintf(p, ...) {}
diff --git a/apps/codecs/libcook/cook.c b/apps/codecs/libcook/cook.c
index 5b2c59a6c5..fd80c1bd2e 100644
--- a/apps/codecs/libcook/cook.c
+++ b/apps/codecs/libcook/cook.c
@@ -70,7 +70,11 @@ const uint8_t ff_log2_tab[256]={
70#define SUBBAND_SIZE 20 70#define SUBBAND_SIZE 20
71#define MAX_SUBPACKETS 5 71#define MAX_SUBPACKETS 5
72//#define COOKDEBUG 72//#define COOKDEBUG
73#define DEBUGF(message,args ...) av_log(NULL,AV_LOG_ERROR,message,## args) 73#if 0
74#define DEBUGF(message,args ...) printf
75#else
76#define DEBUGF(...)
77#endif
74 78
75/** 79/**
76 * Random bit stream generator. 80 * Random bit stream generator.
@@ -89,19 +93,19 @@ static int inline cook_random(COOKContext *q)
89#ifdef COOKDEBUG 93#ifdef COOKDEBUG
90static void dump_int_table(int* table, int size, int delimiter) { 94static void dump_int_table(int* table, int size, int delimiter) {
91 int i=0; 95 int i=0;
92 av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i); 96 DEBUGF("\n[%d]: ",i);
93 for (i=0 ; i<size ; i++) { 97 for (i=0 ; i<size ; i++) {
94 av_log(NULL, AV_LOG_ERROR, "%d, ", table[i]); 98 DEBUGF("%d, ", table[i]);
95 if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1); 99 if ((i+1)%delimiter == 0) DEBUGF("\n[%d]: ",i+1);
96 } 100 }
97} 101}
98 102
99static void dump_short_table(short* table, int size, int delimiter) { 103static void dump_short_table(short* table, int size, int delimiter) {
100 int i=0; 104 int i=0;
101 av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i); 105 DEBUGF("\n[%d]: ",i);
102 for (i=0 ; i<size ; i++) { 106 for (i=0 ; i<size ; i++) {
103 av_log(NULL, AV_LOG_ERROR, "%d, ", table[i]); 107 DEBUGF("%d, ", table[i]);
104 if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1); 108 if ((i+1)%delimiter == 0) DEBUGF("\n[%d]: ",i+1);
105 } 109 }
106} 110}
107 111
@@ -117,7 +121,7 @@ static av_cold int init_cook_vlc_tables(COOKContext *q) {
117 envelope_quant_index_huffbits[i], 1, 1, 121 envelope_quant_index_huffbits[i], 1, 1,
118 envelope_quant_index_huffcodes[i], 2, 2, 0); 122 envelope_quant_index_huffcodes[i], 2, 2, 0);
119 } 123 }
120 av_log(NULL,AV_LOG_DEBUG,"sqvh VLC init\n"); 124 DEBUGF("sqvh VLC init\n");
121 for (i=0 ; i<7 ; i++) { 125 for (i=0 ; i<7 ; i++) {
122 result |= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i], 126 result |= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
123 cvh_huffbits[i], 1, 1, 127 cvh_huffbits[i], 1, 1,
@@ -128,10 +132,10 @@ static av_cold int init_cook_vlc_tables(COOKContext *q) {
128 result |= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1, 132 result |= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1,
129 ccpl_huffbits[q->js_vlc_bits-2], 1, 1, 133 ccpl_huffbits[q->js_vlc_bits-2], 1, 1,
130 ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, 0); 134 ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, 0);
131 av_log(NULL,AV_LOG_DEBUG,"Joint-stereo VLC used.\n"); 135 DEBUGF("Joint-stereo VLC used.\n");
132 } 136 }
133 137
134 av_log(NULL,AV_LOG_ERROR,"VLC tables initialized. Result = %d\n",result); 138 DEBUGF("VLC tables initialized. Result = %d\n",result);
135 return result; 139 return result;
136} 140}
137/*************** init functions end ***********/ 141/*************** init functions end ***********/
@@ -188,7 +192,7 @@ av_cold int cook_decode_close(COOKContext *q)
188{ 192{
189 int i; 193 int i;
190 //COOKContext *q = avctx->priv_data; 194 //COOKContext *q = avctx->priv_data;
191 av_log(NULL,AV_LOG_ERROR, "Deallocating memory.\n"); 195 DEBUGF( "Deallocating memory.\n");
192 196
193 /* Free allocated memory buffers. */ 197 /* Free allocated memory buffers. */
194 av_free(q->decoded_bytes_buffer); 198 av_free(q->decoded_bytes_buffer);
@@ -204,7 +208,7 @@ av_cold int cook_decode_close(COOKContext *q)
204 free_vlc(&q->ccpl); 208 free_vlc(&q->ccpl);
205 } 209 }
206 210
207 av_log(NULL,AV_LOG_ERROR,"Memory deallocated.\n"); 211 DEBUGF("Memory deallocated.\n");
208 212
209 return 0; 213 return 0;
210} 214}
@@ -650,9 +654,9 @@ static int decode_subpacket(COOKContext *q, const uint8_t *inbuffer,
650 int sub_packet_size, int16_t *outbuffer) { 654 int sub_packet_size, int16_t *outbuffer) {
651 /* packet dump */ 655 /* packet dump */
652// for (i=0 ; i<sub_packet_size ; i++) { 656// for (i=0 ; i<sub_packet_size ; i++) {
653// av_log(NULL, AV_LOG_ERROR, "%02x", inbuffer[i]); 657// DEBUGF("%02x", inbuffer[i]);
654// } 658// }
655// av_log(NULL, AV_LOG_ERROR, "\n"); 659// DEBUGF("\n");
656 660
657 decode_bytes_and_gain(q, inbuffer, &q->gains1); 661 decode_bytes_and_gain(q, inbuffer, &q->gains1);
658 662
@@ -710,9 +714,9 @@ int cook_decode_frame(RMContext *rmctx,COOKContext *q,
710static void dump_cook_context(COOKContext *q) 714static void dump_cook_context(COOKContext *q)
711{ 715{
712 //int i=0; 716 //int i=0;
713#define PRINT(a,b) av_log(NULL,AV_LOG_ERROR," %s = %d\n", a, b); 717#define PRINT(a,b) DEBUGF(" %s = %d\n", a, b);
714 av_log(NULL,AV_LOG_ERROR,"COOKextradata\n"); 718 DEBUGF("COOKextradata\n");
715 av_log(NULL,AV_LOG_ERROR,"cookversion=%x\n",q->cookversion); 719 DEBUGF("cookversion=%x\n",q->cookversion);
716 if (q->cookversion > STEREO) { 720 if (q->cookversion > STEREO) {
717 PRINT("js_subband_start",q->js_subband_start); 721 PRINT("js_subband_start",q->js_subband_start);
718 PRINT("js_vlc_bits",q->js_vlc_bits); 722 PRINT("js_vlc_bits",q->js_vlc_bits);
@@ -764,28 +768,28 @@ av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q)
764 q->total_subbands = q->subbands; 768 q->total_subbands = q->subbands;
765 769
766 /* Initialize version-dependent variables */ 770 /* Initialize version-dependent variables */
767 av_log(NULL,AV_LOG_DEBUG,"q->cookversion=%x\n",q->cookversion); 771 DEBUGF("q->cookversion=%x\n",q->cookversion);
768 q->joint_stereo = 0; 772 q->joint_stereo = 0;
769 switch (q->cookversion) { 773 switch (q->cookversion) {
770 case MONO: 774 case MONO:
771 if (q->nb_channels != 1) { 775 if (q->nb_channels != 1) {
772 av_log(NULL,AV_LOG_ERROR,"Container channels != 1, report sample!\n"); 776 DEBUGF("Container channels != 1, report sample!\n");
773 return -1; 777 return -1;
774 } 778 }
775 av_log(NULL,AV_LOG_DEBUG,"MONO\n"); 779 DEBUGF("MONO\n");
776 break; 780 break;
777 case STEREO: 781 case STEREO:
778 if (q->nb_channels != 1) { 782 if (q->nb_channels != 1) {
779 q->bits_per_subpacket = q->bits_per_subpacket/2; 783 q->bits_per_subpacket = q->bits_per_subpacket/2;
780 } 784 }
781 av_log(NULL,AV_LOG_DEBUG,"STEREO\n"); 785 DEBUGF("STEREO\n");
782 break; 786 break;
783 case JOINT_STEREO: 787 case JOINT_STEREO:
784 if (q->nb_channels != 2) { 788 if (q->nb_channels != 2) {
785 av_log(NULL,AV_LOG_ERROR,"Container channels != 2, report sample!\n"); 789 DEBUGF("Container channels != 2, report sample!\n");
786 return -1; 790 return -1;
787 } 791 }
788 av_log(NULL,AV_LOG_ERROR,"JOINT_STEREO\n"); 792 DEBUGF("JOINT_STEREO\n");
789 if (q->extradata_size >= 16){ 793 if (q->extradata_size >= 16){
790 q->total_subbands = q->subbands + q->js_subband_start; 794 q->total_subbands = q->subbands + q->js_subband_start;
791 q->joint_stereo = 1; 795 q->joint_stereo = 1;
@@ -798,11 +802,11 @@ av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q)
798 } 802 }
799 break; 803 break;
800 case MC_COOK: 804 case MC_COOK:
801 av_log(NULL,AV_LOG_ERROR,"MC_COOK not supported!\n"); 805 DEBUGF("MC_COOK not supported!\n");
802 return -1; 806 return -1;
803 break; 807 break;
804 default: 808 default:
805 av_log(NULL,AV_LOG_ERROR,"Unknown Cook version, report sample!\n"); 809 DEBUGF("Unknown Cook version, report sample!\n");
806 return -1; 810 return -1;
807 break; 811 break;
808 } 812 }
@@ -851,20 +855,20 @@ av_cold int cook_decode_init(RMContext *rmctx, COOKContext *q)
851 855
852 /* Try to catch some obviously faulty streams, othervise it might be exploitable */ 856 /* Try to catch some obviously faulty streams, othervise it might be exploitable */
853 if (q->total_subbands > 53) { 857 if (q->total_subbands > 53) {
854 av_log(NULL,AV_LOG_ERROR,"total_subbands > 53, report sample!\n"); 858 DEBUGF("total_subbands > 53, report sample!\n");
855 return -1; 859 return -1;
856 } 860 }
857 if (q->subbands > 50) { 861 if (q->subbands > 50) {
858 av_log(NULL,AV_LOG_ERROR,"subbands > 50, report sample!\n"); 862 DEBUGF("subbands > 50, report sample!\n");
859 return -1; 863 return -1;
860 } 864 }
861 if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) || (q->samples_per_channel == 1024)) { 865 if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) || (q->samples_per_channel == 1024)) {
862 } else { 866 } else {
863 av_log(NULL,AV_LOG_ERROR,"unknown amount of samples_per_channel = %d, report sample!\n",q->samples_per_channel); 867 DEBUGF("unknown amount of samples_per_channel = %d, report sample!\n",q->samples_per_channel);
864 return -1; 868 return -1;
865 } 869 }
866 if ((q->js_vlc_bits > 6) || (q->js_vlc_bits < 0)) { 870 if ((q->js_vlc_bits > 6) || (q->js_vlc_bits < 0)) {
867 av_log(NULL,AV_LOG_ERROR,"q->js_vlc_bits = %d, only >= 0 and <= 6 allowed!\n",q->js_vlc_bits); 871 DEBUGF("q->js_vlc_bits = %d, only >= 0 and <= 6 allowed!\n",q->js_vlc_bits);
868 return -1; 872 return -1;
869 } 873 }
870 874
diff --git a/apps/codecs/libcook/libavutil/avutil.h b/apps/codecs/libcook/libavutil/avutil.h
deleted file mode 100644
index c07e44d660..0000000000
--- a/apps/codecs/libcook/libavutil/avutil.h
+++ /dev/null
@@ -1,63 +0,0 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef AVUTIL_AVUTIL_H
22#define AVUTIL_AVUTIL_H
23
24/**
25 * @file libavutil/avutil.h
26 * external API header
27 */
28
29
30#define AV_STRINGIFY(s) AV_TOSTRING(s)
31#define AV_TOSTRING(s) #s
32
33#define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c)
34#define AV_VERSION_DOT(a, b, c) a ##.## b ##.## c
35#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
36
37#define LIBAVUTIL_VERSION_MAJOR 50
38#define LIBAVUTIL_VERSION_MINOR 0
39#define LIBAVUTIL_VERSION_MICRO 0
40
41#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
42 LIBAVUTIL_VERSION_MINOR, \
43 LIBAVUTIL_VERSION_MICRO)
44#define LIBAVUTIL_VERSION AV_VERSION(LIBAVUTIL_VERSION_MAJOR, \
45 LIBAVUTIL_VERSION_MINOR, \
46 LIBAVUTIL_VERSION_MICRO)
47#define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT
48
49#define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION)
50
51/**
52 * Returns the LIBAVUTIL_VERSION_INT constant.
53 */
54unsigned avutil_version(void);
55
56#include "common.h"
57//#include "mathematics.h"
58//#include "rational.h"
59//#include "intfloat_readwrite.h"
60#include "log.h"
61//#include "pixfmt.h"
62
63#endif /* AVUTIL_AVUTIL_H */
diff --git a/apps/codecs/libcook/libavutil/internal.h b/apps/codecs/libcook/libavutil/internal.h
index f8f9418a76..c28b6f9a5e 100644
--- a/apps/codecs/libcook/libavutil/internal.h
+++ b/apps/codecs/libcook/libavutil/internal.h
@@ -236,8 +236,8 @@ if((y)<(x)){\
236#undef exit 236#undef exit
237#define exit exit_is_forbidden 237#define exit exit_is_forbidden
238#ifndef LIBAVFORMAT_BUILD 238#ifndef LIBAVFORMAT_BUILD
239#undef printf 239//#undef printf
240#define printf please_use_av_log_instead_of_printf 240//#define printf please_use_av_log_instead_of_printf
241#undef fprintf 241#undef fprintf
242#define fprintf please_use_av_log_instead_of_fprintf 242#define fprintf please_use_av_log_instead_of_fprintf
243#undef puts 243#undef puts
diff --git a/apps/codecs/libcook/libavutil/intreadwrite.h b/apps/codecs/libcook/libavutil/intreadwrite.h
deleted file mode 100644
index d27a50061e..0000000000
--- a/apps/codecs/libcook/libavutil/intreadwrite.h
+++ /dev/null
@@ -1,192 +0,0 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVUTIL_INTREADWRITE_H
20#define AVUTIL_INTREADWRITE_H
21
22#include <stdint.h>
23//#include "ffmpeg_config.h"
24#include "bswap.h"
25
26#ifdef __GNUC__
27
28struct unaligned_64 { uint64_t l; } __attribute__((packed));
29struct unaligned_32 { uint32_t l; } __attribute__((packed));
30struct unaligned_16 { uint16_t l; } __attribute__((packed));
31
32#define AV_RN16(a) (((const struct unaligned_16 *) (a))->l)
33#define AV_RN32(a) (((const struct unaligned_32 *) (a))->l)
34#define AV_RN64(a) (((const struct unaligned_64 *) (a))->l)
35
36#define AV_WN16(a, b) (((struct unaligned_16 *) (a))->l) = (b)
37#define AV_WN32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
38#define AV_WN64(a, b) (((struct unaligned_64 *) (a))->l) = (b)
39
40#elif defined(__DECC)
41
42#define AV_RN16(a) (*((const __unaligned uint16_t*)(a)))
43#define AV_RN32(a) (*((const __unaligned uint32_t*)(a)))
44#define AV_RN64(a) (*((const __unaligned uint64_t*)(a)))
45
46#define AV_WN16(a, b) *((__unaligned uint16_t*)(a)) = (b)
47#define AV_WN32(a, b) *((__unaligned uint32_t*)(a)) = (b)
48#define AV_WN64(a, b) *((__unaligned uint64_t*)(a)) = (b)
49
50#else
51
52#define AV_RN16(a) (*((const uint16_t*)(a)))
53#define AV_RN32(a) (*((const uint32_t*)(a)))
54#define AV_RN64(a) (*((const uint64_t*)(a)))
55
56#define AV_WN16(a, b) *((uint16_t*)(a)) = (b)
57#define AV_WN32(a, b) *((uint32_t*)(a)) = (b)
58#define AV_WN64(a, b) *((uint64_t*)(a)) = (b)
59
60#endif /* !__GNUC__ */
61
62/* endian macros */
63#define AV_RB8(x) (((const uint8_t*)(x))[0])
64#define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0)
65
66#define AV_RL8(x) AV_RB8(x)
67#define AV_WL8(p, d) AV_WB8(p, d)
68
69#if HAVE_FAST_UNALIGNED
70# ifdef WORDS_BIGENDIAN
71# define AV_RB16(x) AV_RN16(x)
72# define AV_WB16(p, d) AV_WN16(p, d)
73
74# define AV_RL16(x) bswap_16(AV_RN16(x))
75# define AV_WL16(p, d) AV_WN16(p, bswap_16(d))
76
77# define AV_RB32(x) AV_RN32(x)
78# define AV_WB32(p, d) AV_WN32(p, d)
79
80# define AV_RL32(x) bswap_32(AV_RN32(x))
81# define AV_WL32(p, d) AV_WN32(p, bswap_32(d))
82
83# define AV_RB64(x) AV_RN64(x)
84# define AV_WB64(p, d) AV_WN64(p, d)
85
86# define AV_RL64(x) bswap_64(AV_RN64(x))
87# define AV_WL64(p, d) AV_WN64(p, bswap_64(d))
88# else /* WORDS_BIGENDIAN */
89# define AV_RB16(x) bswap_16(AV_RN16(x))
90# define AV_WB16(p, d) AV_WN16(p, bswap_16(d))
91
92# define AV_RL16(x) AV_RN16(x)
93# define AV_WL16(p, d) AV_WN16(p, d)
94
95# define AV_RB32(x) bswap_32(AV_RN32(x))
96# define AV_WB32(p, d) AV_WN32(p, bswap_32(d))
97
98# define AV_RL32(x) AV_RN32(x)
99# define AV_WL32(p, d) AV_WN32(p, d)
100
101# define AV_RB64(x) bswap_64(AV_RN64(x))
102# define AV_WB64(p, d) AV_WN64(p, bswap_64(d))
103
104# define AV_RL64(x) AV_RN64(x)
105# define AV_WL64(p, d) AV_WN64(p, d)
106# endif
107#else /* HAVE_FAST_UNALIGNED */
108#define AV_RB16(x) ((((const uint8_t*)(x))[0] << 8) | ((const uint8_t*)(x))[1])
109#define AV_WB16(p, d) do { \
110 ((uint8_t*)(p))[1] = (d); \
111 ((uint8_t*)(p))[0] = (d)>>8; } while(0)
112
113#define AV_RL16(x) ((((const uint8_t*)(x))[1] << 8) | \
114 ((const uint8_t*)(x))[0])
115#define AV_WL16(p, d) do { \
116 ((uint8_t*)(p))[0] = (d); \
117 ((uint8_t*)(p))[1] = (d)>>8; } while(0)
118
119#define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \
120 (((const uint8_t*)(x))[1] << 16) | \
121 (((const uint8_t*)(x))[2] << 8) | \
122 ((const uint8_t*)(x))[3])
123#define AV_WB32(p, d) do { \
124 ((uint8_t*)(p))[3] = (d); \
125 ((uint8_t*)(p))[2] = (d)>>8; \
126 ((uint8_t*)(p))[1] = (d)>>16; \
127 ((uint8_t*)(p))[0] = (d)>>24; } while(0)
128
129#define AV_RL32(x) ((((const uint8_t*)(x))[3] << 24) | \
130 (((const uint8_t*)(x))[2] << 16) | \
131 (((const uint8_t*)(x))[1] << 8) | \
132 ((const uint8_t*)(x))[0])
133#define AV_WL32(p, d) do { \
134 ((uint8_t*)(p))[0] = (d); \
135 ((uint8_t*)(p))[1] = (d)>>8; \
136 ((uint8_t*)(p))[2] = (d)>>16; \
137 ((uint8_t*)(p))[3] = (d)>>24; } while(0)
138
139#define AV_RB64(x) (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
140 ((uint64_t)((const uint8_t*)(x))[1] << 48) | \
141 ((uint64_t)((const uint8_t*)(x))[2] << 40) | \
142 ((uint64_t)((const uint8_t*)(x))[3] << 32) | \
143 ((uint64_t)((const uint8_t*)(x))[4] << 24) | \
144 ((uint64_t)((const uint8_t*)(x))[5] << 16) | \
145 ((uint64_t)((const uint8_t*)(x))[6] << 8) | \
146 (uint64_t)((const uint8_t*)(x))[7])
147#define AV_WB64(p, d) do { \
148 ((uint8_t*)(p))[7] = (d); \
149 ((uint8_t*)(p))[6] = (d)>>8; \
150 ((uint8_t*)(p))[5] = (d)>>16; \
151 ((uint8_t*)(p))[4] = (d)>>24; \
152 ((uint8_t*)(p))[3] = (d)>>32; \
153 ((uint8_t*)(p))[2] = (d)>>40; \
154 ((uint8_t*)(p))[1] = (d)>>48; \
155 ((uint8_t*)(p))[0] = (d)>>56; } while(0)
156
157#define AV_RL64(x) (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
158 ((uint64_t)((const uint8_t*)(x))[6] << 48) | \
159 ((uint64_t)((const uint8_t*)(x))[5] << 40) | \
160 ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
161 ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
162 ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
163 ((uint64_t)((const uint8_t*)(x))[1] << 8) | \
164 (uint64_t)((const uint8_t*)(x))[0])
165#define AV_WL64(p, d) do { \
166 ((uint8_t*)(p))[0] = (d); \
167 ((uint8_t*)(p))[1] = (d)>>8; \
168 ((uint8_t*)(p))[2] = (d)>>16; \
169 ((uint8_t*)(p))[3] = (d)>>24; \
170 ((uint8_t*)(p))[4] = (d)>>32; \
171 ((uint8_t*)(p))[5] = (d)>>40; \
172 ((uint8_t*)(p))[6] = (d)>>48; \
173 ((uint8_t*)(p))[7] = (d)>>56; } while(0)
174#endif /* HAVE_FAST_UNALIGNED */
175
176#define AV_RB24(x) ((((const uint8_t*)(x))[0] << 16) | \
177 (((const uint8_t*)(x))[1] << 8) | \
178 ((const uint8_t*)(x))[2])
179#define AV_WB24(p, d) do { \
180 ((uint8_t*)(p))[2] = (d); \
181 ((uint8_t*)(p))[1] = (d)>>8; \
182 ((uint8_t*)(p))[0] = (d)>>16; } while(0)
183
184#define AV_RL24(x) ((((const uint8_t*)(x))[2] << 16) | \
185 (((const uint8_t*)(x))[1] << 8) | \
186 ((const uint8_t*)(x))[0])
187#define AV_WL24(p, d) do { \
188 ((uint8_t*)(p))[0] = (d); \
189 ((uint8_t*)(p))[1] = (d)>>8; \
190 ((uint8_t*)(p))[2] = (d)>>16; } while(0)
191
192#endif /* AVUTIL_INTREADWRITE_H */
diff --git a/apps/codecs/libcook/libavutil/log.c b/apps/codecs/libcook/libavutil/log.c
deleted file mode 100644
index 4bb9652c2c..0000000000
--- a/apps/codecs/libcook/libavutil/log.c
+++ /dev/null
@@ -1,89 +0,0 @@
1/*
2 * log functions
3 * Copyright (c) 2003 Michel Bardiaux
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
23 * @file libavutil/log.c
24 * logging functions
25 */
26
27#include "avutil.h"
28#include "log.h"
29
30int av_log_level = AV_LOG_INFO;
31
32void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
33{
34 static int print_prefix=1;
35 static int count;
36 static char line[1024], prev[1024];
37 AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
38 if(level>av_log_level)
39 return;
40#undef fprintf
41 if(print_prefix && avc) {
42 snprintf(line, sizeof(line), "[%s @ %p]", avc->item_name(ptr), ptr);
43 }else
44 line[0]=0;
45
46 vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
47
48 print_prefix= line[strlen(line)-1] == '\n';
49 if(print_prefix && !strcmp(line, prev)){
50 count++;
51 return;
52 }
53 if(count>0){
54 fprintf(stderr, " Last message repeated %d times\n", count);
55 count=0;
56 }
57 fputs(line, stderr);
58 strcpy(prev, line);
59}
60
61static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
62
63void av_log(void* avcl, int level, const char *fmt, ...)
64{
65 va_list vl;
66 va_start(vl, fmt);
67 av_vlog(avcl, level, fmt, vl);
68 va_end(vl);
69}
70
71void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
72{
73 av_log_callback(avcl, level, fmt, vl);
74}
75
76int av_log_get_level(void)
77{
78 return av_log_level;
79}
80
81void av_log_set_level(int level)
82{
83 av_log_level = level;
84}
85
86void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
87{
88 av_log_callback = callback;
89}
diff --git a/apps/codecs/libcook/libavutil/log.h b/apps/codecs/libcook/libavutil/log.h
deleted file mode 100644
index 1206a2fc38..0000000000
--- a/apps/codecs/libcook/libavutil/log.h
+++ /dev/null
@@ -1,116 +0,0 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef AVUTIL_LOG_H
22#define AVUTIL_LOG_H
23
24#include <stdarg.h>
25#include "avutil.h"
26
27/**
28 * Describes the class of an AVClass context structure. That is an
29 * arbitrary struct of which the first field is a pointer to an
30 * AVClass struct (e.g. AVCodecContext, AVFormatContext etc.).
31 */
32typedef struct AVCLASS AVClass;
33struct AVCLASS {
34 /**
35 * The name of the class; usually it is the same name as the
36 * context structure type to which the AVClass is associated.
37 */
38 const char* class_name;
39
40 /**
41 * A pointer to a function which returns the name of a context
42 * instance \p ctx associated with the class.
43 */
44 const char* (*item_name)(void* ctx);
45
46 /**
47 * a pointer to the first option specified in the class if any or NULL
48 *
49 * @see av_set_default_options()
50 */
51 const struct AVOption *option;
52};
53
54/* av_log API */
55
56#define AV_LOG_QUIET -8
57
58/**
59 * Something went really wrong and we will crash now.
60 */
61#define AV_LOG_PANIC 0
62
63/**
64 * Something went wrong and recovery is not possible.
65 * For example, no header was found for a format which depends
66 * on headers or an illegal combination of parameters is used.
67 */
68#define AV_LOG_FATAL 8
69
70/**
71 * Something went wrong and cannot losslessly be recovered.
72 * However, not all future data is affected.
73 */
74#define AV_LOG_ERROR 16
75
76/**
77 * Something somehow does not look correct. This may or may not
78 * lead to problems. An example would be the use of '-vstrict -2'.
79 */
80#define AV_LOG_WARNING 24
81
82#define AV_LOG_INFO 32
83#define AV_LOG_VERBOSE 40
84
85/**
86 * Stuff which is only useful for libav* developers.
87 */
88#define AV_LOG_DEBUG 48
89
90/**
91 * Sends the specified message to the log if the level is less than or equal
92 * to the current av_log_level. By default, all logging messages are sent to
93 * stderr. This behavior can be altered by setting a different av_vlog callback
94 * function.
95 *
96 * @param avcl A pointer to an arbitrary struct of which the first field is a
97 * pointer to an AVClass struct.
98 * @param level The importance level of the message, lower values signifying
99 * higher importance.
100 * @param fmt The format string (printf-compatible) that specifies how
101 * subsequent arguments are converted to output.
102 * @see av_vlog
103 */
104#ifdef __GNUC__
105void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
106#else
107void av_log(void*, int level, const char *fmt, ...);
108#endif
109
110void av_vlog(void*, int level, const char *fmt, va_list);
111int av_log_get_level(void);
112void av_log_set_level(int);
113void av_log_set_callback(void (*)(void*, int, const char*, va_list));
114void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl);
115
116#endif /* AVUTIL_LOG_H */
diff --git a/apps/codecs/libcook/main.c b/apps/codecs/libcook/main.c
index 2f85295fb5..8b180b249d 100644
--- a/apps/codecs/libcook/main.c
+++ b/apps/codecs/libcook/main.c
@@ -28,7 +28,14 @@
28#include "cook.h" 28#include "cook.h"
29 29
30//#define DUMP_RAW_FRAMES 30//#define DUMP_RAW_FRAMES
31#define DEBUGF(message,args ...) av_log(NULL,AV_LOG_ERROR,message,## args) 31#ifndef DEBUGF
32# if 0
33# define DEBUGF(message,args ...) printf
34# else
35# define DEBUGF(...)
36# endif
37#endif
38
32int main(int argc, char *argv[]) 39int main(int argc, char *argv[])
33{ 40{
34 int fd, fd_dec; 41 int fd, fd_dec;
@@ -74,7 +81,7 @@ int main(int argc, char *argv[])
74 sps= rmctx.block_align; 81 sps= rmctx.block_align;
75 h = rmctx.sub_packet_h; 82 h = rmctx.sub_packet_h;
76 cook_decode_init(&rmctx,&q); 83 cook_decode_init(&rmctx,&q);
77 av_log(NULL,AV_LOG_ERROR,"nb_frames = %d\n",nb_frames); 84 DEBUGF("nb_frames = %d\n",nb_frames);
78 x = 0; 85 x = 0;
79 if(packet_count % h) 86 if(packet_count % h)
80 { 87 {