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