Skip to content

Commit

Permalink
Some simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
osagie98 committed Oct 16, 2024
1 parent 4e08474 commit e16809e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
32 changes: 12 additions & 20 deletions starboard/linux/shared/media_is_audio_supported.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ using ::starboard::shared::starboard::media::kIamfProfileSimple;
using ::starboard::shared::starboard::media::kIamfSubstreamCodecOpus;
using ::starboard::shared::starboard::media::MimeType;

bool HasSupportedIamfProfile(const IamfMimeUtil* mime_util) {
return mime_util->primary_profile() == kIamfProfileSimple ||
mime_util->additional_profile() == kIamfProfileBase;
}

bool SbMediaIsAudioSupported(SbMediaAudioCodec audio_codec,
const MimeType* mime_type,
int64_t bitrate) {
Expand All @@ -43,30 +48,17 @@ bool SbMediaIsAudioSupported(SbMediaAudioCodec audio_codec,
return false;
}
const std::vector<std::string>& codecs = mime_type->GetCodecs();
bool stream_is_supported = false;
for (auto& codec : codecs) {
IamfMimeUtil mime_util(codec);
if (!mime_util.is_valid()) {
continue;
}
// Support only IAMF streams with an Opus substream.
if (mime_util.substream_codec() != kIamfSubstreamCodecOpus) {
continue;
}
// At least one of the profiles must be Base or Simple.
uint32_t primary_profile = mime_util.primary_profile();
uint32_t additional_profile = mime_util.additional_profile();
if (primary_profile != kIamfProfileSimple &&
primary_profile != kIamfProfileBase &&
additional_profile != kIamfProfileSimple &&
additional_profile != kIamfProfileBase) {
continue;
// We support only IAMF Base or Simple profile streams with an Opus
// substream.
if (mime_util.is_valid() &&
mime_util.substream_codec() == kIamfSubstreamCodecOpus &&
HasSupportedIamfProfile(&mime_util)) {
return bitrate <= kSbMediaMaxAudioBitrateInBitsPerSecond;
}
stream_is_supported = true;
break;
}
return stream_is_supported &&
bitrate <= kSbMediaMaxAudioBitrateInBitsPerSecond;
return false;
}
#endif // SB_API_VERSION >= 15

Expand Down
8 changes: 5 additions & 3 deletions starboard/shared/libiamf/iamf_audio_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ bool IamfAudioDecoder::DecodeInternal(
kSbMediaAudioFrameStorageTypeInterleaved, input_buffer->timestamp(),
audio_stream_info_.number_of_channels * info.num_samples *
starboard::media::GetBytesPerSample(GetSampleType()));
int samples_decoded = IAMF_decoder_decode(
decoder_, const_cast<const uint8_t*>(info.data.data()), info.data.size(),
nullptr, reinterpret_cast<void*>(decoded_audio->data()));

int samples_decoded =
IAMF_decoder_decode(decoder_, info.data.data(), info.data.size(), nullptr,
const_cast<uint8_t*>(decoded_audio->data()));

if (samples_decoded < 1) {
ReportError("Failed to decode IAMF sample, error " +
ErrorCodeToString(samples_decoded));
Expand Down
21 changes: 12 additions & 9 deletions starboard/shared/libiamf/iamf_decoder_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ class BufferReader {
if (!HasBytes(1) || !str) {
return false;
}
int bytes_read = ReadStringInternal(buf_ + pos_, str);

// The size of the string is capped to 128 bytes.
// https://aomediacodec.github.io/iamf/v1.0.0-errata.html#convention-data-types
const int kMaxIamfStringSize = 128;
int bytes_read = ReadStringInternal(
buf_ + pos_, str, std::min(RemainingSize(), kMaxIamfStringSize));
if (bytes_read < 0) {
return false;
}
Expand Down Expand Up @@ -148,9 +153,9 @@ class BufferReader {
// Decodes an Leb128 value and stores it in |value|. Returns the number of
// bytes read, capped to |max_bytes_to_read|. Returns the number of bytes
// read, or -1 on error.
int ReadLeb128Internal(const uint8_t* buf,
uint32_t* value,
const int max_bytes_to_read) const {
static int ReadLeb128Internal(const uint8_t* buf,
uint32_t* value,
const int max_bytes_to_read) {
SB_DCHECK(buf);
SB_DCHECK(value);

Expand All @@ -174,14 +179,12 @@ class BufferReader {

// Reads a c-string into |str|. Returns the number of bytes read, capped to
// 128 bytes, or -1 on error.
int ReadStringInternal(const uint8_t* buf, std::string* str) const {
static int ReadStringInternal(const uint8_t* buf,
std::string* str,
int max_bytes_to_read) {
SB_DCHECK(buf);
SB_DCHECK(str);

// The size of the string is capped to 128 bytes.
// https://aomediacodec.github.io/iamf/v1.0.0-errata.html#convention-data-types
const int kMaxIamfStringSize = 128;
int max_bytes_to_read = std::min(RemainingSize(), kMaxIamfStringSize);
str->clear();
str->resize(max_bytes_to_read);

Expand Down

0 comments on commit e16809e

Please sign in to comment.