1 /* 2 * Copyright 2004-2007, Marcus Overhagen. All rights reserved. 3 * Copyright 2008, Maurice Kalinowski. All rights reserved. 4 * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. 5 * 6 * Distributed under the terms of the MIT License. 7 */ 8 #ifndef _MEDIA_EXTRACTOR_H 9 #define _MEDIA_EXTRACTOR_H 10 11 12 #include "ReaderPlugin.h" 13 #include "DecoderPlugin.h" 14 15 16 namespace BPrivate { 17 namespace media { 18 19 20 class ChunkCache; 21 struct chunk_buffer; 22 23 24 struct stream_info { 25 status_t status; 26 void* cookie; 27 bool hasCookie; 28 const void* infoBuffer; 29 size_t infoBufferSize; 30 ChunkCache* chunkCache; 31 chunk_buffer* lastChunk; 32 media_format encodedFormat; 33 }; 34 35 36 class MediaExtractor { 37 public: 38 MediaExtractor(BDataIO* source, int32 flags); 39 ~MediaExtractor(); 40 41 status_t InitCheck(); 42 43 void GetFileFormatInfo( 44 media_file_format* fileFormat) const; 45 46 int32 StreamCount(); 47 48 const char* Copyright(); 49 50 const media_format* EncodedFormat(int32 stream); 51 int64 CountFrames(int32 stream) const; 52 bigtime_t Duration(int32 stream) const; 53 54 status_t Seek(int32 stream, uint32 seekTo, int64* _frame, 55 bigtime_t* _time); 56 status_t FindKeyFrame(int32 stream, uint32 seekTo, 57 int64* _frame, bigtime_t* _time) const; 58 59 status_t GetNextChunk(int32 stream, 60 const void** _chunkBuffer, 61 size_t* _chunkSize, 62 media_header* mediaHeader); 63 64 status_t CreateDecoder(int32 stream, Decoder** _decoder, 65 media_codec_info* codecInfo); 66 67 private: 68 void _RecycleLastChunk(stream_info& info); 69 static int32 _ExtractorEntry(void* arg); 70 void _ExtractorThread(); 71 72 private: 73 status_t fInitStatus; 74 75 sem_id fExtractorWaitSem; 76 thread_id fExtractorThread; 77 78 BDataIO* fSource; 79 Reader* fReader; 80 81 stream_info* fStreamInfo; 82 int32 fStreamCount; 83 84 media_file_format fFileFormat; 85 }; 86 87 } // namespace media 88 } // namespace BPrivate 89 90 using namespace BPrivate::media; 91 92 #endif // _MEDIA_EXTRACTOR_H 93