xine-lib: xine-lib-1.2.12/src/input/libreal/rmff.h Source File

xine-lib 1.2.12

rmff.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2021 the xine project
3 *
4 * This file is part of xine, a free video player.
5 *
6 * xine is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * xine is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * some functions for real media file headers
21 * adopted from joschkas real tools
22 */
23
24#include <sys/types.h>
25#ifdef HAVE_SYS_SOCKET_H
26#include <sys/socket.h>
27#endif
28#ifdef HAVE_NETINET_IN_H
29#include <netinet/in.h>
30#endif
31#ifdef HAVE_NETDB_H
32#include <netdb.h>
33#endif
34#include <unistd.h>
35#include <stdio.h>
36#include <fcntl.h>
37#include <stdlib.h>
38#include <string.h>
39#include <inttypes.h>
40
41#ifndef HAVE_RMFF_H
42#define HAVE_RMFF_H
43
44#include <xine/attributes.h>
45
46#define RMFF_HEADER_SIZE 0x12
47
48#define RMFF_FILEHEADER_SIZE 18
49#define RMFF_PROPHEADER_SIZE 50
50#define RMFF_MDPRHEADER_SIZE 46
51#define RMFF_CONTHEADER_SIZE 18
52#define RMFF_DATAHEADER_SIZE 18
53
54#define FOURCC_TAG( ch0, ch1, ch2, ch3 ) \
55 (((long)(unsigned char)(ch3) ) | \
56 ( (long)(unsigned char)(ch2) << 8 ) | \
57 ( (long)(unsigned char)(ch1) << 16 ) | \
58 ( (long)(unsigned char)(ch0) << 24 ) )
59
60
61#define RMF_TAG FOURCC_TAG('.', 'R', 'M', 'F')
62#define PROP_TAG FOURCC_TAG('P', 'R', 'O', 'P')
63#define MDPR_TAG FOURCC_TAG('M', 'D', 'P', 'R')
64#define CONT_TAG FOURCC_TAG('C', 'O', 'N', 'T')
65#define DATA_TAG FOURCC_TAG('D', 'A', 'T', 'A')
66#define INDX_TAG FOURCC_TAG('I', 'N', 'D', 'X')
67#define PNA_TAG FOURCC_TAG('P', 'N', 'A', 0 )
68
69#define MLTI_TAG FOURCC_TAG('M', 'L', 'T', 'I')
70
71/* prop flags */
72#define PN_SAVE_ENABLED 0x01
73#define PN_PERFECT_PLAY_ENABLED 0x02
74#define PN_LIVE_BROADCAST 0x04
75
76/*
77 * rm header data structs
78 */
79
80 typedef struct {
81
82 uint32_t object_id;
83 uint32_t size;
84 uint16_t object_version;
85
86 uint32_t file_version;
87 uint32_t num_headers;
88} rmff_fileheader_t;
89
90 typedef struct {
91
92 uint32_t object_id;
93 uint32_t size;
94 uint16_t object_version;
95
96 uint32_t max_bit_rate;
97 uint32_t avg_bit_rate;
98 uint32_t max_packet_size;
99 uint32_t avg_packet_size;
100 uint32_t num_packets;
101 uint32_t duration;
102 uint32_t preroll;
103 uint32_t index_offset;
104 uint32_t data_offset;
105 uint16_t num_streams;
106 uint16_t flags;
107
108} rmff_prop_t;
109
110 typedef struct {
111
112 uint32_t object_id;
113 uint32_t size;
114 uint16_t object_version;
115
116 uint16_t stream_number;
117 uint32_t max_bit_rate;
118 uint32_t avg_bit_rate;
119 uint32_t max_packet_size;
120 uint32_t avg_packet_size;
121 uint32_t start_time;
122 uint32_t preroll;
123 uint32_t duration;
124 uint8_t stream_name_size;
125 char *stream_name;
126 uint8_t mime_type_size;
127 char *mime_type;
128 uint32_t type_specific_len;
129 char *type_specific_data;
130
131 int mlti_data_size;
132 char *mlti_data;
133
134} rmff_mdpr_t;
135
136 typedef struct {
137
138 uint32_t object_id;
139 uint32_t size;
140 uint16_t object_version;
141
142 uint16_t title_len;
143 char *title;
144 uint16_t author_len;
145 char *author;
146 uint16_t copyright_len;
147 char *copyright;
148 uint16_t comment_len;
149 char *comment;
150
151} rmff_cont_t;
152
153 typedef struct {
154
155 uint32_t object_id;
156 uint32_t size;
157 uint16_t object_version;
158
159 uint32_t num_packets;
160 uint32_t next_data_header; /* rarely used */
161} rmff_data_t;
162
163 typedef struct {
164
165 rmff_fileheader_t *fileheader;
166 rmff_prop_t *prop;
167 rmff_mdpr_t **streams;
168 rmff_cont_t *cont;
169 rmff_data_t *data;
170} rmff_header_t;
171
172 typedef struct {
173
174 uint16_t object_version;
175
176 uint16_t length;
177 uint16_t stream_number;
178 uint32_t timestamp;
179 uint8_t reserved;
180 uint8_t flags;
181
182} rmff_pheader_t;
183
184/*
185 * constructors for header structs
186 */
187
188 rmff_fileheader_t *rmff_new_fileheader(uint32_t num_headers);
189
190 rmff_prop_t *rmff_new_prop (
191 uint32_t max_bit_rate,
192 uint32_t avg_bit_rate,
193 uint32_t max_packet_size,
194 uint32_t avg_packet_size,
195 uint32_t num_packets,
196 uint32_t duration,
197 uint32_t preroll,
198 uint32_t index_offset,
199 uint32_t data_offset,
200 uint16_t num_streams,
201 uint16_t flags );
202
203 rmff_mdpr_t *rmff_new_mdpr(
204 uint16_t stream_number,
205 uint32_t max_bit_rate,
206 uint32_t avg_bit_rate,
207 uint32_t max_packet_size,
208 uint32_t avg_packet_size,
209 uint32_t start_time,
210 uint32_t preroll,
211 uint32_t duration,
212 const char *stream_name,
213 const char *mime_type,
214 uint32_t type_specific_len,
215 const char *type_specific_data );
216
217 rmff_cont_t *rmff_new_cont(
218 const char *title,
219 const char *author,
220 const char *copyright,
221 const char *comment);
222
223 rmff_data_t *rmff_new_dataheader(
224 uint32_t num_packets, uint32_t next_data_header);
225
226#if 0
227/*
228 * reads header infos from data and returns a newly allocated header struct
229 */
230 rmff_header_t *rmff_scan_header(const char *data) XINE_MALLOC;
231
232/*
233 * scans a data packet header. Notice, that this function does not allocate
234 * the header struct itself.
235 */
236void rmff_scan_pheader(rmff_pheader_t *h, char *data);
237
238/*
239 * reads header infos from stream and returns a newly allocated header struct
240 */
241 rmff_header_t *rmff_scan_header_stream(int fd) XINE_MALLOC;
242
243/*
244 * prints header information in human readible form to stdout
245 */
246void rmff_print_header(rmff_header_t *h);
247#endif
248
249/*
250 * does some checks and fixes header if possible
251 */
252void rmff_fix_header(rmff_header_t *h);
253
254#if 0
255/*
256 * returns the size of the header (incl. first data-header)
257 */
258int rmff_get_header_size(rmff_header_t *h);
259#endif
260
261/*
262 * dumps the header <h> to <buffer>. <max> is the size of <buffer>
263 */
264int rmff_dump_header(rmff_header_t *h, void *buffer, int max);
265
266/*
267 * dumps a packet header
268 */
269void rmff_dump_pheader(rmff_pheader_t *h, uint8_t *data);
270
271#if 0
272/*
273 * frees a header struct
274 */
275void rmff_free_header(rmff_header_t *h);
276#endif
277
278#endif
attributes.h
XINE_MALLOC
#define XINE_MALLOC
Definition: attributes.h:141
rmff_dump_header
int rmff_dump_header(rmff_header_t *h, void *buffer, int max)
Definition: rmff.c:243
rmff_new_cont
rmff_cont_t * rmff_new_cont(const char *title, const char *author, const char *copyright, const char *comment)
Definition: rmff.c:669
rmff_dump_pheader
void rmff_dump_pheader(rmff_pheader_t *h, uint8_t *data)
Definition: rmff.c:280
rmff_new_fileheader
rmff_fileheader_t * rmff_new_fileheader(uint32_t num_headers)
Definition: rmff.c:576
rmff_new_prop
rmff_prop_t * rmff_new_prop(uint32_t max_bit_rate, uint32_t avg_bit_rate, uint32_t max_packet_size, uint32_t avg_packet_size, uint32_t num_packets, uint32_t duration, uint32_t preroll, uint32_t index_offset, uint32_t data_offset, uint16_t num_streams, uint16_t flags)
Definition: rmff.c:589
rmff_fix_header
void rmff_fix_header(rmff_header_t *h)
Definition: rmff.c:789
rmff_new_dataheader
rmff_data_t * rmff_new_dataheader(uint32_t num_packets, uint32_t next_data_header)
Definition: rmff.c:707
rmff_new_mdpr
rmff_mdpr_t * rmff_new_mdpr(uint16_t stream_number, uint32_t max_bit_rate, uint32_t avg_bit_rate, uint32_t max_packet_size, uint32_t avg_packet_size, uint32_t start_time, uint32_t preroll, uint32_t duration, const char *stream_name, const char *mime_type, uint32_t type_specific_len, const char *type_specific_data)
Definition: rmff.c:623
rmff_cont_t
Definition: rmff.h:136
rmff_cont_t::comment_len
uint16_t comment_len
Definition: rmff.h:148
rmff_cont_t::comment
char * comment
Definition: rmff.h:149
rmff_cont_t::object_version
uint16_t object_version
Definition: rmff.h:140
rmff_cont_t::copyright_len
uint16_t copyright_len
Definition: rmff.h:146
rmff_cont_t::title_len
uint16_t title_len
Definition: rmff.h:142
rmff_cont_t::size
uint32_t size
Definition: rmff.h:139
rmff_cont_t::author
char * author
Definition: rmff.h:145
rmff_cont_t::title
char * title
Definition: rmff.h:143
rmff_cont_t::author_len
uint16_t author_len
Definition: rmff.h:144
rmff_cont_t::copyright
char * copyright
Definition: rmff.h:147
rmff_cont_t::object_id
uint32_t object_id
Definition: rmff.h:138
rmff_data_t
Definition: rmff.h:153
rmff_data_t::object_id
uint32_t object_id
Definition: rmff.h:155
rmff_data_t::object_version
uint16_t object_version
Definition: rmff.h:157
rmff_data_t::num_packets
uint32_t num_packets
Definition: rmff.h:159
rmff_data_t::size
uint32_t size
Definition: rmff.h:156
rmff_data_t::next_data_header
uint32_t next_data_header
Definition: rmff.h:160
rmff_fileheader_t
Definition: rmff.h:80
rmff_fileheader_t::object_version
uint16_t object_version
Definition: rmff.h:84
rmff_fileheader_t::file_version
uint32_t file_version
Definition: rmff.h:86
rmff_fileheader_t::size
uint32_t size
Definition: rmff.h:83
rmff_fileheader_t::num_headers
uint32_t num_headers
Definition: rmff.h:87
rmff_fileheader_t::object_id
uint32_t object_id
Definition: rmff.h:82
rmff_header_t
Definition: rmff.h:163
rmff_header_t::prop
rmff_prop_t * prop
Definition: rmff.h:166
rmff_header_t::streams
rmff_mdpr_t ** streams
Definition: rmff.h:167
rmff_header_t::data
rmff_data_t * data
Definition: rmff.h:169
rmff_header_t::cont
rmff_cont_t * cont
Definition: rmff.h:168
rmff_header_t::fileheader
rmff_fileheader_t * fileheader
Definition: rmff.h:165
rmff_mdpr_t
Definition: rmff.h:110
rmff_mdpr_t::object_version
uint16_t object_version
Definition: rmff.h:114
rmff_mdpr_t::avg_bit_rate
uint32_t avg_bit_rate
Definition: rmff.h:118
rmff_mdpr_t::max_packet_size
uint32_t max_packet_size
Definition: rmff.h:119
rmff_mdpr_t::avg_packet_size
uint32_t avg_packet_size
Definition: rmff.h:120
rmff_mdpr_t::duration
uint32_t duration
Definition: rmff.h:123
rmff_mdpr_t::max_bit_rate
uint32_t max_bit_rate
Definition: rmff.h:117
rmff_mdpr_t::stream_name
char * stream_name
Definition: rmff.h:125
rmff_mdpr_t::stream_number
uint16_t stream_number
Definition: rmff.h:116
rmff_mdpr_t::type_specific_data
char * type_specific_data
Definition: rmff.h:129
rmff_mdpr_t::size
uint32_t size
Definition: rmff.h:113
rmff_mdpr_t::start_time
uint32_t start_time
Definition: rmff.h:121
rmff_mdpr_t::mime_type
char * mime_type
Definition: rmff.h:127
rmff_mdpr_t::type_specific_len
uint32_t type_specific_len
Definition: rmff.h:128
rmff_mdpr_t::preroll
uint32_t preroll
Definition: rmff.h:122
rmff_mdpr_t::object_id
uint32_t object_id
Definition: rmff.h:112
rmff_mdpr_t::mime_type_size
uint8_t mime_type_size
Definition: rmff.h:126
rmff_mdpr_t::mlti_data
char * mlti_data
Definition: rmff.h:132
rmff_mdpr_t::mlti_data_size
int mlti_data_size
Definition: rmff.h:131
rmff_mdpr_t::stream_name_size
uint8_t stream_name_size
Definition: rmff.h:124
rmff_pheader_t
Definition: rmff.h:172
rmff_pheader_t::reserved
uint8_t reserved
Definition: rmff.h:179
rmff_pheader_t::length
uint16_t length
Definition: rmff.h:176
rmff_pheader_t::stream_number
uint16_t stream_number
Definition: rmff.h:177
rmff_pheader_t::object_version
uint16_t object_version
Definition: rmff.h:174
rmff_pheader_t::flags
uint8_t flags
Definition: rmff.h:180
rmff_pheader_t::timestamp
uint32_t timestamp
Definition: rmff.h:178
rmff_prop_t
Definition: rmff.h:90
rmff_prop_t::size
uint32_t size
Definition: rmff.h:93
rmff_prop_t::object_id
uint32_t object_id
Definition: rmff.h:92
rmff_prop_t::data_offset
uint32_t data_offset
Definition: rmff.h:104
rmff_prop_t::duration
uint32_t duration
Definition: rmff.h:101
rmff_prop_t::num_packets
uint32_t num_packets
Definition: rmff.h:100
rmff_prop_t::avg_packet_size
uint32_t avg_packet_size
Definition: rmff.h:99
rmff_prop_t::object_version
uint16_t object_version
Definition: rmff.h:94
rmff_prop_t::max_packet_size
uint32_t max_packet_size
Definition: rmff.h:98
rmff_prop_t::num_streams
uint16_t num_streams
Definition: rmff.h:105
rmff_prop_t::flags
uint16_t flags
Definition: rmff.h:106
rmff_prop_t::avg_bit_rate
uint32_t avg_bit_rate
Definition: rmff.h:97
rmff_prop_t::max_bit_rate
uint32_t max_bit_rate
Definition: rmff.h:96
rmff_prop_t::index_offset
uint32_t index_offset
Definition: rmff.h:103
rmff_prop_t::preroll
uint32_t preroll
Definition: rmff.h:102