summaryrefslogtreecommitdiff
path: root/apps/codecs
diff options
context:
space:
mode:
authorMohamed Tarek <mt@rockbox.org>2009-08-14 15:13:14 +0000
committerMohamed Tarek <mt@rockbox.org>2009-08-14 15:13:14 +0000
commit466b2ae2481477a2797f785c269e0a996401597b (patch)
treefe51b38c6ccaefa904ab8fad2cecdb948af1e4bb /apps/codecs
parent0b6aa3851631eacba413d965f931f59cc8e37773 (diff)
downloadrockbox-466b2ae2481477a2797f785c269e0a996401597b.tar.gz
rockbox-466b2ae2481477a2797f785c269e0a996401597b.zip
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
Diffstat (limited to 'apps/codecs')
-rw-r--r--apps/codecs/libcook/cook.c20
-rw-r--r--apps/codecs/librm/bytestream.h37
-rw-r--r--apps/codecs/librm/rm.c48
-rw-r--r--apps/codecs/librm/rm.h1
4 files changed, 57 insertions, 49 deletions
diff --git a/apps/codecs/libcook/cook.c b/apps/codecs/libcook/cook.c
index 7ad994926e..74f695e627 100644
--- a/apps/codecs/libcook/cook.c
+++ b/apps/codecs/libcook/cook.c
@@ -721,27 +721,17 @@ static void dump_cook_context(COOKContext *q)
721 * Cook initialization 721 * Cook initialization
722 */ 722 */
723 723
724static inline uint16_t get_uint16be(uint8_t *buf)
725{
726 return (uint16_t)((buf[0] << 8)|buf[1]);
727}
728
729static inline uint32_t get_uint32be(uint8_t *buf)
730{
731 return (uint32_t)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
732}
733
734 int cook_decode_init(RMContext *rmctx, COOKContext *q) 724 int cook_decode_init(RMContext *rmctx, COOKContext *q)
735 { 725 {
736 726
737 /* cook extradata */ 727 /* cook extradata */
738 q->cookversion = get_uint32be(rmctx->codec_extradata); 728 q->cookversion = rm_get_uint32be(rmctx->codec_extradata);
739 q->samples_per_frame = get_uint16be(&rmctx->codec_extradata[4]); 729 q->samples_per_frame = rm_get_uint16be(&rmctx->codec_extradata[4]);
740 q->subbands = get_uint16be(&rmctx->codec_extradata[6]); 730 q->subbands = rm_get_uint16be(&rmctx->codec_extradata[6]);
741 q->extradata_size = rmctx->extradata_size; 731 q->extradata_size = rmctx->extradata_size;
742 if (q->extradata_size >= 16){ 732 if (q->extradata_size >= 16){
743 q->js_subband_start = get_uint16be(&rmctx->codec_extradata[12]); 733 q->js_subband_start = rm_get_uint16be(&rmctx->codec_extradata[12]);
744 q->js_vlc_bits = get_uint16be(&rmctx->codec_extradata[14]); 734 q->js_vlc_bits = rm_get_uint16be(&rmctx->codec_extradata[14]);
745 } 735 }
746 736
747 /* Take data from the RMContext (RM container). */ 737 /* Take data from the RMContext (RM container). */
diff --git a/apps/codecs/librm/bytestream.h b/apps/codecs/librm/bytestream.h
new file mode 100644
index 0000000000..c2a968a4bd
--- /dev/null
+++ b/apps/codecs/librm/bytestream.h
@@ -0,0 +1,37 @@
1#ifndef RM_BYTESTREAM_H
2#define RM_BYTESTREAM_H
3
4#include <inttypes.h>
5
6static inline void advance_buffer(uint8_t **buf, int val)
7{
8 *buf += val;
9}
10
11static inline uint8_t rm_get_uint8(uint8_t *buf)
12{
13 return (uint8_t)buf[0];
14}
15
16static inline uint16_t rm_get_uint16be(uint8_t *buf)
17{
18 return (uint16_t)((buf[0] << 8)|buf[1]);
19}
20
21static inline uint32_t rm_get_uint32be(uint8_t *buf)
22{
23 return (uint32_t)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
24}
25
26static inline uint16_t rm_get_uint16le(uint8_t *buf)
27{
28 return (uint16_t)((buf[1] << 8)|buf[0]);
29}
30
31static inline uint32_t rm_get_uint32le(uint8_t *buf)
32{
33 return (uint32_t)((buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]);
34}
35
36#endif /* RM_BYTESTREAM_H */
37
diff --git a/apps/codecs/librm/rm.c b/apps/codecs/librm/rm.c
index 80ecbbbd97..d721ceb81f 100644
--- a/apps/codecs/librm/rm.c
+++ b/apps/codecs/librm/rm.c
@@ -29,26 +29,6 @@
29 29
30#define SWAP(a, b) do{uint8_t SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) 30#define SWAP(a, b) do{uint8_t SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
31 31
32void advance_buffer(uint8_t **buf, int val)
33{
34 *buf += val;
35}
36
37static uint8_t get_uint8(uint8_t *buf)
38{
39 return (uint8_t)buf[0];
40}
41
42static uint16_t get_uint16be(uint8_t *buf)
43{
44 return (uint16_t)((buf[0] << 8)|buf[1]);
45}
46
47static uint32_t get_uint32be(uint8_t *buf)
48{
49 return (uint32_t)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
50}
51
52#ifdef TEST 32#ifdef TEST
53#include <fcntl.h> 33#include <fcntl.h>
54#include <unistd.h> 34#include <unistd.h>
@@ -99,12 +79,12 @@ static int read_uint32be(int fd, uint32_t* buf)
99 79
100static void print_cook_extradata(RMContext *rmctx) { 80static void print_cook_extradata(RMContext *rmctx) {
101 81
102 DEBUGF(" cook_version = 0x%08x\n", get_uint32be(rmctx->codec_extradata)); 82 DEBUGF(" cook_version = 0x%08x\n", rm_get_uint32be(rmctx->codec_extradata));
103 DEBUGF(" samples_per_frame_per_channel = %d\n", get_uint16be(&rmctx->codec_extradata[4])); 83 DEBUGF(" samples_per_frame_per_channel = %d\n", rm_get_uint16be(&rmctx->codec_extradata[4]));
104 DEBUGF(" number_of_subbands_in_freq_domain = %d\n", get_uint16be(&rmctx->codec_extradata[6])); 84 DEBUGF(" number_of_subbands_in_freq_domain = %d\n", rm_get_uint16be(&rmctx->codec_extradata[6]));
105 if(rmctx->extradata_size == 16) { 85 if(rmctx->extradata_size == 16) {
106 DEBUGF(" joint_stereo_subband_start = %d\n",get_uint16be(&rmctx->codec_extradata[12])); 86 DEBUGF(" joint_stereo_subband_start = %d\n",rm_get_uint16be(&rmctx->codec_extradata[12]));
107 DEBUGF(" joint_stereo_vlc_bits = %d\n", get_uint16be(&rmctx->codec_extradata[14])); 87 DEBUGF(" joint_stereo_vlc_bits = %d\n", rm_get_uint16be(&rmctx->codec_extradata[14]));
108 } 88 }
109} 89}
110 90
@@ -532,7 +512,7 @@ int rm_get_packet(uint8_t **src,RMContext *rmctx, RMPacket *pkt)
532 do 512 do
533 { 513 {
534 y = rmctx->sub_packet_cnt; 514 y = rmctx->sub_packet_cnt;
535 pkt->version = get_uint16be(*src); 515 pkt->version = rm_get_uint16be(*src);
536 516
537 /* Simple error checking */ 517 /* Simple error checking */
538 if(pkt->version != 0 && pkt->version != 1) 518 if(pkt->version != 0 && pkt->version != 1)
@@ -541,18 +521,18 @@ int rm_get_packet(uint8_t **src,RMContext *rmctx, RMPacket *pkt)
541 return -1; 521 return -1;
542 } 522 }
543 523
544 pkt->length = get_uint16be(*src+2); 524 pkt->length = rm_get_uint16be(*src+2);
545 pkt->stream_number = get_uint16be(*src+4); 525 pkt->stream_number = rm_get_uint16be(*src+4);
546 pkt->timestamp = get_uint32be(*src+6); 526 pkt->timestamp = rm_get_uint32be(*src+6);
547 /*DEBUGF(" version = %d\n" 527 /*DEBUGF(" version = %d\n"
548 " length = %d\n" 528 " length = %d\n"
549 " stream = %d\n" 529 " stream = %d\n"
550 " timestamp= %d\n\n",pkt->version,pkt->length,pkt->stream_number,pkt->timestamp);*/ 530 " timestamp= %d\n\n",pkt->version,pkt->length,pkt->stream_number,pkt->timestamp);*/
551 unknown = get_uint8(*src+10); 531 unknown = rm_get_uint8(*src+10);
552 pkt->flags = get_uint8(*src+11); 532 pkt->flags = rm_get_uint8(*src+11);
553 533
554 if(pkt->version == 1) 534 if(pkt->version == 1)
555 unknown = get_uint8(*src+10); 535 unknown = rm_get_uint8(*src+10);
556 536
557 if (pkt->flags & 2) /* keyframe */ 537 if (pkt->flags & 2) /* keyframe */
558 y = rmctx->sub_packet_cnt = 0; 538 y = rmctx->sub_packet_cnt = 0;
@@ -571,12 +551,12 @@ int rm_get_packet(uint8_t **src,RMContext *rmctx, RMPacket *pkt)
571 } 551 }
572 } 552 }
573 else if (rmctx->codec_type == CODEC_AAC) { 553 else if (rmctx->codec_type == CODEC_AAC) {
574 rmctx->sub_packet_cnt = (get_uint16be(*src) & 0xf0) >> 4; 554 rmctx->sub_packet_cnt = (rm_get_uint16be(*src) & 0xf0) >> 4;
575 advance_buffer(src, 2); 555 advance_buffer(src, 2);
576 consumed += 2; 556 consumed += 2;
577 if (rmctx->sub_packet_cnt) { 557 if (rmctx->sub_packet_cnt) {
578 for(x = 0; x < rmctx->sub_packet_cnt; x++) { 558 for(x = 0; x < rmctx->sub_packet_cnt; x++) {
579 rmctx->sub_packet_lengths[x] = get_uint16be(*src); 559 rmctx->sub_packet_lengths[x] = rm_get_uint16be(*src);
580 advance_buffer(src, 2); 560 advance_buffer(src, 2);
581 consumed += 2; 561 consumed += 2;
582 } 562 }
diff --git a/apps/codecs/librm/rm.h b/apps/codecs/librm/rm.h
index be88701989..c4a4e3a77e 100644
--- a/apps/codecs/librm/rm.h
+++ b/apps/codecs/librm/rm.h
@@ -23,6 +23,7 @@
23 23
24#include <stdio.h> 24#include <stdio.h>
25#include <inttypes.h> 25#include <inttypes.h>
26#include "bytestream.h"
26 27
27#define MAX_EXTRADATA_SIZE 16 28#define MAX_EXTRADATA_SIZE 16
28#define DATA_HEADER_SIZE 18 29#define DATA_HEADER_SIZE 18