xref: /haiku/headers/private/media/MediaExtractor.h (revision 05fc1277c47440dc36134816d70e5723c99cfcd2)
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 <Url.h>
14 
15 #include "ReaderPlugin.h"
16 #include "StreamerPlugin.h"
17 #include "DecoderPlugin.h"
18 
19 
20 namespace BPrivate {
21 namespace media {
22 
23 
24 class ChunkCache;
25 struct chunk_buffer;
26 
27 
28 struct stream_info {
29 	status_t		status;
30 	void*			cookie;
31 	bool			hasCookie;
32 	const void*		infoBuffer;
33 	size_t			infoBufferSize;
34 	ChunkCache*		chunkCache;
35 	chunk_buffer*	lastChunk;
36 	media_format	encodedFormat;
37 };
38 
39 
40 class MediaExtractor {
41 public:
42 								MediaExtractor(BDataIO* source, int32 flags);
43 								MediaExtractor(const BUrl& url, int32 flags);
44 
45 								~MediaExtractor();
46 
47 			status_t			InitCheck();
48 
49 			BDataIO*			Source() const;
50 
51 			void				GetFileFormatInfo(
52 									media_file_format* fileFormat) const;
53 			status_t			GetMetaData(BMessage* _data) const;
54 
55 			int32				StreamCount();
56 
57 			const char*			Copyright();
58 
59 			const media_format*	EncodedFormat(int32 stream);
60 			int64				CountFrames(int32 stream) const;
61 			bigtime_t			Duration(int32 stream) const;
62 
63 			status_t			Seek(int32 stream, uint32 seekTo,
64 									int64* _frame, bigtime_t* _time);
65 			status_t			FindKeyFrame(int32 stream, uint32 seekTo,
66 									int64* _frame, bigtime_t* _time) const;
67 
68 			status_t			GetNextChunk(int32 stream,
69 									const void** _chunkBuffer,
70 									size_t* _chunkSize,
71 									media_header* mediaHeader);
72 
73 			status_t			CreateDecoder(int32 stream, Decoder** _decoder,
74 									media_codec_info* codecInfo);
75 
76 			status_t			GetStreamMetaData(int32 stream,
77 									BMessage* _data) const;
78 
79 private:
80 			void				_Init(BDataIO* source, int32 flags);
81 
82 			void				_RecycleLastChunk(stream_info& info);
83 	static	int32				_ExtractorEntry(void* arg);
84 			void				_ExtractorThread();
85 
86 private:
87 			status_t			fInitStatus;
88 
89 			sem_id				fExtractorWaitSem;
90 			thread_id			fExtractorThread;
91 
92 			BDataIO*			fSource;
93 			Reader*				fReader;
94 			Streamer*			fStreamer;
95 
96 			stream_info*		fStreamInfo;
97 			int32				fStreamCount;
98 
99 			media_file_format	fFileFormat;
100 };
101 
102 } // namespace media
103 } // namespace BPrivate
104 
105 using namespace BPrivate::media;
106 
107 #endif	// _MEDIA_EXTRACTOR_H
108