]> git.sesse.net Git - vlc/blob - modules/access/rtsp/real_rmff.h
f1c23d9bcea3c274d1685465b8e5cacc6d1e36db
[vlc] / modules / access / rtsp / real_rmff.h
1 /*
2  * Copyright (C) 2002-2003 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
19  *
20  * $Id: rmff.h,v 1.5 2004/04/06 19:20:16 valtri Exp $
21  *
22  * some functions for real media file headers
23  * adopted from joschkas real tools
24  */
25
26 #ifndef HAVE_RMFF_H
27 #define HAVE_RMFF_H
28
29
30 #define RMFF_HEADER_SIZE 0x12
31
32 #define FOURCC_TAG( ch0, ch1, ch2, ch3 ) \
33         (((long)(unsigned char)(ch3)       ) | \
34         ( (long)(unsigned char)(ch2) << 8  ) | \
35         ( (long)(unsigned char)(ch1) << 16 ) | \
36         ( (long)(unsigned char)(ch0) << 24 ) )
37
38
39 #define RMF_TAG   FOURCC_TAG('.', 'R', 'M', 'F')
40 #define PROP_TAG  FOURCC_TAG('P', 'R', 'O', 'P')
41 #define MDPR_TAG  FOURCC_TAG('M', 'D', 'P', 'R')
42 #define CONT_TAG  FOURCC_TAG('C', 'O', 'N', 'T')
43 #define DATA_TAG  FOURCC_TAG('D', 'A', 'T', 'A')
44 #define INDX_TAG  FOURCC_TAG('I', 'N', 'D', 'X')
45 #define PNA_TAG   FOURCC_TAG('P', 'N', 'A',  0 )
46
47 #define MLTI_TAG  FOURCC_TAG('M', 'L', 'T', 'I')
48
49 /* prop flags */
50 #define PN_SAVE_ENABLED         0x01
51 #define PN_PERFECT_PLAY_ENABLED 0x02
52 #define PN_LIVE_BROADCAST       0x04
53
54 /*
55  * rm header data structs
56  */
57
58 typedef struct {
59
60   uint32_t object_id;
61   uint32_t size;
62   uint16_t object_version;
63
64   uint32_t file_version;
65   uint32_t num_headers;
66 } rmff_fileheader_t;
67
68 typedef struct {
69
70   uint32_t object_id;
71   uint32_t size;
72   uint16_t object_version;
73
74   uint32_t max_bit_rate;
75   uint32_t avg_bit_rate;
76   uint32_t max_packet_size;
77   uint32_t avg_packet_size;
78   uint32_t num_packets;
79   uint32_t duration;
80   uint32_t preroll;
81   uint32_t index_offset;
82   uint32_t data_offset;
83   uint16_t num_streams;
84   uint16_t flags;
85 } rmff_prop_t;
86
87 typedef struct {
88
89   uint32_t  object_id;
90   uint32_t  size;
91   uint16_t  object_version;
92
93   uint16_t  stream_number;
94   uint32_t  max_bit_rate;
95   uint32_t  avg_bit_rate;
96   uint32_t  max_packet_size;
97   uint32_t  avg_packet_size;
98   uint32_t  start_time;
99   uint32_t  preroll;
100   uint32_t  duration;
101   uint8_t   stream_name_size;
102   char      *stream_name;
103   uint8_t   mime_type_size;
104   char      *mime_type;
105   uint32_t  type_specific_len;
106   char      *type_specific_data;
107
108   int       mlti_data_size;
109   char      *mlti_data;
110
111 } rmff_mdpr_t;
112
113 typedef struct {
114
115   uint32_t  object_id;
116   uint32_t  size;
117   uint16_t  object_version;
118
119   uint16_t  title_len;
120   char      *title;
121   uint16_t  author_len;
122   char      *author;
123   uint16_t  copyright_len;
124   char      *copyright;
125   uint16_t  comment_len;
126   char      *comment;
127
128 } rmff_cont_t;
129
130 typedef struct {
131
132   uint32_t object_id;
133   uint32_t size;
134   uint16_t object_version;
135
136   uint32_t num_packets;
137   uint32_t next_data_header; /* rarely used */
138 } rmff_data_t;
139
140 typedef struct {
141
142   rmff_fileheader_t *fileheader;
143   rmff_prop_t *prop;
144   rmff_mdpr_t **streams;
145   rmff_cont_t *cont;
146   rmff_data_t *data;
147 } rmff_header_t;
148
149 typedef struct {
150
151   uint16_t object_version;
152
153   uint16_t length;
154   uint16_t stream_number;
155   uint32_t timestamp;
156   uint8_t reserved;
157   uint8_t flags;
158
159 } rmff_pheader_t;
160
161 /*
162  * constructors for header structs
163  */
164
165 rmff_fileheader_t *rmff_new_fileheader(uint32_t num_headers);
166
167 rmff_prop_t *rmff_new_prop (
168     uint32_t max_bit_rate,
169     uint32_t avg_bit_rate,
170     uint32_t max_packet_size,
171     uint32_t avg_packet_size,
172     uint32_t num_packets,
173     uint32_t duration,
174     uint32_t preroll,
175     uint32_t index_offset,
176     uint32_t data_offset,
177     uint16_t num_streams,
178     uint16_t flags );
179
180 rmff_mdpr_t *rmff_new_mdpr(
181     uint16_t   stream_number,
182     uint32_t   max_bit_rate,
183     uint32_t   avg_bit_rate,
184     uint32_t   max_packet_size,
185     uint32_t   avg_packet_size,
186     uint32_t   start_time,
187     uint32_t   preroll,
188     uint32_t   duration,
189     const char *stream_name,
190     const char *mime_type,
191     uint32_t   type_specific_len,
192     const char *type_specific_data );
193
194 rmff_cont_t *rmff_new_cont(
195     const char *title,
196     const char *author,
197     const char *copyright,
198     const char *comment);
199
200 rmff_data_t *rmff_new_dataheader(
201     uint32_t num_packets, uint32_t next_data_header);
202
203 /*
204  * reads header infos from data and returns a newly allocated header struct
205  */
206 rmff_header_t *rmff_scan_header(const char *data);
207
208 /*
209  * scans a data packet header. Notice, that this function does not allocate
210  * the header struct itself.
211  */
212 void rmff_scan_pheader(rmff_pheader_t *h, char *data);
213
214 /*
215  * reads header infos from stream and returns a newly allocated header struct
216  */
217 rmff_header_t *rmff_scan_header_stream(int fd);
218
219 /*
220  * prints header information in human readible form to stdout
221  */
222 void rmff_print_header(rmff_header_t *h);
223
224 /*
225  * does some checks and fixes header if possible
226  */
227 void rmff_fix_header(rmff_header_t *h);
228
229 /*
230  * returns the size of the header (incl. first data-header)
231  */
232 int rmff_get_header_size(rmff_header_t *h);
233  
234 /*
235  * dumps the header <h> to <buffer>. <max> is the size of <buffer>
236  */
237 int rmff_dump_header(rmff_header_t *h, char *buffer, int max);
238
239 /*
240  * dumps a packet header
241  */
242 void rmff_dump_pheader(rmff_pheader_t *h, char *data);
243
244 /*
245  * frees a header struct
246  */
247 void rmff_free_header(rmff_header_t *h);
248
249 #endif