Commit 09a09494 authored by Xiaohan Wang's avatar Xiaohan Wang Committed by Commit Bot

media: Use GetMimeTypeForFile() in MediaSourceTest

This CL converts MediaSourceTest to use GetMimeTypeForFile() to get the
mime type for test files to remove duplicate code.

Bug: 897767
Test: No functionality change
Change-Id: I5953cf8ae4e466d6fbb9c5d0ea021077a6f27f7f
Reviewed-on: https://chromium-review.googlesource.com/c/1296998Reviewed-by: default avatarChrome Cunningham <chcunningham@chromium.org>
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602131}
parent 8d8668dc
...@@ -13,27 +13,6 @@ ...@@ -13,27 +13,6 @@
#include "base/android/build_info.h" #include "base/android/build_info.h"
#endif #endif
// Common media types.
#if BUILDFLAG(USE_PROPRIETARY_CODECS) && !defined(OS_ANDROID)
const char kAAC_ADTS_AudioOnly[] = "audio/aac";
#endif
const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
#if !defined(OS_ANDROID)
const char kWebMOpusAudioOnly[] = "audio/webm; codecs=\"opus\"";
#endif
const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\"";
const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
const char kMp4FlacAudioOnly[] = "audio/mp4; codecs=\"flac\"";
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
const char kMp4AudioOnly[] = "audio/mp4; codecs=\"mp4a.40.2\"'";
const char kMp4VideoOnly[] = "video/mp4; codecs=\"avc1.4D4041\"'";
#if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER)
const char kMp2tAudioVideo[] = "video/mp2t; codecs=\"mp4a.40.2, avc1.42E01E\"";
#endif // BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER)
#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
namespace content { namespace content {
class MediaSourceTest : public MediaBrowserTest { class MediaSourceTest : public MediaBrowserTest {
...@@ -42,20 +21,35 @@ class MediaSourceTest : public MediaBrowserTest { ...@@ -42,20 +21,35 @@ class MediaSourceTest : public MediaBrowserTest {
const std::string& media_type, const std::string& media_type,
const std::string& expectation) { const std::string& expectation) {
base::StringPairs query_params; base::StringPairs query_params;
query_params.push_back(std::make_pair("mediaFile", media_file)); query_params.emplace_back("mediaFile", media_file);
query_params.push_back(std::make_pair("mediaType", media_type)); query_params.emplace_back("mediaType", media_type);
RunMediaTestPage("media_source_player.html", query_params, expectation, RunMediaTestPage("media_source_player.html", query_params, expectation,
false); false);
} }
void TestSimplePlayback(const std::string& media_file,
const std::string& expectation) {
TestSimplePlayback(media_file, media::GetMimeTypeForFile(media_file),
expectation);
}
base::StringPairs GetAudioVideoQueryParams(const std::string& audio_file,
const std::string& video_file) {
base::StringPairs params;
params.emplace_back("audioFile", audio_file);
params.emplace_back("audioFormat", media::GetMimeTypeForFile(audio_file));
params.emplace_back("videoFile", video_file);
params.emplace_back("videoFormat", media::GetMimeTypeForFile(video_file));
return params;
}
}; };
IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_VideoAudio_WebM) { IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_VideoAudio_WebM) {
TestSimplePlayback("bear-320x240.webm", kWebMAudioVideo, media::kEnded); TestSimplePlayback("bear-320x240.webm", media::kEnded);
} }
IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_VideoOnly_WebM) { IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_VideoOnly_WebM) {
TestSimplePlayback("bear-320x240-video-only.webm", kWebMVideoOnly, TestSimplePlayback("bear-320x240-video-only.webm", media::kEnded);
media::kEnded);
} }
// TODO(servolk): Android is supposed to support AAC in ADTS container with // TODO(servolk): Android is supposed to support AAC in ADTS container with
...@@ -63,23 +57,24 @@ IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_VideoOnly_WebM) { ...@@ -63,23 +57,24 @@ IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_VideoOnly_WebM) {
// some issue in OMX AAC decoder (crbug.com/528361) // some issue in OMX AAC decoder (crbug.com/528361)
#if BUILDFLAG(USE_PROPRIETARY_CODECS) && !defined(OS_ANDROID) #if BUILDFLAG(USE_PROPRIETARY_CODECS) && !defined(OS_ANDROID)
IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_AudioOnly_AAC_ADTS) { IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_AudioOnly_AAC_ADTS) {
TestSimplePlayback("sfx.adts", kAAC_ADTS_AudioOnly, media::kEnded); TestSimplePlayback("sfx.adts", media::kEnded);
} }
#endif #endif
// Opus is not supported in Android as of now. // Opus is not supported in Android as of now.
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_AudioOnly_Opus_WebM) { IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_AudioOnly_Opus_WebM) {
TestSimplePlayback("bear-opus.webm", kWebMOpusAudioOnly, media::kEnded); TestSimplePlayback("bear-opus.webm", media::kEnded);
} }
#endif #endif
IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_AudioOnly_WebM) { IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_AudioOnly_WebM) {
TestSimplePlayback("bear-320x240-audio-only.webm", kWebMAudioOnly, TestSimplePlayback("bear-320x240-audio-only.webm", media::kEnded);
media::kEnded);
} }
// Test the case where test file and mime type mismatch.
IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_Type_Error) { IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_Type_Error) {
const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
TestSimplePlayback("bear-320x240-video-only.webm", kWebMAudioOnly, TestSimplePlayback("bear-320x240-video-only.webm", kWebMAudioOnly,
media::kErrorEvent); media::kErrorEvent);
} }
...@@ -93,39 +88,29 @@ IN_PROC_BROWSER_TEST_F(MediaSourceTest, ConfigChangeVideo) { ...@@ -93,39 +88,29 @@ IN_PROC_BROWSER_TEST_F(MediaSourceTest, ConfigChangeVideo) {
#if BUILDFLAG(USE_PROPRIETARY_CODECS) #if BUILDFLAG(USE_PROPRIETARY_CODECS)
IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_Video_MP4_Audio_WEBM) { IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_Video_MP4_Audio_WEBM) {
base::StringPairs query_params; auto query_params = GetAudioVideoQueryParams("bear-320x240-audio-only.webm",
query_params.push_back( "bear-640x360-v_frag.mp4");
std::make_pair("videoFile", "bear-640x360-v_frag.mp4")); RunMediaTestPage("mse_different_containers.html", std::move(query_params),
query_params.push_back(std::make_pair("videoFormat", kMp4VideoOnly)); media::kEnded, true);
query_params.push_back(
std::make_pair("audioFile", "bear-320x240-audio-only.webm"));
query_params.push_back(std::make_pair("audioFormat", kWebMAudioOnly));
RunMediaTestPage("mse_different_containers.html", query_params, media::kEnded,
true);
} }
IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_Video_WEBM_Audio_MP4) { IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_Video_WEBM_Audio_MP4) {
base::StringPairs query_params; auto query_params = GetAudioVideoQueryParams("bear-640x360-a_frag.mp4",
query_params.push_back( "bear-320x240-video-only.webm");
std::make_pair("videoFile", "bear-320x240-video-only.webm")); RunMediaTestPage("mse_different_containers.html", std::move(query_params),
query_params.push_back(std::make_pair("videoFormat", kWebMVideoOnly)); media::kEnded, true);
query_params.push_back(
std::make_pair("audioFile", "bear-640x360-a_frag.mp4"));
query_params.push_back(std::make_pair("audioFormat", kMp4AudioOnly));
RunMediaTestPage("mse_different_containers.html", query_params, media::kEnded,
true);
} }
#endif // BUILDFLAG(USE_PROPRIETARY_CODECS) #endif // BUILDFLAG(USE_PROPRIETARY_CODECS)
IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_AudioOnly_FLAC_MP4) { IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_AudioOnly_FLAC_MP4) {
TestSimplePlayback("bear-flac_frag.mp4", kMp4FlacAudioOnly, media::kEnded); TestSimplePlayback("bear-flac_frag.mp4", media::kEnded);
} }
#if BUILDFLAG(USE_PROPRIETARY_CODECS) #if BUILDFLAG(USE_PROPRIETARY_CODECS)
#if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER)
IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_AudioVideo_Mp2t) { IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_AudioVideo_Mp2t) {
TestSimplePlayback("bear-1280x720.ts", kMp2tAudioVideo, media::kEnded); TestSimplePlayback("bear-1280x720.ts", media::kEnded);
} }
#endif #endif
#endif #endif
......
...@@ -19,15 +19,20 @@ namespace media { ...@@ -19,15 +19,20 @@ namespace media {
namespace { namespace {
// Mime types for test files. Sorted in alphabetical order. // Mime types for test files. Sorted in alphabetical order.
const char kAacAdtsAudioOnly[] = "audio/aac";
const char kMp2tAudioVideo[] = "video/mp2t; codecs=\"mp4a.40.2, avc1.42E01E\"";
const char kMp4AacAudioOnly[] = "audio/mp4; codecs=\"mp4a.40.2\""; const char kMp4AacAudioOnly[] = "audio/mp4; codecs=\"mp4a.40.2\"";
const char kMp4AudioOnly[] = "audio/mp4; codecs=\"mp4a.40.2\"'";
const char kMp4Av110bitVideoOnly[] = "video/mp4; codecs=\"av01.0.04M.10\""; const char kMp4Av110bitVideoOnly[] = "video/mp4; codecs=\"av01.0.04M.10\"";
const char kMp4Av1VideoOnly[] = "video/mp4; codecs=\"av01.0.04M.08\""; const char kMp4Av1VideoOnly[] = "video/mp4; codecs=\"av01.0.04M.08\"";
const char kMp4Avc1VideoOnly[] = "video/mp4; codecs=\"avc1.64001E\""; const char kMp4Avc1VideoOnly[] = "video/mp4; codecs=\"avc1.64001E\"";
const char kMp4FlacAudioOnly[] = "audio/mp4; codecs=\"flac\""; const char kMp4FlacAudioOnly[] = "audio/mp4; codecs=\"flac\"";
const char kMp4VideoOnly[] = "video/mp4; codecs=\"avc1.4D4041\"'";
const char kMp4Vp9Profile2VideoOnly[] = const char kMp4Vp9Profile2VideoOnly[] =
"video/mp4; codecs=\"vp09.02.10.10.01.02.02.02.00\""; "video/mp4; codecs=\"vp09.02.10.10.01.02.02.02.00\"";
const char kMp4Vp9VideoOnly[] = const char kMp4Vp9VideoOnly[] =
"video/mp4; codecs=\"vp09.00.10.08.01.02.02.02.00\""; "video/mp4; codecs=\"vp09.00.10.08.01.02.02.02.00\"";
const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
const char kWebMAv110bitVideoOnly[] = "video/webm; codecs=\"av01.0.04M.10\""; const char kWebMAv110bitVideoOnly[] = "video/webm; codecs=\"av01.0.04M.10\"";
const char kWebMAv1VideoOnly[] = "video/webm; codecs=\"av01.0.04M.08\""; const char kWebMAv1VideoOnly[] = "video/webm; codecs=\"av01.0.04M.08\"";
const char kWebMOpusAudioOnly[] = "audio/webm; codecs=\"opus\""; const char kWebMOpusAudioOnly[] = "audio/webm; codecs=\"opus\"";
...@@ -47,6 +52,7 @@ using FileToMimeTypeMap = base::flat_map<std::string, std::string>; ...@@ -47,6 +52,7 @@ using FileToMimeTypeMap = base::flat_map<std::string, std::string>;
// alphabetical order. // alphabetical order.
const FileToMimeTypeMap& GetFileToMimeTypeMap() { const FileToMimeTypeMap& GetFileToMimeTypeMap() {
static const base::NoDestructor<FileToMimeTypeMap> kFileToMimeTypeMap({ static const base::NoDestructor<FileToMimeTypeMap> kFileToMimeTypeMap({
{"bear-1280x720.ts", kMp2tAudioVideo},
{"bear-320x240-audio-only.webm", kWebMVorbisAudioOnly}, {"bear-320x240-audio-only.webm", kWebMVorbisAudioOnly},
{"bear-320x240-av_enc-a.webm", kWebMVorbisAudioVp8Video}, {"bear-320x240-av_enc-a.webm", kWebMVorbisAudioVp8Video},
{"bear-320x240-av_enc-av.webm", kWebMVorbisAudioVp8Video}, {"bear-320x240-av_enc-av.webm", kWebMVorbisAudioVp8Video},
...@@ -63,20 +69,26 @@ const FileToMimeTypeMap& GetFileToMimeTypeMap() { ...@@ -63,20 +69,26 @@ const FileToMimeTypeMap& GetFileToMimeTypeMap() {
{"bear-320x240-v_enc-v.webm", kWebMVp8VideoOnly}, {"bear-320x240-v_enc-v.webm", kWebMVp8VideoOnly},
{"bear-320x240-v_frag-vp9-cenc.mp4", kMp4Vp9VideoOnly}, {"bear-320x240-v_frag-vp9-cenc.mp4", kMp4Vp9VideoOnly},
{"bear-320x240-video-only.webm", kWebMVp8VideoOnly}, {"bear-320x240-video-only.webm", kWebMVp8VideoOnly},
{"bear-320x240.webm", kWebMAudioVideo},
{"bear-640x360-a_frag-cbcs.mp4", kMp4AacAudioOnly}, {"bear-640x360-a_frag-cbcs.mp4", kMp4AacAudioOnly},
{"bear-640x360-a_frag-cenc.mp4", kMp4AacAudioOnly}, {"bear-640x360-a_frag-cenc.mp4", kMp4AacAudioOnly},
{"bear-640x360-a_frag.mp4", kMp4AudioOnly},
{"bear-640x360-v_frag-cbc1.mp4", kMp4Avc1VideoOnly}, {"bear-640x360-v_frag-cbc1.mp4", kMp4Avc1VideoOnly},
{"bear-640x360-v_frag-cbcs.mp4", kMp4Avc1VideoOnly}, {"bear-640x360-v_frag-cbcs.mp4", kMp4Avc1VideoOnly},
{"bear-640x360-v_frag-cenc-mdat.mp4", kMp4Avc1VideoOnly}, {"bear-640x360-v_frag-cenc-mdat.mp4", kMp4Avc1VideoOnly},
{"bear-640x360-v_frag-cenc.mp4", kMp4Avc1VideoOnly}, {"bear-640x360-v_frag-cenc.mp4", kMp4Avc1VideoOnly},
{"bear-640x360-v_frag-cens.mp4", kMp4Avc1VideoOnly}, {"bear-640x360-v_frag-cens.mp4", kMp4Avc1VideoOnly},
{"bear-640x360-v_frag.mp4", kMp4VideoOnly},
{"bear-a_enc-a.webm", kWebMVorbisAudioOnly}, {"bear-a_enc-a.webm", kWebMVorbisAudioOnly},
{"bear-av1-320x180-10bit-cenc.mp4", kMp4Av110bitVideoOnly}, {"bear-av1-320x180-10bit-cenc.mp4", kMp4Av110bitVideoOnly},
{"bear-av1-320x180-10bit-cenc.webm", kWebMAv110bitVideoOnly}, {"bear-av1-320x180-10bit-cenc.webm", kWebMAv110bitVideoOnly},
{"bear-av1-cenc.mp4", kMp4Av1VideoOnly}, {"bear-av1-cenc.mp4", kMp4Av1VideoOnly},
{"bear-av1-cenc.webm", kWebMAv1VideoOnly}, {"bear-av1-cenc.webm", kWebMAv1VideoOnly},
{"bear-flac-cenc.mp4", kMp4FlacAudioOnly}, {"bear-flac-cenc.mp4", kMp4FlacAudioOnly},
{"bear-flac_frag.mp4", kMp4FlacAudioOnly},
{"bear-opus.webm", kWebMOpusAudioOnly},
{"frame_size_change-av_enc-v.webm", kWebMVorbisAudioVp8Video}, {"frame_size_change-av_enc-v.webm", kWebMVorbisAudioVp8Video},
{"sfx.adts", kAacAdtsAudioOnly},
}); });
return *kFileToMimeTypeMap; return *kFileToMimeTypeMap;
...@@ -146,10 +158,9 @@ scoped_refptr<DecoderBuffer> ReadTestDataFile(const std::string& name) { ...@@ -146,10 +158,9 @@ scoped_refptr<DecoderBuffer> ReadTestDataFile(const std::string& name) {
int file_size = base::checked_cast<int>(tmp); int file_size = base::checked_cast<int>(tmp);
scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(file_size)); scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(file_size));
CHECK_EQ(file_size, auto* data = reinterpret_cast<char*>(buffer->writable_data());
base::ReadFile( CHECK_EQ(file_size, base::ReadFile(file_path, data, file_size))
file_path, reinterpret_cast<char*>(buffer->writable_data()), << "Failed to read '" << name << "'";
file_size)) << "Failed to read '" << name << "'";
return buffer; return buffer;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment