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

Ensure that MP3, FLAC, and PCM are not supported for MediaSource. #1359

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions cobalt/media/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ target(gtest_target_type, "media_test") {
"base/decoder_buffer_cache_test.cc",
"bidirectional_fit_reuse_allocator_test.cc",
"file_data_source_test.cc",
"media_module_test.cc",
"progressive/demuxer_extension_wrapper_test.cc",
"progressive/mock_data_source_reader.h",
"progressive/mp4_map_unittest.cc",
Expand Down
14 changes: 11 additions & 3 deletions cobalt/media/media_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class CanPlayTypeHandlerStarboard : public CanPlayTypeHandler {
// progressive.
SbMediaSupportType support_type;
media::FormatSupportQueryMetrics metrics;
if (strstr(mime_type.c_str(), "video/mp4") == 0 &&
strstr(mime_type.c_str(), "application/x-mpegURL") == 0) {
if (strstr(mime_type.c_str(), "video/mp4") == NULL &&
strstr(mime_type.c_str(), "application/x-mpegURL") == NULL) {
support_type = kSbMediaSupportTypeNotSupported;
} else {
support_type = CanPlayType(mime_type, "");
Expand All @@ -135,8 +135,16 @@ class CanPlayTypeHandlerStarboard : public CanPlayTypeHandler {
SbMediaSupportType CanPlayAdaptive(
const std::string& mime_type,
const std::string& key_system) const override {
SbMediaSupportType support_type;
media::FormatSupportQueryMetrics metrics;
SbMediaSupportType support_type = CanPlayType(mime_type, key_system);
// Only mp4 and webm videos are supported for adaptive playback in Cobalt;
// any other containers can be immediately rejected.
if (strstr(mime_type.c_str(), "video/mp4") == NULL &&
strstr(mime_type.c_str(), "video/webm") == NULL) {
jasonzhangxx marked this conversation as resolved.
Show resolved Hide resolved
support_type = kSbMediaSupportTypeNotSupported;
} else {
support_type = CanPlayType(mime_type, key_system);
}
metrics.RecordAndLogQuery("MediaSource::IsTypeSupported", mime_type,
key_system, support_type);
return support_type;
Expand Down
81 changes: 81 additions & 0 deletions cobalt/media/media_module_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2023 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "cobalt/media/media_module.h"

#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace cobalt {
namespace media {
namespace {

using ::testing::NotNull;

#if SB_API_VERSION >= 14
TEST(MediaModuleTest, DoesNotSupportMp3Adaptive) {
std::unique_ptr<CanPlayTypeHandler> handler =
MediaModule::CreateCanPlayTypeHandler();
ASSERT_THAT(handler, NotNull());
EXPECT_FALSE(handler->CanPlayAdaptive("audio/mpeg; codecs=\"mp3\"",
/*key_system=*/""));
EXPECT_FALSE(handler->CanPlayAdaptive("audio/mpeg", /*key_system=*/""));
}

TEST(MediaModuleTest, DoesNotSupportMp3Progressive) {
std::unique_ptr<CanPlayTypeHandler> handler =
MediaModule::CreateCanPlayTypeHandler();
ASSERT_THAT(handler, NotNull());
EXPECT_FALSE(handler->CanPlayProgressive("audio/mpeg; codecs=\"mp3\""));
EXPECT_FALSE(handler->CanPlayProgressive("audio/mpeg"));
}

TEST(MediaModuleTest, DoesNotSupportFlacAdaptive) {
std::unique_ptr<CanPlayTypeHandler> handler =
MediaModule::CreateCanPlayTypeHandler();
ASSERT_THAT(handler, NotNull());
EXPECT_FALSE(handler->CanPlayAdaptive("audio/ogg; codecs=\"flac\"",
/*key_system=*/""));
EXPECT_FALSE(handler->CanPlayAdaptive("audio/flac; codecs=\"flac\"",
/*key_system=*/""));
}

TEST(MediaModuleTest, DoesNotSupportFlacProgressive) {
std::unique_ptr<CanPlayTypeHandler> handler =
MediaModule::CreateCanPlayTypeHandler();
ASSERT_THAT(handler, NotNull());
EXPECT_FALSE(handler->CanPlayProgressive("audio/ogg; codecs=\"flac\""));
EXPECT_FALSE(handler->CanPlayProgressive("audio/flac; codecs=\"flac\""));
}

TEST(MediaModuleTest, DoesNotSupportPcmAdaptive) {
std::unique_ptr<CanPlayTypeHandler> handler =
MediaModule::CreateCanPlayTypeHandler();
ASSERT_THAT(handler, NotNull());
EXPECT_FALSE(handler->CanPlayAdaptive("audio/wav; codecs=\"1\"",
/*key_system=*/""));
}

TEST(MediaModuleTest, DoesNotSupportPcmProgressive) {
std::unique_ptr<CanPlayTypeHandler> handler =
MediaModule::CreateCanPlayTypeHandler();
ASSERT_THAT(handler, NotNull());
EXPECT_FALSE(handler->CanPlayProgressive("audio/wav; codecs=\"1\""));
}

#endif // SB_API_VERSION >= 14

} // namespace
} // namespace media
} // namespace cobalt