MediaEncoder.h revision 278d03da
1/*
2 * Copyright 2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _MEDIA_ENCODER_H
6#define _MEDIA_ENCODER_H
7
8
9#include <MediaFormats.h>
10
11
12namespace BCodecKit {
13	class BEncoder;
14}
15
16
17class BMediaEncoder {
18public:
19								BMediaEncoder();
20								BMediaEncoder(
21									const media_format* outputFormat);
22								BMediaEncoder(const media_codec_info* info);
23	virtual						~BMediaEncoder();
24
25			status_t			InitCheck() const;
26
27			status_t			SetTo(const media_format* outputFormat);
28			status_t			SetTo(const media_codec_info* info);
29			status_t			SetFormat(media_format* inputFormat,
30									media_format* outputFormat,
31									media_file_format* fileFormat = NULL);
32
33			status_t			Encode(const void* buffer, int64 frameCount,
34									media_encode_info* info);
35
36			status_t			GetEncodeParameters(
37									encode_parameters* parameters) const;
38			status_t			SetEncodeParameters(
39									encode_parameters* parameters);
40
41protected:
42	virtual	status_t			WriteChunk(const void* buffer, size_t size,
43									media_encode_info* info) = 0;
44
45	virtual	status_t			AddTrackInfo(uint32 code, const char* data,
46									size_t size);
47
48	// TODO: Needs Perform() method for FBC!
49
50private:
51	// FBC padding and forbidden methods
52	virtual	status_t			_Reserved_BMediaEncoder_0(int32 arg, ...);
53	virtual	status_t			_Reserved_BMediaEncoder_1(int32 arg, ...);
54	virtual	status_t			_Reserved_BMediaEncoder_2(int32 arg, ...);
55	virtual	status_t			_Reserved_BMediaEncoder_3(int32 arg, ...);
56	virtual	status_t			_Reserved_BMediaEncoder_4(int32 arg, ...);
57	virtual	status_t			_Reserved_BMediaEncoder_5(int32 arg, ...);
58	virtual	status_t			_Reserved_BMediaEncoder_6(int32 arg, ...);
59	virtual	status_t			_Reserved_BMediaEncoder_7(int32 arg, ...);
60	virtual	status_t			_Reserved_BMediaEncoder_8(int32 arg, ...);
61	virtual	status_t			_Reserved_BMediaEncoder_9(int32 arg, ...);
62	virtual	status_t			_Reserved_BMediaEncoder_10(int32 arg, ...);
63	virtual	status_t			_Reserved_BMediaEncoder_11(int32 arg, ...);
64	virtual	status_t			_Reserved_BMediaEncoder_12(int32 arg, ...);
65	virtual	status_t			_Reserved_BMediaEncoder_13(int32 arg, ...);
66	virtual	status_t			_Reserved_BMediaEncoder_14(int32 arg, ...);
67	virtual	status_t			_Reserved_BMediaEncoder_15(int32 arg, ...);
68
69								BMediaEncoder(const BMediaEncoder& other);
70			BMediaEncoder&		operator=(const BMediaEncoder& other);
71
72private:
73			status_t			_AttachToEncoder();
74
75	static	status_t			write_chunk(void* classPtr,
76									const void* buffer, size_t size,
77									media_encode_info* info);
78
79			void				Init();
80			void				ReleaseEncoder();
81
82			uint32				_reserved_was_fEncoderMgr;
83			BCodecKit::BEncoder* fEncoder;
84
85			int32				fEncoderID;
86			bool				fFormatValid;
87			bool				fEncoderStarted;
88			status_t			fInitStatus;
89
90			uint32				_reserved_BMediaEncoder_[32];
91};
92
93
94class BMediaBufferEncoder : public BMediaEncoder {
95public:
96								BMediaBufferEncoder();
97								BMediaBufferEncoder(
98									const media_format* outputFormat);
99								BMediaBufferEncoder(
100									const media_codec_info* info);
101
102			status_t			EncodeToBuffer(void* outputBuffer,
103									size_t* _size, const void* inputBuffer,
104									int64 frameCount, media_encode_info* info);
105
106protected:
107	virtual	status_t			WriteChunk(const void* buffer, size_t size,
108									media_encode_info* info);
109
110protected:
111			void*				fBuffer;
112			int32				fBufferSize;
113};
114
115#endif // _MEDIA_ENCODER_H
116
117