Skip to content

Commit

Permalink
Remove IamfMimeUtil redundancies
Browse files Browse the repository at this point in the history
  • Loading branch information
osagie98 committed Oct 1, 2024
1 parent fa49cad commit 46d8d39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 44 deletions.
23 changes: 4 additions & 19 deletions starboard/shared/starboard/media/iamf_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ IamfMimeUtil::IamfMimeUtil(const std::string& mime_type) {
// v1.0.0
// 6.3. Codecs Parameter String
// (https://aomediacodec.github.io/iamf/v1.0.0-errata.html#codecsparameter)
if (mime_type.find("iamf") == std::string::npos) {
if (mime_type.find("iamf") != 0) {
return;
}

Expand All @@ -42,7 +42,6 @@ IamfMimeUtil::IamfMimeUtil(const std::string& mime_type) {
// +1 delimiting period.
// +9 The remaining string is one of "Opus", "mp4a.40.2", "fLaC", or "ipcm".
constexpr int kMaxIamfCodecIdLength = 22;

if (mime_type.size() > kMaxIamfCodecIdLength) {
return;
}
Expand All @@ -54,10 +53,6 @@ IamfMimeUtil::IamfMimeUtil(const std::string& mime_type) {
return;
}

if (vec[0] != "iamf") {
return;
}

// The primary profile string should be three digits, and should be between 0
// and 255 inclusive.
int primary_profile;
Expand All @@ -78,8 +73,8 @@ IamfMimeUtil::IamfMimeUtil(const std::string& mime_type) {

// The codec string should be one of "Opus", "mp4a", "fLaC", or "ipcm".
std::string codec = vec[3];
if (codec.size() != 4 || ((codec != "Opus") && (codec != "mp4a") &&
(codec != "fLaC") && (codec != "ipcm"))) {
if (((codec != "Opus") && (codec != "mp4a") && (codec != "fLaC") &&
(codec != "ipcm"))) {
return;
}

Expand All @@ -91,17 +86,7 @@ IamfMimeUtil::IamfMimeUtil(const std::string& mime_type) {
}

// The fields following "mp4a" should be "40" and "2" to signal AAC-LC.
stream = std::stringstream(vec[4]);
int object_type_indication;
stream >> object_type_indication;
if (stream.fail() || vec[4].size() != 2 || object_type_indication != 40) {
return;
}

stream = std::stringstream(vec[5]);
int audio_object_type;
stream >> audio_object_type;
if (stream.fail() || vec[5].size() != 1 || audio_object_type != 2) {
if (vec[4] != "40" || vec[5] != "2") {
return;
}
substream_codec_ = kIamfSubstreamCodecMp4a;
Expand Down
16 changes: 12 additions & 4 deletions starboard/shared/starboard/media/iamf_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@
#include <limits>
#include <string>

#include "starboard/common/log.h"

namespace starboard {
namespace shared {
namespace starboard {
namespace media {

enum IamfSubstreamCodec {
kIamfSubstreamCodecUnknown,
kIamfSubstreamCodecOpus,
kIamfSubstreamCodecMp4a,
kIamfSubstreamCodecFlac,
kIamfSubstreamCodecIpcm,
kIamfSubstreamCodecUnknown
kIamfSubstreamCodecIpcm
};

// These values must match the profile values defined in
Expand All @@ -48,8 +50,14 @@ class IamfMimeUtil {
return profile_ <= kIamfProfileMax &&
substream_codec_ != kIamfSubstreamCodecUnknown;
}
int profile() const { return profile_; }
IamfSubstreamCodec substream_codec() const { return substream_codec_; }
int profile() const {
SB_DCHECK(is_valid());
return profile_;
}
IamfSubstreamCodec substream_codec() const {
SB_DCHECK(is_valid());
return substream_codec_;
}

private:
int profile_ = std::numeric_limits<int>::max();
Expand Down
22 changes: 1 addition & 21 deletions starboard/shared/starboard/media/iamf_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,8 @@ TEST(IamfUtilTest, IsValid) {
}

TEST(IamfUtilTest, SubstreamCodec) {
std::string codec_param = "iamf.000.000.vorbis";
std::string codec_param = "iamf.000.000.Opus";
IamfMimeUtil util(codec_param);
EXPECT_EQ(util.substream_codec(), kIamfSubstreamCodecUnknown);

codec_param = "iamf.000.000";
util = IamfMimeUtil(codec_param);
EXPECT_EQ(util.substream_codec(), kIamfSubstreamCodecUnknown);

codec_param = "iamf.000.000.opus";
util = IamfMimeUtil(codec_param);
EXPECT_EQ(util.substream_codec(), kIamfSubstreamCodecUnknown);

codec_param = "iamf.000.000.flac";
util = IamfMimeUtil(codec_param);
EXPECT_EQ(util.substream_codec(), kIamfSubstreamCodecUnknown);

codec_param = "iamf.000.000.mp4a.40.3";
util = IamfMimeUtil(codec_param);
EXPECT_EQ(util.substream_codec(), kIamfSubstreamCodecUnknown);

codec_param = "iamf.000.000.Opus";
util = IamfMimeUtil(codec_param);
EXPECT_EQ(util.substream_codec(), kIamfSubstreamCodecOpus);

codec_param = "iamf.000.000.fLaC";
Expand Down

0 comments on commit 46d8d39

Please sign in to comment.