xref: /haiku/headers/private/media/EncoderPlugin.h (revision e433b3cfc3f089f7681f6d4e81d43f950ca6a440)
1 /*
2  * Copyright 2009-2015, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT license.
4  */
5 #ifndef _ENCODER_PLUGIN_H
6 #define _ENCODER_PLUGIN_H
7 
8 
9 #include <MediaTrack.h>
10 #include <MediaFormats.h>
11 #include <View.h>
12 #include "MediaPlugin.h"
13 
14 
15 namespace BPrivate { namespace media {
16 
17 class PluginManager;
18 
19 class ChunkWriter {
20 public:
21 	virtual						~ChunkWriter() {};
22 	virtual	status_t			WriteChunk(const void* chunkBuffer,
23 									size_t chunkSize,
24 									media_encode_info* encodeInfo) = 0;
25 };
26 
27 
28 class Encoder {
29 public:
30 								Encoder();
31 	virtual						~Encoder();
32 
33 	// Some codecs may only support certain input color spaces, or output
34 	// color spaces, or multiple of 16 width/height... This method is needed
35 	// for get_next_encoder() functionality. If _acceptedInputFormat is NULL,
36 	// you simply return a status indicating if proposed format is acceptable.
37 	// If it contains wildcards for fields that you have restrictions on,
38 	// return an error. In that case, the user should be using the form of
39 	// get_next_encoder() that allows to specify the accepted format. If
40 	// _acceptedInputFormat is not NULL, copy the proposedFormat into
41 	// _acceptedInputFormat and specialize any wildcards. You must (!) also
42 	// change non-wildcard fields, like the video width if you want to round to
43 	// the nearest multiple of 16 for example. Only if the format is completely
44 	// unacceptable, return an error.
45 	virtual	status_t			AcceptedFormat(
46 									const media_format* proposedInputFormat,
47 									media_format* _acceptedInputFormat = NULL)
48 										= 0;
49 
50 	// The passed media_format may not contain wildcards and must be the same
51 	// format that was passed to get_next_encoder() (or it must be the format
52 	// returned in _acceptedInputFormat).
53 	virtual	status_t			SetUp(const media_format* inputFormat) = 0;
54 
55 	virtual	status_t			AddTrackInfo(uint32 code, const void* data,
56 									size_t size, uint32 flags = 0);
57 
58 	// Ownership of the BView and BParameterWeb remain with the Encoder.
59 	// A window embedding the view must remove it before it is destroyed.
60 	virtual	BView*				ParameterView();
61 
62 	virtual	BParameterWeb*		ParameterWeb();
63 	virtual	status_t			GetParameterValue(int32 id, void* value,
64 									size_t* size) const;
65 	virtual	status_t			SetParameterValue(int32 id, const void* value,
66 									size_t size);
67 
68 	virtual status_t			GetEncodeParameters(
69 									encode_parameters* parameters) const;
70 	virtual status_t			SetEncodeParameters(
71 									encode_parameters* parameters);
72 
73 	virtual status_t			Encode(const void* buffer, int64 frameCount,
74 									media_encode_info* info) = 0;
75 
76 			status_t			WriteChunk(const void* chunkBuffer,
77 									size_t chunkSize,
78 									media_encode_info* encodeInfo);
79 
80 			void				SetChunkWriter(ChunkWriter* writer);
81 
82 	virtual status_t			Perform(perform_code code, void* data);
83 
84 private:
85 			ChunkWriter*		fChunkWriter;
86 
87 	// needed for plug-in reference count management
88 	friend class PluginManager;
89 			MediaPlugin*		fMediaPlugin;
90 
91 private:
92 	// FBC padding
93 			uint32				fReserved[20];
94 
95 	virtual void				_ReservedEncoder1();
96 	virtual void				_ReservedEncoder2();
97 	virtual void				_ReservedEncoder3();
98 	virtual void				_ReservedEncoder4();
99 	virtual void				_ReservedEncoder5();
100 	virtual void				_ReservedEncoder6();
101 	virtual void				_ReservedEncoder7();
102 	virtual void				_ReservedEncoder8();
103 	virtual void				_ReservedEncoder9();
104 	virtual void				_ReservedEncoder10();
105 	virtual void				_ReservedEncoder11();
106 	virtual void				_ReservedEncoder12();
107 	virtual void				_ReservedEncoder13();
108 	virtual void				_ReservedEncoder14();
109 	virtual void				_ReservedEncoder15();
110 	virtual void				_ReservedEncoder16();
111 	virtual void				_ReservedEncoder17();
112 	virtual void				_ReservedEncoder18();
113 	virtual void				_ReservedEncoder19();
114 	virtual void				_ReservedEncoder20();
115 };
116 
117 
118 class EncoderPlugin : public virtual MediaPlugin {
119 public:
120 								EncoderPlugin();
121 
122 	virtual	Encoder*			NewEncoder(
123 									const media_codec_info& codecInfo) = 0;
124 
125 	virtual	Encoder*			NewEncoder(
126 									const media_format& format) = 0;
127 
128 	virtual	status_t			RegisterNextEncoder(int32* cookie,
129 									media_codec_info* codecInfo,
130 									media_format_family* formatFamily,
131 									media_format* inputFormat,
132 									media_format* outputFormat) = 0;
133 };
134 
135 } } // namespace BPrivate::media
136 
137 using namespace BPrivate::media;
138 
139 #endif // _ENCODER_PLUGIN_H
140