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