~ubuntu-dev/ubuntu/lucid/mpd/lucid-201002101854

« back to all changes in this revision

Viewing changes to src/mp4ff/mp4util.c

  • Committer: Bazaar Package Importer
  • Author(s): Charles Majola
  • Date: 2005-02-15 10:43:58 UTC
  • Revision ID: james.westby@ubuntu.com-20050215104358-w8b7yaqqfmsoxj5k
Tags: upstream-0.11.5
ImportĀ upstreamĀ versionĀ 0.11.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
 
3
** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
 
4
**
 
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.
 
9
**
 
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.
 
14
**
 
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.
 
18
**
 
19
** Any non-GPL usage of this software or parts of this software is strictly
 
20
** forbidden.
 
21
**
 
22
** Commercial non-GPL licensing of this software is possible.
 
23
** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 
24
**
 
25
** $Id: mp4util.c,v 1.15 2004/01/11 15:52:19 menno Exp $
 
26
**/
 
27
 
 
28
#include "mp4ffint.h"
 
29
#include <stdlib.h>
 
30
 
 
31
int32_t mp4ff_read_data(mp4ff_t *f, int8_t *data, uint32_t size)
 
32
{
 
33
    int32_t result = 1;
 
34
 
 
35
    result = f->stream->read(f->stream->user_data, data, size);
 
36
 
 
37
    f->current_position += size;
 
38
 
 
39
    return result;
 
40
}
 
41
 
 
42
int32_t mp4ff_truncate(mp4ff_t * f)
 
43
{
 
44
        return f->stream->truncate(f->stream->user_data);
 
45
}
 
46
 
 
47
int32_t mp4ff_write_data(mp4ff_t *f, int8_t *data, uint32_t size)
 
48
{
 
49
    int32_t result = 1;
 
50
 
 
51
    result = f->stream->write(f->stream->user_data, data, size);
 
52
 
 
53
    f->current_position += size;
 
54
 
 
55
    return result;
 
56
}
 
57
 
 
58
int32_t mp4ff_write_int32(mp4ff_t *f,const uint32_t data)
 
59
{
 
60
        uint32_t result;
 
61
    uint32_t a, b, c, d;
 
62
    int8_t temp[4];
 
63
    
 
64
    *(uint32_t*)temp = data;
 
65
    a = (uint8_t)temp[0];
 
66
    b = (uint8_t)temp[1];
 
67
    c = (uint8_t)temp[2];
 
68
    d = (uint8_t)temp[3];
 
69
 
 
70
    result = (a<<24) | (b<<16) | (c<<8) | d;
 
71
 
 
72
    return mp4ff_write_data(f,(uint8_t*)&result,sizeof(result));
 
73
}
 
74
 
 
75
int32_t mp4ff_set_position(mp4ff_t *f, const int64_t position)
 
76
{
 
77
    f->stream->seek(f->stream->user_data, position);
 
78
    f->current_position = position;
 
79
 
 
80
    return 0;
 
81
}
 
82
 
 
83
int64_t mp4ff_position(const mp4ff_t *f)
 
84
{
 
85
    return f->current_position;
 
86
}
 
87
 
 
88
uint64_t mp4ff_read_int64(mp4ff_t *f)
 
89
{
 
90
    uint8_t data[8];
 
91
    uint64_t result = 0;
 
92
    int8_t i;
 
93
 
 
94
    mp4ff_read_data(f, data, 8);
 
95
 
 
96
    for (i = 0; i < 8; i++)
 
97
    {
 
98
        result |= ((uint64_t)data[i]) << ((7 - i) * 8);
 
99
    }
 
100
 
 
101
    return result;
 
102
}
 
103
 
 
104
uint32_t mp4ff_read_int32(mp4ff_t *f)
 
105
{
 
106
    uint32_t result;
 
107
    uint32_t a, b, c, d;
 
108
    int8_t data[4];
 
109
    
 
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];
 
115
 
 
116
    result = (a<<24) | (b<<16) | (c<<8) | d;
 
117
    return (uint32_t)result;
 
118
}
 
119
 
 
120
uint32_t mp4ff_read_int24(mp4ff_t *f)
 
121
{
 
122
    uint32_t result;
 
123
    uint32_t a, b, c;
 
124
    int8_t data[4];
 
125
    
 
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];
 
130
 
 
131
    result = (a<<16) | (b<<8) | c;
 
132
    return (uint32_t)result;
 
133
}
 
134
 
 
135
uint16_t mp4ff_read_int16(mp4ff_t *f)
 
136
{
 
137
    uint32_t result;
 
138
    uint32_t a, b;
 
139
    int8_t data[2];
 
140
    
 
141
    mp4ff_read_data(f, data, 2);
 
142
    a = (uint8_t)data[0];
 
143
    b = (uint8_t)data[1];
 
144
 
 
145
    result = (a<<8) | b;
 
146
    return (uint16_t)result;
 
147
}
 
148
 
 
149
char * mp4ff_read_string(mp4ff_t * f,uint32_t length)
 
150
{
 
151
        char * str = (char*)malloc(length + 1);
 
152
        if (str!=0)
 
153
        {
 
154
                if ((uint32_t)mp4ff_read_data(f,str,length)!=length)
 
155
                {
 
156
                        free(str);
 
157
                        str = 0;
 
158
                }
 
159
                else
 
160
                {
 
161
                        str[length] = 0;
 
162
                }
 
163
        }
 
164
        return str;     
 
165
}
 
166
 
 
167
uint8_t mp4ff_read_char(mp4ff_t *f)
 
168
{
 
169
    uint8_t output;
 
170
    mp4ff_read_data(f, &output, 1);
 
171
    return output;
 
172
}
 
173
 
 
174
uint32_t mp4ff_read_mp4_descr_length(mp4ff_t *f)
 
175
{
 
176
    uint8_t b;
 
177
    uint8_t numBytes = 0;
 
178
    uint32_t length = 0;
 
179
 
 
180
    do
 
181
    {
 
182
        b = mp4ff_read_char(f);
 
183
        numBytes++;
 
184
        length = (length << 7) | (b & 0x7F);
 
185
    } while ((b & 0x80) && numBytes < 4);
 
186
 
 
187
    return length;
 
188
}