Move GetNextEncoder implementations to BCodecRoster
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018, Dario Casalinuovo. All rights reserved.
|
* Copyright 2018, Dario Casalinuovo. All rights reserved.
|
||||||
|
* Copyright 2004-2009, The Haiku Project. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Axel Dörfler
|
||||||
|
* Marcus Overhagen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <CodecRoster.h>
|
#include <CodecRoster.h>
|
||||||
@@ -115,8 +120,45 @@ BCodecRoster::GetNextEncoder(int32* cookie, const media_file_format* fileFormat,
|
|||||||
const media_format* inputFormat, media_format* _outputFormat,
|
const media_format* inputFormat, media_format* _outputFormat,
|
||||||
media_codec_info* _codecInfo)
|
media_codec_info* _codecInfo)
|
||||||
{
|
{
|
||||||
return get_next_encoder(cookie, fileFormat,
|
// TODO: If fileFormat is provided (existing apps also pass NULL),
|
||||||
inputFormat, _outputFormat, _codecInfo);
|
// 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_codec_info* _codecInfo, media_format* _acceptedInputFormat,
|
||||||
media_format* _acceptedOutputFormat)
|
media_format* _acceptedOutputFormat)
|
||||||
{
|
{
|
||||||
return get_next_encoder(cookie, fileFormat, inputFormat, outputFormat,
|
// TODO: If fileFormat is provided (existing apps also pass NULL),
|
||||||
_codecInfo, _acceptedInputFormat, _acceptedOutputFormat);
|
// 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
|
status_t
|
||||||
BCodecRoster::GetNextEncoder(int32* cookie, media_codec_info* _codecInfo)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,45 +35,8 @@ get_next_encoder(int32* cookie, const media_file_format* fileFormat,
|
|||||||
const media_format* inputFormat, media_format* _outputFormat,
|
const media_format* inputFormat, media_format* _outputFormat,
|
||||||
media_codec_info* _codecInfo)
|
media_codec_info* _codecInfo)
|
||||||
{
|
{
|
||||||
// TODO: If fileFormat is provided (existing apps also pass NULL),
|
return BCodecKit::BCodecRoster::GetNextEncoder(cookie, fileFormat,
|
||||||
// we could at least check fileFormat->capabilities against
|
inputFormat, _outputFormat, _codecInfo);
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -83,77 +46,16 @@ get_next_encoder(int32* cookie, const media_file_format* fileFormat,
|
|||||||
media_codec_info* _codecInfo, media_format* _acceptedInputFormat,
|
media_codec_info* _codecInfo, media_format* _acceptedInputFormat,
|
||||||
media_format* _acceptedOutputFormat)
|
media_format* _acceptedOutputFormat)
|
||||||
{
|
{
|
||||||
// TODO: If fileFormat is provided (existing apps also pass NULL),
|
return BCodecKit::BCodecRoster::GetNextEncoder(cookie, fileFormat,
|
||||||
// we could at least check fileFormat->capabilities against
|
inputFormat, outputFormat, _codecInfo, _acceptedInputFormat,
|
||||||
// outputFormat->type without even contacting the server.
|
_acceptedOutputFormat);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
get_next_encoder(int32* cookie, media_codec_info* _codecInfo)
|
get_next_encoder(int32* cookie, media_codec_info* _codecInfo)
|
||||||
{
|
{
|
||||||
if (cookie == NULL || _codecInfo == NULL)
|
return BCodecKit::BCodecRoster::GetNextEncoder(cookie, _codecInfo);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user