Factor out bytestream reading functions needed in rm parsers/codecs.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22308 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Mohamed Tarek 2009-08-14 15:13:14 +00:00
parent 0b6aa38516
commit 466b2ae248
5 changed files with 62 additions and 66 deletions

View file

@ -721,27 +721,17 @@ static void dump_cook_context(COOKContext *q)
* Cook initialization
*/
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 */
q->cookversion = get_uint32be(rmctx->codec_extradata);
q->samples_per_frame = get_uint16be(&rmctx->codec_extradata[4]);
q->subbands = get_uint16be(&rmctx->codec_extradata[6]);
q->cookversion = rm_get_uint32be(rmctx->codec_extradata);
q->samples_per_frame = rm_get_uint16be(&rmctx->codec_extradata[4]);
q->subbands = rm_get_uint16be(&rmctx->codec_extradata[6]);
q->extradata_size = rmctx->extradata_size;
if (q->extradata_size >= 16){
q->js_subband_start = get_uint16be(&rmctx->codec_extradata[12]);
q->js_vlc_bits = get_uint16be(&rmctx->codec_extradata[14]);
q->js_subband_start = rm_get_uint16be(&rmctx->codec_extradata[12]);
q->js_vlc_bits = rm_get_uint16be(&rmctx->codec_extradata[14]);
}
/* Take data from the RMContext (RM container). */

View file

@ -0,0 +1,37 @@
#ifndef RM_BYTESTREAM_H
#define RM_BYTESTREAM_H
#include <inttypes.h>
static inline void advance_buffer(uint8_t **buf, int val)
{
*buf += val;
}
static inline uint8_t rm_get_uint8(uint8_t *buf)
{
return (uint8_t)buf[0];
}
static inline uint16_t rm_get_uint16be(uint8_t *buf)
{
return (uint16_t)((buf[0] << 8)|buf[1]);
}
static inline uint32_t rm_get_uint32be(uint8_t *buf)
{
return (uint32_t)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
}
static inline uint16_t rm_get_uint16le(uint8_t *buf)
{
return (uint16_t)((buf[1] << 8)|buf[0]);
}
static inline uint32_t rm_get_uint32le(uint8_t *buf)
{
return (uint32_t)((buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]);
}
#endif /* RM_BYTESTREAM_H */

View file

@ -29,26 +29,6 @@
#define SWAP(a, b) do{uint8_t SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
void advance_buffer(uint8_t **buf, int val)
{
*buf += val;
}
static uint8_t get_uint8(uint8_t *buf)
{
return (uint8_t)buf[0];
}
static uint16_t get_uint16be(uint8_t *buf)
{
return (uint16_t)((buf[0] << 8)|buf[1]);
}
static uint32_t get_uint32be(uint8_t *buf)
{
return (uint32_t)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
}
#ifdef TEST
#include <fcntl.h>
#include <unistd.h>
@ -99,12 +79,12 @@ static int read_uint32be(int fd, uint32_t* buf)
static void print_cook_extradata(RMContext *rmctx) {
DEBUGF(" cook_version = 0x%08x\n", get_uint32be(rmctx->codec_extradata));
DEBUGF(" samples_per_frame_per_channel = %d\n", get_uint16be(&rmctx->codec_extradata[4]));
DEBUGF(" number_of_subbands_in_freq_domain = %d\n", get_uint16be(&rmctx->codec_extradata[6]));
DEBUGF(" cook_version = 0x%08x\n", rm_get_uint32be(rmctx->codec_extradata));
DEBUGF(" samples_per_frame_per_channel = %d\n", rm_get_uint16be(&rmctx->codec_extradata[4]));
DEBUGF(" number_of_subbands_in_freq_domain = %d\n", rm_get_uint16be(&rmctx->codec_extradata[6]));
if(rmctx->extradata_size == 16) {
DEBUGF(" joint_stereo_subband_start = %d\n",get_uint16be(&rmctx->codec_extradata[12]));
DEBUGF(" joint_stereo_vlc_bits = %d\n", get_uint16be(&rmctx->codec_extradata[14]));
DEBUGF(" joint_stereo_subband_start = %d\n",rm_get_uint16be(&rmctx->codec_extradata[12]));
DEBUGF(" joint_stereo_vlc_bits = %d\n", rm_get_uint16be(&rmctx->codec_extradata[14]));
}
}
@ -532,7 +512,7 @@ int rm_get_packet(uint8_t **src,RMContext *rmctx, RMPacket *pkt)
do
{
y = rmctx->sub_packet_cnt;
pkt->version = get_uint16be(*src);
pkt->version = rm_get_uint16be(*src);
/* Simple error checking */
if(pkt->version != 0 && pkt->version != 1)
@ -541,18 +521,18 @@ int rm_get_packet(uint8_t **src,RMContext *rmctx, RMPacket *pkt)
return -1;
}
pkt->length = get_uint16be(*src+2);
pkt->stream_number = get_uint16be(*src+4);
pkt->timestamp = get_uint32be(*src+6);
pkt->length = rm_get_uint16be(*src+2);
pkt->stream_number = rm_get_uint16be(*src+4);
pkt->timestamp = rm_get_uint32be(*src+6);
/*DEBUGF(" version = %d\n"
" length = %d\n"
" stream = %d\n"
" timestamp= %d\n\n",pkt->version,pkt->length,pkt->stream_number,pkt->timestamp);*/
unknown = get_uint8(*src+10);
pkt->flags = get_uint8(*src+11);
unknown = rm_get_uint8(*src+10);
pkt->flags = rm_get_uint8(*src+11);
if(pkt->version == 1)
unknown = get_uint8(*src+10);
unknown = rm_get_uint8(*src+10);
if (pkt->flags & 2) /* keyframe */
y = rmctx->sub_packet_cnt = 0;
@ -571,12 +551,12 @@ int rm_get_packet(uint8_t **src,RMContext *rmctx, RMPacket *pkt)
}
}
else if (rmctx->codec_type == CODEC_AAC) {
rmctx->sub_packet_cnt = (get_uint16be(*src) & 0xf0) >> 4;
rmctx->sub_packet_cnt = (rm_get_uint16be(*src) & 0xf0) >> 4;
advance_buffer(src, 2);
consumed += 2;
if (rmctx->sub_packet_cnt) {
for(x = 0; x < rmctx->sub_packet_cnt; x++) {
rmctx->sub_packet_lengths[x] = get_uint16be(*src);
rmctx->sub_packet_lengths[x] = rm_get_uint16be(*src);
advance_buffer(src, 2);
consumed += 2;
}

View file

@ -23,6 +23,7 @@
#include <stdio.h>
#include <inttypes.h>
#include "bytestream.h"
#define MAX_EXTRADATA_SIZE 16
#define DATA_HEADER_SIZE 18

View file

@ -38,26 +38,14 @@
#define DEBUGF(...)
#endif
#ifdef DEBUG_RM
static uint16_t get_uint16be(uint8_t *buf)
{
return (uint16_t)((buf[0] << 8)|buf[1]);
}
static uint32_t get_uint32be(uint8_t *buf)
{
return (uint32_t)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
}
#endif
static inline void print_cook_extradata(RMContext *rmctx) {
DEBUGF(" cook_version = 0x%08lx\n", get_uint32be(rmctx->codec_extradata));
DEBUGF(" samples_per_frame_per_channel = %d\n", get_uint16be(&rmctx->codec_extradata[4]));
DEBUGF(" number_of_subbands_in_freq_domain = %d\n", get_uint16be(&rmctx->codec_extradata[6]));
DEBUGF(" cook_version = 0x%08lx\n", rm_get_uint32be(rmctx->codec_extradata));
DEBUGF(" samples_per_frame_per_channel = %d\n", rm_get_uint16be(&rmctx->codec_extradata[4]));
DEBUGF(" number_of_subbands_in_freq_domain = %d\n", rm_get_uint16be(&rmctx->codec_extradata[6]));
if(rmctx->extradata_size == 16) {
DEBUGF(" joint_stereo_subband_start = %d\n",get_uint16be(&rmctx->codec_extradata[12]));
DEBUGF(" joint_stereo_vlc_bits = %d\n", get_uint16be(&rmctx->codec_extradata[14]));
DEBUGF(" joint_stereo_subband_start = %d\n",rm_get_uint16be(&rmctx->codec_extradata[12]));
DEBUGF(" joint_stereo_vlc_bits = %d\n", rm_get_uint16be(&rmctx->codec_extradata[14]));
}
}