Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[linux] Implement libiamf-based IAMF decoder #4221

Merged
merged 31 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
77bc761
Implement IAMF audio decoder
osagie98 Jun 27, 2024
4c71f32
Update config parsing
osagie98 Jul 9, 2024
416f7b4
Decode samples to int16
osagie98 Jul 10, 2024
f0c1c57
Enable Android IAMF decode support
osagie98 Jul 11, 2024
7bffaf1
Add build args
osagie98 Jul 17, 2024
819d65b
Remove flac dep
osagie98 Jul 18, 2024
8a1aa26
Move location of libiamf binaries
osagie98 Aug 5, 2024
4b6608a
Max IamfConfigReader actually servicable
osagie98 Sep 1, 2024
dd0ebdf
Max IamfAudioDecoder actually servicable
osagie98 Sep 3, 2024
82bc941
Minor formatting
osagie98 Sep 3, 2024
4c3c957
Update DCHECK in mix_presentation_id()
osagie98 Sep 3, 2024
08ccf79
IamfConfigReader becomes IamfBufferParser
osagie98 Sep 5, 2024
c7e3ab8
Update handling of surround audio configurations
osagie98 Sep 6, 2024
55d6ae0
Remove Android IAMF support
osagie98 Oct 7, 2024
1fd6ba5
Remove Android IAMF support
osagie98 Oct 7, 2024
57c5c3a
formatting
osagie98 Oct 8, 2024
c302b43
further formatting
osagie98 Oct 8, 2024
c1b181d
Even further formatting
osagie98 Oct 8, 2024
8ee950b
Merge branch '25.lts.1+' into iamf-decode-linux
osagie98 Oct 14, 2024
06e1d21
Remove unused variable
osagie98 Oct 14, 2024
a9b012b
Use IamfMimeUtil to check IAMF support
osagie98 Oct 14, 2024
f98d344
Various updates
osagie98 Oct 15, 2024
bbe1984
Check additional profile
osagie98 Oct 16, 2024
6dac7cb
Fix handling of profile rejection
osagie98 Oct 16, 2024
8889907
Minor abstraction
osagie98 Oct 16, 2024
4e08474
Add missing const
osagie98 Oct 16, 2024
e16809e
Some simplification
osagie98 Oct 16, 2024
76a242c
Check decoder validity
osagie98 Oct 18, 2024
b47672e
update comment
osagie98 Oct 18, 2024
609328b
update comments
osagie98 Oct 18, 2024
bf43e00
Filter tests
osagie98 Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions media/base/starboard_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ int GetBitsPerPixel(const std::string& mime_type) {
return 8;
}

int GetMaxChannelCount() {
int channels = 2;
int index = 0;
SbMediaAudioConfiguration configuration;
while (SbMediaGetAudioConfiguration(index++, &configuration)) {
if (configuration.number_of_channels > channels)
channels = configuration.number_of_channels;
xiaomings marked this conversation as resolved.
Show resolved Hide resolved
}
return channels;
}

} // namespace

SbMediaAudioCodec MediaAudioCodecToSbMediaAudioCodec(AudioCodec codec) {
Expand Down Expand Up @@ -91,7 +102,7 @@ SbMediaAudioCodec MediaAudioCodecToSbMediaAudioCodec(AudioCodec codec) {
return kSbMediaAudioCodecPcm;
#if SB_API_VERSION >= 15
case AudioCodec::kIAMF:
return kSbMediaAudioCodecIamf;
return kSbMediaAudioCodecIamf;
#endif // SB_API_VERSION >= 15
default:
// Cobalt only supports a subset of audio codecs defined by Chromium.
Expand Down Expand Up @@ -142,15 +153,21 @@ SbMediaAudioStreamInfo MediaAudioConfigToSbMediaAudioStreamInfo(

#if SB_API_VERSION < 15
audio_stream_info.format_tag = 0x00ff;
#endif // SB_API_VERSION < 15
audio_stream_info.number_of_channels =
#endif // SB_API_VERSION < 15
audio_stream_info.number_of_channels =
xiaomings marked this conversation as resolved.
Show resolved Hide resolved
ChannelLayoutToChannelCount(audio_decoder_config.channel_layout());
#if SB_API_VERSION >= 15
if (audio_stream_info.codec == kSbMediaAudioCodecIamf) {
// IAMF mixes audio signals to the highest available speaker layout.
audio_stream_info.number_of_channels = GetMaxChannelCount();
}
jasonzhangxx marked this conversation as resolved.
Show resolved Hide resolved
#endif // SB_API_VERSION >= 15
audio_stream_info.samples_per_second =
audio_decoder_config.samples_per_second();
#if SB_API_VERSION < 15
audio_stream_info.average_bytes_per_second = 1;
audio_stream_info.block_alignment = 4;
#endif // SB_API_VERSION < 15
#endif // SB_API_VERSION < 15
audio_stream_info.bits_per_sample = audio_decoder_config.bits_per_channel();

const auto& extra_data = audio_stream_info.codec == kSbMediaAudioCodecAac
Expand Down
2 changes: 2 additions & 0 deletions starboard/build/config/BUILDCONFIG.gn
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ declare_args() {
build_with_separate_cobalt_toolchain = false

use_xcode_clang = false

enable_iamf_decode = false
}

_is_on_pythonpath = exec_script("//starboard/build/is_on_path.py", [], "json")
Expand Down
11 changes: 11 additions & 0 deletions starboard/linux/shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,17 @@ static_library("starboard_platform_sources") {
if (is_debug || is_devel) {
defines += [ "SB_PLAYER_ENABLE_VIDEO_DUMPER" ]
}

if (enable_iamf_decode) {
sources += [
"//starboard/shared/libiamf/iamf_audio_decoder.cc",
"//starboard/shared/libiamf/iamf_audio_decoder.h",
"//starboard/shared/libiamf/iamf_decoder_utils.cc",
"//starboard/shared/libiamf/iamf_decoder_utils.h",
]

defines += [ "ENABLE_IAMF_DECODE" ]
}
}

if (current_toolchain == starboard_toolchain) {
Expand Down
30 changes: 30 additions & 0 deletions starboard/linux/shared/media_is_audio_supported.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
#include "starboard/configuration.h"
#include "starboard/configuration_constants.h"
#include "starboard/media.h"
#include "starboard/shared/starboard/media/iamf_util.h"

using ::starboard::shared::starboard::media::IamfMimeUtil;
using ::starboard::shared::starboard::media::kIamfProfileBase;
using ::starboard::shared::starboard::media::kIamfProfileSimple;
using ::starboard::shared::starboard::media::kIamfSubstreamCodecOpus;
using ::starboard::shared::starboard::media::MimeType;

bool SbMediaIsAudioSupported(SbMediaAudioCodec audio_codec,
Expand All @@ -32,6 +37,31 @@ bool SbMediaIsAudioSupported(SbMediaAudioCodec audio_codec,
return bitrate <= kSbMediaMaxAudioBitrateInBitsPerSecond;
}

#if SB_API_VERSION >= 15 && ENABLE_IAMF_DECODE
if (audio_codec == kSbMediaAudioCodecIamf) {
if (!mime_type || !mime_type->is_valid()) {
return false;
}
const std::vector<std::string>& codecs = mime_type->GetCodecs();
if (codecs.size() != 1) {
return false;
}

IamfMimeUtil mime_util(codecs[0]);
if (!mime_util.is_valid()) {
return false;
}
uint32_t profile = mime_util.primary_profile();
// Support only IAMF streams with a base or simple profile and an Opus
// substream.
if (mime_util.substream_codec() != kIamfSubstreamCodecOpus ||
(profile != kIamfProfileSimple && profile != kIamfProfileBase)) {
return false;
}
return bitrate <= kSbMediaMaxAudioBitrateInBitsPerSecond;
}
#endif // SB_API_VERSION >= 15

if (audio_codec == kSbMediaAudioCodecAc3 ||
audio_codec == kSbMediaAudioCodecEac3) {
#if SB_API_VERSION < 15
Expand Down
11 changes: 11 additions & 0 deletions starboard/linux/shared/player_components_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#include "starboard/shared/starboard/player/filter/video_render_algorithm_impl.h"
#include "starboard/shared/starboard/player/filter/video_renderer_sink.h"

#if ENABLE_IAMF_DECODE
#include "starboard/shared/libiamf/iamf_audio_decoder.h"
#endif // ENABLE_IAMF_DECODE

namespace starboard {
namespace shared {
namespace starboard {
Expand Down Expand Up @@ -86,6 +90,13 @@ class PlayerComponentsFactory : public PlayerComponents::Factory {
libfdkaac::LibfdkaacHandle::GetHandle()->IsLoaded()) {
SB_LOG(INFO) << "Playing audio using FdkAacAudioDecoder.";
return std::unique_ptr<AudioDecoder>(new FdkAacAudioDecoder());
#if SB_API_VERSION >= 15 && ENABLE_IAMF_DECODE
} else if (audio_stream_info.codec == kSbMediaAudioCodecIamf) {
SB_LOG(INFO) << "Playing audio using IamfAudioDecoder.";
return std::unique_ptr<AudioDecoder>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check if it's valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, done

new ::starboard::shared::libiamf::IamfAudioDecoder(
audio_stream_info));
#endif // SB_API_VERSION >= 15 && ENABLE_IAMF_DECODE
} else {
std::unique_ptr<FfmpegAudioDecoder> audio_decoder_impl(
FfmpegAudioDecoder::Create(audio_stream_info));
Expand Down
3 changes: 3 additions & 0 deletions starboard/linux/x64x11/shared/platform_configuration/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ config("platform_configuration") {

config("libraries") {
configs = [ "//starboard/linux/shared/platform_configuration:libraries" ]
if (enable_iamf_decode) {
libs = [ "//third_party/libiamf/platforms/linux/libiamf.a" ]
}
}

config("linker_flags") {
Expand Down
Loading
Loading