PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pvidfile.h
Go to the documentation of this file.
1 /*
2  * pvidfile.cxx
3  *
4  * Video file declaration
5  *
6  * Portable Windows Library
7  *
8  * Copyright (C) 2004 Post Increment
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is
23  * Craig Southeren <craigs@postincrement.com>
24  *
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 30106 $
30  * $Author: rjongbloed $
31  * $Date: 2013-07-04 18:12:37 +1000 (Thu, 04 Jul 2013) $
32  */
33 
34 #ifndef PTLIB_PVIDFILE_H
35 #define PTLIB_PVIDFILE_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 #include <ptlib.h>
42 
43 #if P_VIDEO
44 #if P_VIDFILE
45 
46 #include <ptlib/videoio.h>
47 
48 
52 class PVideoFile : public PVideoFrameInfo
53 {
54  PCLASSINFO(PVideoFile, PVideoFrameInfo);
55  protected:
56  PVideoFile();
57 
58  public:
59  virtual PBoolean Open(
60  const PFilePath & name, // Name of file to open.
61  PFile::OpenMode mode = PFile::ReadWrite, // Mode in which to open the file.
62  PFile::OpenOptions opts = PFile::ModeDefault // <code>OpenOptions</code> enum# for open operation.
63  );
64 
65  virtual PBoolean IsOpen() const { return m_file.IsOpen(); }
66  virtual PBoolean Close() { return m_file.Close(); }
67 
68  virtual PBoolean WriteFrame(const void * frame);
69  virtual PBoolean ReadFrame(void * frame);
70 
71  virtual off_t GetLength() const;
72  virtual PBoolean SetLength(
73  off_t len // New length of file in frames.
74  );
75 
76  virtual off_t GetPosition() const;
77  virtual PBoolean SetPosition(
78  off_t pos,
80  );
81 
82  virtual PBoolean SetFrameSize(
83  unsigned width,
84  unsigned height
85  );
86  virtual PBoolean SetFrameRate(
87  unsigned rate
88  );
89 
90  const PFilePath & GetFilePath() const { return m_file.GetFilePath(); }
91  PChannel::Errors GetErrorCode(PChannel::ErrorGroup group = PChannel::NumErrorGroups) const { return m_file.GetErrorCode(group); }
92  int GetErrorNumber(PChannel::ErrorGroup group = PChannel::NumErrorGroups) const { return m_file.GetErrorNumber(group); }
93  PString GetErrorText(PChannel::ErrorGroup group = PChannel::NumErrorGroups) const { return m_file.GetErrorText(group); }
94  PINDEX GetFrameBytes() const { return m_frameBytes; }
95 
96  bool SetFrameSizeFromFilename(const PString & fn);
97  bool SetFPSFromFilename(const PString & fn);
98 
99  protected:
100  bool m_fixedFrameSize;
101  bool m_fixedFrameRate;
102  PINDEX m_frameBytes;
103  off_t m_headerOffset;
104  off_t m_frameHeaderLen;
105  PFile m_file;
106 };
107 
113 class PYUVFile : public PVideoFile
114 {
115  PCLASSINFO(PYUVFile, PVideoFile);
116  public:
117  PYUVFile();
118 
119  virtual PBoolean Open(
120  const PFilePath & name, // Name of file to open.
121  PFile::OpenMode mode = PFile::ReadWrite, // Mode in which to open the file.
122  PFile::OpenOptions opts = PFile::ModeDefault // <code>OpenOptions</code> enum# for open operation.
123  );
124 
125  virtual PBoolean WriteFrame(const void * frame);
126  virtual PBoolean ReadFrame(void * frame);
127 
128  protected:
129  bool m_y4mMode;
130 };
131 
132 typedef PFactory<PVideoFile, PFilePathString> PVideoFileFactory;
133 
134 PFACTORY_LOAD(PYUVFile);
135 
136 
137 #if P_JPEG_DECODER
138 
143 class PJPEGFile : public PVideoFile
144 {
145  PCLASSINFO(PJPEGFile, PVideoFile);
146  public:
147  PJPEGFile();
148  ~PJPEGFile();
149 
150  virtual bool Open(
151  const PFilePath & name, // Name of file to open.
152  PFile::OpenMode mode = PFile::ReadWrite, // Mode in which to open the file.
153  PFile::OpenOptions opts = PFile::ModeDefault // <code>OpenOptions</code> enum# for open operation.
154  );
155 
156  virtual PBoolean WriteFrame(const void * frame);
157  virtual PBoolean ReadFrame(void * frame);
158 
159  bool Close();
160  PBoolean IsOpen() const;
161  off_t GetLength() const;
162  off_t GetPosition() const;
163  bool SetPosition(off_t pos, PFile::FilePositionOrigin origin);
164 
165  protected:
166  PBYTEArray m_pixelData;
167 };
168 
169 PFACTORY_LOAD(PJPEGFile);
170 
171 #endif // P_JPEG_DECODER
172 
173 #endif // P_VIDFILE
174 
175 #endif // P_VIDEO
176 
177 #endif // PTLIB_PVIDFILE_H
178 
179 
180 // End Of File ///////////////////////////////////////////////////////////////