Main Page | Data Structures | File List | Data Fields | Globals

librmff.h

Go to the documentation of this file.
00001 /*
00002   librmff.h
00003 
00004   Copyright (C) Moritz Bunkus - March 2004
00005 
00006   librmff is free software; you can redistribute it and/or modify
00007   it under the terms of the GNU Lesser General Public License as published by
00008   the Free Software Foundation; either version 2.1, or (at your option)
00009   any later version.
00010 
00011   librmff is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014   GNU General Public License for more details.
00015 
00016   You should have received a copy of the GNU Lesser General Public License
00017   along with this library; see the file COPYING.  If not, write to
00018   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00019 
00020 */
00021 
00240 #ifndef __RMFF_H
00241 #define __RMFF_H
00242 
00243 #if defined(__cplusplus)
00244 extern "C" {
00245 #endif
00246 
00247 #include "os.h"
00248 
00249 #include <inttypes.h>
00250 #include <stdio.h>
00251 
00252 #include "mb_file_io.h"
00253 
00254 #define RMFF_VERSION_MAJOR 0
00255 #define RMFF_VERSION_MINOR 6
00256 #define RMFF_VERSION_MICRO 2
00257 #define RMFF_VERSION (RMFF_VERSION_MAJOR * 10000 + RMFF_VERSION_MINOR * 100 + \
00258                       RMFF_VERSION_MICRO)
00259 
00262 #define RMFF_FILE_FLAG_SAVE_ENABLED     0x0001
00263 
00265 #define RMFF_FILE_FLAG_PERFECT_PLAY     0x0002
00266 
00268 #define RMFF_FILE_FLAG_LIVE_BROADCAST   0x0004
00269 
00271 #define RMFF_FILE_FLAG_DOWNLOAD_ENABLED 0x0008
00272 
00275 typedef struct rmff_object_t {
00277   uint32_t  id;
00279   uint32_t size;
00281   uint16_t version;
00282 } rmff_object_t;
00283 
00286 typedef struct rmff_rmf_t {
00287   rmff_object_t obj;
00288   uint32_t format_version;
00289   uint32_t num_headers;
00290 } rmff_rmf_t;
00291 
00300 typedef struct rmff_prop_t {
00301   rmff_object_t obj;
00302   uint32_t max_bit_rate;
00303   uint32_t avg_bit_rate;
00304   uint32_t max_packet_size;
00305   uint32_t avg_packet_size;
00306   uint32_t num_packets;
00307   uint32_t duration;
00308   uint32_t preroll;
00309   uint32_t index_offset;
00310   uint32_t data_offset;
00311   uint16_t num_streams;
00312   uint16_t flags;
00313 } rmff_prop_t;
00314 
00321 typedef struct rmff_cont_t {
00322   rmff_object_t obj;
00323   char *title;
00324   char *author;
00325   char *copyright;
00326   char *comment;
00327 } rmff_cont_t;
00328 
00337 typedef struct rmff_mdpr_t {
00338   rmff_object_t obj;
00340   uint16_t id;
00345   uint32_t max_bit_rate;
00349   uint32_t avg_bit_rate;
00354   uint32_t max_packet_size;
00359   uint32_t avg_packet_size;
00360   uint32_t start_time;
00361   uint32_t preroll;
00362   uint32_t duration;
00366   char *name;
00370   char *mime_type;
00372   uint32_t type_specific_size;
00377   unsigned char *type_specific_data;
00378 } rmff_mdpr_t;
00379 
00380 typedef struct __attribute__((__packed__)) real_video_props_t {
00381   uint32_t size;
00382   uint32_t fourcc1;
00383   uint32_t fourcc2;
00384   uint16_t width;
00385   uint16_t height;
00386   uint16_t bpp;
00387   uint32_t unknown1;
00388   uint32_t fps;
00389   uint32_t type1;
00390   uint32_t type2;
00391 } real_video_props_t;
00392 
00393 typedef struct __attribute__((__packed__)) real_audio_v4_props_t {
00394   uint32_t fourcc1;             /* '.', 'r', 'a', 0xfd */
00395   uint16_t version1;            /* 4 or 5 */
00396   uint16_t unknown1;            /* 00 00 */
00397   uint32_t fourcc2;             /* .ra4 or .ra5 */
00398   uint32_t stream_length;       /* ??? */
00399   uint16_t version2;            /* 4 or 5 */
00400   uint32_t header_size;         /* == 0x4e */
00401   uint16_t flavor;              /* codec flavor id */
00402   uint32_t coded_frame_size;    /* coded frame size */
00403   uint32_t unknown3;            /* big number */
00404   uint32_t unknown4;            /* bigger number */
00405   uint32_t unknown5;            /* yet another number */
00406   uint16_t sub_packet_h;
00407   uint16_t frame_size;
00408   uint16_t sub_packet_size;
00409   uint16_t unknown6;            /* 00 00 */
00410   uint16_t sample_rate;
00411   uint16_t unknown8;            /* 0 */
00412   uint16_t sample_size;
00413   uint16_t channels;
00414 } real_audio_v4_props_t;
00415 
00416 typedef struct __attribute__((__packed__)) real_audio_v5_props_t {
00417   uint32_t fourcc1;             /* '.', 'r', 'a', 0xfd */
00418   uint16_t version1;            /* 4 or 5 */
00419   uint16_t unknown1;            /* 00 00 */
00420   uint32_t fourcc2;             /* .ra4 or .ra5 */
00421   uint32_t stream_length;       /* ??? */
00422   uint16_t version2;            /* 4 or 5 */
00423   uint32_t header_size;         /* == 0x4e */
00424   uint16_t flavor;              /* codec flavor id */
00425   uint32_t coded_frame_size;    /* coded frame size */
00426   uint32_t unknown3;            /* big number */
00427   uint32_t unknown4;            /* bigger number */
00428   uint32_t unknown5;            /* yet another number */
00429   uint16_t sub_packet_h;
00430   uint16_t frame_size;
00431   uint16_t sub_packet_size;
00432   uint16_t unknown6;            /* 00 00 */
00433   uint8_t unknown7[6];          /* 0, srate, 0 */
00434   uint16_t sample_rate;
00435   uint16_t unknown8;            /* 0 */
00436   uint16_t sample_size;
00437   uint16_t channels;
00438   uint32_t genr;                /* "genr" */
00439   uint32_t fourcc3;             /* fourcc */
00440 } real_audio_v5_props_t;
00441 
00442 typedef struct rmff_index_entry_t {
00443   uint32_t pos;
00444   uint32_t timecode;
00445   uint32_t packet_number;
00446 } rmff_index_entry_t;
00447 
00450 #define RMFF_FRAME_FLAG_RELIABLE 0x01
00451 
00453 #define RMFF_FRAME_FLAG_KEYFRAME 0x02
00454 
00466 typedef struct rmff_frame_t {
00468   unsigned char *data;
00470   uint32_t size;
00473   int allocated_by_rmff;
00474 
00477   uint16_t id;
00479   uint32_t timecode;
00480   uint8_t reserved;
00482   uint8_t flags;
00483 } rmff_frame_t;
00484 
00486 #define RMFF_TRACK_TYPE_UNKNOWN                        0
00487 
00488 #define RMFF_TRACK_TYPE_AUDIO                          1
00489 
00490 #define RMFF_TRACK_TYPE_VIDEO                          2
00491 
00492 struct rmff_file_t;
00493 
00494 typedef struct rmff_track_t {
00495   uint32_t id;
00496   int type;
00497   rmff_mdpr_t mdpr_header;
00498 
00499   rmff_index_entry_t *index;
00500   int num_index_entries;
00501 
00502   struct rmff_file_t *file;
00503 
00504   void *app_data;
00505   void *internal;
00506 } rmff_track_t;
00507 
00508 typedef struct rmff_file_t {
00509   mb_file_io_t *io;
00510   void *handle;
00511   char *name;
00512   int open_mode;
00513   int64_t size;
00514 
00515   int headers_read;
00516 
00517   rmff_rmf_t rmf_header;
00518   rmff_prop_t prop_header;
00519   rmff_cont_t cont_header;
00520   int cont_header_present;
00521   uint32_t num_packets_in_chunk;
00522   uint32_t num_packets_read;
00523 
00524   rmff_track_t **tracks;
00525   int num_tracks;
00526 
00527   void *app_data;
00528   void *internal;
00529 } rmff_file_t;
00530 
00532 #define RMFF_ERR_OK                                    0
00533 
00534 #define RMFF_ERR_NOT_RMFF                             -1
00535 
00536 #define RMFF_ERR_DATA                                 -2
00537 
00538 #define RMFF_ERR_EOF                                  -3
00539 
00540 #define RMFF_ERR_IO                                   -4
00541 
00542 #define RMFF_ERR_PARAMETERS                           -5
00543 
00544 #define RMFF_ERR_CHECK_ERRNO                          -6
00545 
00547 #define rmffFOURCC(a, b, c, d) \
00548   (uint32_t)((((unsigned char)a) << 24) + \
00549   (((unsigned char)b) << 16) + \
00550   (((unsigned char)c) << 8) + \
00551   ((unsigned char)d))
00552 
00554 #define RMFF_OPEN_MODE_READING                         0
00555 
00556 #define RMFF_OPEN_MODE_WRITING                         1
00557 
00573 rmff_file_t *rmff_open_file(const char *path, int mode);
00574 
00590 rmff_file_t *rmff_open_file_with_io(const char *path, int mode,
00591                                     mb_file_io_t *io);
00592 
00602 void rmff_close_file(rmff_file_t *file);
00603 
00615 int rmff_read_headers(rmff_file_t *file);
00616 
00624 int rmff_get_next_frame_size(rmff_file_t *file);
00625 
00641 rmff_frame_t *rmff_read_next_frame(rmff_file_t *file, void *buffer);
00642 
00654 rmff_frame_t *rmff_allocate_frame(uint32_t size, void *buffer);
00655 
00662 void rmff_release_frame(rmff_frame_t *frame);
00663 
00677 rmff_track_t *rmff_add_track(rmff_file_t *file, int create_index);
00678 
00692 void rmff_set_std_audio_v4_values(real_audio_v4_props_t *props);
00693 
00707 void rmff_set_std_audio_v5_values(real_audio_v5_props_t *props);
00708 
00722 void rmff_set_std_video_values(real_video_props_t *props);
00723 
00738 void rmff_set_cont_header(rmff_file_t *file, const char *title,
00739                           const char *author, const char *copyright,
00740                           const char *comment);
00741 
00753 void rmff_set_track_data(rmff_track_t *track, const char *name,
00754                          const char *mime_type);
00755 
00768 void rmff_set_type_specific_data(rmff_track_t *track,
00769                                  const unsigned char *data, uint32_t size);
00770 
00783 int rmff_write_headers(rmff_file_t *file);
00784 
00797 int rmff_fix_headers(rmff_file_t *file);
00798 
00810 int rmff_write_frame(rmff_track_t *track, rmff_frame_t *frame);
00811 
00826 int rmff_write_packed_video_frame(rmff_track_t *track, rmff_frame_t *frame);
00827 
00850 int rmff_assemble_packed_video_frame(rmff_track_t *track, rmff_frame_t *frame);
00851 
00869 rmff_frame_t *rmff_get_packed_video_frame(rmff_track_t *track);
00870 
00886 int rmff_write_index(rmff_file_t *file);
00887 
00897 void rmff_copy_track_headers(rmff_track_t *dst, rmff_track_t *src);
00898 
00906 rmff_track_t *rmff_find_track_with_id(rmff_file_t *file, uint16_t id);
00907 
00914 extern int rmff_last_error;
00915 
00921 extern const char *rmff_last_error_msg;
00922 
00932 const char *rmff_get_error_str(int code);
00933 
00943 uint16_t rmff_get_uint16_be(const void *buf);
00944 
00954 uint32_t rmff_get_uint32_be(const void *buf);
00955 
00965 uint32_t rmff_get_uint32_le(const void *buf);
00966 
00975 void rmff_put_uint16_be(void *buf, uint16_t value);
00976 
00985 void rmff_put_uint32_be(void *buf, uint32_t value);
00986 
00995 void rmff_put_uint32_le(void *buf, uint32_t value);
00996 
00997 #if defined(ARCH_LITTLEENDIAN)
00998 # define rmff_get_uint32_me(b) rmff_get_uint32_le(b)
00999 # define rmff_put_uint32_me(b) rmff_put_uint32_le(b)
01000 #elif defined(ARCH_BIGENDIAN)
01001 # define rmff_get_uint32_me(b) rmff_get_uint32_be(b)
01002 # define rmff_put_uint32_me(b) rmff_put_uint32_be(b)
01003 #else
01004 # error Neither ARCH_LITTLEENDIAN nor ARCH_BIGENDIAN has been defined.
01005 #endif
01006 
01007 #if defined(__cplusplus)
01008 }
01009 #endif
01010 
01011 #endif /* __RMFF_H */

Generated on Thu Jun 24 16:21:13 2004 for librmff by doxygen 1.3.6-20040222