From 901013c34e9a07f7bee3608c220f6e9c0d04095e Mon Sep 17 00:00:00 2001 From: Bartek Zdanowski Date: Mon, 1 May 2023 23:57:40 +0200 Subject: [PATCH] feat: CMake port media/trick_play (#1146) Issue #1047 (CMake porting) --------- Co-authored-by: Joey Parrish --- CMakeLists.txt | 8 ++-- packager/media/CMakeLists.txt | 5 ++- packager/media/base/media_handler_test_base.h | 11 ++++-- packager/media/trick_play/CMakeLists.txt | 25 ++++++++++++ packager/media/trick_play/trick_play.gyp | 38 ------------------- .../media/trick_play/trick_play_handler.cc | 3 +- .../trick_play/trick_play_handler_unittest.cc | 2 +- packager/third_party/protobuf/CMakeLists.txt | 3 ++ 8 files changed, 46 insertions(+), 49 deletions(-) create mode 100644 packager/media/trick_play/CMakeLists.txt delete mode 100644 packager/media/trick_play/trick_play.gyp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c681f6ed1..55a815d0c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,14 +6,14 @@ # Root-level CMake build file. -# Project name. May not contain spaces. Versioning is managed elsewhere. -cmake_policy(SET CMP0048 NEW) -project(shaka-packager VERSION "") - # Minimum CMake version. # We could require as low as 3.10, but glog requires 3.16. cmake_minimum_required(VERSION 3.16) +# Project name. May not contain spaces. Versioning is managed elsewhere. +cmake_policy(SET CMP0048 NEW) +project(shaka-packager VERSION "") + # The only build option for Shaka Packager is whether to build a shared # libpackager library. By default, don't. option(LIBPACKAGER_SHARED "Build libpackager as a shared library" OFF) diff --git a/packager/media/CMakeLists.txt b/packager/media/CMakeLists.txt index 9fe1450345..587051732f 100644 --- a/packager/media/CMakeLists.txt +++ b/packager/media/CMakeLists.txt @@ -6,8 +6,9 @@ # Subdirectories with their own CMakeLists.txt, all of whose targets are built. add_subdirectory(base) +add_subdirectory(codecs) +add_subdirectory(formats) add_subdirectory(origin) add_subdirectory(replicator) add_subdirectory(test) -add_subdirectory(codecs) -add_subdirectory(formats) +add_subdirectory(trick_play) diff --git a/packager/media/base/media_handler_test_base.h b/packager/media/base/media_handler_test_base.h index ef6d5957a6..59e3f3ab8e 100644 --- a/packager/media/base/media_handler_test_base.h +++ b/packager/media/base/media_handler_test_base.h @@ -1,4 +1,4 @@ -// Copyright 2017 Google LLC. All rights reserved. +// Copyright 2022 Google LLC. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file or at @@ -11,8 +11,10 @@ #include #include "absl/strings/escaping.h" +#include "absl/strings/numbers.h" #include "packager/media/base/media_handler.h" #include "packager/media/base/video_stream_info.h" +#include "packager/utils/bytes_to_string_view.h" namespace shaka { namespace media { @@ -145,8 +147,11 @@ MATCHER_P6(MatchEncryptionConfig, constant_iv, key_id, "") { - const std::string constant_iv_hex = absl::BytesToHexString(arg.constant_iv); - const std::string key_id_hex = absl::BytesToHexString(arg.key_id); + const std::string_view constant_iv_data = + byte_vector_to_string_view(constant_iv); + const std::string constant_iv_hex = absl::BytesToHexString(constant_iv_data); + const std::string key_id_data(arg.key_id.data(), arg.key_id.size()); + const std::string key_id_hex = absl::BytesToHexString(key_id_data); const std::string protection_scheme_as_string = FourCCToString(arg.protection_scheme); // Convert to integers so that they will print as a number and not a uint8_t diff --git a/packager/media/trick_play/CMakeLists.txt b/packager/media/trick_play/CMakeLists.txt new file mode 100644 index 0000000000..bb684f1ed0 --- /dev/null +++ b/packager/media/trick_play/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright 2022 Google LLC. All rights reserved. +# +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file or at +# https://developers.google.com/open-source/licenses/bsd + +add_library(media_trick_play STATIC + trick_play_handler.cc) +target_link_libraries(media_trick_play + media_base + absl::base + glog) + +add_executable(media_trick_play_unittest + trick_play_handler_unittest.cc) +target_link_libraries(media_trick_play_unittest + media_base + media_trick_play + media_handler_test_base + status + gmock + gtest + gtest_main) + +add_test(NAME media_trick_play_unittest COMMAND media_trick_play_unittest) diff --git a/packager/media/trick_play/trick_play.gyp b/packager/media/trick_play/trick_play.gyp deleted file mode 100644 index 3ad9c8e25d..0000000000 --- a/packager/media/trick_play/trick_play.gyp +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2017 Google LLC. All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -{ - 'variables': { - 'shaka_code': 1, - }, - 'targets': [ - { - 'target_name': 'trick_play', - 'type': '<(component)', - 'sources': [ - 'trick_play_handler.cc', - 'trick_play_handler.h', - ], - 'dependencies': [ - '../base/media_base.gyp:media_base', - ], - }, - { - 'target_name': 'trick_play_unittest', - 'type': '<(gtest_target_type)', - 'sources': [ - 'trick_play_handler_unittest.cc', - ], - 'dependencies': [ - '../../testing/gtest.gyp:gtest', - '../../testing/gmock.gyp:gmock', - '../base/media_base.gyp:media_handler_test_base', - '../test/media_test.gyp:media_test_support', - 'trick_play', - ] - }, - ], -} diff --git a/packager/media/trick_play/trick_play_handler.cc b/packager/media/trick_play/trick_play_handler.cc index 983151fef6..0e77c9875a 100644 --- a/packager/media/trick_play/trick_play_handler.cc +++ b/packager/media/trick_play/trick_play_handler.cc @@ -6,8 +6,9 @@ #include "packager/media/trick_play/trick_play_handler.h" -#include "packager/base/logging.h" +#include "glog/logging.h" #include "packager/media/base/video_stream_info.h" +#include "packager/status/status.h" namespace shaka { namespace media { diff --git a/packager/media/trick_play/trick_play_handler_unittest.cc b/packager/media/trick_play/trick_play_handler_unittest.cc index 01c9366e79..e46bdd93c4 100644 --- a/packager/media/trick_play/trick_play_handler_unittest.cc +++ b/packager/media/trick_play/trick_play_handler_unittest.cc @@ -12,7 +12,7 @@ #include "packager/media/base/audio_stream_info.h" #include "packager/media/base/media_handler_test_base.h" #include "packager/media/base/video_stream_info.h" -#include "packager/status_test_util.h" +#include "packager/status/status_test_util.h" using ::testing::_; diff --git a/packager/third_party/protobuf/CMakeLists.txt b/packager/third_party/protobuf/CMakeLists.txt index a1fdba6ae8..37f69f3cc9 100644 --- a/packager/third_party/protobuf/CMakeLists.txt +++ b/packager/third_party/protobuf/CMakeLists.txt @@ -22,6 +22,9 @@ set(protobuf_DISABLE_RTTI ON) # The latest version of protobuf requires a path to ABSL. set(ABSL_ROOT_DIR get_filename_component(ABSOLUTE_PATH ../abseil-cpp/source ABSOLUTE)) +# Make sure protoc links against the same MSVC runtime as internal libs. +set(protobuf_MSVC_STATIC_RUNTIME OFF) + # Disable these errors/warnings: if(MSVC) add_compile_options(