Commit 5526e3a4 authored by Xiaohan Wang's avatar Xiaohan Wang Committed by Commit Bot

media: Add GetMimeTypeForFile() for test

This removes the duplicate code to specify mime type for a given test
file in multiple media tests.

In this CL chrome/content encrypted_media_browsertest.cc are updated to
use the new function.

In the next CL, media_source_browsertest.cc and
pipeline_integration_test.cc will be updated as well.

Bug: 897767
Test: No functionality change.
Change-Id: I2e408d125fcc339352ad7c18a56b951f179f736c
Reviewed-on: https://chromium-review.googlesource.com/c/1295151Reviewed-by: default avatarChrome Cunningham <chcunningham@chromium.org>
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602036}
parent 0825d4cd
......@@ -6,8 +6,10 @@
#include <stdint.h>
#include "base/containers/flat_map.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/numerics/safe_conversions.h"
#include "base/path_service.h"
#include "media/base/decoder_buffer.h"
......@@ -16,6 +18,70 @@ namespace media {
namespace {
// Mime types for test files. Sorted in alphabetical order.
const char kMp4AacAudioOnly[] = "audio/mp4; codecs=\"mp4a.40.2\"";
const char kMp4Av110bitVideoOnly[] = "video/mp4; codecs=\"av01.0.04M.10\"";
const char kMp4Av1VideoOnly[] = "video/mp4; codecs=\"av01.0.04M.08\"";
const char kMp4Avc1VideoOnly[] = "video/mp4; codecs=\"avc1.64001E\"";
const char kMp4FlacAudioOnly[] = "audio/mp4; codecs=\"flac\"";
const char kMp4Vp9Profile2VideoOnly[] =
"video/mp4; codecs=\"vp09.02.10.10.01.02.02.02.00\"";
const char kMp4Vp9VideoOnly[] =
"video/mp4; codecs=\"vp09.00.10.08.01.02.02.02.00\"";
const char kWebMAv110bitVideoOnly[] = "video/webm; codecs=\"av01.0.04M.10\"";
const char kWebMAv1VideoOnly[] = "video/webm; codecs=\"av01.0.04M.08\"";
const char kWebMOpusAudioOnly[] = "audio/webm; codecs=\"opus\"";
const char kWebMOpusAudioVp9Video[] = "video/webm; codecs=\"opus, vp9\"";
const char kWebMVorbisAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
const char kWebMVorbisAudioVp8Video[] = "video/webm; codecs=\"vorbis, vp8\"";
const char kWebMVp8VideoOnly[] = "video/webm; codecs=\"vp8\"";
const char kWebMVp9Profile2VideoOnly[] =
"video/webm; codecs=\"vp09.02.10.10.01.02.02.02.00\"";
const char kWebMVp9VideoOnly[] = "video/webm; codecs=\"vp9\"";
// A map from a test file name to its mime type. The file is located at
// media/test/data.
using FileToMimeTypeMap = base::flat_map<std::string, std::string>;
// Wrapped to avoid static initializer startup cost. The list is sorted in
// alphabetical order.
const FileToMimeTypeMap& GetFileToMimeTypeMap() {
static const base::NoDestructor<FileToMimeTypeMap> kFileToMimeTypeMap({
{"bear-320x240-audio-only.webm", kWebMVorbisAudioOnly},
{"bear-320x240-av_enc-a.webm", kWebMVorbisAudioVp8Video},
{"bear-320x240-av_enc-av.webm", kWebMVorbisAudioVp8Video},
{"bear-320x240-av_enc-v.webm", kWebMVorbisAudioVp8Video},
{"bear-320x240-opus-a_enc-a.webm", kWebMOpusAudioOnly},
{"bear-320x240-opus-av_enc-av.webm", kWebMOpusAudioVp9Video},
{"bear-320x240-opus-av_enc-v.webm", kWebMOpusAudioVp9Video},
{"bear-320x240-v-vp9_fullsample_enc-v.webm", kWebMVp9VideoOnly},
{"bear-320x240-v-vp9_profile2_subsample_cenc-v.mp4",
kMp4Vp9Profile2VideoOnly},
{"bear-320x240-v-vp9_profile2_subsample_cenc-v.webm",
kWebMVp9Profile2VideoOnly},
{"bear-320x240-v-vp9_subsample_enc-v.webm", kWebMVp9VideoOnly},
{"bear-320x240-v_enc-v.webm", kWebMVp8VideoOnly},
{"bear-320x240-v_frag-vp9-cenc.mp4", kMp4Vp9VideoOnly},
{"bear-320x240-video-only.webm", kWebMVp8VideoOnly},
{"bear-640x360-a_frag-cbcs.mp4", kMp4AacAudioOnly},
{"bear-640x360-a_frag-cenc.mp4", kMp4AacAudioOnly},
{"bear-640x360-v_frag-cbc1.mp4", kMp4Avc1VideoOnly},
{"bear-640x360-v_frag-cbcs.mp4", kMp4Avc1VideoOnly},
{"bear-640x360-v_frag-cenc-mdat.mp4", kMp4Avc1VideoOnly},
{"bear-640x360-v_frag-cenc.mp4", kMp4Avc1VideoOnly},
{"bear-640x360-v_frag-cens.mp4", kMp4Avc1VideoOnly},
{"bear-a_enc-a.webm", kWebMVorbisAudioOnly},
{"bear-av1-320x180-10bit-cenc.mp4", kMp4Av110bitVideoOnly},
{"bear-av1-320x180-10bit-cenc.webm", kWebMAv110bitVideoOnly},
{"bear-av1-cenc.mp4", kMp4Av1VideoOnly},
{"bear-av1-cenc.webm", kWebMAv1VideoOnly},
{"bear-flac-cenc.mp4", kMp4FlacAudioOnly},
{"frame_size_change-av_enc-v.webm", kWebMVorbisAudioVp8Video},
});
return *kFileToMimeTypeMap;
}
// Key used to encrypt test files.
const uint8_t kSecretKey[] = {0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c};
......@@ -23,7 +89,8 @@ const uint8_t kSecretKey[] = {0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
// The key ID for all encrypted files.
const uint8_t kKeyId[] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35};
}
} // namespace
// TODO(sandersd): Change the tests to use a more unique message.
// See http://crbug.com/592067
......@@ -51,6 +118,13 @@ base::FilePath GetTestDataPath() {
return base::FilePath(kTestDataPath);
}
std::string GetMimeTypeForFile(const std::string& file_name) {
const auto& map = GetFileToMimeTypeMap();
auto itr = map.find(file_name);
CHECK(itr != map.end()) << ": file_name = " << file_name;
return itr->second;
}
std::string GetURLQueryString(const base::StringPairs& query_params) {
std::string query = "";
auto itr = query_params.begin();
......
......@@ -29,6 +29,9 @@ base::FilePath GetTestDataFilePath(const std::string& name);
// Returns relative path for test data folder: media/test/data.
base::FilePath GetTestDataPath();
// Returns the mime type for media/test/data/<file_name>.
std::string GetMimeTypeForFile(const std::string& file_name);
// Returns a string containing key value query params in the form of:
// "key_1=value_1&key_2=value2"
std::string GetURLQueryString(const base::StringPairs& query_params);
......
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