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