Debian Codegraph @

lib/aviread/ReadHandlers.h

raw
1 #ifndef READHANDLERS_H
2 #define READHANDLERS_H
3
4 /**
5 *
6 * Interfaces that provide uniform access to data in Audio Video streams,
7 * local and networked files (Avi, Asf, maybe more later)
8 *
9 */
10
11 #include "avifile.h"
12 #include "StreamInfoPriv.h"
13 #include "string.h"
14
15 AVM_BEGIN_NAMESPACE;
16
17 // StreamPacket implemented in ReadStream.cpp
18 class StreamPacket
19 {
20 protected:
21 uint8_t* memory;
22 size_t size;
23 size_t read;
24 int flags;
25 framepos_t position;
26 int64_t timestamp; // timestamp in microseconds
27 uint_t refcount;
28
29 public:
30 static const size_t MAX_PACKET_SIZE = 10000000;
31 static const int64_t NO_TIMESTAMP = -1LL;
32
33 StreamPacket(size_t bsize = 0, void* mem = 0);
34 virtual ~StreamPacket();
35 /** return number of read bytes from packet */
36 size_t Read(void* to, size_t read_size);
37 uint8_t* GetData() const { return memory + read; }
38 size_t GetSize() const { return size - read; }
39 size_t GetRead() const { return read; }
40 int GetFlags() const { return flags; }
41 void SetFlags(int f) { flags = f; }
42 framepos_t GetPos() const { return position; }
43 void SetPos(framepos_t p) { position = p; }
44 int64_t GetTimestamp() const { return timestamp; }
45 void SetTimestamp(int64_t t) { timestamp = t; }
46 double GetTime() const { return (double)timestamp / 1000000.; }
47 void SetTime(double t) { timestamp = (int64_t)(t * 1000000.); }
48 void SwapData(StreamPacket& p) { uint8_t* m = memory; memory = p.memory; p.memory = m; }
49 void AddRef() { refcount++; }
50 void Release() { refcount--; if (!refcount) delete this; }
51 };
52
53 class IMediaReadStream : public IStream
54 {
55 public:
56
57 virtual ~IMediaReadStream() {}
58
59 /* 1 cache full, 0 cache empty */
60 virtual double CacheSize() const = 0;
61
62 /* Clear the internal stream cache */
63 virtual void ClearCache() = 0;
64
65 /**
66 * Return structure describing main stream header
67 *
68 * NOTE: format is in the stream based one!
69 * Use GetStreamInfo to obtain standard set of informations
70 * about stream
71 * this call will be eliminated later!!
72 */
73 virtual size_t GetHeader(void *header, size_t size) const = 0;
74
75 /** Retrieval of stream-specific format data */
76 // XXXXXXXXXXXXX
77 virtual size_t GetFormat(void *format = 0, size_t size = 0) const = 0;
78
79 /** Stream frame time - might be just average for whole stream */
80 // XXXXXXXXXXXXX
81 virtual double GetFrameTime() const = 0;
82
83 /** Length of the stream in samples - equals with last frame position */
84 virtual framepos_t GetLength() const = 0;
85
86 /** Length of the stream in seconds */
87 // XXXXXXXXXXXXX
88 virtual double GetLengthTime() const = 0;
89
90 /**
91 * position of previous, next and nearest key frame
92 * related to frame pos ( ERR means current frame )
93 */
94 virtual framepos_t GetNearestKeyFrame(framepos_t pos = ERR) const = 0;
95 virtual framepos_t GetNextKeyFrame(framepos_t pos = ERR) const = 0;
96 virtual framepos_t GetPrevKeyFrame(framepos_t pos = ERR) const = 0;
97
98 /** Timestamp of sample no. lSample ( ERR = current sample ) */
99 virtual double GetTime(framepos_t lSample = ERR) const = 0;
100
101 /** Returns 0 for variable frame size stream (usually video), >0 for audio */
102 virtual size_t GetSampleSize() const = 0;
103
104 /**
105 * Various useful stream information
106 *
107 * this is preffered way to obtain information about stream!
108 */
109 virtual StreamInfo* GetStreamInfo() const = 0;
110
111 /** Type of stream - usually fcc 'vids' or 'auds' */
112 virtual StreamType GetType() const = 0;
113
114 /**
115 * Return true if frame no. pos ( ERR means current frame ) is keyframe
116 */
117 virtual bool IsKeyFrame(framepos_t pos = ERR) const = 0;
118
119 /** Obtain whole packet - new prefered way for reading streams */
120 virtual StreamPacket* ReadPacket() = 0;
121
122 /** Seek to frame position pos in stream */
123 virtual int Seek(framepos_t pos) = 0;
124
125 /** Seek to time */
126 virtual int SeekTime(double time) = 0;
127
128 virtual int SkipFrame() = 0;
129 virtual int SkipTo(double time) = 0;
130
131 // this is currently cruel hack
132 virtual int FixAvgBytes(uint_t bps) { return -1; }
133 };
134
135 class IMediaReadHandler : public IStream
136 {
137 public:
138 virtual ~IMediaReadHandler() {}
139
140 /* vids/auds, 0-... */
141 virtual IMediaReadStream* GetStream(uint_t stream_id, StreamType type) = 0;
142 virtual size_t GetStreamCount(StreamType type) = 0;
143 virtual size_t GetHeader(void* header, size_t size) = 0;
144
145 /* All calls for network-oriented readers should be interruptible */
146 virtual void Interrupt() = 0;
147
148 /* in case of asynchronous opening */
149 virtual bool IsOpened() = 0;
150 virtual bool IsValid() = 0;
151 virtual bool IsRedirector() = 0;
152 virtual bool GetURLs(avm::vector<avm::string> &urls) = 0;
153 };
154
155 /* Read handler for AVI file */
156 IMediaReadHandler* CreateAviReadHandler(const char *pszFile, int flags);
157
158 /* Read handler for ASF/WMV/ASX file */
159 IMediaReadHandler* CreateAsfReadHandler(const char *pszFile);
160
161 /* Read handler for everything :) file */
162 IMediaReadHandler* CreateFFReadHandler(const char *pszFile);
163
164 AVM_END_NAMESPACE;
165
166 #endif // READHANDLERS_H