vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / media / plugins / asf_reader / libasf / asfint.h
blob99031ddffb9d7e06f2244bee25d838ae701e377b
1 /* libasf - An Advanced Systems Format media file parser
2 * Copyright (C) 2006-2010 Juho Vähä-Herttua
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.
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.
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
19 #ifndef ASFINT_H
20 #define ASFINT_H
22 #include <string.h>
24 #include "asf.h"
25 #include "guid.h"
26 #include "compat.h"
28 static INLINE void
29 GetGUID(const void *pointer, asf_guid_t *guid)
31 const uint8_t *data = pointer;
32 guid->v1 = GetDWLE(data);
33 guid->v2 = GetWLE(data + 4);
34 guid->v3 = GetWLE(data + 6);
35 memcpy(guid->v4, data + 8, 8);
38 #define GETLEN2b(bits) (((bits) == 0x03) ? 4 : bits)
39 #define GETVALUE2b(bits, data) \
40 (((bits) != 0x03) ? ((bits) != 0x02) ? ((bits) != 0x01) ? \
41 0 : *((uint8_t *)data) : GetWLE(data) : GetDWLE(data))
45 /* DO NOT MODIFY THE FIRST 3 VARIABLES, BECAUSE THEY ARE
46 * ALSO DEFINED IN asf.h HEADER AND WILL BREAK THINGS */
47 #define ASF_OBJECT_COMMON \
48 asf_guid_t guid; \
49 uint64_t size; \
50 uint8_t *full_data; \
51 uint64_t datalen; \
52 uint8_t *data; \
53 guid_type_t type; \
54 struct asfint_object_s *next;
56 struct asfint_object_s {
57 ASF_OBJECT_COMMON
59 typedef struct asfint_object_s asfint_object_t;
61 struct asf_object_headerext_s {
62 ASF_OBJECT_COMMON
63 asf_guid_t reserved1;
64 uint16_t reserved2;
65 struct asfint_object_s *first;
66 struct asfint_object_s *last;
68 typedef struct asf_object_headerext_s asf_object_headerext_t;
70 struct asf_object_header_s {
71 ASF_OBJECT_COMMON
72 uint16_t subobjects;
73 uint8_t reserved1; /* 0x01, but could be safely ignored */
74 uint8_t reserved2; /* 0x02, if not must failed to source the contain */
75 asf_object_headerext_t *ext; /* this is here just for convenience */
76 struct asfint_object_s *first;
77 struct asfint_object_s *last;
79 typedef struct asf_object_header_s asf_object_header_t;
81 struct asf_object_data_s {
82 ASF_OBJECT_COMMON
83 asf_guid_t file_id;
84 uint64_t total_data_packets;
85 uint16_t reserved;
86 uint64_t packets_position;
88 typedef struct asf_object_data_s asf_object_data_t;
90 struct asf_index_entry_s {
91 uint32_t packet_index;
92 uint16_t packet_count;
94 typedef struct asf_index_entry_s asf_index_entry_t;
96 struct asf_object_index_s {
97 ASF_OBJECT_COMMON
98 asf_guid_t file_id;
99 uint64_t entry_time_interval;
100 uint32_t max_packet_count;
101 uint32_t entry_count;
102 asf_index_entry_t *entries;
104 typedef struct asf_object_index_s asf_object_index_t;
106 #define ASF_FLAG_BROADCAST 1
107 #define ASF_FLAG_SEEKABLE 2
109 #define ASF_MAX_STREAMS 128
111 struct asf_file_s {
112 const char *filename;
113 asf_iostream_t iostream;
115 uint64_t position;
116 uint64_t packet;
118 /* Top level objects */
119 struct asf_object_header_s *header;
120 struct asf_object_data_s *data;
121 struct asf_object_index_s *index;
123 /* position (in bytes) of data and index objects */
124 uint64_t data_position;
125 uint64_t index_position;
127 asf_guid_t file_id;
128 uint64_t file_size;
129 uint64_t creation_date;
130 uint64_t data_packets_count;
131 uint64_t play_duration;
132 uint64_t send_duration;
133 uint64_t preroll;
134 uint16_t flags;
135 uint32_t packet_size;
136 uint32_t max_bitrate;
138 asf_stream_t streams[ASF_MAX_STREAMS];
141 #endif