media_kit: Remove most private dependencies from codec_kit

* Move to BCodecKit namespace and make extensive use
of BCodecRoster.
* This is a first step in the right direction of
decreasing private dependencies. Some APIs are being
translated to the CodecKit. I am doing an investigation
on which APIs are really used among apps, so that the new
kit can be more slim and oriented toward easy development
and can be extended in the right direction instead to
continue maintaning unuseful code.
* BMediaFormats needs still a bit of love.
* General improvements in style and code maintainability.
This commit is contained in:
Barrett17 2018-11-27 11:35:01 +01:00
parent 5232a91136
commit 278d03da22
10 changed files with 74 additions and 85 deletions

View File

@ -1,7 +1,7 @@
#ifndef MEDIADECODER_H
#define MEDIADECODER_H
#include <MediaDefs.h>
#include <MediaFormats.h>

View File

@ -8,14 +8,10 @@
#include <MediaFormats.h>
namespace BPrivate {
namespace media {
class BEncoder;
class BEncoderPlugin;
}
}
using namespace BPrivate::media;
namespace BCodecKit {
class BEncoder;
}
class BMediaEncoder {
@ -84,7 +80,7 @@ private:
void ReleaseEncoder();
uint32 _reserved_was_fEncoderMgr;
BEncoder* fEncoder;
BCodecKit::BEncoder* fEncoder;
int32 fEncoderID;
bool fFormatValid;

View File

@ -13,12 +13,13 @@
#include <StorageDefs.h>
namespace BCodecKit {
class BMediaExtractor;
class BMediaStreamer;
class BMediaWriter;
}
namespace BPrivate {
namespace media {
class BMediaExtractor;
class BMediaStreamer;
class BMediaWriter;
}
class _AddonManager;
}
@ -162,18 +163,18 @@ private:
status_t ControlFile(int32 selector, void* ioData,
size_t size);
BPrivate::media::BMediaExtractor* fExtractor;
BCodecKit::BMediaExtractor* fExtractor;
int32 _reserved_BMediaFile_was_fExtractorID;
int32 fTrackNum;
status_t fErr;
BPrivate::_AddonManager* fEncoderMgr;
BPrivate::_AddonManager* fWriterMgr;
BPrivate::media::BMediaWriter* fWriter;
BCodecKit::BMediaWriter* fWriter;
int32 fWriterID;
media_file_format fMFI;
BPrivate::media::BMediaStreamer* fStreamer;
BCodecKit::BMediaStreamer* fStreamer;
bool fFileClosed;
bool fDeleteSource;

View File

@ -9,12 +9,12 @@
#include <MediaFormats.h>
namespace BPrivate { namespace media {
namespace BCodecKit {
class BDecoder;
class BEncoder;
class BMediaExtractor;
class BMediaWriter;
} }
}
class BMessage;
class BView;
@ -219,12 +219,12 @@ private:
// For read-only access to a BMediaTrack
BMediaTrack(
BPrivate::media::BMediaExtractor* extractor,
BCodecKit::BMediaExtractor* extractor,
int32 streamIndex);
// For write-only access to a BMediaTrack
BMediaTrack(
BPrivate::media::BMediaWriter* writer,
BCodecKit::BMediaWriter* writer,
int32 streamIndex, media_format* format,
const media_codec_info* codecInfo);
@ -235,9 +235,9 @@ private:
private:
status_t fInitStatus;
BPrivate::media::BDecoder* fDecoder;
BPrivate::media::BDecoder* fRawDecoder;
BPrivate::media::BMediaExtractor* fExtractor;
BCodecKit::BDecoder* fDecoder;
BCodecKit::BDecoder* fRawDecoder;
BCodecKit::BMediaExtractor* fExtractor;
int32 fStream;
int64 fCurrentFrame;
@ -245,9 +245,9 @@ private:
media_codec_info fCodecInfo;
BPrivate::media::BEncoder* fEncoder;
BCodecKit::BEncoder* fEncoder;
int32 fEncoderID;
BPrivate::media::BMediaWriter* fWriter;
BCodecKit::BMediaWriter* fWriter;
media_format fFormat;
uint32 fWorkaroundFlags;

View File

@ -46,7 +46,7 @@ BMediaDecoder::BMediaDecoder(const media_codec_info *mci)
/* virtual */
BMediaDecoder::~BMediaDecoder()
{
gPluginManager.DestroyDecoder(fDecoder);
BCodecRoster::ReleaseDecoder(fDecoder);
}
@ -62,10 +62,10 @@ BMediaDecoder::SetTo(const media_format *in_format,
const void *info,
size_t info_size)
{
gPluginManager.DestroyDecoder(fDecoder);
BCodecRoster::ReleaseDecoder(fDecoder);
fDecoder = NULL;
status_t err = gPluginManager.CreateDecoder(&fDecoder, *in_format);
status_t err = BCodecRoster::InstantiateDecoder(&fDecoder, *in_format);
if (err < B_OK)
goto fail;
@ -81,7 +81,7 @@ BMediaDecoder::SetTo(const media_format *in_format,
return B_OK;
fail:
gPluginManager.DestroyDecoder(fDecoder);
BCodecRoster::ReleaseDecoder(fDecoder);
fDecoder = NULL;
fInitStatus = B_NO_INIT;
return err;
@ -91,10 +91,10 @@ fail:
status_t
BMediaDecoder::SetTo(const media_codec_info *mci)
{
gPluginManager.DestroyDecoder(fDecoder);
BCodecRoster::ReleaseDecoder(fDecoder);
fDecoder = NULL;
status_t err = gPluginManager.CreateDecoder(&fDecoder, *mci);
status_t err = BCodecRoster::InstantiateDecoder(&fDecoder, *mci);
if (err < B_OK)
goto fail;
@ -106,7 +106,7 @@ BMediaDecoder::SetTo(const media_codec_info *mci)
return B_OK;
fail:
gPluginManager.DestroyDecoder(fDecoder);
BCodecRoster::ReleaseDecoder(fDecoder);
fDecoder = NULL;
fInitStatus = B_NO_INIT;
return err;
@ -182,7 +182,7 @@ BMediaDecoder::GetDecoderInfo(media_codec_info *out_info) const
if (!fDecoder)
return B_NO_INIT;
return gPluginManager.GetDecoderInfo(fDecoder, out_info);
return BCodecRoster::GetDecoderInfo(fDecoder, out_info);
}

View File

@ -13,6 +13,7 @@
#include <Application.h>
#include <Bitmap.h>
#include <Catalog.h>
#include <CodecRoster.h>
#include <LaunchRoster.h>
#include <Locale.h>
#include <MediaNode.h>
@ -24,7 +25,6 @@
#include <stdio.h>
#include <string.h>
#include "AddOnManager.h"
#include "DataExchange.h"
#include "MediaDebug.h"
#include "MediaMisc.h"
@ -1218,16 +1218,7 @@ operator<(const media_file_format_id& a, const media_file_format_id& b)
status_t
get_next_file_format(int32* cookie, media_file_format* mff)
{
if (cookie == NULL || mff == NULL)
return B_BAD_VALUE;
status_t ret = AddOnManager::GetInstance()->GetFileFormat(mff, *cookie);
if (ret != B_OK)
return ret;
*cookie = *cookie + 1;
return B_OK;
return BCodecKit::BCodecRoster::GetNextFileFormat(cookie, mff);
}
@ -1255,5 +1246,3 @@ media_decode_info::media_decode_info()
codec_data = NULL;
codec_data_size = 0;
}

View File

@ -9,13 +9,16 @@
#include <MediaEncoder.h>
#include <CodecRoster.h>
#include <Encoder.h>
#include <PluginManager.h>
#include <new>
#include "MediaDebug.h"
using namespace BCodecKit;
/*************************************************************
* public BMediaEncoder
*************************************************************/
@ -76,7 +79,7 @@ BMediaEncoder::SetTo(const media_format* outputFormat)
return fInitStatus;
media_format format = *outputFormat;
err = gPluginManager.CreateEncoder(&fEncoder, format);
err = BCodecRoster::InstantiateEncoder(&fEncoder, format);
if (fEncoder != NULL && err == B_OK) {
err = _AttachToEncoder();
if (err == B_OK)
@ -94,7 +97,7 @@ BMediaEncoder::SetTo(const media_codec_info* mci)
CALLED();
ReleaseEncoder();
status_t err = gPluginManager.CreateEncoder(&fEncoder, mci, 0);
status_t err = BCodecRoster::InstantiateEncoder(&fEncoder, mci, 0);
if (fEncoder != NULL && err == B_OK) {
err = _AttachToEncoder();
if (err == B_OK) {
@ -216,7 +219,7 @@ BMediaEncoder::ReleaseEncoder()
{
CALLED();
if (fEncoder != NULL) {
gPluginManager.DestroyEncoder(fEncoder);
BCodecRoster::ReleaseEncoder(fEncoder);
fEncoder = NULL;
}
fInitStatus = B_NO_INIT;

View File

@ -6,20 +6,21 @@
#include <MediaFile.h>
#include <File.h>
#include <MediaExtractor.h>
#include <MediaStreamer.h>
#include <MediaTrack.h>
#include <MediaWriter.h>
#include <Url.h>
#include <new>
#include <stdlib.h>
#include <string.h>
#include <File.h>
#include <MediaTrack.h>
#include <Url.h>
#include "MediaDebug.h"
#include "MediaExtractor.h"
#include "MediaStreamer.h"
#include "MediaWriter.h"
using namespace BCodecKit;
BMediaFile::BMediaFile(const entry_ref* ref)

View File

@ -7,6 +7,12 @@
* Marcus Overhagen
*/
#include <MediaFormats.h>
#include <CodecRoster.h>
#include <ObjectList.h>
#include <Message.h>
#include <Autolock.h>
#include "AddOnManager.h"
#include "DataExchange.h"
@ -14,11 +20,6 @@
#include "MetaFormat.h"
#include "MediaDebug.h"
#include <MediaFormats.h>
#include <ObjectList.h>
#include <Message.h>
#include <Autolock.h>
#include <string.h>
using namespace BPrivate::media;
@ -47,7 +48,7 @@ get_next_encoder(int32* cookie, const media_file_format* fileFormat,
media_format candidateInputFormat;
media_format candidateOutputFormat;
status_t ret = AddOnManager::GetInstance()->GetCodecInfo(
status_t ret = BCodecKit::BCodecRoster::GetCodecInfo(
&candidateCodecInfo, &candidateFormatFamily,
&candidateInputFormat, &candidateOutputFormat, *cookie);
@ -97,7 +98,7 @@ get_next_encoder(int32* cookie, const media_file_format* fileFormat,
media_format candidateInputFormat;
media_format candidateOutputFormat;
status_t ret = AddOnManager::GetInstance()->GetCodecInfo(
status_t ret = BCodecKit::BCodecRoster::GetCodecInfo(
&candidateCodecInfo, &candidateFormatFamily, &candidateInputFormat,
&candidateOutputFormat, *cookie);
@ -145,7 +146,7 @@ get_next_encoder(int32* cookie, media_codec_info* _codecInfo)
media_format inputFormat;
media_format outputFormat;
status_t ret = AddOnManager::GetInstance()->GetCodecInfo(_codecInfo,
status_t ret = BCodecKit::BCodecRoster::GetCodecInfo(_codecInfo,
&formatFamily, &inputFormat, &outputFormat, *cookie);
if (ret != B_OK)
return ret;
@ -366,7 +367,7 @@ update_media_formats()
// We want the add-ons to register themselves with the format manager, so
// the list is up to date.
AddOnManager::GetInstance()->RegisterAddOns();
BCodecKit::BPrivate::AddOnManager::GetInstance()->RegisterAddOns();
BMessage reply;
FormatManager::GetInstance()->GetFormats(sLastFormatsUpdate, reply);
@ -621,10 +622,8 @@ BMediaFormats::MakeFormatFor(const media_format_description* descriptions,
int32 descriptionCount, media_format* format, uint32 flags,
void* _reserved)
{
status_t status = FormatManager::GetInstance()->MakeFormatFor(descriptions,
return BCodecKit::BCodecRoster::MakeFormatFor(descriptions,
descriptionCount, *format, flags, _reserved);
return status;
}
@ -638,4 +637,3 @@ BMediaFormats::MakeFormatFor(const media_format_description& description,
*_outFormat = inFormat;
return MakeFormatFor(&description, 1, _outFormat);
}

View File

@ -12,17 +12,18 @@
#include <MediaTrack.h>
#include <CodecRoster.h>
#include <MediaExtractor.h>
#include <MediaWriter.h>
#include <Roster.h>
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Roster.h>
#include "MediaExtractor.h"
#include "MediaWriter.h"
#include "PluginManager.h"
using namespace BCodecKit;
//#define TRACE_MEDIA_TRACK
@ -84,9 +85,9 @@ BMediaTrack::~BMediaTrack()
{
CALLED();
gPluginManager.DestroyDecoder(fRawDecoder);
gPluginManager.DestroyDecoder(fDecoder);
gPluginManager.DestroyEncoder(fEncoder);
BCodecRoster::ReleaseDecoder(fRawDecoder);
BCodecRoster::ReleaseDecoder(fDecoder);
BCodecRoster::ReleaseEncoder(fEncoder);
}
/*************************************************************
@ -163,7 +164,7 @@ BMediaTrack::DecodedFormat(media_format* _format, uint32 flags)
if (fExtractor == NULL || fDecoder == NULL)
return B_NO_INIT;
gPluginManager.DestroyDecoder(fRawDecoder);
BCodecRoster::ReleaseDecoder(fRawDecoder);
fRawDecoder = NULL;
#ifdef TRACE_MEDIA_TRACK
@ -839,7 +840,7 @@ BMediaTrack::Perform(int32 selector, void* data)
// #pragma mark - private
BMediaTrack::BMediaTrack(BPrivate::media::BMediaExtractor* extractor,
BMediaTrack::BMediaTrack(BCodecKit::BMediaExtractor* extractor,
int32 stream)
{
CALLED();
@ -871,7 +872,7 @@ BMediaTrack::BMediaTrack(BPrivate::media::BMediaExtractor* extractor,
}
BMediaTrack::BMediaTrack(BPrivate::media::BMediaWriter* writer,
BMediaTrack::BMediaTrack(BCodecKit::BMediaWriter* writer,
int32 streamIndex, media_format* format,
const media_codec_info* codecInfo)
{
@ -950,7 +951,7 @@ BMediaTrack::SetupWorkaround()
bool
BMediaTrack::SetupFormatTranslation(const media_format &from, media_format* to)
{
gPluginManager.DestroyDecoder(fRawDecoder);
BCodecRoster::ReleaseDecoder(fRawDecoder);
fRawDecoder = NULL;
#ifdef TRACE_MEDIA_TRACK
@ -959,7 +960,7 @@ BMediaTrack::SetupFormatTranslation(const media_format &from, media_format* to)
printf("BMediaTrack::SetupFormatTranslation: from: %s\n", s);
#endif
status_t result = gPluginManager.CreateDecoder(&fRawDecoder, from);
status_t result = BCodecRoster::InstantiateDecoder(&fRawDecoder, from);
if (result != B_OK) {
ERROR("BMediaTrack::SetupFormatTranslation: CreateDecoder failed\n");
return false;
@ -1007,7 +1008,7 @@ BMediaTrack::SetupFormatTranslation(const media_format &from, media_format* to)
return true;
error:
gPluginManager.DestroyDecoder(fRawDecoder);
BCodecRoster::ReleaseDecoder(fRawDecoder);
fRawDecoder = NULL;
return false;
}