2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 ** Any non-GPL usage of this software or parts of this software is strictly
22 ** Commercial non-GPL licensing of this software is possible.
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
25 ** $Id: mp4util.c,v 1.15 2004/01/11 15:52:19 menno Exp $
31 int32_t mp4ff_read_data(mp4ff_t
*f
, int8_t *data
, uint32_t size
)
35 result
= f
->stream
->read(f
->stream
->user_data
, data
, size
);
37 f
->current_position
+= size
;
42 int32_t mp4ff_truncate(mp4ff_t
* f
)
44 return f
->stream
->truncate(f
->stream
->user_data
);
47 int32_t mp4ff_write_data(mp4ff_t
*f
, int8_t *data
, uint32_t size
)
51 result
= f
->stream
->write(f
->stream
->user_data
, data
, size
);
53 f
->current_position
+= size
;
58 int32_t mp4ff_write_int32(mp4ff_t
*f
,const uint32_t data
)
64 *(uint32_t*)temp
= data
;
70 result
= (a
<<24) | (b
<<16) | (c
<<8) | d
;
72 return mp4ff_write_data(f
,(uint8_t*)&result
,sizeof(result
));
75 int32_t mp4ff_set_position(mp4ff_t
*f
, const int64_t position
)
77 f
->stream
->seek(f
->stream
->user_data
, position
);
78 f
->current_position
= position
;
83 int64_t mp4ff_position(const mp4ff_t
*f
)
85 return f
->current_position
;
88 uint64_t mp4ff_read_int64(mp4ff_t
*f
)
94 mp4ff_read_data(f
, data
, 8);
96 for (i
= 0; i
< 8; i
++)
98 result
|= ((uint64_t)data
[i
]) << ((7 - i
) * 8);
104 uint32_t mp4ff_read_int32(mp4ff_t
*f
)
110 mp4ff_read_data(f
, data
, 4);
111 a
= (uint8_t)data
[0];
112 b
= (uint8_t)data
[1];
113 c
= (uint8_t)data
[2];
114 d
= (uint8_t)data
[3];
116 result
= (a
<<24) | (b
<<16) | (c
<<8) | d
;
117 return (uint32_t)result
;
120 uint32_t mp4ff_read_int24(mp4ff_t
*f
)
126 mp4ff_read_data(f
, data
, 3);
127 a
= (uint8_t)data
[0];
128 b
= (uint8_t)data
[1];
129 c
= (uint8_t)data
[2];
131 result
= (a
<<16) | (b
<<8) | c
;
132 return (uint32_t)result
;
135 uint16_t mp4ff_read_int16(mp4ff_t
*f
)
141 mp4ff_read_data(f
, data
, 2);
142 a
= (uint8_t)data
[0];
143 b
= (uint8_t)data
[1];
146 return (uint16_t)result
;
149 char * mp4ff_read_string(mp4ff_t
* f
,uint32_t length
)
151 char * str
= (char*)malloc(length
+ 1);
154 if ((uint32_t)mp4ff_read_data(f
,str
,length
)!=length
)
167 uint8_t mp4ff_read_char(mp4ff_t
*f
)
170 mp4ff_read_data(f
, &output
, 1);
174 uint32_t mp4ff_read_mp4_descr_length(mp4ff_t
*f
)
177 uint8_t numBytes
= 0;
182 b
= mp4ff_read_char(f
);
184 length
= (length
<< 7) | (b
& 0x7F);
185 } while ((b
& 0x80) && numBytes
< 4);