]> git.sesse.net Git - mlt/blob - src/modules/kino/filehandler.h
Initial version
[mlt] / src / modules / kino / filehandler.h
1 /*
2 * filehandler.h
3 * Copyright (C) 2000 Arne Schirmacher <arne@schirmacher.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 #ifndef _FILEHANDLER_H
21 #define _FILEHANDLER_H
22
23 // enum { PAL_FORMAT, NTSC_FORMAT, AVI_DV1_FORMAT, AVI_DV2_FORMAT, QT_FORMAT, RAW_FORMAT, TEST_FORMAT, UNDEFINED };
24
25 #include <vector>
26 using std::vector;
27
28 #include <string>
29 using std::string;
30
31 #include "riff.h"
32 #include "avi.h"
33 #include <sys/types.h>
34 #include <stdint.h>
35
36 enum { AVI, PLAYLIST, RAW_DV, QT, UNKNOWN_FORMAT };
37 enum { PAL_FORMAT, NTSC_FORMAT, AVI_DV1_FORMAT, AVI_DV2_FORMAT, QT_FORMAT, RAW_FORMAT, TEST_FORMAT, UNDEFINED };
38 enum { DISPLAY_XX, DISPLAY_GDKRGB, DISPLAY_GDKRGB32, DISPLAY_XV, DISPLAY_SDL };
39
40 enum { NORM_UNSPECIFIED=0, NORM_PAL=1, NORM_NTSC=2 };
41 enum { AUDIO_32KHZ=0, AUDIO_44KHZ=1, AUDIO_48KHZ=2 };
42 enum { ASPECT_43=0, ASPECT_169=1 };
43
44 enum FileCaptureMode {
45     CAPTURE_IGNORE,
46     CAPTURE_FRAME_APPEND,
47     CAPTURE_FRAME_INSERT,
48     CAPTURE_MOVIE_APPEND
49 };
50
51 class FileTracker
52 {
53 protected:
54         FileTracker();
55         ~FileTracker();
56 public:
57         static FileTracker &GetInstance( );
58         void SetMode( FileCaptureMode );
59         FileCaptureMode GetMode( );
60         unsigned int Size();
61         char *Get( int );
62         void Add( const char * );
63         void Clear( );
64 private:
65         static FileTracker *instance;
66         vector <char *> list;
67         FileCaptureMode mode;
68 };
69
70 class FileHandler
71 {
72 public:
73
74         FileHandler();
75         virtual ~FileHandler();
76
77         virtual bool GetAutoSplit() const;
78         virtual bool GetTimeStamp() const;
79         virtual string GetBaseName() const;
80         virtual string GetExtension() const;
81         virtual int GetMaxFrameCount() const;
82         virtual off_t GetMaxFileSize() const;
83         virtual off_t GetFileSize() = 0;
84         virtual int GetTotalFrames() = 0;
85         virtual string GetFilename() const;
86
87         virtual void SetAutoSplit( bool );
88         virtual void SetTimeStamp( bool );
89         virtual void SetBaseName( const string& base );
90         virtual void SetMaxFrameCount( int );
91         virtual void SetEveryNthFrame( int );
92         virtual void SetMaxFileSize( off_t );
93         //virtual void SetSampleFrame( const Frame& sample );
94
95         //virtual bool WriteFrame( const Frame& frame );
96         virtual bool FileIsOpen() = 0;
97         virtual bool Create( const string& filename ) = 0;
98         //virtual int Write( const Frame& frame ) = 0;
99         virtual int Close() = 0;
100         virtual bool Done( void );
101
102         virtual bool Open( const char *s ) = 0;
103         virtual int GetFrame( uint8_t *data, int frameNum ) = 0;
104         int GetFramesWritten() const
105         {
106                 return framesWritten;
107         }
108
109 protected:
110         bool done;
111         bool autoSplit;
112         bool timeStamp;
113         int maxFrameCount;
114         int framesWritten;
115         int everyNthFrame;
116         int framesToSkip;
117         off_t maxFileSize;
118         string base;
119         string extension;
120         string filename;
121 };
122
123
124 class RawHandler: public FileHandler
125 {
126 public:
127         int fd;
128
129         RawHandler();
130         ~RawHandler();
131
132         bool FileIsOpen();
133         bool Create( const string& filename );
134         //int Write( const Frame& frame );
135         int Close();
136         off_t GetFileSize();
137         int GetTotalFrames();
138         bool Open( const char *s );
139         int GetFrame( uint8_t *data, int frameNum );
140 private:
141         int numBlocks;
142 };
143
144
145 class AVIHandler: public FileHandler
146 {
147 public:
148         AVIHandler( int format = AVI_DV1_FORMAT );
149         ~AVIHandler();
150
151         //void SetSampleFrame( const Frame& sample );
152         bool FileIsOpen();
153         bool Create( const string& filename );
154         //int Write( const Frame& frame );
155         int Close();
156         off_t GetFileSize();
157         int GetTotalFrames();
158         bool Open( const char *s );
159         int GetFrame( uint8_t *data, int frameNum );
160         bool GetOpenDML() const;
161         void SetOpenDML( bool );
162         int GetFormat() const
163         {
164                 return aviFormat;
165         }
166
167 protected:
168         AVIFile *avi;
169         int aviFormat;
170         //AudioInfo audioInfo;
171         //VideoInfo videoInfo;
172         bool isOpenDML;
173         DVINFO dvinfo;
174         FOURCC  fccHandler;
175         int channels;
176         bool isFullyInitialized;
177         int16_t *audioBuffer;
178         int16_t *audioChannels[ 4 ];
179 };
180
181
182 #ifdef HAVE_LIBQUICKTIME
183 #include <quicktime/quicktime.h>
184
185 class QtHandler: public FileHandler
186 {
187 public:
188         QtHandler();
189         ~QtHandler();
190
191         bool FileIsOpen();
192         bool Create( const string& filename );
193         //int Write( const Frame& frame );
194         int Close();
195         off_t GetFileSize();
196         int GetTotalFrames();
197         bool Open( const char *s );
198         int GetFrame( uint8_t *data, int frameNum );
199         void AllocateAudioBuffers();
200
201 private:
202         quicktime_t *fd;
203         long samplingRate;
204         int samplesPerBuffer;
205         int channels;
206         bool isFullyInitialized;
207         unsigned int audioBufferSize;
208         int16_t *audioBuffer;
209         short int** audioChannelBuffer;
210
211         void Init();
212         inline void DeinterlaceStereo16( void* pInput, int iBytes, void* pLOutput, void* pROutput );
213
214 };
215 #endif
216
217 #endif