xine-lib  1.2.10
rmff.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2017 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;
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;
125  char *stream_name;
126  uint8_t mime_type_size;
127  char *mime_type;
130 
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 
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 
183 
184 /*
185  * constructors for header structs
186  */
187 
188 rmff_fileheader_t *rmff_new_fileheader(uint32_t num_headers);
189 
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 
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 
218  const char *title,
219  const char *author,
220  const char *copyright,
221  const char *comment);
222 
224  uint32_t num_packets, uint32_t next_data_header);
225 
226 /*
227  * reads header infos from data and returns a newly allocated header struct
228  */
229 rmff_header_t *rmff_scan_header(const char *data) XINE_MALLOC;
230 
231 #if 0
232 /*
233  * scans a data packet header. Notice, that this function does not allocate
234  * the header struct itself.
235  */
236 void 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  */
246 void rmff_print_header(rmff_header_t *h);
247 #endif
248 
249 /*
250  * does some checks and fixes header if possible
251  */
253 
254 #if 0
255 /*
256  * returns the size of the header (incl. first data-header)
257  */
258 int 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  */
264 int rmff_dump_header(rmff_header_t *h, void *buffer, int max);
265 
266 /*
267  * dumps a packet header
268  */
269 void rmff_dump_pheader(rmff_pheader_t *h, uint8_t *data);
270 
271 #if 0
272 /*
273  * frees a header struct
274  */
275 void rmff_free_header(rmff_header_t *h);
276 #endif
277 
278 #endif
rmff_header_t::cont
rmff_cont_t * cont
Definition: rmff.h:168
rmff_prop_t::index_offset
uint32_t index_offset
Definition: rmff.h:103
rmff_dump_mdpr
static int rmff_dump_mdpr(rmff_mdpr_t *mdpr, uint8_t *buffer, int bufsize)
Definition: rmff.c:114
rmff_mdpr_t::avg_packet_size
uint32_t avg_packet_size
Definition: rmff.h:120
rmff_new_cont
rmff_cont_t * rmff_new_cont(const char *title, const char *author, const char *copyright, const char *comment)
Definition: rmff.c:651
RMF_TAG
#define RMF_TAG
Definition: rmff.h:61
XINE_MALLOC
#define XINE_MALLOC
Definition: attributes.h:139
rmff_mdpr_t::start_time
uint32_t start_time
Definition: rmff.h:121
xine_buffer_free
#define xine_buffer_free(buf)
Definition: xine_buffer.c:149
xineutils.h
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:571
rmff_mdpr_t::preroll
uint32_t preroll
Definition: rmff.h:122
RMFF_PROPHEADER_SIZE
#define RMFF_PROPHEADER_SIZE
Definition: rmff.h:49
rmff_cont_t::object_version
uint16_t object_version
Definition: rmff.h:140
rmff_prop_t::object_id
uint32_t object_id
Definition: rmff.h:92
CONT_TAG
#define CONT_TAG
Definition: demux_real.c:70
xine_buffer_ensure_size
#define xine_buffer_ensure_size(buf, data)
Definition: xine_buffer.c:332
rmff_cont_t::object_id
uint32_t object_id
Definition: rmff.h:138
rmff_scan_header
rmff_header_t * rmff_scan_header(const char *data)
Definition: rmff.c:437
rmff_prop_t::size
uint32_t size
Definition: rmff.h:93
RMFF_MDPRHEADER_SIZE
#define RMFF_MDPRHEADER_SIZE
Definition: rmff.h:50
rmff_prop_t
Definition: rmff.h:90
rmff_prop_t::object_version
uint16_t object_version
Definition: rmff.h:94
xine_memdup0
void * xine_memdup0(const void *src, size_t length)
Definition: utils.c:317
rmff_header_t
Definition: rmff.h:163
rmff_prop_t::num_packets
uint32_t num_packets
Definition: rmff.h:100
rmff_fileheader_t
Definition: rmff.h:80
rmff_cont_t::author_len
uint16_t author_len
Definition: rmff.h:144
rmff_fileheader_t::object_id
uint32_t object_id
Definition: rmff.h:82
rmff_mdpr_t::mlti_data_size
int mlti_data_size
Definition: rmff.h:131
rmff_pheader_t::object_version
uint16_t object_version
Definition: rmff.h:174
rmff_dump_header
int rmff_dump_header(rmff_header_t *h, void *buf_gen, 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:651
rmff_fileheader_t::num_headers
uint32_t num_headers
Definition: rmff.h:87
rmff_scan_mdpr
static rmff_mdpr_t * rmff_scan_mdpr(const char *data)
Definition: rmff.c:339
rmff_mdpr_t::max_bit_rate
uint32_t max_bit_rate
Definition: rmff.h:117
rmff_mdpr_t::max_packet_size
uint32_t max_packet_size
Definition: rmff.h:119
rmff_data_t::object_id
uint32_t object_id
Definition: rmff.h:155
rmff_prop_t::max_bit_rate
uint32_t max_bit_rate
Definition: rmff.h:96
rmff_pheader_t::flags
uint8_t flags
Definition: rmff.h:180
lprintf
#define lprintf(...)
Definition: xineutils.h:620
rmff_mdpr_t::duration
uint32_t duration
Definition: rmff.h:123
RMFF_FILEHEADER_SIZE
#define RMFF_FILEHEADER_SIZE
Definition: rmff.h:48
PN_SAVE_ENABLED
#define PN_SAVE_ENABLED
Definition: rmff.h:72
rmff_mdpr_t::mime_type_size
uint8_t mime_type_size
Definition: rmff.h:126
attributes.h
rmff_cont_t::comment
char * comment
Definition: rmff.h:149
rmff_mdpr_t::avg_bit_rate
uint32_t avg_bit_rate
Definition: rmff.h:118
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:605
_X_BE_16
#define _X_BE_16(x)
Definition: bswap.h:40
rmff_cont_t::copyright
char * copyright
Definition: rmff.h:147
rmff_mdpr_t
Definition: rmff.h:110
rmff_header_t::prop
rmff_prop_t * prop
Definition: rmff.h:166
NULL
NULL
Definition: xine_plugin.c:78
rmff_new_dataheader
rmff_data_t * rmff_new_dataheader(uint32_t num_packets, uint32_t next_data_header)
Definition: rmff.c:689
rmff_prop_t::avg_bit_rate
uint32_t avg_bit_rate
Definition: rmff.h:97
RMFF_DATAHEADER_SIZE
#define RMFF_DATAHEADER_SIZE
Definition: rmff.h:52
rmff_scan_fileheader
static rmff_fileheader_t * rmff_scan_fileheader(const char *data)
Definition: rmff.c:296
rmff_pheader_t::reserved
uint8_t reserved
Definition: rmff.h:179
rmff_prop_t::duration
uint32_t duration
Definition: rmff.h:101
RMFF_CONTHEADER_SIZE
#define RMFF_CONTHEADER_SIZE
Definition: rmff.h:51
rmff_cont_t::author
char * author
Definition: rmff.h:145
rmff_cont_t::size
uint32_t size
Definition: rmff.h:139
rmff_new_dataheader
rmff_data_t * rmff_new_dataheader(uint32_t num_packets, uint32_t next_data_header)
Definition: rmff.c:689
rmff_data_t::num_packets
uint32_t num_packets
Definition: rmff.h:159
rmff_fileheader_t::object_version
uint16_t object_version
Definition: rmff.h:84
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:571
rmff_prop_t::max_packet_size
uint32_t max_packet_size
Definition: rmff.h:98
xine_hexdump
void xine_hexdump(const void *buf_gen, int length)
Definition: utils.c:576
rmff_new_fileheader
rmff_fileheader_t * rmff_new_fileheader(uint32_t num_headers)
Definition: rmff.c:558
rmff_cont_t::copyright_len
uint16_t copyright_len
Definition: rmff.h:146
PN_PERFECT_PLAY_ENABLED
#define PN_PERFECT_PLAY_ENABLED
Definition: rmff.h:73
xine_memdup
void * xine_memdup(const void *src, size_t length)
Definition: utils.c:308
rmff_pheader_t::stream_number
uint16_t stream_number
Definition: rmff.h:177
rmff_prop_t::flags
uint16_t flags
Definition: rmff.h:106
rmff_mdpr_t::object_id
uint32_t object_id
Definition: rmff.h:112
rmff_new_fileheader
rmff_fileheader_t * rmff_new_fileheader(uint32_t num_headers)
Definition: rmff.c:558
rmff_data_t::size
uint32_t size
Definition: rmff.h:156
rmff_mdpr_t::type_specific_len
uint32_t type_specific_len
Definition: rmff.h:128
rmff_cont_t::comment_len
uint16_t comment_len
Definition: rmff.h:148
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:605
rmff_scan_dataheader
static rmff_data_t * rmff_scan_dataheader(const char *data)
Definition: rmff.c:420
rmff_dump_header
int rmff_dump_header(rmff_header_t *h, void *buffer, int max)
Definition: rmff.c:243
rmff_fix_header
void rmff_fix_header(rmff_header_t *h)
Definition: rmff.c:771
rmff_data_t
Definition: rmff.h:153
DATA_TAG
#define DATA_TAG
Definition: demux_ac3.c:57
rmff_mdpr_t::stream_name
char * stream_name
Definition: rmff.h:125
MDPR_TAG
#define MDPR_TAG
Definition: demux_real.c:69
PN_LIVE_BROADCAST
#define PN_LIVE_BROADCAST
Definition: rmff.h:74
rmff_mdpr_t::mlti_data
char * mlti_data
Definition: rmff.h:132
rmff_mdpr_t::stream_name_size
uint8_t stream_name_size
Definition: rmff.h:124
rmff_cont_t
Definition: rmff.h:136
rmff_mdpr_t::object_version
uint16_t object_version
Definition: rmff.h:114
rmff_dump_prop
static int rmff_dump_prop(rmff_prop_t *prop, uint8_t *buffer, int bufsize)
Definition: rmff.c:68
rmff_mdpr_t::size
uint32_t size
Definition: rmff.h:113
rmff_dump_fileheader
static int rmff_dump_fileheader(rmff_fileheader_t *fileheader, uint8_t *buffer, int bufsize)
Definition: rmff.c:42
rmff_data_t::object_version
uint16_t object_version
Definition: rmff.h:157
rmff_scan_header
rmff_header_t * rmff_scan_header(const char *data)
Definition: rmff.c:437
rmff_header_t::fileheader
rmff_fileheader_t * fileheader
Definition: rmff.h:165
rmff_dump_dataheader
static int rmff_dump_dataheader(rmff_data_t *data, uint8_t *buffer, int bufsize)
Definition: rmff.c:217
rmff_mdpr_t::mime_type
char * mime_type
Definition: rmff.h:127
rmff_cont_t::title
char * title
Definition: rmff.h:143
bswap.h
rmff_dump_pheader
void rmff_dump_pheader(rmff_pheader_t *h, uint8_t *data)
Definition: rmff.c:280
rmff_dump_cont
static int rmff_dump_cont(rmff_cont_t *cont, uint8_t *buffer, int bufsize)
Definition: rmff.c:169
rmff_pheader_t::timestamp
uint32_t timestamp
Definition: rmff.h:178
_X_BE_32
#define _X_BE_32(x)
Definition: bswap.h:45
rmff_prop_t::num_streams
uint16_t num_streams
Definition: rmff.h:105
config.h
rmff_dump_pheader
void rmff_dump_pheader(rmff_pheader_t *h, uint8_t *data)
Definition: rmff.c:280
rmff_data_t::next_data_header
uint32_t next_data_header
Definition: rmff.h:160
rmff_scan_prop
static rmff_prop_t * rmff_scan_prop(const char *data)
Definition: rmff.c:313
rmff_fix_header
void rmff_fix_header(rmff_header_t *h)
Definition: rmff.c:771
PROP_TAG
#define PROP_TAG
Definition: demux_real.c:68
rmff_prop_t::data_offset
uint32_t data_offset
Definition: rmff.h:104
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_mdpr_t::type_specific_data
char * type_specific_data
Definition: rmff.h:129
rmff.h
rmff_mdpr_t::stream_number
uint16_t stream_number
Definition: rmff.h:116
xine_buffer_init
void * xine_buffer_init(int chunk_size)
Definition: xine_buffer.c:129
rmff_prop_t::avg_packet_size
uint32_t avg_packet_size
Definition: rmff.h:99
rmff_pheader_t::length
uint16_t length
Definition: rmff.h:176
rmff_pheader_t
Definition: rmff.h:172
rmff_prop_t::preroll
uint32_t preroll
Definition: rmff.h:102
rmff_fileheader_t::file_version
uint32_t file_version
Definition: rmff.h:86
rmff_cont_t::title_len
uint16_t title_len
Definition: rmff.h:142
rmff_scan_cont
static rmff_cont_t * rmff_scan_cont(const char *data)
Definition: rmff.c:392
rmff_fileheader_t::size
uint32_t size
Definition: rmff.h:83