forked from len0rd/rockbox
Generic codec-extradata parsing, in preparation for addition of AAC/RM.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21941 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
6539b535ad
commit
6f4294219e
6 changed files with 45 additions and 68 deletions
|
|
@ -156,7 +156,7 @@ seek_start :
|
||||||
return CODEC_ERROR;
|
return CODEC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ci->pcmbuf_insert(outbuf, NULL, rmctx.samples_pf_pc / rmctx.nb_channels);
|
ci->pcmbuf_insert(outbuf, NULL, q.samples_per_frame / rmctx.nb_channels);
|
||||||
ci->set_elapsed(rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i);
|
ci->set_elapsed(rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i);
|
||||||
}
|
}
|
||||||
packet_count -= rmctx.audio_pkt_cnt;
|
packet_count -= rmctx.audio_pkt_cnt;
|
||||||
|
|
|
||||||
|
|
@ -708,16 +708,27 @@ static void dump_cook_context(COOKContext *q)
|
||||||
* Cook initialization
|
* Cook initialization
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int cook_decode_init(RMContext *rmctx, COOKContext *q)
|
static inline uint16_t get_uint16be(uint8_t *buf)
|
||||||
{
|
{
|
||||||
|
return (uint16_t)((buf[0] << 8)|buf[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t get_uint32be(uint8_t *buf)
|
||||||
|
{
|
||||||
|
return (uint32_t)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int cook_decode_init(RMContext *rmctx, COOKContext *q)
|
||||||
|
{
|
||||||
|
|
||||||
/* cook extradata */
|
/* cook extradata */
|
||||||
q->cookversion = rmctx->cook_version;
|
q->cookversion = get_uint32be(rmctx->codec_extradata);
|
||||||
q->samples_per_frame = rmctx->samples_pf_pc;
|
q->samples_per_frame = get_uint16be(&rmctx->codec_extradata[4]);
|
||||||
q->subbands = rmctx->nb_subbands;
|
q->subbands = get_uint16be(&rmctx->codec_extradata[6]);
|
||||||
q->extradata_size = rmctx->extradata_size;
|
q->extradata_size = rmctx->extradata_size;
|
||||||
if (q->extradata_size >= 16){
|
if (q->extradata_size >= 16){
|
||||||
q->js_subband_start = rmctx->js_subband_start;
|
q->js_subband_start = get_uint16be(&rmctx->codec_extradata[12]);
|
||||||
q->js_vlc_bits = rmctx->js_vlc_bits;
|
q->js_vlc_bits = get_uint16be(&rmctx->codec_extradata[14]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Take data from the RMContext (RM container). */
|
/* Take data from the RMContext (RM container). */
|
||||||
|
|
|
||||||
|
|
@ -58,11 +58,11 @@ int open_wav(char* filename) {
|
||||||
return(fd);
|
return(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void close_wav(int fd, RMContext *rmctx) {
|
void close_wav(int fd, RMContext *rmctx, COOKContext *q) {
|
||||||
int x,res;
|
int x,res;
|
||||||
int filesize;
|
int filesize;
|
||||||
int bytes_per_sample = 2;
|
int bytes_per_sample = 2;
|
||||||
int samples_per_frame = rmctx->samples_pf_pc;
|
int samples_per_frame = q->samples_per_frame;
|
||||||
int nb_channels = rmctx->nb_channels;
|
int nb_channels = rmctx->nb_channels;
|
||||||
int sample_rate = rmctx->sample_rate;
|
int sample_rate = rmctx->sample_rate;
|
||||||
int nb_frames = rmctx->audio_framesize/rmctx->block_align * rmctx->nb_packets - 2; // first 2 frames have no valid audio; skipped in output
|
int nb_frames = rmctx->audio_framesize/rmctx->block_align * rmctx->nb_packets - 2; // first 2 frames have no valid audio; skipped in output
|
||||||
|
|
@ -182,7 +182,7 @@ int main(int argc, char *argv[])
|
||||||
packet_count -= rmctx.audio_pkt_cnt;
|
packet_count -= rmctx.audio_pkt_cnt;
|
||||||
rmctx.audio_pkt_cnt = 0;
|
rmctx.audio_pkt_cnt = 0;
|
||||||
}
|
}
|
||||||
close_wav(fd_dec,&rmctx);
|
close_wav(fd_dec, &rmctx, &q);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,27 +95,14 @@ static int read_uint32be(int fd, uint32_t* buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int read_cook_extradata(int fd, RMContext *rmctx) {
|
|
||||||
read_uint32be(fd, &rmctx->cook_version);
|
|
||||||
read_uint16be(fd, &rmctx->samples_pf_pc);
|
|
||||||
read_uint16be(fd, &rmctx->nb_subbands);
|
|
||||||
if(rmctx->extradata_size == 16) {
|
|
||||||
read_uint32be(fd, &rmctx->unused);
|
|
||||||
read_uint16be(fd, &rmctx->js_subband_start);
|
|
||||||
read_uint16be(fd, &rmctx->js_vlc_bits);
|
|
||||||
}
|
|
||||||
return rmctx->extradata_size; /* for 'skipped' */
|
|
||||||
}
|
|
||||||
|
|
||||||
static void print_cook_extradata(RMContext *rmctx) {
|
static void print_cook_extradata(RMContext *rmctx) {
|
||||||
|
|
||||||
DEBUGF(" cook_version = 0x%08x\n", rmctx->cook_version);
|
DEBUGF(" cook_version = 0x%08x\n", get_uint32be(rmctx->codec_extradata));
|
||||||
DEBUGF(" samples_per_frame_per_channel = %d\n", rmctx->samples_pf_pc);
|
DEBUGF(" samples_per_frame_per_channel = %d\n", get_uint16be(&rmctx->codec_extradata[4]));
|
||||||
DEBUGF(" number_of_subbands_in_freq_domain = %d\n", rmctx->nb_subbands);
|
DEBUGF(" number_of_subbands_in_freq_domain = %d\n", get_uint16be(&rmctx->codec_extradata[6]));
|
||||||
if(rmctx->extradata_size == 16) {
|
if(rmctx->extradata_size == 16) {
|
||||||
DEBUGF(" joint_stereo_subband_start = %d\n",rmctx->js_subband_start);
|
DEBUGF(" joint_stereo_subband_start = %d\n",get_uint16be(&rmctx->codec_extradata[12]));
|
||||||
DEBUGF(" joint_stereo_vlc_bits = %d\n", rmctx->js_vlc_bits);
|
DEBUGF(" joint_stereo_vlc_bits = %d\n", get_uint16be(&rmctx->codec_extradata[14]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -250,10 +237,8 @@ static int real_read_audio_stream_info(int fd, RMContext *rmctx)
|
||||||
|
|
||||||
read_uint32be(fd, &rmctx->extradata_size);
|
read_uint32be(fd, &rmctx->extradata_size);
|
||||||
skipped += 4;
|
skipped += 4;
|
||||||
if(!strncmp(fourcc2str(fourcc),"cook",4)){
|
read(fd, rmctx->codec_extradata, rmctx->extradata_size);
|
||||||
skipped += read_cook_extradata(fd, rmctx);
|
skipped += rmctx->extradata_size;
|
||||||
rmctx->codec_type = cook;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DEBUGF(" flavor = %d\n",flavor);
|
DEBUGF(" flavor = %d\n",flavor);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
enum codecs{cook};
|
#define MAX_EXTRADATA_SIZE 16
|
||||||
|
|
||||||
|
enum codecs{cook, aac};
|
||||||
typedef struct rm_packet
|
typedef struct rm_packet
|
||||||
{
|
{
|
||||||
uint8_t *frames[100]; /* Pointers to ordered audio frames in buffer */
|
uint8_t *frames[100]; /* Pointers to ordered audio frames in buffer */
|
||||||
|
|
@ -62,20 +64,14 @@ typedef struct rm_context
|
||||||
uint16_t block_align;
|
uint16_t block_align;
|
||||||
uint32_t nb_packets;
|
uint32_t nb_packets;
|
||||||
int frame_number;
|
int frame_number;
|
||||||
uint32_t extradata_size;
|
|
||||||
uint16_t sample_rate;
|
uint16_t sample_rate;
|
||||||
uint16_t nb_channels;
|
uint16_t nb_channels;
|
||||||
uint32_t bit_rate;
|
uint32_t bit_rate;
|
||||||
uint16_t flags;
|
uint16_t flags;
|
||||||
|
|
||||||
/*cook extradata*/
|
/*codec extradata*/
|
||||||
uint32_t cook_version;
|
uint32_t extradata_size;
|
||||||
uint16_t samples_pf_pc; /* samples per frame per channel */
|
uint8_t codec_extradata[MAX_EXTRADATA_SIZE];
|
||||||
uint16_t nb_subbands; /* number of subbands in the frequency domain */
|
|
||||||
/* extra 8 bytes for joint-stereo data */
|
|
||||||
uint32_t unused;
|
|
||||||
uint16_t js_subband_start; /* joint stereo subband start */
|
|
||||||
uint16_t js_vlc_bits;
|
|
||||||
|
|
||||||
} RMContext;
|
} RMContext;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,26 +38,14 @@
|
||||||
#define DEBUGF(...)
|
#define DEBUGF(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline int read_cook_extradata(int fd, RMContext *rmctx) {
|
|
||||||
read_uint32be(fd, &rmctx->cook_version);
|
|
||||||
read_uint16be(fd, &rmctx->samples_pf_pc);
|
|
||||||
read_uint16be(fd, &rmctx->nb_subbands);
|
|
||||||
if(rmctx->extradata_size == 16) {
|
|
||||||
lseek(fd, sizeof(uint32_t), SEEK_CUR); /* reserved */
|
|
||||||
read_uint16be(fd, &rmctx->js_subband_start);
|
|
||||||
read_uint16be(fd, &rmctx->js_vlc_bits);
|
|
||||||
}
|
|
||||||
return rmctx->extradata_size; /* for 'skipped' */
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void print_cook_extradata(RMContext *rmctx) {
|
static inline void print_cook_extradata(RMContext *rmctx) {
|
||||||
|
|
||||||
DEBUGF(" cook_version = 0x%08lx\n", rmctx->cook_version);
|
DEBUGF(" cook_version = 0x%08x\n", get_uint32be(rmctx->codec_extradata));
|
||||||
DEBUGF(" samples_per_frame_per_channel = %d\n", rmctx->samples_pf_pc);
|
DEBUGF(" samples_per_frame_per_channel = %d\n", get_uint16be(&rmctx->codec_extradata[4]));
|
||||||
DEBUGF(" number_of_subbands_in_freq_domain = %d\n", rmctx->nb_subbands);
|
DEBUGF(" number_of_subbands_in_freq_domain = %d\n", get_uint16be(&rmctx->codec_extradata[6]));
|
||||||
if(rmctx->extradata_size == 16) {
|
if(rmctx->extradata_size == 16) {
|
||||||
DEBUGF(" joint_stereo_subband_start = %d\n",rmctx->js_subband_start);
|
DEBUGF(" joint_stereo_subband_start = %d\n",get_uint16be(&rmctx->codec_extradata[12]));
|
||||||
DEBUGF(" joint_stereo_vlc_bits = %d\n", rmctx->js_vlc_bits);
|
DEBUGF(" joint_stereo_vlc_bits = %d\n", get_uint16be(&rmctx->codec_extradata[14]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -174,13 +162,10 @@ static inline int real_read_audio_stream_info(int fd, RMContext *rmctx)
|
||||||
|
|
||||||
read_uint32be(fd, &rmctx->extradata_size);
|
read_uint32be(fd, &rmctx->extradata_size);
|
||||||
skipped += 4;
|
skipped += 4;
|
||||||
/*if(!strncmp(fourcc2str(fourcc),"cook",4)){
|
read(fd, rmctx->codec_extradata, rmctx->extradata_size);
|
||||||
skipped += read_cook_extradata(fd, rmctx);
|
skipped += rmctx->extradata_size;
|
||||||
rmctx->codec_type = cook;
|
|
||||||
}*/
|
|
||||||
switch(fourcc) {
|
switch(fourcc) {
|
||||||
case FOURCC('c','o','o','k'):
|
case FOURCC('c','o','o','k'):
|
||||||
skipped += read_cook_extradata(fd, rmctx);
|
|
||||||
rmctx->codec_type = cook;
|
rmctx->codec_type = cook;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue