AVI.hpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. //=====================================================================
  2. //
  3. // Copyright (c) 1999-2003 On2 Technologies Inc. All Rights Reserved.
  4. //
  5. //---------------------------------------------------------------------
  6. //
  7. // File: $Workfile: AVI.hpp$
  8. //
  9. // Date: $Date: 2010/07/23 19:10:47 $
  10. //
  11. // Revision: $Revision: 1.1 $
  12. //
  13. //---------------------------------------------------------------------
  14. #ifndef AVI_HPP
  15. #define AVI_HPP
  16. #pragma warning(disable:4786)
  17. #include "FourCC.hpp"
  18. #include <exception>
  19. #include <iosfwd>
  20. #include <list>
  21. #include <deque>
  22. #include <string>
  23. #include <vector>
  24. #if defined WIN32
  25. #include <windows.h>
  26. #endif
  27. namespace AVI
  28. {
  29. #if defined WIN32
  30. typedef unsigned __int64 size_type;
  31. typedef DWORD dword;
  32. typedef __int64 offset_t;
  33. typedef unsigned __int32 length_t;
  34. #elif defined LINUX
  35. typedef unsigned long long size_type;
  36. typedef unsigned long dword;
  37. typedef long long offset_t;
  38. typedef unsigned int length_t;
  39. #endif
  40. int asStreamId(const FourCC&);
  41. enum ChunkType
  42. {
  43. waveform,
  44. waveform_encrypted,
  45. DIB_compressed,
  46. DIB_uncompressed,
  47. DIB_encrypted,
  48. kChunkTypeUnknown
  49. };
  50. ChunkType asChunkType(const FourCC&);
  51. const FourCC asChunkId(int stream, ChunkType type);
  52. const FourCC asIndexChunkExId(int stream);
  53. size_type estimatedFileSize(
  54. int width,
  55. int height,
  56. int frameCount);
  57. const std::string offtoa(offset_t);
  58. class FileError : public std::exception
  59. {
  60. public:
  61. FileError(dword messageId);
  62. FileError(const char* message);
  63. ~FileError() throw();
  64. const char* what() const throw();
  65. dword id() const;
  66. private:
  67. std::string message;
  68. dword m_id;
  69. };
  70. struct MainHeader
  71. {
  72. enum Flag
  73. {
  74. hasIndex = 0x00000010,
  75. mustUseIndex = 0x00000020,
  76. isInterleaved = 0x00000100,
  77. indexIsAbsolute = 0x00000800, //? "trust cktype"
  78. wasCaptureFile = 0x00010000,
  79. copyrighted = 0x00020000
  80. };
  81. dword microSecPerFrame;
  82. dword maxBytesPerSec;
  83. dword paddingGranularity;
  84. dword flags;
  85. dword totalFrames;
  86. dword initialFrames;
  87. dword streams;
  88. dword suggestedBufferSize;
  89. dword width;
  90. dword height;
  91. dword reserved[4];
  92. const std::string flagsAsStr() const;
  93. };
  94. std::ostream& operator<<(std::ostream&, const MainHeader&);
  95. class Chunk
  96. {
  97. public:
  98. Chunk(const FourCC, length_t, const unsigned char* data = 0);
  99. const FourCC fcc() const;
  100. length_t length() const;
  101. const unsigned char* data() const;
  102. unsigned char* data();
  103. void data(const unsigned char* d);
  104. private:
  105. FourCC m_fcc;
  106. // length_t m_length;
  107. // unsigned char* m_data;
  108. typedef std::vector<unsigned char> data_t;
  109. data_t m_data;
  110. };
  111. std::ostream& operator<<(std::ostream& os, const Chunk&);
  112. typedef std::vector<Chunk> ExtraHeaderVector;
  113. struct Rectangle
  114. {
  115. typedef unsigned short T;
  116. T left;
  117. T top;
  118. T right;
  119. T bottom;
  120. Rectangle()
  121. : left(0), top(0), right(0), bottom(0)
  122. {
  123. }
  124. Rectangle(T l, T t, T r, T b)
  125. : left(l), top(t), right(r), bottom(b)
  126. {
  127. }
  128. };
  129. struct StreamHeader
  130. {
  131. enum Flag
  132. {
  133. disabled = 0x00000001,
  134. formatChanges = 0x00010000
  135. };
  136. FourCC fccType;
  137. FourCC fccHandler;
  138. dword flags;
  139. unsigned short priority;
  140. unsigned short language;
  141. dword initialFrames;
  142. dword scale;
  143. dword rate;
  144. dword start;
  145. dword length;
  146. dword suggestedBufferSize;
  147. long quality;
  148. dword sampleSize;
  149. Rectangle frame;
  150. const std::string flagsAsStr() const;
  151. };
  152. std::ostream& operator<<(std::ostream&, const StreamHeader&);
  153. struct BitmapInfoHeader
  154. {
  155. dword size;
  156. long width;
  157. long height;
  158. unsigned short planes;
  159. unsigned short bitCount;
  160. FourCC compression;
  161. dword sizeImage;
  162. long xPelsPerMeter;
  163. long yPelsPerMeter;
  164. dword clrUsed;
  165. dword clrImportant;
  166. };
  167. std::ostream& operator<<(std::ostream&, const BitmapInfoHeader&);
  168. // namespace Compression
  169. // {
  170. // enum CompressionType
  171. // {
  172. // RGB,
  173. // RLE8,
  174. // RLE4,
  175. // bitfields,
  176. // unknown
  177. // };
  178. //
  179. // bool operator==(CompressionType, const FourCC&);
  180. // bool operator==(const FourCC&, CompressionType);
  181. //
  182. // CompressionType asCompression(const FourCC&);
  183. // const FourCC asFourCC(CompressionType);
  184. //
  185. // std::ostream& operator<<(std::ostream&, CompressionType);
  186. // }
  187. struct PCMWaveFormat
  188. {
  189. unsigned short formatTag;
  190. unsigned short nChannels;
  191. dword samplesPerSec;
  192. dword avgBytesPerSec;
  193. unsigned short blockAlign;
  194. unsigned short bitsPerSample;
  195. };
  196. struct WaveFormatEx : public PCMWaveFormat
  197. {
  198. typedef std::vector<unsigned char> ByteArray;
  199. ByteArray extra;
  200. };
  201. std::ostream& operator<<(std::ostream&, const WaveFormatEx&);
  202. //not currently used; it's for palette changes,
  203. //which isn't implemented yet
  204. struct RGBQuad
  205. {
  206. unsigned char blue;
  207. unsigned char green;
  208. unsigned char red;
  209. unsigned char reserved;
  210. };
  211. struct IndexEntry
  212. {
  213. enum Flags
  214. {
  215. list = 0x00000001,
  216. keyframe = 0x00000010,
  217. notime = 0x00000100,
  218. compuse = 0x0FFF0000
  219. };
  220. FourCC chunkId;
  221. dword flags;
  222. dword chunkOffset;
  223. dword chunkLength;
  224. const std::string flagsAsStr() const;
  225. };
  226. std::ostream& operator<<(std::ostream&, const IndexEntry&);
  227. typedef std::vector<IndexEntry> IEVector;
  228. struct FrameIndexEntry
  229. {
  230. union
  231. {
  232. offset_t offset;
  233. struct
  234. {
  235. unsigned long offset_low;
  236. unsigned long offset_high;
  237. };
  238. };
  239. size_t size;
  240. bool keyframe;
  241. };
  242. typedef std::vector<FrameIndexEntry> FrameIEVector;
  243. typedef std::list<FrameIndexEntry> FrameIEList;
  244. typedef std::deque<FrameIndexEntry> FrameIndex;
  245. struct IndexChunkEx
  246. {
  247. FourCC code;
  248. unsigned long length;
  249. unsigned short longsPerEntry;
  250. unsigned char subtype;
  251. unsigned char type;
  252. unsigned long entriesInUse;
  253. FourCC chunkId;
  254. unsigned long reserved[3];
  255. };
  256. std::ostream& operator<<(std::ostream&, const IndexChunkEx&);
  257. struct StandardIndexChunk
  258. {
  259. FourCC code;
  260. unsigned long length;
  261. unsigned short longsPerEntry;
  262. unsigned char subtype;
  263. unsigned char type;
  264. unsigned long entriesInUse;
  265. FourCC chunkId;
  266. unsigned long baseOffset_low;
  267. unsigned long baseOffset_high;
  268. unsigned long reserved;
  269. struct Entry
  270. {
  271. unsigned long offset;
  272. unsigned long size;
  273. } index[1];
  274. };
  275. std::ostream& operator<<(std::ostream&, const StandardIndexChunk&);
  276. std::ostream& operator<<(std::ostream&, const StandardIndexChunk::Entry&);
  277. struct SuperIndexChunk
  278. {
  279. FourCC code;
  280. unsigned long length;
  281. unsigned short longsPerEntry;
  282. unsigned char subtype;
  283. unsigned char type;
  284. unsigned long entriesInUse;
  285. FourCC chunkId;
  286. unsigned long reserved[3];
  287. struct Entry
  288. {
  289. offset_t offset;
  290. unsigned long size;
  291. unsigned long duration;
  292. } index[1];
  293. };
  294. std::ostream& operator<<(std::ostream&, const SuperIndexChunk&);
  295. std::ostream& operator<<(std::ostream&, const SuperIndexChunk::Entry&);
  296. class File
  297. {
  298. public:
  299. enum mode_t {in, out, inout};
  300. enum OutputType
  301. {
  302. OT_AVI,
  303. OT_On2
  304. };
  305. File();
  306. File(const char* name, mode_t mode);
  307. ~File();
  308. void open(const char* name, mode_t mode, dword flags = 0);
  309. void outputType(OutputType ot);
  310. void close();
  311. bool isOpen() const;
  312. mode_t mode() const;
  313. const char* name() const;
  314. void mapinit();
  315. void mapfinal();
  316. unsigned long map(
  317. offset_t offset,
  318. length_t size,
  319. unsigned char*& base,
  320. length_t& baseSize,
  321. length_t& offsetInView) const;
  322. void unmap(unsigned char* base, length_t size) const;
  323. const MainHeader& mainHeader() const;
  324. MainHeader& mainHeader();
  325. int extraHeaderCount() const;
  326. const Chunk& extraHeader(int nChunk) const;
  327. void extraHeader(FourCC fcc, length_t length, unsigned char* data);
  328. void extraHeader(int nStream, FourCC fcc, length_t length, unsigned char* data);
  329. dword totalFrames() const;
  330. dword& totalFrames();
  331. int streamCount() const;
  332. int makeStreamHeaderVideo(int superIndexEntryCount = 0);
  333. int makeStreamHeaderAudio(int superIndexEntryCount = 0);
  334. const StreamHeader& streamHeader(int stream) const;
  335. StreamHeader& streamHeader(int stream);
  336. const unsigned char* strf(int nStream) const;
  337. size_t strfSize(int nStream) const;
  338. const BitmapInfoHeader& videoFormat(int stream) const;
  339. BitmapInfoHeader& videoFormat(int stream);
  340. const WaveFormatEx& audioFormat(int stream) const;
  341. WaveFormatEx& audioFormat(int stream);
  342. dword streamDataSize(int stream) const;
  343. const unsigned char* streamData(int stream) const;
  344. void setStreamData(int nStream, dword sds, const unsigned char* psd);
  345. const char* streamName(int stream) const;
  346. void setStreamName(int nStream, const char* psn);
  347. SuperIndexChunk& superIndexChunk(int stream);
  348. const SuperIndexChunk& superIndexChunk(int stream) const;
  349. int superIndexEntryCount(int stream) const;
  350. offset_t tell() const;
  351. void seek(offset_t) const;
  352. void seekCurrent(offset_t) const;
  353. offset_t dataOffset() const;
  354. offset_t idx1Offset() const;
  355. length_t idx1Size() const;
  356. void rewriteHeaders();
  357. //For use by header updaters, throws if position of movi list
  358. //changes, positions at beginning of data.
  359. void seekMainHeader();
  360. void writeMainHeader();
  361. length_t seekStreamHeader(int stream);
  362. void writeStreamHeader(int stream);
  363. void seekVideoFormat(int stream);
  364. void writeVideoFormat(int stream);
  365. void seekAudioFormat(int stream);
  366. void writeAudioFormat(int stream);
  367. void seekStreamData(int stream);
  368. void writeStreamData(int stream);
  369. void seekSuperIndexChunk(int stream);
  370. void writeSuperIndexChunk(int stream);
  371. int indexCount() const;
  372. void seekIndex() const;
  373. void read(IndexEntry&) const;
  374. void load(int stream, IEVector& index) const;
  375. void load(int stream, FrameIndex& index) const;
  376. void loadIndex(int, FrameIndex&) const;
  377. void loadIndexEx(int, FrameIndex&) const;
  378. void writeIndexChunkHeader(int number_of_index_entries);
  379. void write(const IndexEntry&) const;
  380. void writeIndexChunk(const IEVector& index);
  381. void writeIndexChunk(
  382. const FourCC& chunkId,
  383. const FrameIndex& index);
  384. void writeStandardIndexChunk(
  385. int stream,
  386. const FrameIndex& index,
  387. offset_t baseOffset);
  388. void writeStandardIndexChunk(
  389. int stream,
  390. const FrameIndex& index);
  391. size_t makeSegment();
  392. int segmentCount() const;
  393. offset_t segmentOffset() const;
  394. const FourCC readFourCC() const;
  395. void writeFourCC(const FourCC&);
  396. const FourCC testFourCC() const;
  397. length_t readLength() const;
  398. void writeLength(length_t length);
  399. void read(void* buffer, size_t size) const;
  400. void write(const void* data, size_t size, bool adjust = true);
  401. void writeJunkChunk(length_t);
  402. int countIndexEntries(int stream) const;
  403. bool indexIsRelative() const;
  404. offset_t size() const;
  405. private:
  406. File(const File& rhs);
  407. File& operator=(const File& rhs);
  408. //void readUnknownChunk() const;
  409. void readJunkChunk() const;
  410. bool readInit();
  411. bool readHeaderList();
  412. void readMainHeader();
  413. void readExtraHeaders();
  414. void readStreamHeaderList();
  415. void readStreamHeader(StreamHeader& h);
  416. void readStreamVideoFormat(BitmapInfoHeader& f);
  417. struct StreamInfoVideo;
  418. void readStreamVideoFormat(StreamInfoVideo* psiv);
  419. void readStreamAudioFormat(WaveFormatEx& f);
  420. void readStreamName(std::string& name);
  421. void readExtendedAVIHeader();
  422. void writeExtendedAVIHeader();
  423. bool readDataList();
  424. void readDataRecChunk() const;
  425. void readDataChunk() const;
  426. void readIndexList();
  427. void writeInit();
  428. void writeFinal();
  429. void writeHeader();
  430. void writeStreamHeaderList(int stream);
  431. void writeStreamHeader(const StreamHeader& h);
  432. void writeStreamVideoFormatChunk(const BitmapInfoHeader& f);
  433. void writeStreamVideoFormat(const BitmapInfoHeader& f);
  434. void writeStreamVideoFormatChunk(const unsigned char* pData, size_t sizeData);
  435. void writeStreamVideoFormat(const unsigned char* pData, size_t sizeData);
  436. void writeStreamAudioFormatChunk(const WaveFormatEx&);
  437. void writeStreamAudioFormat(const WaveFormatEx&);
  438. int headerLength() const;
  439. int streamHeaderLength(int stream) const;
  440. void load(const SuperIndexChunk::Entry&, FrameIndex&) const;
  441. class handle_t
  442. {
  443. public:
  444. handle_t();
  445. void open(const char*, mode_t, dword) throw (FileError);
  446. void close();
  447. bool isOpen() const;
  448. offset_t size() const;
  449. void read(void*, size_t) const;
  450. void write(const void*, size_t) const;
  451. void truncate() const;
  452. void seekCurrent(offset_t) const;
  453. void seek(offset_t) const;
  454. offset_t tell() const;
  455. void mapinit();
  456. void mapfinal();
  457. unsigned long map(
  458. offset_t offset,
  459. length_t size,
  460. unsigned char*& view,
  461. length_t& viewSize,
  462. length_t& offsetWithinView) const;
  463. void unmap(unsigned char*, length_t) const;
  464. private:
  465. #if defined WIN32
  466. HANDLE m_hFile;
  467. HANDLE m_hFileMappingObject;
  468. #elif defined LINUX
  469. int m_fd;
  470. #endif
  471. };
  472. handle_t m_handle;
  473. mode_t m_mode;
  474. std::string m_name;
  475. OutputType m_ot;
  476. MainHeader m_mainHeader;
  477. ExtraHeaderVector m_extraHeaderVector;
  478. class indx_t
  479. {
  480. public:
  481. indx_t();
  482. indx_t(int entryCount);
  483. ~indx_t();
  484. int entryCount() const;
  485. size_t size() const;
  486. operator SuperIndexChunk&() const;
  487. void read(File&);
  488. void write(File&) const;
  489. private:
  490. indx_t(const indx_t&);
  491. indx_t& operator=(const indx_t&);
  492. dword* m_rep;
  493. };
  494. struct StreamInfo
  495. {
  496. virtual ~StreamInfo();
  497. void write(File&) const;
  498. int length() const;
  499. StreamHeader header;
  500. typedef std::vector<unsigned char> data_t;
  501. data_t m_data;
  502. std::string m_name;
  503. ExtraHeaderVector m_extraHeaderVector;
  504. indx_t m_indx;
  505. protected:
  506. StreamInfo(int);
  507. StreamInfo(const StreamHeader&);
  508. virtual int strf_length() const = 0;
  509. virtual void strf_write(File&) const = 0;
  510. private:
  511. StreamInfo(const StreamInfo&);
  512. StreamInfo& operator=(const StreamInfo&);
  513. };
  514. struct StreamInfoVideo : public StreamInfo
  515. {
  516. StreamInfoVideo(int entryCount);
  517. StreamInfoVideo(const StreamHeader&);
  518. ~StreamInfoVideo();
  519. // BitmapInfoHeader m_strf;
  520. unsigned char* m_strf;
  521. size_t m_strfSize;
  522. protected:
  523. int strf_length() const;
  524. void strf_write(File&) const;
  525. };
  526. struct StreamInfoAudio : public StreamInfo
  527. {
  528. StreamInfoAudio(int entryCount);
  529. StreamInfoAudio(const StreamHeader&);
  530. WaveFormatEx m_strf;
  531. protected:
  532. int strf_length() const;
  533. void strf_write(File&) const;
  534. };
  535. friend struct StreamInfo;
  536. friend struct StreamInfoVideo;
  537. friend struct StreamInfoAudio;
  538. void readStreamData(StreamInfo::data_t&);
  539. typedef std::vector<StreamInfo*> infoVector_t;
  540. infoVector_t infoVector;
  541. dword m_totalFrames;
  542. offset_t m_dataPosn;
  543. offset_t m_indexPosn;
  544. int m_indexCount;
  545. length_t m_idx1Size;
  546. struct SegmentInfo
  547. {
  548. offset_t offset;
  549. size_t size;
  550. SegmentInfo() {}
  551. SegmentInfo(offset_t offset_) : offset(offset_) {}
  552. };
  553. typedef std::vector<SegmentInfo> SegmentInfoVector;
  554. SegmentInfoVector m_segmentInfo;
  555. };
  556. #if defined WIN32
  557. class MappedFile
  558. {
  559. public:
  560. enum { invalid_offset = -1 };
  561. MappedFile();
  562. MappedFile(const char* name);
  563. ~MappedFile();
  564. void open(const char* name);
  565. void close();
  566. bool isOpen() const;
  567. const char* name() const;
  568. const MainHeader& mainHeader() const;
  569. const StreamHeader& streamHeader(int stream) const;
  570. const BitmapInfoHeader& videoFormat(int stream) const;
  571. const WaveFormatEx& audioFormat(int stream) const;
  572. const char* streamName(int stream) const;
  573. dword totalFrames() const;
  574. offset_t dataOffset() const;
  575. offset_t indexOffset() const;
  576. size_t indexSize() const;
  577. offset_t indexChunkExOffset(int stream) const;
  578. size_t indexChunkExSize(int stream) const;
  579. const void* map(offset_t, size_t) const;
  580. void unmap(const void*) const;
  581. void load(int stream, FrameIEVector& index) const;
  582. private:
  583. MappedFile(const MappedFile&);
  584. MappedFile& operator=(const MappedFile&);
  585. void init();
  586. void unmapAllViews();
  587. offset_t offset() const;
  588. void setFilePointerCurrent(LONG) const;
  589. const FourCC readFourCC() const;
  590. const FourCC queryFourCC() const;
  591. dword readLength() const;
  592. void readHeaderList();
  593. void readDataList();
  594. void readIndexList();
  595. void readJunkChunk() const;
  596. void readUnknownChunk() const;
  597. void readMainHeaderChunk();
  598. void readStreamHeaderList(int stream);
  599. void readStreamHeaderChunk(StreamHeader&) const;
  600. void readStreamVideoFormatChunk(BitmapInfoHeader&) const;
  601. void readStreamAudioFormatChunk(WaveFormatEx&) const;
  602. void readStreamNameChunk(std::string&) const;
  603. void readIndexChunkEx(offset_t&, size_t&) const;
  604. void readExtendedAVIHeaderList() const;
  605. std::string m_name;
  606. HANDLE m_file;
  607. HANDLE m_fileMappingObject;
  608. DWORD m_allocationGranularity;
  609. MainHeader m_mainHeader;
  610. struct StreamInfo
  611. {
  612. StreamHeader streamHeader;
  613. union
  614. {
  615. BitmapInfoHeader* videoFormat;
  616. WaveFormatEx* audioFormat;
  617. };
  618. std::string name;
  619. offset_t indexChunkExOffset;
  620. size_t indexChunkExSize;
  621. };
  622. typedef std::vector<StreamInfo> StreamInfoVector;
  623. StreamInfoVector m_streamInfoVector;
  624. size_t readChunkSize(offset_t) const;
  625. int countEntries(int, const IndexEntry*, int) const;
  626. int countEntries(const SuperIndexChunk&) const;
  627. void loadIndex(int, FrameIEVector&) const;
  628. void loadIndexEx(int, FrameIEVector&) const;
  629. void load(const SuperIndexChunk::Entry&, FrameIEVector&) const;
  630. mutable dword m_totalFrames;
  631. offset_t m_dataOffset;
  632. offset_t m_indexOffset;
  633. size_t m_indexSize;
  634. struct ViewInfo
  635. {
  636. unsigned char* pView;
  637. unsigned char* pChunk;
  638. };
  639. typedef std::list<ViewInfo> Views;
  640. mutable Views m_views;
  641. Views::iterator findView(const void*) const;
  642. };
  643. #endif
  644. }
  645. //inline HANDLE AVI::File::handle() const
  646. //{
  647. // return m_handle;
  648. //}
  649. inline AVI::Chunk::Chunk(
  650. const FourCC fcc,
  651. length_t length,
  652. const unsigned char* d)
  653. : m_fcc(fcc)
  654. {
  655. // if (m_length > 0)
  656. // {
  657. // m_data = new unsigned char[m_length];
  658. // if (m_data == 0)
  659. // {
  660. // throw FileError("Error allocating Chunk data.");
  661. // }
  662. // if (data != 0)
  663. // {
  664. // memcpy(m_data, data, m_length);
  665. // }
  666. // }
  667. if (length)
  668. {
  669. if (d)
  670. {
  671. //typedef data_t::const_iterator iter_t;
  672. //const iter_t first = iter_t(d);
  673. //const data_t::size_type n = length;
  674. //const iter_t last = first + n;
  675. m_data.assign(d, d + length);
  676. }
  677. else
  678. {
  679. const data_t::size_type n = length;
  680. m_data.assign(n, 0);
  681. }
  682. }
  683. else
  684. {
  685. m_data.assign(data_t::size_type(0), 0);
  686. }
  687. }
  688. inline const FourCC AVI::Chunk::fcc() const
  689. {
  690. return m_fcc;
  691. }
  692. inline AVI::length_t AVI::Chunk::length() const
  693. {
  694. const data_t::size_type n = m_data.size();
  695. return n;
  696. }
  697. inline const unsigned char* AVI::Chunk::data() const
  698. {
  699. return &m_data[0];
  700. }
  701. inline unsigned char* AVI::Chunk::data()
  702. {
  703. return &m_data[0];
  704. }
  705. inline void AVI::Chunk::data(const unsigned char* d)
  706. {
  707. //typedef data_t::const_iterator iter_t;
  708. //const iter_t first = iter_t(d);
  709. //const data_t::size_type n = m_data.size();
  710. //const iter_t last = first + n;
  711. m_data.assign(d, d + m_data.size());
  712. }
  713. inline AVI::dword AVI::FileError::id() const
  714. {
  715. return m_id;
  716. }
  717. #endif