2009-07-31 00:05:11 +04:00
|
|
|
/*
|
2015-12-02 17:24:17 +03:00
|
|
|
* Copyright 2009-2015, Haiku Inc. All rights reserved.
|
2009-07-31 00:05:11 +04:00
|
|
|
* Distributed under the terms of the MIT license.
|
|
|
|
*/
|
2009-07-29 20:25:30 +04:00
|
|
|
#ifndef _ENCODER_PLUGIN_H
|
|
|
|
#define _ENCODER_PLUGIN_H
|
|
|
|
|
2009-07-31 00:05:11 +04:00
|
|
|
|
2009-07-29 20:25:30 +04:00
|
|
|
#include <MediaTrack.h>
|
|
|
|
#include <MediaFormats.h>
|
Encoder:
* Fleshed out the Encoder API to support parameter setters/getters and returning
a BView for configuration. (Not yet sure if this is a good idea.)
BMediaTrack:
* Implemented all but one of the unimplemented methods in BMediaTrack. It should
be working as far as that class is concerned, unless I missed some of the
vision. ReplaceFrames() remains a stub, added a comment on why it probably
stays that way.
* Release the Encoder reference in the destructor.
FFmpeg plugin:
* Refactoring to delay opening the AVCodec until encoding the first chunk,
so that we can still adjust parameters.
* Support adjusting parameters via [Set|Get]EncodeParameters(). Currently,
only quality is supported, added TODOs about supporting the bit_rate setup
versus the automatically calculated bit_rate.
* Extended EncoderDescription by a bit_rate scale. The Encoder calculates the
raw bitrate needed by the current media format, and then divides that
number by the specific codec's bit_rate_scale, while taking into account the
desired quality. This seems to work very well already (tested with MPEG4),
although a lot more parameters could be specified for libavcodec, depending
on the desired quality.
* Enabled the ogg muxer in libavformat, although it is currently still disabled
in MuxerTable.cpp, because it rejects unknown codecs. Added TODO to this
effect.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32124 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-08-05 14:21:36 +04:00
|
|
|
#include <View.h>
|
2019-05-17 21:43:32 +03:00
|
|
|
#include "MediaPlugin.h"
|
2018-10-29 11:41:21 +03:00
|
|
|
|
2009-07-29 20:25:30 +04:00
|
|
|
|
2019-05-17 21:43:32 +03:00
|
|
|
namespace BPrivate { namespace media {
|
2009-07-31 00:05:11 +04:00
|
|
|
|
2019-05-17 21:43:32 +03:00
|
|
|
class PluginManager;
|
2009-07-29 20:25:30 +04:00
|
|
|
|
2019-05-17 21:43:32 +03:00
|
|
|
class ChunkWriter {
|
2009-07-29 20:25:30 +04:00
|
|
|
public:
|
2019-05-17 21:43:32 +03:00
|
|
|
virtual ~ChunkWriter() {};
|
2009-07-29 20:25:30 +04:00
|
|
|
virtual status_t WriteChunk(const void* chunkBuffer,
|
2009-07-31 14:46:58 +04:00
|
|
|
size_t chunkSize,
|
|
|
|
media_encode_info* encodeInfo) = 0;
|
2009-07-29 20:25:30 +04:00
|
|
|
};
|
|
|
|
|
2009-07-31 00:05:11 +04:00
|
|
|
|
2019-05-17 21:43:32 +03:00
|
|
|
class Encoder {
|
2009-07-29 20:25:30 +04:00
|
|
|
public:
|
2019-05-17 21:43:32 +03:00
|
|
|
Encoder();
|
|
|
|
virtual ~Encoder();
|
|
|
|
|
2009-07-31 14:46:58 +04:00
|
|
|
// Some codecs may only support certain input color spaces, or output
|
|
|
|
// color spaces, or multiple of 16 width/height... This method is needed
|
|
|
|
// for get_next_encoder() functionality. If _acceptedInputFormat is NULL,
|
|
|
|
// you simply return a status indicating if proposed format is acceptable.
|
|
|
|
// If it contains wildcards for fields that you have restrictions on,
|
|
|
|
// return an error. In that case, the user should be using the form of
|
|
|
|
// get_next_encoder() that allows to specify the accepted format. If
|
|
|
|
// _acceptedInputFormat is not NULL, copy the proposedFormat into
|
|
|
|
// _acceptedInputFormat and specialize any wildcards. You must (!) also
|
|
|
|
// change non-wildcard fields, like the video width if you want to round to
|
|
|
|
// the nearest multiple of 16 for example. Only if the format is completely
|
|
|
|
// unacceptable, return an error.
|
|
|
|
virtual status_t AcceptedFormat(
|
|
|
|
const media_format* proposedInputFormat,
|
|
|
|
media_format* _acceptedInputFormat = NULL)
|
|
|
|
= 0;
|
|
|
|
|
|
|
|
// The passed media_format may not contain wildcards and must be the same
|
|
|
|
// format that was passed to get_next_encoder() (or it must be the format
|
|
|
|
// returned in _acceptedInputFormat).
|
|
|
|
virtual status_t SetUp(const media_format* inputFormat) = 0;
|
2009-07-29 20:25:30 +04:00
|
|
|
|
|
|
|
virtual status_t AddTrackInfo(uint32 code, const void* data,
|
2009-07-31 14:46:58 +04:00
|
|
|
size_t size, uint32 flags = 0);
|
2009-07-29 20:25:30 +04:00
|
|
|
|
Encoder:
* Fleshed out the Encoder API to support parameter setters/getters and returning
a BView for configuration. (Not yet sure if this is a good idea.)
BMediaTrack:
* Implemented all but one of the unimplemented methods in BMediaTrack. It should
be working as far as that class is concerned, unless I missed some of the
vision. ReplaceFrames() remains a stub, added a comment on why it probably
stays that way.
* Release the Encoder reference in the destructor.
FFmpeg plugin:
* Refactoring to delay opening the AVCodec until encoding the first chunk,
so that we can still adjust parameters.
* Support adjusting parameters via [Set|Get]EncodeParameters(). Currently,
only quality is supported, added TODOs about supporting the bit_rate setup
versus the automatically calculated bit_rate.
* Extended EncoderDescription by a bit_rate scale. The Encoder calculates the
raw bitrate needed by the current media format, and then divides that
number by the specific codec's bit_rate_scale, while taking into account the
desired quality. This seems to work very well already (tested with MPEG4),
although a lot more parameters could be specified for libavcodec, depending
on the desired quality.
* Enabled the ogg muxer in libavformat, although it is currently still disabled
in MuxerTable.cpp, because it rejects unknown codecs. Added TODO to this
effect.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32124 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-08-05 14:21:36 +04:00
|
|
|
// Ownership of the BView and BParameterWeb remain with the Encoder.
|
|
|
|
// A window embedding the view must remove it before it is destroyed.
|
|
|
|
virtual BView* ParameterView();
|
|
|
|
|
|
|
|
virtual BParameterWeb* ParameterWeb();
|
|
|
|
virtual status_t GetParameterValue(int32 id, void* value,
|
|
|
|
size_t* size) const;
|
|
|
|
virtual status_t SetParameterValue(int32 id, const void* value,
|
|
|
|
size_t size);
|
|
|
|
|
2009-07-29 20:25:30 +04:00
|
|
|
virtual status_t GetEncodeParameters(
|
2009-07-31 14:46:58 +04:00
|
|
|
encode_parameters* parameters) const;
|
2009-07-29 20:25:30 +04:00
|
|
|
virtual status_t SetEncodeParameters(
|
Encoder:
* Fleshed out the Encoder API to support parameter setters/getters and returning
a BView for configuration. (Not yet sure if this is a good idea.)
BMediaTrack:
* Implemented all but one of the unimplemented methods in BMediaTrack. It should
be working as far as that class is concerned, unless I missed some of the
vision. ReplaceFrames() remains a stub, added a comment on why it probably
stays that way.
* Release the Encoder reference in the destructor.
FFmpeg plugin:
* Refactoring to delay opening the AVCodec until encoding the first chunk,
so that we can still adjust parameters.
* Support adjusting parameters via [Set|Get]EncodeParameters(). Currently,
only quality is supported, added TODOs about supporting the bit_rate setup
versus the automatically calculated bit_rate.
* Extended EncoderDescription by a bit_rate scale. The Encoder calculates the
raw bitrate needed by the current media format, and then divides that
number by the specific codec's bit_rate_scale, while taking into account the
desired quality. This seems to work very well already (tested with MPEG4),
although a lot more parameters could be specified for libavcodec, depending
on the desired quality.
* Enabled the ogg muxer in libavformat, although it is currently still disabled
in MuxerTable.cpp, because it rejects unknown codecs. Added TODO to this
effect.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32124 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-08-05 14:21:36 +04:00
|
|
|
encode_parameters* parameters);
|
2009-07-31 14:46:58 +04:00
|
|
|
|
2009-07-29 20:25:30 +04:00
|
|
|
virtual status_t Encode(const void* buffer, int64 frameCount,
|
|
|
|
media_encode_info* info) = 0;
|
2009-07-31 14:46:58 +04:00
|
|
|
|
2009-07-29 20:25:30 +04:00
|
|
|
status_t WriteChunk(const void* chunkBuffer,
|
2009-07-31 14:46:58 +04:00
|
|
|
size_t chunkSize,
|
|
|
|
media_encode_info* encodeInfo);
|
2009-07-29 20:25:30 +04:00
|
|
|
|
2019-05-17 21:43:32 +03:00
|
|
|
void SetChunkWriter(ChunkWriter* writer);
|
2009-07-29 20:25:30 +04:00
|
|
|
|
2018-11-18 14:05:48 +03:00
|
|
|
virtual status_t Perform(perform_code code, void* data);
|
|
|
|
|
2009-07-29 20:25:30 +04:00
|
|
|
private:
|
2019-05-17 21:43:32 +03:00
|
|
|
ChunkWriter* fChunkWriter;
|
2018-10-29 11:41:21 +03:00
|
|
|
|
2009-07-29 20:25:30 +04:00
|
|
|
// needed for plug-in reference count management
|
2019-05-17 21:43:32 +03:00
|
|
|
friend class PluginManager;
|
|
|
|
MediaPlugin* fMediaPlugin;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// FBC padding
|
|
|
|
uint32 fReserved[20];
|
2009-07-29 20:25:30 +04:00
|
|
|
|
Encoder:
* Fleshed out the Encoder API to support parameter setters/getters and returning
a BView for configuration. (Not yet sure if this is a good idea.)
BMediaTrack:
* Implemented all but one of the unimplemented methods in BMediaTrack. It should
be working as far as that class is concerned, unless I missed some of the
vision. ReplaceFrames() remains a stub, added a comment on why it probably
stays that way.
* Release the Encoder reference in the destructor.
FFmpeg plugin:
* Refactoring to delay opening the AVCodec until encoding the first chunk,
so that we can still adjust parameters.
* Support adjusting parameters via [Set|Get]EncodeParameters(). Currently,
only quality is supported, added TODOs about supporting the bit_rate setup
versus the automatically calculated bit_rate.
* Extended EncoderDescription by a bit_rate scale. The Encoder calculates the
raw bitrate needed by the current media format, and then divides that
number by the specific codec's bit_rate_scale, while taking into account the
desired quality. This seems to work very well already (tested with MPEG4),
although a lot more parameters could be specified for libavcodec, depending
on the desired quality.
* Enabled the ogg muxer in libavformat, although it is currently still disabled
in MuxerTable.cpp, because it rejects unknown codecs. Added TODO to this
effect.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32124 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-08-05 14:21:36 +04:00
|
|
|
virtual void _ReservedEncoder1();
|
|
|
|
virtual void _ReservedEncoder2();
|
|
|
|
virtual void _ReservedEncoder3();
|
|
|
|
virtual void _ReservedEncoder4();
|
|
|
|
virtual void _ReservedEncoder5();
|
|
|
|
virtual void _ReservedEncoder6();
|
|
|
|
virtual void _ReservedEncoder7();
|
|
|
|
virtual void _ReservedEncoder8();
|
|
|
|
virtual void _ReservedEncoder9();
|
|
|
|
virtual void _ReservedEncoder10();
|
|
|
|
virtual void _ReservedEncoder11();
|
|
|
|
virtual void _ReservedEncoder12();
|
|
|
|
virtual void _ReservedEncoder13();
|
|
|
|
virtual void _ReservedEncoder14();
|
|
|
|
virtual void _ReservedEncoder15();
|
|
|
|
virtual void _ReservedEncoder16();
|
|
|
|
virtual void _ReservedEncoder17();
|
|
|
|
virtual void _ReservedEncoder18();
|
|
|
|
virtual void _ReservedEncoder19();
|
|
|
|
virtual void _ReservedEncoder20();
|
2009-07-29 20:25:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-17 21:43:32 +03:00
|
|
|
class EncoderPlugin : public virtual MediaPlugin {
|
2009-07-29 20:25:30 +04:00
|
|
|
public:
|
2019-05-17 21:43:32 +03:00
|
|
|
EncoderPlugin();
|
2009-07-29 20:25:30 +04:00
|
|
|
|
2019-05-17 21:43:32 +03:00
|
|
|
virtual Encoder* NewEncoder(
|
2009-07-31 00:05:11 +04:00
|
|
|
const media_codec_info& codecInfo) = 0;
|
|
|
|
|
2019-05-17 21:43:32 +03:00
|
|
|
virtual Encoder* NewEncoder(
|
2015-12-02 17:24:17 +03:00
|
|
|
const media_format& format) = 0;
|
|
|
|
|
2009-07-31 04:46:36 +04:00
|
|
|
virtual status_t RegisterNextEncoder(int32* cookie,
|
|
|
|
media_codec_info* codecInfo,
|
|
|
|
media_format_family* formatFamily,
|
|
|
|
media_format* inputFormat,
|
|
|
|
media_format* outputFormat) = 0;
|
2009-07-29 20:25:30 +04:00
|
|
|
};
|
|
|
|
|
2019-05-17 21:43:32 +03:00
|
|
|
} } // namespace BPrivate::media
|
2009-07-29 20:25:30 +04:00
|
|
|
|
2019-05-17 21:43:32 +03:00
|
|
|
using namespace BPrivate::media;
|
2009-07-29 20:25:30 +04:00
|
|
|
|
|
|
|
#endif // _ENCODER_PLUGIN_H
|