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 41 ~MediaExtractor(); 42 43 status_t InitCheck(); 44 45 BDataIO* Source() const; 46 47 void GetFileFormatInfo( 48 media_file_format* fileFormat) const; 49 status_t GetMetaData(BMessage* _data) const; 50 51 int32 StreamCount(); 52 53 const char* Copyright(); 54 55 const media_format* EncodedFormat(int32 stream); 56 int64 CountFrames(int32 stream) const; 57 bigtime_t Duration(int32 stream) const; 58 59 status_t Seek(int32 stream, uint32 seekTo, 60 int64* _frame, bigtime_t* _time); 61 status_t FindKeyFrame(int32 stream, uint32 seekTo, 62 int64* _frame, bigtime_t* _time) const; 63 64 status_t GetNextChunk(int32 stream, 65 const void** _chunkBuffer, 66 size_t* _chunkSize, 67 media_header* mediaHeader); 68 69 status_t CreateDecoder(int32 stream, Decoder** _decoder, 70 media_codec_info* codecInfo); 71 72 status_t GetStreamMetaData(int32 stream, 73 BMessage* _data) const; 74 75 void StopProcessing(); 76 77 78 private: 79 void _Init(BDataIO* source, int32 flags); 80 81 void _RecycleLastChunk(stream_info& info); 82 static int32 _ExtractorEntry(void* arg); 83 void _ExtractorThread(); 84 85 private: 86 status_t fInitStatus; 87 88 sem_id fExtractorWaitSem; 89 thread_id fExtractorThread; 90 91 BDataIO* fSource; 92 Reader* fReader; 93 94 stream_info* fStreamInfo; 95 int32 fStreamCount; 96 97 media_file_format fFileFormat; 98 }; 99 100 } // namespace media 101 } // namespace BPrivate 102 103 using namespace BPrivate::media; 104 105 #endif // _MEDIA_EXTRACTOR_H 106