DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/aviwriter/avi_writer.h
00001 /*
00002  *  Copyright (C) 2018-2020 Jon Campbell
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License along
00015  *  with this program; if not, write to the Free Software Foundation, Inc.,
00016  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #ifndef __ISP_UTILS_AVI_WRITER_H
00020 #define __ISP_UTILS_AVI_WRITER_H
00021 
00022 #include "avi.h"
00023 
00024 enum {
00025         AVI_WRITER_STATE_INIT=0,
00026         AVI_WRITER_STATE_HEADER,
00027         AVI_WRITER_STATE_BODY,
00028         AVI_WRITER_STATE_FOOTER,
00029         AVI_WRITER_STATE_DONE
00030 };
00031 
00032 typedef struct avi_writer_stream_index {
00033         uint64_t                        stream_offset;
00034         uint64_t                        offset;
00035         uint32_t                        length;
00036         uint32_t                        dwFlags;        /* flags in AVIOLDINDEX. In OpenDML 2.0 indexes, only the keyframe bit has meaning */
00037 } avi_writer_stream_index;
00038 
00039 typedef struct avi_writer_stream {
00040         int                             index;
00041         riff_strh_AVISTREAMHEADER       header;
00042         riff_indx_AVISUPERINDEX         superindex;
00043     const char*         name;
00044         void*                           format;
00045         size_t                          format_len;
00046         riff_chunk                      strh,indx,indx_junk;
00047         avi_writer_stream_index*        sample_index;
00048         unsigned int                    sample_index_alloc,sample_index_max;
00049         unsigned int                    sample_write_offset;
00050         unsigned int                    sample_write_chunk;
00051         unsigned int                    indx_entryofs;
00052         uint32_t                        chunk_fourcc;   /* such as: 00dc, 00db, 00wb, etc. */
00053         uint32_t                        group0_len;
00054 } avi_writer_stream;
00055 
00056 typedef struct avi_writer {
00057         int                             fd,own_fd;      /* file descriptor, and whether we retain ownership of it */
00058         riff_stack*                     riff;
00059         riff_chunk                      movi,avih;
00060         int                             state;
00061         int                             avi_stream_max;
00062         int                             avi_stream_alloc;
00063         avi_writer_stream*              avi_stream;
00064         riff_avih_AVIMAINHEADER         main_header;
00065         unsigned char                   enable_opendml_index;   /* 1=write OpenDML index */
00066         unsigned char                   enable_avioldindex;     /* 1=write AVIOLDINDEX */
00067         unsigned char                   enable_opendml;         /* 1=enable RIFF:AVIX extensions to allow files >= 2GB */
00068         unsigned char                   enable_stream_writing;  /* 1=try to always write as a stream to disk at the expense of some AVI structure integrity */
00069         unsigned char                   wrote_idx1;
00070         unsigned int                    group;
00071 } avi_writer;
00072 
00073 int avi_writer_stream_check_samplecount(avi_writer_stream *s,unsigned int len);
00074 int avi_writer_stream_set_format(avi_writer_stream *s,void *data,size_t len);
00075 riff_strh_AVISTREAMHEADER *avi_writer_stream_header(avi_writer_stream *s);
00076 riff_avih_AVIMAINHEADER *avi_writer_main_header(avi_writer *w);
00077 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() */
00078 void avi_writer_free_stream(avi_writer_stream *s);
00079 void avi_writer_free_streams(avi_writer *w);
00080 avi_writer *avi_writer_create();
00081 void avi_writer_close_file(avi_writer *w);
00082 int avi_writer_open_file(avi_writer *w,const char *path);
00083 avi_writer *avi_writer_destroy(avi_writer *w);
00084 int avi_writer_begin_data(avi_writer *w);
00085 int avi_writer_begin_header(avi_writer *w);
00086 int avi_writer_stream_write(avi_writer *w,avi_writer_stream *s,void *data,size_t len,uint32_t flags);
00087 int avi_writer_stream_repeat_last_chunk(avi_writer *w,avi_writer_stream *s);
00088 int avi_writer_set_stream_writing(avi_writer *w);
00089 int avi_writer_end_data(avi_writer *w);
00090 int avi_writer_finish(avi_writer *w);
00091 
00092 /* TODO: remove from header, these functions are private */
00093 uint64_t avi_writer_stream_alloc_superindex(avi_writer *w,avi_writer_stream *s);
00094 int avi_writer_emit_avioldindex(avi_writer *w);
00095 int avi_writer_emit_opendml_indexes(avi_writer *w);
00096 int avi_writer_update_avi_and_stream_headers(avi_writer *w);
00097 
00098 #endif /* __ISP_UTILS_AVI_WRITER_H */
00099