Debian Codegraph @

lib/aviread/AsfInputStream.h

raw
1 #ifndef AVIFILE_ASFITERATOR_H
2 #define AVIFILE_ASFITERATOR_H
3
4 #include "asffmt.h"
5
6 AVM_BEGIN_NAMESPACE;
7
8 struct chunk_info
9 {
10 static const int KEYFRAME = 1 << 31;
11
12 uint32_t object_start_time;
13 uint32_t object_length; // 31bit marks keyframe - anyone has frames >2^31 bytes?
14 uint32_t packet_id;
15 uint16_t fragment_id; // let's cheat here
16
17 uint_t GetChunkLength() const { return object_length & ~KEYFRAME; }
18 bool IsKeyFrame() const { return object_length & KEYFRAME; }
19 void SetKeyFrame(bool s) { if (s) object_length |= KEYFRAME; }
20 };
21
22 class AsfStreamSeekInfo: public avm::vector<chunk_info>
23 {
24 public:
25 static const framepos_t ERR = ~0U;
26
27 framepos_t find(uint_t time) const;
28 framepos_t nearestKeyFrame(framepos_t kf = ERR) const;
29 framepos_t nextKeyFrame(framepos_t kf = ERR) const;
30 framepos_t prevKeyFrame(framepos_t kf = ERR) const;
31 };
32
33 /*
34 * This logic is needed to properly handle reading from networked streams.
35 * Each stream owns an 'iterator' that can be used to access packets.
36 * If the stream is local, it allows iterators for different streams
37 * to point at completely independent packets ( and seek independently ).
38 * If it isn't, seek() on one iterator invalidates the other, and when
39 * seek() is called on invalidated iterator, it's automatically
40 * reposition at the place of last seek.
41 */
42
43 class AsfIterator
44 {
45 public:
46 AsfIterator(int id = 0) : m_iRefcount(1), m_iId(id), m_bEof(false) {}
47 virtual ~AsfIterator();
48 virtual void addRef() { m_iRefcount++; }
49 virtual void release() { m_iRefcount--; if (!m_iRefcount) delete this; }
50 virtual bool isEof() { return m_bEof; }
51
52 virtual AsfPacket* getPacket() =0;
53 virtual const AsfStreamSeekInfo* getSeekInfo() =0;
54 virtual int seek(framepos_t pos, chunk_info* pch) =0;
55 virtual int seekTime(double timestamp, chunk_info* pch) =0;
56 int getId() { return m_iId; }
57 protected:
58 int m_iRefcount;
59 int m_iId;
60 bool m_bEof;
61 };
62
63 class AsfInputStream
64 {
65 public:
66 static const uint_t ASF_STREAMS = 0x7f;
67
68 virtual ~AsfInputStream();
69 virtual const ASFMainHeader& getHeader() const { return m_Header; }
70 virtual const avm::vector<ASFStreamHeader>& getStreams() const { return m_Streams; }
71 virtual AsfIterator* getIterator(uint_t id) { return 0; }
72 virtual double cacheSize() const { return 1.; }
73 virtual void clear() {}
74 virtual void interrupt() {}
75 virtual bool isOpened() { return true; }
76 virtual bool isValid() { return true; }
77 virtual bool isRedirector() { return false; }
78 virtual bool getURLs(avm::vector<avm::string>& urls) { return false; }
79 int getMaxBitrate(uint_t i)
80 {
81 return (i <= ASF_STREAMS) ? m_MaxBitrates[i] : ~0U;
82 }
83 protected:
84 bool parseHeader(uint8_t* b, size_t size, int level = 0);
85 ASFMainHeader m_Header;
86 avm::vector<ASFStreamHeader> m_Streams;
87 avm::vector<avm::string> m_Description;
88 uint_t m_MaxBitrates[ASF_STREAMS + 1];
89 };
90
91 AVM_END_NAMESPACE;
92
93 #endif // AVIFILE_ITERATOR_H