MKIO.hpp

00001 #ifdef ENABLE_MKV 00002 00003 /*********************************************************************** 00004 * * 00005 * ViTooKi * 00006 * * 00007 * title: MKIO.hpp * 00008 * * 00009 * * 00010 * * 00011 * ITEC institute of the University of Klagenfurt (Austria) * 00012 * http://www.itec.uni-klu.ac.at * 00013 * * 00014 * * 00015 * For more information visit the ViTooKi homepage: * 00016 * http://ViTooKi.sourceforge.net * 00017 * vitooki-user@lists.sourceforge.net * 00018 * vitooki-devel@lists.sourceforge.net * 00019 * * 00020 * This file is part of ViTooKi, a free video toolkit. * 00021 * ViTooKi is free software; you can redistribute it and/or * 00022 * modify it under the terms of the GNU General Public License * 00023 * as published by the Free Software Foundation; either version 2 * 00024 * of the License, or (at your option) any later version. * 00025 * * 00026 * This program is distributed in the hope that it will be useful, * 00027 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00029 * GNU General Public License for more details. * 00030 * * 00031 * You should have received a copy of the GNU General Public License * 00032 * along with this program; if not, write to the Free Software * 00033 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00034 * MA 02111-1307, USA. * 00035 * * 00036 ***********************************************************************/ 00037 00038 /*********************************************************************** 00039 * * 00040 * REVISION HISTORY: * 00041 * * 00042 * * 00043 * * 00044 ***********************************************************************/ 00045 00046 #ifndef _MK_SERVER_MKIO_HPP 00047 #define _MK_SERVER_MKIO_HPP 00048 00049 #include "IO.hpp" 00050 00051 #include <stdlib.h> 00052 #include <stdio.h> 00053 #include <string.h> 00054 00055 #ifdef ENABLE_MKV_WRITE 00056 #include <fcntl.h> 00057 #include <errno.h> 00058 #include "ebml/StdIOCallback.h" 00059 #include "ebml/EbmlHead.h" 00060 #include "ebml/EbmlSubHead.h" 00061 #include "ebml/EbmlVoid.h" 00062 #include "matroska/FileKax.h" 00063 #include "matroska/KaxSegment.h" 00064 #include "matroska/KaxTracks.h" 00065 #include "matroska/KaxTrackEntryData.h" 00066 #include "matroska/KaxTrackAudio.h" 00067 #include "matroska/KaxTrackVideo.h" 00068 #include "matroska/KaxCluster.h" 00069 #include "matroska/KaxClusterData.h" 00070 #include "matroska/KaxSeekHead.h" 00071 #include "matroska/KaxCues.h" 00072 #include "matroska/KaxInfo.h" 00073 #include "matroska/KaxInfoData.h" 00074 #include "matroska/KaxTags.h" 00075 #include "matroska/KaxTag.h" 00076 #include "matroska/KaxChapters.h" 00077 #include "matroska/KaxContentEncoding.h" 00078 #endif 00079 00080 00081 #ifdef __cplusplus 00082 extern "C" { 00083 #include "../container/MatroskaParser.h" 00084 } 00085 #endif 00086 00087 #define CACHESIZE 65536 00088 #define SAFETYDIST 4 00089 #define MAXVOPSIZE 64000 00090 #define MAXMP3VOPSIZE 64000 00091 #define STREAMREADER_DEF_BUFFER_SIZE 4096 00092 00093 00094 struct StdIoStream { 00095 struct InputStream base; 00096 FILE *fp; 00097 int error; 00098 }; 00099 00100 00101 00102 typedef struct StdIoStream StdIoStream; 00103 00104 00105 class Frame; 00106 class ESInfo; 00107 00119 class MKIO:public IO { 00120 public: 00125 MKIO(ESInfo * es, const char *mkvFile, bool writeOnly); 00126 00128 virtual ~ MKIO(); 00129 00134 Frame *getFrame(); 00135 00137 int writeFrame(Frame * frm, ESInfo *out_es = NULL); 00138 00141 bool open(); 00142 00143 IO::State play(double prefetchTime); 00144 00145 bool close(bool immediate=false); 00146 00151 bool destroy(); 00152 00153 bool setToFrameNumber(u32 frameNumber); 00154 00157 int getBufferFillLevel() const; 00158 00160 const char *getURL() const { return input; }; 00161 00162 void setESInfo(ESInfo * esi) { es=esi; }; 00163 00164 ESInfo* getESInfo() { return es; }; 00165 00166 00167 00168 protected: 00169 00170 // AVFormatContext *ic; 00171 // AVInputFormat *file_iformat; 00172 //AVFormatParameters *ap; 00173 // AVFormatParameters ap1, *ap; 00174 int streamID; 00175 00176 bool writeOnly; 00177 dfadd(fp); 00178 00179 private: 00180 void printPat(int *pat, int len); 00181 void patSplit(int *pat, int len, int maxdepth, int *actpos); 00182 int patSplitRec(int *pat, int len, int actdepth, int maxdepth, int gowhere, int *actpos); 00183 00184 u64 DTS; 00185 bool openForReading(); 00186 bool openForWriting(); 00187 00188 StdIoStream st; 00189 MatroskaFile *mf; 00190 char err_msg[256]; 00191 00192 char *input; 00193 ESInfo * es; 00194 00195 bool headerWritten; //Matroska header 00196 StdIOCallback *out_file; 00197 LIBMATROSKA_NAMESPACE::KaxSegment FileSegment; 00198 LIBMATROSKA_NAMESPACE::KaxSeekHead MetaSeek; 00199 //LIBMATROSKA_NAMESPACE::KaxTracks & MyTracks; 00200 00201 FILE *priofp; 00202 int prioTable[256]; //highest possible framerate of video 00203 int tableSize; 00204 }; 00205 00206 #endif 00207 00208 00209 #endif 00210