DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/aviwriter/avi_writer.h
00001 #ifndef __ISP_UTILS_AVI_WRITER_H
00002 #define __ISP_UTILS_AVI_WRITER_H
00003 
00004 #include "avi.h"
00005 
00006 enum {
00007         AVI_WRITER_STATE_INIT=0,
00008         AVI_WRITER_STATE_HEADER,
00009         AVI_WRITER_STATE_BODY,
00010         AVI_WRITER_STATE_FOOTER,
00011         AVI_WRITER_STATE_DONE
00012 };
00013 
00014 typedef struct avi_writer_stream_index {
00015         uint64_t                        stream_offset;
00016         uint64_t                        offset;
00017         uint32_t                        length;
00018         uint32_t                        dwFlags;        /* flags in AVIOLDINDEX. In OpenDML 2.0 indexes, only the keyframe bit has meaning */
00019 } avi_writer_stream_index;
00020 
00021 typedef struct avi_writer_stream {
00022         int                             index;
00023         riff_strh_AVISTREAMHEADER       header;
00024         riff_indx_AVISUPERINDEX         superindex;
00025     const char*         name;
00026         void*                           format;
00027         size_t                          format_len;
00028         riff_chunk                      strh,indx,indx_junk;
00029         avi_writer_stream_index*        sample_index;
00030         unsigned int                    sample_index_alloc,sample_index_max;
00031         unsigned int                    sample_write_offset;
00032         unsigned int                    sample_write_chunk;
00033         unsigned int                    indx_entryofs;
00034         uint32_t                        chunk_fourcc;   /* such as: 00dc, 00db, 00wb, etc. */
00035         uint32_t                        group0_len;
00036 } avi_writer_stream;
00037 
00038 typedef struct avi_writer {
00039         int                             fd,own_fd;      /* file descriptor, and whether we retain ownership of it */
00040         riff_stack*                     riff;
00041         riff_chunk                      movi,avih;
00042         int                             state;
00043         int                             avi_stream_max;
00044         int                             avi_stream_alloc;
00045         avi_writer_stream*              avi_stream;
00046         riff_avih_AVIMAINHEADER         main_header;
00047         unsigned char                   enable_opendml_index;   /* 1=write OpenDML index */
00048         unsigned char                   enable_avioldindex;     /* 1=write AVIOLDINDEX */
00049         unsigned char                   enable_opendml;         /* 1=enable RIFF:AVIX extensions to allow files >= 2GB */
00050         unsigned char                   enable_stream_writing;  /* 1=try to always write as a stream to disk at the expense of some AVI structure integrity */
00051         unsigned char                   wrote_idx1;
00052         unsigned int                    group;
00053 } avi_writer;
00054 
00055 int avi_writer_stream_check_samplecount(avi_writer_stream *s,unsigned int len);
00056 int avi_writer_stream_set_format(avi_writer_stream *s,void *data,size_t len);
00057 riff_strh_AVISTREAMHEADER *avi_writer_stream_header(avi_writer_stream *s);
00058 riff_avih_AVIMAINHEADER *avi_writer_main_header(avi_writer *w);
00059 avi_writer_stream *avi_writer_new_stream(avi_writer *w); /* reminder: you are not required to free this pointer, the writer does it for you on close_file() */
00060 void avi_writer_free_stream(avi_writer_stream *s);
00061 void avi_writer_free_streams(avi_writer *w);
00062 avi_writer *avi_writer_create();
00063 void avi_writer_close_file(avi_writer *w);
00064 int avi_writer_open_file(avi_writer *w,const char *path);
00065 avi_writer *avi_writer_destroy(avi_writer *w);
00066 int avi_writer_begin_data(avi_writer *w);
00067 int avi_writer_begin_header(avi_writer *w);
00068 int avi_writer_stream_write(avi_writer *w,avi_writer_stream *s,void *data,size_t len,uint32_t flags);
00069 int avi_writer_stream_repeat_last_chunk(avi_writer *w,avi_writer_stream *s);
00070 int avi_writer_set_stream_writing(avi_writer *w);
00071 int avi_writer_end_data(avi_writer *w);
00072 int avi_writer_finish(avi_writer *w);
00073 
00074 /* TODO: remove from header, these functions are private */
00075 uint64_t avi_writer_stream_alloc_superindex(avi_writer *w,avi_writer_stream *s);
00076 int avi_writer_emit_avioldindex(avi_writer *w);
00077 int avi_writer_emit_opendml_indexes(avi_writer *w);
00078 int avi_writer_update_avi_and_stream_headers(avi_writer *w);
00079 
00080 #endif /* __ISP_UTILS_AVI_WRITER_H */
00081