1/* 2 * Copyright (c) 2007, Marcus Overhagen 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * * Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 21 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 22 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 23 * OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25#ifndef _INDEX_H 26#define _INDEX_H 27 28#include <SupportDefs.h> 29#include <vector> 30 31#include "OpenDMLParser.h" 32 33/* 34 This class handles all indexing of an AVI file 35 Subclasses should override Init and create index entries based on the 36 specialised index. 37 38 Seek and GetNextChunk will then work. 39 40 Current known subclasses are: 41 Standard Index - Original AVI index idx1 42 OpenDMLIndex - Open DML Standard Index 43 FallBackIndex - Index created from the movi chunk 44*/ 45 46 47class BPositionIO; 48class OpenDMLParser; 49 50class IndexEntry { 51public: 52 IndexEntry() {frame_no = 0;position=0;size=0;pts=0;keyframe=false;}; 53 54 uint64 frame_no; // frame_no or sample_no 55 off_t position; // The offset in the stream where the frame is 56 uint32 size; // The size of the data available 57 bigtime_t pts; // Presentation Time Stamp for this frame 58 bool keyframe; // Is this a keyframe. 59}; 60 61class MediaStream { 62public: 63 MediaStream() {seek_index_next=0;current_chunk=0;} ; 64 ~MediaStream() {seek_index.clear();}; 65 std::vector<IndexEntry> seek_index; 66 uint64 seek_index_next; 67 uint64 current_chunk; 68}; 69 70class Index { 71public: 72 Index(BPositionIO *source, OpenDMLParser *parser); 73 virtual ~Index(); 74 75 virtual status_t Init() = 0; 76 77 status_t GetNextChunkInfo(int stream_index, off_t *start, 78 uint32 *size, bool *keyframe); 79 80 status_t Seek(int stream_index, uint32 seekTo, int64 *frame, 81 bigtime_t *time, bool readOnly); 82 83 void AddIndex(int stream_index, off_t position, uint32 size, uint64 frame, bigtime_t pts, bool keyframe); 84 void DumpIndex(int stream_index); 85 86protected: 87 BPositionIO * fSource; 88 OpenDMLParser * fParser; 89 int fStreamCount; 90 91private: 92 std::vector<MediaStream> fStreamData; 93}; 94 95#endif // _INDEX_H 96