Move GetNextEncoder implementations to BCodecRoster

This commit is contained in:
Barrett17 2018-12-28 00:42:34 +01:00
parent 708de94fde
commit f3e317617f
2 changed files with 115 additions and 109 deletions

View File

@ -1,6 +1,11 @@
/*
* Copyright 2018, Dario Casalinuovo. All rights reserved.
* Copyright 2004-2009, The Haiku Project. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler
* Marcus Overhagen
*/
#include <CodecRoster.h>
@ -115,8 +120,45 @@ 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);
// TODO: If fileFormat is provided (existing apps also pass NULL),
// we could at least check fileFormat->capabilities against
// outputFormat->type without even contacting the server.
if (cookie == NULL || inputFormat == NULL || _codecInfo == NULL)
return B_BAD_VALUE;
while (true) {
media_codec_info candidateCodecInfo;
media_format_family candidateFormatFamily;
media_format candidateInputFormat;
media_format candidateOutputFormat;
status_t ret = BCodecRoster::GetCodecInfo(&candidateCodecInfo,
&candidateFormatFamily, &candidateInputFormat,
&candidateOutputFormat, *cookie);
if (ret != B_OK)
return ret;
*cookie = *cookie + 1;
if (fileFormat != NULL && candidateFormatFamily != B_ANY_FORMAT_FAMILY
&& fileFormat->family != B_ANY_FORMAT_FAMILY
&& fileFormat->family != candidateFormatFamily) {
continue;
}
if (!candidateInputFormat.Matches(inputFormat))
continue;
if (_outputFormat != NULL)
*_outputFormat = candidateOutputFormat;
*_codecInfo = candidateCodecInfo;
break;
}
return B_OK;
}
@ -126,15 +168,77 @@ BCodecRoster::GetNextEncoder(int32* cookie, const media_file_format* fileFormat,
media_codec_info* _codecInfo, media_format* _acceptedInputFormat,
media_format* _acceptedOutputFormat)
{
return get_next_encoder(cookie, fileFormat, inputFormat, outputFormat,
_codecInfo, _acceptedInputFormat, _acceptedOutputFormat);
// TODO: If fileFormat is provided (existing apps also pass NULL),
// we could at least check fileFormat->capabilities against
// outputFormat->type without even contacting the server.
if (cookie == NULL || inputFormat == NULL || outputFormat == NULL
|| _codecInfo == NULL) {
return B_BAD_VALUE;
}
while (true) {
media_codec_info candidateCodecInfo;
media_format_family candidateFormatFamily;
media_format candidateInputFormat;
media_format candidateOutputFormat;
status_t ret = BCodecRoster::GetCodecInfo(&candidateCodecInfo,
&candidateFormatFamily, &candidateInputFormat,
&candidateOutputFormat, *cookie);
if (ret != B_OK)
return ret;
*cookie = *cookie + 1;
if (fileFormat != NULL && candidateFormatFamily != B_ANY_FORMAT_FAMILY
&& fileFormat->family != B_ANY_FORMAT_FAMILY
&& fileFormat->family != candidateFormatFamily) {
continue;
}
if (!candidateInputFormat.Matches(inputFormat)
|| !candidateOutputFormat.Matches(outputFormat)) {
continue;
}
// TODO: These formats are currently way too generic. For example,
// an encoder may want to adjust video width to a multiple of 16,
// or overwrite the intput and or output color space. To make this
// possible, we actually have to instantiate an Encoder here and
// ask it to specifiy the format.
if (_acceptedInputFormat != NULL)
*_acceptedInputFormat = candidateInputFormat;
if (_acceptedOutputFormat != NULL)
*_acceptedOutputFormat = candidateOutputFormat;
*_codecInfo = candidateCodecInfo;
break;
}
return B_OK;
}
status_t
BCodecRoster::GetNextEncoder(int32* cookie, media_codec_info* _codecInfo)
{
return get_next_encoder(cookie, _codecInfo);
if (cookie == NULL || _codecInfo == NULL)
return B_BAD_VALUE;
media_format_family formatFamily;
media_format inputFormat;
media_format outputFormat;
status_t ret = BCodecRoster::GetCodecInfo(_codecInfo,
&formatFamily, &inputFormat, &outputFormat, *cookie);
if (ret != B_OK)
return ret;
*cookie = *cookie + 1;
return B_OK;
}

View File

@ -35,45 +35,8 @@ get_next_encoder(int32* cookie, const media_file_format* fileFormat,
const media_format* inputFormat, media_format* _outputFormat,
media_codec_info* _codecInfo)
{
// TODO: If fileFormat is provided (existing apps also pass NULL),
// we could at least check fileFormat->capabilities against
// outputFormat->type without even contacting the server.
if (cookie == NULL || inputFormat == NULL || _codecInfo == NULL)
return B_BAD_VALUE;
while (true) {
media_codec_info candidateCodecInfo;
media_format_family candidateFormatFamily;
media_format candidateInputFormat;
media_format candidateOutputFormat;
status_t ret = BCodecKit::BCodecRoster::GetCodecInfo(
&candidateCodecInfo, &candidateFormatFamily,
&candidateInputFormat, &candidateOutputFormat, *cookie);
if (ret != B_OK)
return ret;
*cookie = *cookie + 1;
if (fileFormat != NULL && candidateFormatFamily != B_ANY_FORMAT_FAMILY
&& fileFormat->family != B_ANY_FORMAT_FAMILY
&& fileFormat->family != candidateFormatFamily) {
continue;
}
if (!candidateInputFormat.Matches(inputFormat))
continue;
if (_outputFormat != NULL)
*_outputFormat = candidateOutputFormat;
*_codecInfo = candidateCodecInfo;
break;
}
return B_OK;
return BCodecKit::BCodecRoster::GetNextEncoder(cookie, fileFormat,
inputFormat, _outputFormat, _codecInfo);
}
@ -83,77 +46,16 @@ get_next_encoder(int32* cookie, const media_file_format* fileFormat,
media_codec_info* _codecInfo, media_format* _acceptedInputFormat,
media_format* _acceptedOutputFormat)
{
// TODO: If fileFormat is provided (existing apps also pass NULL),
// we could at least check fileFormat->capabilities against
// outputFormat->type without even contacting the server.
if (cookie == NULL || inputFormat == NULL || outputFormat == NULL
|| _codecInfo == NULL) {
return B_BAD_VALUE;
}
while (true) {
media_codec_info candidateCodecInfo;
media_format_family candidateFormatFamily;
media_format candidateInputFormat;
media_format candidateOutputFormat;
status_t ret = BCodecKit::BCodecRoster::GetCodecInfo(
&candidateCodecInfo, &candidateFormatFamily, &candidateInputFormat,
&candidateOutputFormat, *cookie);
if (ret != B_OK)
return ret;
*cookie = *cookie + 1;
if (fileFormat != NULL && candidateFormatFamily != B_ANY_FORMAT_FAMILY
&& fileFormat->family != B_ANY_FORMAT_FAMILY
&& fileFormat->family != candidateFormatFamily) {
continue;
}
if (!candidateInputFormat.Matches(inputFormat)
|| !candidateOutputFormat.Matches(outputFormat)) {
continue;
}
// TODO: These formats are currently way too generic. For example,
// an encoder may want to adjust video width to a multiple of 16,
// or overwrite the intput and or output color space. To make this
// possible, we actually have to instantiate an Encoder here and
// ask it to specifiy the format.
if (_acceptedInputFormat != NULL)
*_acceptedInputFormat = candidateInputFormat;
if (_acceptedOutputFormat != NULL)
*_acceptedOutputFormat = candidateOutputFormat;
*_codecInfo = candidateCodecInfo;
break;
}
return B_OK;
return BCodecKit::BCodecRoster::GetNextEncoder(cookie, fileFormat,
inputFormat, outputFormat, _codecInfo, _acceptedInputFormat,
_acceptedOutputFormat);
}
status_t
get_next_encoder(int32* cookie, media_codec_info* _codecInfo)
{
if (cookie == NULL || _codecInfo == NULL)
return B_BAD_VALUE;
media_format_family formatFamily;
media_format inputFormat;
media_format outputFormat;
status_t ret = BCodecKit::BCodecRoster::GetCodecInfo(_codecInfo,
&formatFamily, &inputFormat, &outputFormat, *cookie);
if (ret != B_OK)
return ret;
*cookie = *cookie + 1;
return B_OK;
return BCodecKit::BCodecRoster::GetNextEncoder(cookie, _codecInfo);
}