Commit d807ec30 authored by Xiaohan Wang's avatar Xiaohan Wang Committed by Commit Bot

media: Make "clear_key_cdm" target a loadable_module

According to the gn reference (and from brettw@): the "loadable_module"
target type allows you to create an object file that is (and can only
be) loaded and unloaded at runtime, which is exactly what we want for
Clear Key CDM.

Bug: 584449
Test: Existing tests pass.
Change-Id: I2a3a322cb13a7c052c7c43fdd1235ccadd0742ce
Reviewed-on: https://chromium-review.googlesource.com/988814Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarJohn Rummell <jrummell@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547591}
parent e39b4f37
...@@ -98,13 +98,21 @@ BASE_EXPORT void UnloadNativeLibrary(NativeLibrary library); ...@@ -98,13 +98,21 @@ BASE_EXPORT void UnloadNativeLibrary(NativeLibrary library);
BASE_EXPORT void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, BASE_EXPORT void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
StringPiece name); StringPiece name);
// Returns the full platform specific name for a native library. // Returns the full platform-specific name for a native library. |name| must be
// |name| must be ASCII. // ASCII. This is also the default name for the output of a gn |shared_library|
// For example: // target. See tools/gn/docs/reference.md#shared_library.
// "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux, // For example for "mylib", it returns:
// "libmylib.dylib" on Mac. // - "mylib.dll" on Windows
// - "libmylib.so" on Linux
// - "libmylib.dylib" on Mac
BASE_EXPORT std::string GetNativeLibraryName(StringPiece name); BASE_EXPORT std::string GetNativeLibraryName(StringPiece name);
// Returns the full platform-specific name for a gn |loadable_module| target.
// See tools/gn/docs/reference.md#loadable_module
// The returned name is the same as GetNativeLibraryName() on all platforms
// except for Mac where for "mylib" it returns "mylib.so".
BASE_EXPORT std::string GetLoadableModuleName(StringPiece name);
} // namespace base } // namespace base
#endif // BASE_NATIVE_LIBRARY_H_ #endif // BASE_NATIVE_LIBRARY_H_
...@@ -14,7 +14,6 @@ std::string NativeLibraryLoadError::ToString() const { ...@@ -14,7 +14,6 @@ std::string NativeLibraryLoadError::ToString() const {
return message; return message;
} }
// static
NativeLibrary LoadNativeLibraryWithOptions(const base::FilePath& library_path, NativeLibrary LoadNativeLibraryWithOptions(const base::FilePath& library_path,
const NativeLibraryOptions& options, const NativeLibraryOptions& options,
NativeLibraryLoadError* error) { NativeLibraryLoadError* error) {
...@@ -24,23 +23,24 @@ NativeLibrary LoadNativeLibraryWithOptions(const base::FilePath& library_path, ...@@ -24,23 +23,24 @@ NativeLibrary LoadNativeLibraryWithOptions(const base::FilePath& library_path,
return nullptr; return nullptr;
} }
// static
void UnloadNativeLibrary(NativeLibrary library) { void UnloadNativeLibrary(NativeLibrary library) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
DCHECK(!library); DCHECK(!library);
} }
// static
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
StringPiece name) { StringPiece name) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
return nullptr; return nullptr;
} }
// static
std::string GetNativeLibraryName(StringPiece name) { std::string GetNativeLibraryName(StringPiece name) {
DCHECK(IsStringASCII(name)); DCHECK(IsStringASCII(name));
return name.as_string(); return name.as_string();
} }
std::string GetLoadableModuleName(StringPiece name) {
return GetNativeLibraryName(name);
}
} // namespace base } // namespace base
...@@ -38,7 +38,6 @@ std::string NativeLibraryLoadError::ToString() const { ...@@ -38,7 +38,6 @@ std::string NativeLibraryLoadError::ToString() const {
return message; return message;
} }
// static
NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path, NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path,
const NativeLibraryOptions& options, const NativeLibraryOptions& options,
NativeLibraryLoadError* error) { NativeLibraryLoadError* error) {
...@@ -75,7 +74,6 @@ NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path, ...@@ -75,7 +74,6 @@ NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path,
return native_lib; return native_lib;
} }
// static
void UnloadNativeLibrary(NativeLibrary library) { void UnloadNativeLibrary(NativeLibrary library) {
if (library->objc_status == OBJC_NOT_PRESENT) { if (library->objc_status == OBJC_NOT_PRESENT) {
if (library->type == BUNDLE) { if (library->type == BUNDLE) {
...@@ -95,7 +93,6 @@ void UnloadNativeLibrary(NativeLibrary library) { ...@@ -95,7 +93,6 @@ void UnloadNativeLibrary(NativeLibrary library) {
delete library; delete library;
} }
// static
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
StringPiece name) { StringPiece name) {
void* function_pointer = nullptr; void* function_pointer = nullptr;
...@@ -118,10 +115,14 @@ void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, ...@@ -118,10 +115,14 @@ void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
return function_pointer; return function_pointer;
} }
// static
std::string GetNativeLibraryName(StringPiece name) { std::string GetNativeLibraryName(StringPiece name) {
DCHECK(IsStringASCII(name)); DCHECK(IsStringASCII(name));
return "lib" + name.as_string() + ".dylib"; return "lib" + name.as_string() + ".dylib";
} }
std::string GetLoadableModuleName(StringPiece name) {
DCHECK(IsStringASCII(name));
return name.as_string() + ".so";
}
} // namespace base } // namespace base
...@@ -18,7 +18,6 @@ std::string NativeLibraryLoadError::ToString() const { ...@@ -18,7 +18,6 @@ std::string NativeLibraryLoadError::ToString() const {
return message; return message;
} }
// static
NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path, NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path,
const NativeLibraryOptions& options, const NativeLibraryOptions& options,
NativeLibraryLoadError* error) { NativeLibraryLoadError* error) {
...@@ -46,7 +45,6 @@ NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path, ...@@ -46,7 +45,6 @@ NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path,
return dl; return dl;
} }
// static
void UnloadNativeLibrary(NativeLibrary library) { void UnloadNativeLibrary(NativeLibrary library) {
int ret = dlclose(library); int ret = dlclose(library);
if (ret < 0) { if (ret < 0) {
...@@ -55,16 +53,18 @@ void UnloadNativeLibrary(NativeLibrary library) { ...@@ -55,16 +53,18 @@ void UnloadNativeLibrary(NativeLibrary library) {
} }
} }
// static
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
StringPiece name) { StringPiece name) {
return dlsym(library, name.data()); return dlsym(library, name.data());
} }
// static
std::string GetNativeLibraryName(StringPiece name) { std::string GetNativeLibraryName(StringPiece name) {
DCHECK(IsStringASCII(name)); DCHECK(IsStringASCII(name));
return "lib" + name.as_string() + ".so"; return "lib" + name.as_string() + ".so";
} }
std::string GetLoadableModuleName(StringPiece name) {
return GetNativeLibraryName(name);
}
} // namespace base } // namespace base
...@@ -40,6 +40,20 @@ TEST(NativeLibraryTest, GetNativeLibraryName) { ...@@ -40,6 +40,20 @@ TEST(NativeLibraryTest, GetNativeLibraryName) {
EXPECT_EQ(kExpectedName, GetNativeLibraryName("mylib")); EXPECT_EQ(kExpectedName, GetNativeLibraryName("mylib"));
} }
TEST(NativeLibraryTest, GetLoadableModuleName) {
const char kExpectedName[] =
#if defined(OS_IOS)
"mylib";
#elif defined(OS_MACOSX)
"mylib.so";
#elif defined(OS_POSIX)
"libmylib.so";
#elif defined(OS_WIN)
"mylib.dll";
#endif
EXPECT_EQ(kExpectedName, GetLoadableModuleName("mylib"));
}
// We don't support dynamic loading on iOS, and ASAN will complain about our // We don't support dynamic loading on iOS, and ASAN will complain about our
// intentional ODR violation because of |g_native_library_exported_value| being // intentional ODR violation because of |g_native_library_exported_value| being
// defined globally both here and in the shared library. // defined globally both here and in the shared library.
......
...@@ -150,28 +150,28 @@ std::string NativeLibraryLoadError::ToString() const { ...@@ -150,28 +150,28 @@ std::string NativeLibraryLoadError::ToString() const {
return StringPrintf("%lu", code); return StringPrintf("%lu", code);
} }
// static
NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path, NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path,
const NativeLibraryOptions& options, const NativeLibraryOptions& options,
NativeLibraryLoadError* error) { NativeLibraryLoadError* error) {
return LoadNativeLibraryHelper(library_path, error); return LoadNativeLibraryHelper(library_path, error);
} }
// static
void UnloadNativeLibrary(NativeLibrary library) { void UnloadNativeLibrary(NativeLibrary library) {
FreeLibrary(library); FreeLibrary(library);
} }
// static
void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
StringPiece name) { StringPiece name) {
return reinterpret_cast<void*>(GetProcAddress(library, name.data())); return reinterpret_cast<void*>(GetProcAddress(library, name.data()));
} }
// static
std::string GetNativeLibraryName(StringPiece name) { std::string GetNativeLibraryName(StringPiece name) {
DCHECK(IsStringASCII(name)); DCHECK(IsStringASCII(name));
return name.as_string() + ".dll"; return name.as_string() + ".dll";
} }
std::string GetLoadableModuleName(StringPiece name) {
return GetNativeLibraryName(name);
}
} // namespace base } // namespace base
...@@ -86,7 +86,7 @@ TEST(LoadCDMPerfTest, Widevine) { ...@@ -86,7 +86,7 @@ TEST(LoadCDMPerfTest, Widevine) {
TEST(LoadCDMPerfTest, ExternalClearKey) { TEST(LoadCDMPerfTest, ExternalClearKey) {
MeasureSizeAndTimeToLoadCdm( MeasureSizeAndTimeToLoadCdm(
media::kClearKeyCdmBaseDirectory, media::kClearKeyCdmBaseDirectory,
base::GetNativeLibraryName(media::kClearKeyCdmLibraryName)); base::GetLoadableModuleName(media::kClearKeyCdmLibraryName));
} }
#endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS)
...@@ -21,7 +21,7 @@ void RegisterClearKeyCdm(base::CommandLine* command_line, ...@@ -21,7 +21,7 @@ void RegisterClearKeyCdm(base::CommandLine* command_line,
cdm_path = cdm_path cdm_path = cdm_path
.Append(media::GetPlatformSpecificDirectory( .Append(media::GetPlatformSpecificDirectory(
media::kClearKeyCdmBaseDirectory)) media::kClearKeyCdmBaseDirectory))
.AppendASCII(base::GetNativeLibraryName(cdm_library_name)); .AppendASCII(base::GetLoadableModuleName(cdm_library_name));
// Append the switch to register the Clear Key CDM path. // Append the switch to register the Clear Key CDM path.
command_line->AppendSwitchNative(switches::kClearKeyCdmPathForTesting, command_line->AppendSwitchNative(switches::kClearKeyCdmPathForTesting,
......
...@@ -37,7 +37,7 @@ void ExternalClearKeyTestHelper::LoadLibrary() { ...@@ -37,7 +37,7 @@ void ExternalClearKeyTestHelper::LoadLibrary() {
cdm_base_path = cdm_base_path.Append( cdm_base_path = cdm_base_path.Append(
GetPlatformSpecificDirectory(kClearKeyCdmBaseDirectory)); GetPlatformSpecificDirectory(kClearKeyCdmBaseDirectory));
library_path_ = cdm_base_path.AppendASCII( library_path_ = cdm_base_path.AppendASCII(
base::GetNativeLibraryName(kClearKeyCdmLibraryName)); base::GetLoadableModuleName(kClearKeyCdmLibraryName));
ASSERT_TRUE(base::PathExists(library_path_)) << library_path_.value(); ASSERT_TRUE(base::PathExists(library_path_)) << library_path_.value();
// Now load the CDM library. // Now load the CDM library.
......
...@@ -6,7 +6,7 @@ import("//build/config/features.gni") ...@@ -6,7 +6,7 @@ import("//build/config/features.gni")
import("//media/cdm/library_cdm/cdm_paths.gni") import("//media/cdm/library_cdm/cdm_paths.gni")
import("//media/media_options.gni") import("//media/media_options.gni")
shared_library("clear_key_cdm") { loadable_module("clear_key_cdm") {
output_dir = "$root_out_dir/$clearkey_cdm_path" output_dir = "$root_out_dir/$clearkey_cdm_path"
output_name = "clearkeycdm" output_name = "clearkeycdm"
sources = [ sources = [
...@@ -51,10 +51,6 @@ shared_library("clear_key_cdm") { ...@@ -51,10 +51,6 @@ shared_library("clear_key_cdm") {
defines += [ "CLEAR_KEY_CDM_USE_FFMPEG_DECODER" ] defines += [ "CLEAR_KEY_CDM_USE_FFMPEG_DECODER" ]
deps += [ "//third_party/ffmpeg" ] deps += [ "//third_party/ffmpeg" ]
} }
if (is_mac) {
ldflags = [ "-Wl,-install_name,@loader_path/libclearkeycdm.dylib" ]
}
} }
source_set("clear_key_cdm_proxy") { source_set("clear_key_cdm_proxy") {
......
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