~ubuntu-branches/ubuntu/wily/xmms2/wily

« back to all changes in this revision

Viewing changes to src/plugins/asf/libasf/byteio.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2008-05-29 10:14:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080529101425-ycw1nbd980uhvzfp
Tags: 0.4DrKosmos-4ubuntu1
* Merge from debian unstable (LP: #178477), remaining changes:
  - debian/control: Update Maintainer field
  - debian/control: add lpia to xmms2-plugin-alsa supported architectures
* This version reads AAC files (LP: #156359)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  libasf - An Advanced Systems Format media file parser
 
2
 *  Copyright (C) 2006-2007 Juho Vähä-Herttua
 
3
 *
 
4
 *  This library is free software; you can redistribute it and/or
 
5
 *  modify it under the terms of the GNU Lesser General Public
 
6
 *  License as published by the Free Software Foundation; either
 
7
 *  version 2.1 of the License, or (at your option) any later version.
 
8
 *
 
9
 *  This library is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
12
 *  Lesser General Public License for more details.
 
13
 *
 
14
 *  You should have received a copy of the GNU Lesser General Public
 
15
 *  License along with this library; if not, write to the Free Software
 
16
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 */
 
18
 
 
19
#include <string.h>
 
20
#include "byteio.h"
 
21
 
 
22
uint16_t
 
23
asf_byteio_getWLE(uint8_t *data)
 
24
{
 
25
        uint16_t ret;
 
26
        int i;
 
27
 
 
28
        for (i=1, ret=0; i>=0; i--) {
 
29
                ret <<= 8;
 
30
                ret |= data[i];
 
31
        }
 
32
 
 
33
        return ret;
 
34
}
 
35
 
 
36
uint32_t
 
37
asf_byteio_getDWLE(uint8_t *data)
 
38
{
 
39
        uint32_t ret;
 
40
        int i;
 
41
 
 
42
        for (i=3, ret=0; i>=0; i--) {
 
43
                ret <<= 8;
 
44
                ret |= data[i];
 
45
        }
 
46
 
 
47
        return ret;
 
48
}
 
49
 
 
50
uint64_t
 
51
asf_byteio_getQWLE(uint8_t *data)
 
52
{
 
53
        uint64_t ret;
 
54
        int i;
 
55
 
 
56
        for (i=7, ret=0; i>=0; i--) {
 
57
                ret <<= 8;
 
58
                ret |= data[i];
 
59
        }
 
60
 
 
61
        return ret;
 
62
}
 
63
 
 
64
void
 
65
asf_byteio_getGUID(guid_t *guid, uint8_t *data)
 
66
{
 
67
        guid->v1 = asf_byteio_getDWLE(data);
 
68
        guid->v2 = asf_byteio_getWLE(data + 4);
 
69
        guid->v3 = asf_byteio_getWLE(data + 6);
 
70
        memcpy(guid->v4, data + 8, 8);
 
71
}
 
72
 
 
73
void
 
74
asf_byteio_get_string(uint16_t *string, uint16_t strlen, uint8_t *data)
 
75
{
 
76
        int i;
 
77
 
 
78
        for (i=0; i<strlen; i++) {
 
79
                string[i] = asf_byteio_getWLE(data + i*2);
 
80
        }
 
81
}
 
82
 
 
83
int
 
84
asf_byteio_readbyte(asf_stream_t *stream)
 
85
{
 
86
        uint8_t byte;
 
87
        int ret;
 
88
 
 
89
        if ((ret = asf_byteio_read(&byte, 1, stream)) <= 0) {
 
90
                return (ret == 0) ? ASF_ERROR_EOF : ASF_ERROR_IO;
 
91
        }
 
92
 
 
93
        return byte;
 
94
}
 
95
 
 
96
int
 
97
asf_byteio_read(uint8_t *data, int size, asf_stream_t *stream)
 
98
{
 
99
        int read = 0, tmp;
 
100
 
 
101
        if (!stream->read) {
 
102
                return ASF_ERROR_INTERNAL;
 
103
        }
 
104
 
 
105
        while ((tmp = stream->read(stream->opaque, data+read, size-read)) > 0) {
 
106
                read += tmp;
 
107
 
 
108
                if (read == size) {
 
109
                        return read;
 
110
                }
 
111
        }
 
112
 
 
113
        return (tmp == 0) ? ASF_ERROR_EOF : ASF_ERROR_IO;
 
114
}
 
115