1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * $Id$ main.c 20898 2009-05-09 23:24:02Z dave $
10 * Copyright (C) 2009 Mohamed Tarek
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <sys/types.h>
30 //#define DUMP_RAW_FRAMES
31 #define DEBUGF(message,args ...) av_log(NULL,AV_LOG_ERROR,message,## args)
32 int main(int argc
, char *argv
[])
35 int res
, datasize
,x
,i
;
37 #ifdef DUMP_RAW_FRAMES
44 uint32_t packet_count
;
49 memset(&q
,0,sizeof(COOKContext
));
50 memset(&rmctx
,0,sizeof(RMContext
));
51 memset(&pkt
,0,sizeof(RMPacket
));
54 DEBUGF("Incorrect number of arguments\n");
58 fd
= open(argv
[1],O_RDONLY
);
60 DEBUGF("Error opening file %s\n", argv
[1]);
64 fd_dec
= open_wav("output.wav");
66 DEBUGF("Error creating output file\n");
69 res
= real_parse_header(fd
, &rmctx
);
70 packet_count
= rmctx
.nb_packets
;
71 rmctx
.audio_framesize
= rmctx
.block_align
;
72 rmctx
.block_align
= rmctx
.sub_packet_size
;
73 fs
= rmctx
.audio_framesize
;
74 sps
= rmctx
.block_align
;
75 h
= rmctx
.sub_packet_h
;
76 cook_decode_init(&rmctx
,&q
);
77 av_log(NULL
,AV_LOG_ERROR
,"nb_frames = %d\n",nb_frames
);
81 packet_count
+= h
- (packet_count
% h
);
82 rmctx
.nb_packets
= packet_count
;
87 memset(pkt
.data
,0,sizeof(pkt
.data
));
88 rm_get_packet(fd
, &rmctx
, &pkt
);
89 DEBUGF("total frames = %d packet count = %d output counter = %d \n",rmctx
.audio_pkt_cnt
*(fs
/sps
), packet_count
,rmctx
.audio_pkt_cnt
);
90 for(i
= 0; i
< rmctx
.audio_pkt_cnt
*(fs
/sps
) ; i
++)
92 /* output raw audio frames that are sent to the decoder into separate files */
93 #ifdef DUMP_RAW_FRAMES
94 snprintf(filename
,sizeof(filename
),"dump%d.raw",++x
);
95 fd_out
= open(filename
,O_WRONLY
|O_CREAT
|O_APPEND
);
96 write(fd_out
,pkt
.data
+i
*sps
,sps
);
100 memcpy(inbuf
,pkt
.data
+i
*sps
,sps
);
101 nb_frames
= cook_decode_frame(&rmctx
,&q
, outbuf
, &datasize
, inbuf
, rmctx
.block_align
);
102 rmctx
.frame_number
++;
103 write(fd_dec
,outbuf
,datasize
);
105 packet_count
-= rmctx
.audio_pkt_cnt
;
106 rmctx
.audio_pkt_cnt
= 0;
108 cook_decode_close(&q
);
109 close_wav(fd_dec
,&rmctx
);