1 /******************************************************************************/ 2 /* Mednafen - Multi-system Emulator */ 3 /******************************************************************************/ 4 /* qtrecord.h: 5 ** Copyright (C) 2010-2016 Mednafen Team 6 ** 7 ** This program is free software; you can redistribute it and/or 8 ** modify it under the terms of the GNU General Public License 9 ** as published by the Free Software Foundation; either version 2 10 ** of the License, or (at your option) any later version. 11 ** 12 ** This program is distributed in the hope that it will be useful, 13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 ** GNU General Public License for more details. 16 ** 17 ** You should have received a copy of the GNU General Public License 18 ** along with this program; if not, write to the Free Software Foundation, Inc., 19 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef __MDFN_QTRECORD_H 23 #define __MDFN_QTRECORD_H 24 25 #include <mednafen/FileStream.h> 26 #include "resampler/resampler.h" 27 28 namespace Mednafen 29 { 30 31 class QTRecord 32 { 33 public: 34 35 enum 36 { 37 VCODEC_RAW = 0, 38 VCODEC_CSCD, 39 VCODEC_PNG 40 }; 41 42 struct VideoSpec 43 { 44 uint32 SoundRate; 45 uint32 SoundChan; // Number of sound channels 46 47 uint32 VideoWidth; 48 uint32 VideoHeight; 49 50 double AspectXAdjust; 51 double AspectYAdjust; 52 53 int64 MasterClock; // Fixed-point, 32.32, should be used when SoundRate == 0 54 55 int VideoCodec; 56 }; 57 58 QTRecord(const std::string& path, const VideoSpec &spec_arg); 59 void Finish(); 60 ~QTRecord(); 61 62 void WriteFrame(const MDFN_Surface *surface, const MDFN_Rect &DisplayRect, const int32 *LineWidths, 63 const int16 *SoundBuf, const int32 SoundBufSize, const int64 MasterCycles); 64 private: 65 66 void w8(uint8 val); 67 void w16(uint16 val); 68 void w32(uint32 val); 69 void w32s(const char *str); 70 void w64s(const char *str); 71 void w64(uint64 val); 72 void wps(const char *str, uint8 fixed_len = 0); 73 void atom_begin(uint32 type, bool small_atom = true); 74 void atom_begin(const char *type, bool small_atom = true); 75 void atom_end(void); 76 77 void vardata_begin(void); 78 void vardata_end(void); 79 80 void Write_ftyp(void); 81 void Write_mvhd(void); 82 void Write_tkhd(void); 83 void Write_stsd(void); 84 void Write_stts(void); 85 void Write_stsc(void); 86 void Write_stsz(void); 87 void Write_co64(void); 88 void Write_stco(void); 89 void Write_stbl(void); 90 void Write_mdhd(void); 91 void Write_smhd(void); 92 void Write_vmhd(void); 93 void Write_hdlr(const char *str, const char *comp_name); 94 void Write_dinf(void); 95 void Write_minf(void); 96 void Write_mdia(void); 97 void Write_edts(void); 98 void Write_trak(void); 99 void Write_udta(void); 100 void Write_moov(void); 101 102 103 FileStream qtfile; 104 105 std::vector<uint8> RawVideoBuffer; 106 std::vector<uint8> CompressedVideoBuffer; 107 108 std::list<bool> atom_smalls; 109 std::list<uint64> atom_foffsets; 110 std::list<uint64> vardata_foffsets; 111 bool OnAudioTrack; // Yay spaghetti code power. 112 113 struct QTChunk 114 { 115 uint64 video_foffset; 116 uint64 video_byte_size; 117 118 uint64 audio_foffset; 119 uint64 audio_byte_size; 120 121 uint32 time_length; 122 }; 123 124 int VideoCodec; 125 uint32 QTVideoWidth; 126 uint32 QTVideoHeight; 127 uint32 SoundRate; 128 uint32 SoundChan; 129 uint32 A; 130 uint32 D; 131 132 uint32 CreationTS; 133 uint32 ModificationTS; 134 135 std::vector<QTChunk> QTChunks; 136 uint64 SoundFramesWritten; 137 138 uint32 TimeScale; 139 uint64 TimeIndex; 140 uint64 MCAccum; 141 uint64 MC; 142 143 bool Finished; 144 145 SpeexResamplerState *resampler; 146 uint32 ResampInRate; 147 std::vector<int16> ResampInBuffer; 148 uint32 ResampInBufferFramesInCount; 149 std::vector<int16> ResampOutBuffer; 150 }; 151 152 } 153 #endif 154