DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
src/aviwriter/riff.h
00001 
00002 #ifndef __VIDEOMGRUTIL_RIFF_H
00003 #define __VIDEOMGRUTIL_RIFF_H
00004 
00005 #include <stdint.h>
00006 #include <string.h>
00007 #include <stdio.h>
00008 
00009 #include "informational.h"
00010 
00011 typedef uint32_t riff_fourcc_t;
00012 #define riff_fourcc_const(a,b,c,d)      ( (((uint32_t)(a)) << 0U) | (((uint32_t)(b)) << 8U) | (((uint32_t)(c)) << 16U) | (((uint32_t)(d)) << 24U) )
00013 
00014 #define riff_LIST               riff_fourcc_const('L','I','S','T')
00015 #define riff_RIFF               riff_fourcc_const('R','I','F','F')
00016 
00017 #define riff_wav_fmt            riff_fourcc_const('f','m','t',' ')
00018 #define riff_wav_data           riff_fourcc_const('d','a','t','a')
00019 
00020 typedef struct {
00021         int64_t                 absolute_header_offset;
00022         int64_t                 absolute_data_offset;
00023         int64_t                 absolute_offset_next_chunk;
00024         riff_fourcc_t           fourcc;
00025         uint32_t                data_length;
00026         uint32_t                absolute_data_length;
00027         riff_fourcc_t           list_fourcc;
00028         int64_t                 read_offset;
00029         int64_t                 write_offset;
00030         int                     wmode;
00031         unsigned char           disable_sync;           /* 1=riff_stack_pop() will NOT rewrite the header.
00032                                                            caller would use this if using riff_stack_streamwrite()
00033                                                            to blast the data to disk as fast as possible */
00034         unsigned char           placeholder;            /* 1=write 0xFFFFFFFF as a placeholder for the actual size
00035                                                            until the header is actually updated. you should really
00036                                                            only set this flag for LIST chunks that are unlikely to
00037                                                            be zero bytes in length. flag is cleared automatically
00038                                                            by riff_stack_pop(). do NOT set if disable_sync is set. */
00039 } riff_chunk;
00040 
00041 static const riff_chunk RIFF_CHUNK_INIT = {
00042         0,
00043         0,
00044         0,
00045         0,
00046         0,
00047         0,
00048         0,
00049         0,
00050         0,
00051         0,
00052         0,
00053         0
00054 };
00055 
00056 typedef struct {
00057         int                     current,depth;
00058         riff_chunk              *stack,*top;
00059 
00060         int                     fd;
00061         int                     eof;
00062         void*                   user;
00063         int                     wmode;
00064         int64_t                 next_read;
00065         int64_t                 next_write;
00066         void*                   buffer;
00067         size_t                  buflen;
00068         size_t                  bufofs;
00069         int                     (*read)(void *a,void *b,size_t c);
00070         int64_t                 (*seek)(void *a,int64_t offset);
00071         int                     (*write)(void *a,const void *b,size_t c);
00072 
00073         /* flags for controlling some of the optimizations used in this code */
00074         unsigned char           always_lseek;           /* 1=always lseek()
00075                                                            0=ignore lseek() if file pointer should be at that point anyway
00076                                                            EXPLANATION: Linux disk I/O caching is more likely to provide better
00077                                                                         throughput if we avoid lseek() and write structures and
00078                                                                         data using only a continuous series of read() or write()
00079                                                                         calls. */
00080 
00081         /* variables provided for the file I/O code */
00082         int64_t                 trk_file_pointer;
00083 
00084         /* more flags */
00085         unsigned int            fd_owner:1;             /* if set, we take ownership of the file descriptor */
00086 } riff_stack;
00087 
00088 int riff_std_read(void *a,void *b,size_t c);
00089 int riff_std_write(void *a,const void *b,size_t c);
00090 int64_t riff_std_seek(void *a,int64_t offset);
00091 
00092 riff_stack *riff_stack_create(int depth);
00093 riff_stack *riff_stack_destroy(riff_stack *s);
00094 int riff_stack_is_empty(riff_stack *s);
00095 int riff_stack_empty(riff_stack *s);
00096 riff_chunk *riff_stack_top(riff_stack *s);
00097 riff_chunk *riff_stack_pop(riff_stack *s);
00098 int riff_stack_push(riff_stack *s,riff_chunk *c);
00099 int64_t riff_stack_seek(riff_stack *s,riff_chunk *c,int64_t of);
00100 int riff_stack_read(riff_stack *s,riff_chunk *c,void *buf,size_t len);
00101 int riff_stack_write(riff_stack *s,riff_chunk *c,const void *buf,size_t len);
00102 int riff_stack_streamwrite(riff_stack *s,riff_chunk *c,const void *buf,size_t len);
00103 int64_t riff_stack_current_chunk_offset(riff_stack *s);
00104 int riff_stack_assign_fd(riff_stack *s,int fd);
00105 int riff_stack_assign_fd_ownership(riff_stack *s);
00106 int riff_stack_assign_buffer(riff_stack *s,void *buffer,size_t len);
00107 int riff_stack_chunk_contains_subchunks(riff_chunk *c);
00108 int riff_stack_readchunk(riff_stack *s,riff_chunk *pc,riff_chunk *c);
00109 int riff_stack_set_chunk_data_type(riff_chunk *c,riff_fourcc_t fcc);
00110 int riff_stack_set_chunk_list_type(riff_chunk *c,riff_fourcc_t list,riff_fourcc_t fcc);
00111 void riff_stack_debug_chunk_dump(FILE *fp,riff_stack *riff,riff_chunk *chunk);
00112 void riff_stack_debug_print(FILE *fp,int level,riff_chunk *chunk);
00113 void riff_chunk_improvise(riff_chunk *c,uint64_t ofs,uint32_t size);
00114 void riff_stack_fourcc_to_str(riff_fourcc_t t,char *tmp);
00115 void riff_stack_debug_print_indent(FILE *fp,int level);
00116 int riff_stack_eof(riff_stack *r);
00117 int riff_stack_prepare_for_writing(riff_stack *r,int wmode);
00118 int riff_stack_begin_new_chunk_here(riff_stack *s,riff_chunk *c);
00119 int riff_stack_header_sync(riff_stack *s,riff_chunk *c);
00120 int riff_stack_header_sync_all(riff_stack *s);
00121 int riff_stack_chunk_limit(riff_stack *s,int len);
00122 int riff_stack_enable_placeholder(riff_stack *s,riff_chunk *c);
00123 void riff_stack_writing_sync(riff_stack *s);
00124 
00125 #define RIFF_CHUNK_HEADER_LENGTH                8
00126 #define RIFF_LIST_CHUNK_HEADER_LENGTH           12
00127 
00128 #endif
00129