From 44fc903a8f226e0c3cdc43ffad05a859ec3aaa53 Mon Sep 17 00:00:00 2001 From: Barrett17 Date: Thu, 22 Nov 2018 17:30:57 +0100 Subject: [PATCH] Codec Kit: Introduce BCodecRoster * This class include almost everything you need to manage codecs and iterate over them. --- headers/os/codec/CodecRoster.h | 122 +++++++++++++++++++++++++++++++ src/kits/codec/CodecRoster.cpp | 126 +++++++++++++++++++++++++++++++++ src/kits/codec/Jamfile | 1 + 3 files changed, 249 insertions(+) create mode 100644 headers/os/codec/CodecRoster.h create mode 100644 src/kits/codec/CodecRoster.cpp diff --git a/headers/os/codec/CodecRoster.h b/headers/os/codec/CodecRoster.h new file mode 100644 index 0000000000..92432a86d9 --- /dev/null +++ b/headers/os/codec/CodecRoster.h @@ -0,0 +1,122 @@ +/* + * Copyright 2018, Dario Casalinuovo. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _CODEC_ROSTER_H +#define _CODEC_ROSTER_H + + +#include +#include +#include +#include + + +namespace BPrivate { +namespace media { + + +class BCodecRoster { +public: + + static status_t InstantiateReader(Reader** reader, + int32* streamCount, media_file_format* mff, + BDataIO* source); + static void ReleaseReader(Reader* reader); + + static status_t InstantiateDecoder(Decoder** decoder, + const media_format& format); + static status_t InstantiateDecoder(Decoder** decoder, + const media_codec_info& mci); + static void ReleaseDecoder(Decoder* decoder); + + static status_t InstantiateWriter(Writer** writer, + const media_file_format& mff, + BDataIO* target); + static void ReleaseWriter(Writer* writer); + + static status_t InstantiateEncoder(Encoder** encoder, + const media_format& format); + static status_t InstantiateEncoder(Encoder** encoder, + const media_codec_info* codecInfo, + uint32 flags); + static void ReleaseEncoder(Encoder* encoder); + + static status_t InstantiateStreamer(Streamer** streamer, + BUrl url, BDataIO** source); + static void ReleaseStreamer(Streamer* streamer); + +/*! \brief Use this to iterate through the available encoders for a given file + format. + \param cookie A pointer to a preallocated cookie, which you need + to initialize to \c 0 before calling this function + the first time. + \param fileFormat A pointer to a valid media_file_format structure + as can be obtained through get_next_file_format(). + \param inputFormat This is the type of data given to the encoder. + \param _outputFormat This is the type of data the encoder will output. + \param _codecInfo Pointer to a preallocated media_codec_info structure, + information about the encoder is placed there. + + \return + - \c B_OK: Everything went fine. + - \c B_BAD_INDEX: There are no more encoders. + */ + static status_t GetNextEncoder(int32* cookie, const media_file_format* fileFormat, + const media_format* inputFormat, media_format* _outputFormat, + media_codec_info* _codecInfo); + +/*! \brief Use this to iterate through the available encoders with + restrictions to the input and output media_format while the + encoders can specialize wildcards in the media_formats. + + \param cookie A pointer to a preallocated cookie, which you need + to initialize to \c 0 before calling this function + the first time. + \param fileFormat A pointer to a valid media_file_format structure + as can be obtained through get_next_file_format(). + You can pass \c NULL if you don't care. + \param inputFormat This is the type of data given to the encoder, + wildcards are accepted. + \param outputFormat This is the type of data you want the encoder to + output. Wildcards are accepted. + \param _codecInfo Pointer to a preallocated media_codec_info structure, + information about the encoder is placed there. + \param _acceptedInputFormat This is the type of data that the encoder will + accept as input. Wildcards in \a inFormat will be + specialized here. + \param _acceptedOutputFormat This is the type of data that the encoder will + output. Wildcards in \a _outFormat will be specialized + here. + + \return + - \c B_OK: Everything went fine. + - \c B_BAD_INDEX: There are no more encoders. +*/ + static status_t GetNextEncoder(int32* cookie, const media_file_format* fileFormat, + const media_format* inputFormat, const media_format* outputFormat, + media_codec_info* _codecInfo, media_format* _acceptedInputFormat, + media_format* _acceptedOutputFormat); + +/*! \brief Iterate over the all the available encoders without media_format + restrictions. + + \param cookie A pointer to a preallocated cookie, which you need + to initialize to \c 0 before calling this function + the first time. + \param _codecInfo Pointer to a preallocated media_codec_info structure, + information about the encoder is placed there. + + \return + - \c B_OK: Everything went fine. + - \c B_BAD_INDEX: There are no more encoders. +*/ + static status_t GetNextEncoder(int32* cookie, media_codec_info* _codecInfo); +}; + +} // namespace media +} // namespace BPrivate + +using namespace BPrivate::media; + +#endif // _CODEC_ROSTER_H diff --git a/src/kits/codec/CodecRoster.cpp b/src/kits/codec/CodecRoster.cpp new file mode 100644 index 0000000000..e989dc7bd8 --- /dev/null +++ b/src/kits/codec/CodecRoster.cpp @@ -0,0 +1,126 @@ +/* + * Copyright 2018, Dario Casalinuovo. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include + +#include + +#include "PluginManager.h" + + +status_t +BCodecRoster::InstantiateReader(Reader** reader, int32* streamCount, + media_file_format* mff, BDataIO* source) +{ + return gPluginManager.CreateReader(reader, streamCount, mff, source); +} + + +void +BCodecRoster::ReleaseReader(Reader* reader) +{ + return gPluginManager.DestroyReader(reader); +} + + +status_t +BCodecRoster::InstantiateDecoder(Decoder** decoder, const media_format& format) +{ + return gPluginManager.CreateDecoder(decoder, format); +} + + +status_t +BCodecRoster::InstantiateDecoder(Decoder** decoder, const media_codec_info& mci) +{ + return gPluginManager.CreateDecoder(decoder, mci); +} + + +void +BCodecRoster::ReleaseDecoder(Decoder* decoder) +{ + return gPluginManager.DestroyDecoder(decoder); +} + + +status_t +BCodecRoster::InstantiateWriter(Writer** writer, const media_file_format& mff, + BDataIO* target) +{ + return gPluginManager.CreateWriter(writer, mff, target); +} + + +void +BCodecRoster::ReleaseWriter(Writer* writer) +{ + return gPluginManager.DestroyWriter(writer); +} + + +status_t +BCodecRoster::InstantiateEncoder(Encoder** encoder, const media_format& format) +{ + return gPluginManager.CreateEncoder(encoder, format); +} + + +status_t +BCodecRoster::InstantiateEncoder(Encoder** encoder, + const media_codec_info* codecInfo, uint32 flags) +{ + return gPluginManager.CreateEncoder(encoder, codecInfo, flags); +} + + +void +BCodecRoster::ReleaseEncoder(Encoder* encoder) +{ + return gPluginManager.DestroyEncoder(encoder); +} + + +status_t +BCodecRoster::InstantiateStreamer(Streamer** streamer, BUrl url, + BDataIO** source) +{ + return gPluginManager.CreateStreamer(streamer, url, source); +} + + +void +BCodecRoster::ReleaseStreamer(Streamer* streamer) +{ + return gPluginManager.DestroyStreamer(streamer); +} + + +status_t +BCodecRoster::GetNextEncoder(int32* cookie, const media_file_format* fileFormat, + const media_format* inputFormat, media_format* _outputFormat, + media_codec_info* _codecInfo) +{ + return get_next_encoder(cookie, fileFormat, + inputFormat, _outputFormat, _codecInfo); +} + + +status_t +BCodecRoster::GetNextEncoder(int32* cookie, const media_file_format* fileFormat, + const media_format* inputFormat, const media_format* outputFormat, + media_codec_info* _codecInfo, media_format* _acceptedInputFormat, + media_format* _acceptedOutputFormat) +{ + return get_next_encoder(cookie, fileFormat, inputFormat, outputFormat, + _codecInfo, _acceptedInputFormat, _acceptedOutputFormat); +} + + +status_t +BCodecRoster::GetNextEncoder(int32* cookie, media_codec_info* _codecInfo) +{ + return get_next_encoder(cookie, _codecInfo); +} diff --git a/src/kits/codec/Jamfile b/src/kits/codec/Jamfile index 5afb253a75..2b46be1559 100644 --- a/src/kits/codec/Jamfile +++ b/src/kits/codec/Jamfile @@ -19,6 +19,7 @@ for architectureObject in [ MultiArchSubDirSetup ] { # Support API MetaData.cpp + CodecRoster.cpp # Codec Plugin API ChunkCache.cpp