feat: port media/event to CMake (#1222)

Rebasing #1155 and applying some fixes. Had to comment out the
`mpd_notify_muxer_listener_unittest` because it depends on
`MockMpdNotifier` from `mpd/base` which has not been ported yet. Can
bring this test back once that has been ported.

Related to #1047

---------

Co-authored-by: Carlos Bentzen <carlos.bentzen@bitmovin.com>
Co-authored-by: Joey Parrish <joeyparrish@google.com>
This commit is contained in:
Cosmin Stejerean 2023-07-14 01:25:42 +02:00 committed by GitHub
parent 3a551f428f
commit 8d3b2c66b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 167 additions and 154 deletions

View File

@ -34,6 +34,12 @@ std::string generate_unique_temp_path() {
return temp_path_template_string; return temp_path_template_string;
} }
void delete_file(const std::string& path) {
std::error_code ec;
std::filesystem::remove(path, ec);
// Ignore errors.
}
TempFile::TempFile() : path_(generate_unique_temp_path()) {} TempFile::TempFile() : path_(generate_unique_temp_path()) {}
TempFile::~TempFile() { TempFile::~TempFile() {

View File

@ -43,6 +43,7 @@ namespace shaka {
// Generate a unique filename. // Generate a unique filename.
std::string generate_unique_temp_path(); std::string generate_unique_temp_path();
void delete_file(const std::string& path);
// A temporary file that is removed from the filesystem when the object is // A temporary file that is removed from the filesystem when the object is
// destroyed. Useful in tests that use ASSERT to avoid leaving behind temp // destroyed. Useful in tests that use ASSERT to avoid leaving behind temp

View File

@ -8,6 +8,7 @@
add_subdirectory(base) add_subdirectory(base)
add_subdirectory(codecs) add_subdirectory(codecs)
add_subdirectory(chunking) add_subdirectory(chunking)
add_subdirectory(event)
add_subdirectory(formats) add_subdirectory(formats)
add_subdirectory(origin) add_subdirectory(origin)
add_subdirectory(replicator) add_subdirectory(replicator)

View File

@ -0,0 +1,54 @@
# 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_event STATIC
combined_muxer_listener.cc
hls_notify_muxer_listener.cc
mpd_notify_muxer_listener.cc
multi_codec_muxer_listener.cc
muxer_listener_factory.cc
muxer_listener_internal.cc
vod_media_info_dump_muxer_listener.cc
)
target_link_libraries(media_event
file
mpd_media_info_proto
media_base
codecs
)
add_library(mock_muxer_listener STATIC
mock_muxer_listener.cc
)
target_link_libraries(mock_muxer_listener
gmock
media_event
)
add_executable(media_event_unittest
hls_notify_muxer_listener_unittest.cc
muxer_listener_internal_unittest.cc
# TODO(cmake): Re-enable when mpd/base is ported (needs MockMpdNotifier)
# mpd_notify_muxer_listener_unittest.cc
multi_codec_muxer_listener_unittest.cc
muxer_listener_test_helper.cc
vod_media_info_dump_muxer_listener_unittest.cc
)
target_link_libraries(media_event_unittest
file
file_test_util
mpd_media_info_proto
gmock
gtest
gtest_main
media_event
mock_muxer_listener
)
add_test(NAME media_event_unittest COMMAND media_event_unittest)

View File

@ -47,7 +47,9 @@ class CombinedMuxerListener : public MuxerListener {
uint64_t segment_file_size) override; uint64_t segment_file_size) override;
void OnCompletedSegment(int64_t duration, void OnCompletedSegment(int64_t duration,
uint64_t segment_file_size) override; uint64_t segment_file_size) override;
void OnKeyFrame(int64_t timestamp, uint64_t start_byte_offset, uint64_t size); void OnKeyFrame(int64_t timestamp,
uint64_t start_byte_offset,
uint64_t size) override;
void OnCueEvent(int64_t timestamp, const std::string& cue_data) override; void OnCueEvent(int64_t timestamp, const std::string& cue_data) override;
/// @} /// @}

View File

@ -7,7 +7,8 @@
#include "packager/media/event/hls_notify_muxer_listener.h" #include "packager/media/event/hls_notify_muxer_listener.h"
#include <memory> #include <memory>
#include "packager/base/logging.h"
#include "glog/logging.h"
#include "packager/hls/base/hls_notifier.h" #include "packager/hls/base/hls_notifier.h"
#include "packager/media/base/muxer_options.h" #include "packager/media/base/muxer_options.h"
#include "packager/media/base/protection_system_specific_info.h" #include "packager/media/base/protection_system_specific_info.h"
@ -46,6 +47,7 @@ void HlsNotifyMuxerListener::OnEncryptionInfoReady(
const std::vector<uint8_t>& key_id, const std::vector<uint8_t>& key_id,
const std::vector<uint8_t>& iv, const std::vector<uint8_t>& iv,
const std::vector<ProtectionSystemSpecificInfo>& key_system_infos) { const std::vector<ProtectionSystemSpecificInfo>& key_system_infos) {
UNUSED(is_initial_encryption_info);
if (!stream_id_) { if (!stream_id_) {
next_key_id_ = key_id; next_key_id_ = key_id;
next_iv_ = iv; next_iv_ = iv;
@ -147,6 +149,7 @@ void HlsNotifyMuxerListener::OnSampleDurationReady(int32_t sample_duration) {
void HlsNotifyMuxerListener::OnMediaEnd(const MediaRanges& media_ranges, void HlsNotifyMuxerListener::OnMediaEnd(const MediaRanges& media_ranges,
float duration_seconds) { float duration_seconds) {
UNUSED(duration_seconds);
DCHECK(media_info_); DCHECK(media_info_);
// TODO(kqyang): Should we just Flush here to avoid calling Flush explicitly? // TODO(kqyang): Should we just Flush here to avoid calling Flush explicitly?
// Don't flush the notifier here. Flushing here would write all the playlists // Don't flush the notifier here. Flushing here would write all the playlists
@ -263,7 +266,7 @@ void HlsNotifyMuxerListener::OnKeyFrame(int64_t timestamp,
void HlsNotifyMuxerListener::OnCueEvent(int64_t timestamp, void HlsNotifyMuxerListener::OnCueEvent(int64_t timestamp,
const std::string& cue_data) { const std::string& cue_data) {
// Not using |cue_data| at this moment. UNUSED(cue_data);
if (!media_info_->has_segment_template()) { if (!media_info_->has_segment_template()) {
EventInfo event_info; EventInfo event_info;
event_info.type = EventInfoType::kCue; event_info.type = EventInfoType::kCue;

View File

@ -8,10 +8,10 @@
#define PACKAGER_MEDIA_EVENT_HLS_NOTIFY_MUXER_LISTENER_H_ #define PACKAGER_MEDIA_EVENT_HLS_NOTIFY_MUXER_LISTENER_H_
#include <memory> #include <memory>
#include <optional>
#include <string> #include <string>
#include <vector> #include <vector>
#include "packager/base/optional.h"
#include "packager/media/event/event_info.h" #include "packager/media/event/event_info.h"
#include "packager/media/event/muxer_listener.h" #include "packager/media/event/muxer_listener.h"
#include "packager/mpd/base/media_info.pb.h" #include "packager/mpd/base/media_info.pb.h"
@ -68,7 +68,9 @@ class HlsNotifyMuxerListener : public MuxerListener {
int64_t start_time, int64_t start_time,
int64_t duration, int64_t duration,
uint64_t segment_file_size) override; uint64_t segment_file_size) override;
void OnKeyFrame(int64_t timestamp, uint64_t start_byte_offset, uint64_t size); void OnKeyFrame(int64_t timestamp,
uint64_t start_byte_offset,
uint64_t size) override;
void OnCueEvent(int64_t timestamp, const std::string& cue_data) override; void OnCueEvent(int64_t timestamp, const std::string& cue_data) override;
/// @} /// @}
@ -84,7 +86,7 @@ class HlsNotifyMuxerListener : public MuxerListener {
const std::string ext_x_media_group_id_; const std::string ext_x_media_group_id_;
const std::vector<std::string> characteristics_; const std::vector<std::string> characteristics_;
hls::HlsNotifier* const hls_notifier_; hls::HlsNotifier* const hls_notifier_;
base::Optional<uint32_t> stream_id_; std::optional<uint32_t> stream_id_;
bool must_notify_encryption_start_ = false; bool must_notify_encryption_start_ = false;
// Cached encryption info before OnMediaStart() is called. // Cached encryption info before OnMediaStart() is called.

View File

@ -177,8 +177,8 @@ TEST_F(HlsNotifyMuxerListenerTest, OnMediaStart) {
// OnEncryptionInfoReady() and OnMediaStart(). // OnEncryptionInfoReady() and OnMediaStart().
TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionStart) { TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionStart) {
std::vector<uint8_t> system_id(kAnySystemId, std::vector<uint8_t> system_id(kAnySystemId,
kAnySystemId + arraysize(kAnySystemId)); kAnySystemId + std::size(kAnySystemId));
std::vector<uint8_t> pssh(kAnyData, kAnyData + arraysize(kAnyData)); std::vector<uint8_t> pssh(kAnyData, kAnyData + std::size(kAnyData));
std::vector<uint8_t> key_id(16, 0x05); std::vector<uint8_t> key_id(16, 0x05);
std::vector<uint8_t> iv(16, 0x54); std::vector<uint8_t> iv(16, 0x54);
@ -211,8 +211,8 @@ TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionStart) {
// OnMediaStart(). // OnMediaStart().
TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionStartBeforeMediaStart) { TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionStartBeforeMediaStart) {
std::vector<uint8_t> system_id(kAnySystemId, std::vector<uint8_t> system_id(kAnySystemId,
kAnySystemId + arraysize(kAnySystemId)); kAnySystemId + std::size(kAnySystemId));
std::vector<uint8_t> pssh(kAnyData, kAnyData + arraysize(kAnyData)); std::vector<uint8_t> pssh(kAnyData, kAnyData + std::size(kAnyData));
std::vector<uint8_t> key_id(16, 0x05); std::vector<uint8_t> key_id(16, 0x05);
std::vector<uint8_t> iv(16, 0x54); std::vector<uint8_t> iv(16, 0x54);
@ -278,8 +278,8 @@ TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionInfoReady) {
MuxerListener::kContainerMpeg2ts); MuxerListener::kContainerMpeg2ts);
std::vector<uint8_t> system_id(kAnySystemId, std::vector<uint8_t> system_id(kAnySystemId,
kAnySystemId + arraysize(kAnySystemId)); kAnySystemId + std::size(kAnySystemId));
std::vector<uint8_t> pssh(kAnyData, kAnyData + arraysize(kAnyData)); std::vector<uint8_t> pssh(kAnyData, kAnyData + std::size(kAnyData));
std::vector<uint8_t> key_id(16, 0x05); std::vector<uint8_t> key_id(16, 0x05);
std::vector<uint8_t> iv(16, 0x54); std::vector<uint8_t> iv(16, 0x54);

View File

@ -1,80 +0,0 @@
# Copyright 2014 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': 'media_event',
'type': '<(component)',
'sources': [
'combined_muxer_listener.cc',
'combined_muxer_listener.h',
'event_info.h',
'hls_notify_muxer_listener.cc',
'hls_notify_muxer_listener.h',
'mpd_notify_muxer_listener.cc',
'mpd_notify_muxer_listener.h',
'multi_codec_muxer_listener.cc',
'multi_codec_muxer_listener.h',
'muxer_listener.h',
'muxer_listener_factory.cc',
'muxer_listener_factory.h',
'muxer_listener_internal.cc',
'muxer_listener_internal.h',
'vod_media_info_dump_muxer_listener.cc',
'vod_media_info_dump_muxer_listener.h',
],
'dependencies': [
'../../file/file.gyp:file',
'../../mpd/mpd.gyp:media_info_proto',
# Depends on full protobuf to read/write with TextFormat.
'../../third_party/protobuf/protobuf.gyp:protobuf_full_do_not_use',
'../base/media_base.gyp:media_base',
'../codecs/codecs.gyp:codecs',
],
},
{
'target_name': 'mock_muxer_listener',
'type': '<(component)',
'sources': [
'mock_muxer_listener.cc',
'mock_muxer_listener.h',
],
'dependencies': [
'../../testing/gmock.gyp:gmock',
'media_event',
],
},
{
'target_name': 'media_event_unittest',
'type': '<(gtest_target_type)',
'sources': [
'hls_notify_muxer_listener_unittest.cc',
'muxer_listener_internal_unittest.cc',
'mpd_notify_muxer_listener_unittest.cc',
'multi_codec_muxer_listener_unittest.cc',
'muxer_listener_test_helper.cc',
'muxer_listener_test_helper.h',
'vod_media_info_dump_muxer_listener_unittest.cc',
],
'dependencies': [
'../../base/base.gyp:base',
'../../mpd/mpd.gyp:media_info_proto',
'../../mpd/mpd.gyp:mpd_mocks',
'../../testing/gmock.gyp:gmock',
'../../testing/gtest.gyp:gtest',
# Depends on full protobuf to read/write with TextFormat.
'../../third_party/protobuf/protobuf.gyp:protobuf_full_do_not_use',
'../test/media_test.gyp:run_tests_with_atexit_manager',
'media_event',
'mock_muxer_listener',
],
},
],
}

View File

@ -8,7 +8,7 @@
#include <cmath> #include <cmath>
#include "packager/base/logging.h" #include "glog/logging.h"
#include "packager/media/base/audio_stream_info.h" #include "packager/media/base/audio_stream_info.h"
#include "packager/media/base/protection_system_specific_info.h" #include "packager/media/base/protection_system_specific_info.h"
#include "packager/media/base/video_stream_info.h" #include "packager/media/base/video_stream_info.h"
@ -34,6 +34,7 @@ void MpdNotifyMuxerListener::OnEncryptionInfoReady(
const std::vector<uint8_t>& key_id, const std::vector<uint8_t>& key_id,
const std::vector<uint8_t>& iv, const std::vector<uint8_t>& iv,
const std::vector<ProtectionSystemSpecificInfo>& key_system_info) { const std::vector<ProtectionSystemSpecificInfo>& key_system_info) {
UNUSED(iv);
if (is_initial_encryption_info) { if (is_initial_encryption_info) {
LOG_IF(WARNING, is_encrypted_) LOG_IF(WARNING, is_encrypted_)
<< "Updating initial encryption information."; << "Updating initial encryption information.";
@ -191,6 +192,7 @@ void MpdNotifyMuxerListener::OnNewSegment(const std::string& file_name,
int64_t start_time, int64_t start_time,
int64_t duration, int64_t duration,
uint64_t segment_file_size) { uint64_t segment_file_size) {
UNUSED(file_name);
if (mpd_notifier_->dash_profile() == DashProfile::kLive) { if (mpd_notifier_->dash_profile() == DashProfile::kLive) {
mpd_notifier_->NotifyNewSegment(notification_id_.value(), start_time, mpd_notifier_->NotifyNewSegment(notification_id_.value(), start_time,
duration, segment_file_size); duration, segment_file_size);
@ -214,11 +216,14 @@ void MpdNotifyMuxerListener::OnKeyFrame(int64_t timestamp,
uint64_t start_byte_offset, uint64_t start_byte_offset,
uint64_t size) { uint64_t size) {
// NO-OP for DASH. // NO-OP for DASH.
UNUSED(timestamp);
UNUSED(start_byte_offset);
UNUSED(size);
} }
void MpdNotifyMuxerListener::OnCueEvent(int64_t timestamp, void MpdNotifyMuxerListener::OnCueEvent(int64_t timestamp,
const std::string& cue_data) { const std::string& cue_data) {
// Not using |cue_data| at this moment. UNUSED(cue_data);
if (mpd_notifier_->dash_profile() == DashProfile::kLive) { if (mpd_notifier_->dash_profile() == DashProfile::kLive) {
mpd_notifier_->NotifyCueEvent(notification_id_.value(), timestamp); mpd_notifier_->NotifyCueEvent(notification_id_.value(), timestamp);
} else { } else {

View File

@ -10,9 +10,9 @@
#define PACKAGER_MEDIA_EVENT_MPD_NOTIFY_MUXER_LISTENER_H_ #define PACKAGER_MEDIA_EVENT_MPD_NOTIFY_MUXER_LISTENER_H_
#include <memory> #include <memory>
#include <optional>
#include <vector> #include <vector>
#include "packager/base/optional.h"
#include "packager/media/base/muxer_options.h" #include "packager/media/base/muxer_options.h"
#include "packager/media/event/event_info.h" #include "packager/media/event/event_info.h"
#include "packager/media/event/muxer_listener.h" #include "packager/media/event/muxer_listener.h"
@ -55,7 +55,9 @@ class MpdNotifyMuxerListener : public MuxerListener {
uint64_t segment_file_size) override; uint64_t segment_file_size) override;
void OnCompletedSegment(int64_t duration, void OnCompletedSegment(int64_t duration,
uint64_t segment_file_size) override; uint64_t segment_file_size) override;
void OnKeyFrame(int64_t timestamp, uint64_t start_byte_offset, uint64_t size); void OnKeyFrame(int64_t timestamp,
uint64_t start_byte_offset,
uint64_t size) override;
void OnCueEvent(int64_t timestamp, const std::string& cue_data) override; void OnCueEvent(int64_t timestamp, const std::string& cue_data) override;
/// @} /// @}
@ -72,7 +74,7 @@ class MpdNotifyMuxerListener : public MuxerListener {
bool NotifyNewContainer(); bool NotifyNewContainer();
MpdNotifier* const mpd_notifier_ = nullptr; MpdNotifier* const mpd_notifier_ = nullptr;
base::Optional<uint32_t> notification_id_; std::optional<uint32_t> notification_id_;
std::unique_ptr<MediaInfo> media_info_; std::unique_ptr<MediaInfo> media_info_;
std::vector<std::string> accessibilities_; std::vector<std::string> accessibilities_;

View File

@ -13,7 +13,6 @@
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include "packager/base/stl_util.h"
#include "packager/media/base/video_stream_info.h" #include "packager/media/base/video_stream_info.h"
#include "packager/media/event/muxer_listener_test_helper.h" #include "packager/media/event/muxer_listener_test_helper.h"
#include "packager/mpd/base/content_protection_element.h" #include "packager/mpd/base/content_protection_element.h"
@ -204,7 +203,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodEncryptedContent) {
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
const std::vector<uint8_t> default_key_id( const std::vector<uint8_t> default_key_id(
kDefaultKeyId, kDefaultKeyId + arraysize(kDefaultKeyId) - 1); kDefaultKeyId, kDefaultKeyId + std::size(kDefaultKeyId) - 1);
const std::string kExpectedMediaInfo = const std::string kExpectedMediaInfo =
std::string(kExpectedDefaultMediaInfo) + std::string(kExpectedDefaultMediaInfo) +
@ -220,7 +219,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodEncryptedContent) {
EXPECT_CALL(*notifier_, NotifyNewContainer(_, _)).Times(0); EXPECT_CALL(*notifier_, NotifyNewContainer(_, _)).Times(0);
std::vector<uint8_t> iv(kBogusIv, kBogusIv + arraysize(kBogusIv)); std::vector<uint8_t> iv(kBogusIv, kBogusIv + std::size(kBogusIv));
listener_->OnEncryptionInfoReady(kInitialEncryptionInfo, FOURCC_cenc, listener_->OnEncryptionInfoReady(kInitialEncryptionInfo, FOURCC_cenc,
default_key_id, iv, default_key_id, iv,
GetDefaultKeySystemInfo()); GetDefaultKeySystemInfo());
@ -247,7 +246,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodEncryptedContentSegmentList) {
CreateVideoStreamInfo(video_params); CreateVideoStreamInfo(video_params);
const std::vector<uint8_t> default_key_id( const std::vector<uint8_t> default_key_id(
kDefaultKeyId, kDefaultKeyId + arraysize(kDefaultKeyId) - 1); kDefaultKeyId, kDefaultKeyId + std::size(kDefaultKeyId) - 1);
const std::string kExpectedMediaInfo = const std::string kExpectedMediaInfo =
std::string(kExpectedDefaultMediaInfoSubsegmentRange) + std::string(kExpectedDefaultMediaInfoSubsegmentRange) +
@ -263,7 +262,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodEncryptedContentSegmentList) {
EXPECT_CALL(*notifier_, NotifyNewContainer(_, _)).Times(0); EXPECT_CALL(*notifier_, NotifyNewContainer(_, _)).Times(0);
std::vector<uint8_t> iv(kBogusIv, kBogusIv + arraysize(kBogusIv)); std::vector<uint8_t> iv(kBogusIv, kBogusIv + std::size(kBogusIv));
listener_->OnEncryptionInfoReady(kInitialEncryptionInfo, FOURCC_cenc, listener_->OnEncryptionInfoReady(kInitialEncryptionInfo, FOURCC_cenc,
default_key_id, iv, default_key_id, iv,
GetDefaultKeySystemInfo()); GetDefaultKeySystemInfo());
@ -681,7 +680,7 @@ TEST_P(MpdNotifyMuxerListenerTest, LiveNoKeyRotation) {
const int64_t kDuration2 = 3787; const int64_t kDuration2 = 3787;
const uint64_t kSegmentFileSize2 = 83743u; const uint64_t kSegmentFileSize2 = 83743u;
const std::vector<uint8_t> default_key_id( const std::vector<uint8_t> default_key_id(
kDefaultKeyId, kDefaultKeyId + arraysize(kDefaultKeyId) - 1); kDefaultKeyId, kDefaultKeyId + std::size(kDefaultKeyId) - 1);
InSequence s; InSequence s;
EXPECT_CALL(*notifier_, NotifyEncryptionUpdate(_, _, _, _)).Times(0); EXPECT_CALL(*notifier_, NotifyEncryptionUpdate(_, _, _, _)).Times(0);
@ -699,7 +698,7 @@ TEST_P(MpdNotifyMuxerListenerTest, LiveNoKeyRotation) {
if (GetParam() == MpdType::kDynamic) if (GetParam() == MpdType::kDynamic)
EXPECT_CALL(*notifier_, Flush()); EXPECT_CALL(*notifier_, Flush());
std::vector<uint8_t> iv(kBogusIv, kBogusIv + arraysize(kBogusIv)); std::vector<uint8_t> iv(kBogusIv, kBogusIv + std::size(kBogusIv));
listener_->OnEncryptionInfoReady(kInitialEncryptionInfo, FOURCC_cbcs, listener_->OnEncryptionInfoReady(kInitialEncryptionInfo, FOURCC_cbcs,
default_key_id, iv, default_key_id, iv,
GetDefaultKeySystemInfo()); GetDefaultKeySystemInfo());
@ -754,7 +753,7 @@ TEST_P(MpdNotifyMuxerListenerTest, LiveWithKeyRotation) {
const int64_t kDuration2 = 3787; const int64_t kDuration2 = 3787;
const uint64_t kSegmentFileSize2 = 83743u; const uint64_t kSegmentFileSize2 = 83743u;
const std::vector<uint8_t> default_key_id( const std::vector<uint8_t> default_key_id(
kDefaultKeyId, kDefaultKeyId + arraysize(kDefaultKeyId) - 1); kDefaultKeyId, kDefaultKeyId + std::size(kDefaultKeyId) - 1);
InSequence s; InSequence s;
EXPECT_CALL(*notifier_, EXPECT_CALL(*notifier_,
@ -771,7 +770,7 @@ TEST_P(MpdNotifyMuxerListenerTest, LiveWithKeyRotation) {
if (GetParam() == MpdType::kDynamic) if (GetParam() == MpdType::kDynamic)
EXPECT_CALL(*notifier_, Flush()); EXPECT_CALL(*notifier_, Flush());
std::vector<uint8_t> iv(kBogusIv, kBogusIv + arraysize(kBogusIv)); std::vector<uint8_t> iv(kBogusIv, kBogusIv + std::size(kBogusIv));
listener_->OnEncryptionInfoReady(kInitialEncryptionInfo, FOURCC_cbc1, listener_->OnEncryptionInfoReady(kInitialEncryptionInfo, FOURCC_cbc1,
default_key_id, iv, default_key_id, iv,
std::vector<ProtectionSystemSpecificInfo>()); std::vector<ProtectionSystemSpecificInfo>());

View File

@ -6,8 +6,8 @@
#include "packager/media/event/multi_codec_muxer_listener.h" #include "packager/media/event/multi_codec_muxer_listener.h"
#include "packager/base/logging.h" #include "absl/strings/str_split.h"
#include "packager/base/strings/string_split.h" #include "glog/logging.h"
#include "packager/media/base/stream_info.h" #include "packager/media/base/stream_info.h"
namespace shaka { namespace shaka {
@ -18,11 +18,10 @@ void MultiCodecMuxerListener::OnMediaStart(const MuxerOptions& muxer_options,
int32_t time_scale, int32_t time_scale,
ContainerType container_type) { ContainerType container_type) {
size_t num_codecs = 0; size_t num_codecs = 0;
for (const std::string& codec_string : for (const auto& codec_string :
base::SplitString(stream_info.codec_string(), ";", base::KEEP_WHITESPACE, absl::StrSplit(stream_info.codec_string(), ";", absl::SkipEmpty())) {
base::SPLIT_WANT_NONEMPTY)) {
std::unique_ptr<StreamInfo> current_stream_info = stream_info.Clone(); std::unique_ptr<StreamInfo> current_stream_info = stream_info.Clone();
current_stream_info->set_codec_string(codec_string); current_stream_info->set_codec_string(std::string(codec_string));
MuxerListener* current_muxer_listener = MuxerListenerAt(num_codecs++); MuxerListener* current_muxer_listener = MuxerListenerAt(num_codecs++);
if (!current_muxer_listener) { if (!current_muxer_listener) {
LOG(WARNING) << "'" << codec_string << "' is not handled."; LOG(WARNING) << "'" << codec_string << "' is not handled.";

View File

@ -15,6 +15,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "packager/macros.h"
#include "packager/media/base/fourccs.h" #include "packager/media/base/fourccs.h"
#include "packager/media/base/range.h" #include "packager/media/base/range.h"

View File

@ -8,8 +8,8 @@
#include <list> #include <list>
#include "packager/base/memory/ptr_util.h" #include "absl/strings/str_format.h"
#include "packager/base/strings/stringprintf.h" #include "glog/logging.h"
#include "packager/hls/base/hls_notifier.h" #include "packager/hls/base/hls_notifier.h"
#include "packager/media/event/combined_muxer_listener.h" #include "packager/media/event/combined_muxer_listener.h"
#include "packager/media/event/hls_notify_muxer_listener.h" #include "packager/media/event/hls_notify_muxer_listener.h"
@ -39,7 +39,7 @@ std::unique_ptr<MuxerListener> CreateMpdListenerInternal(
MpdNotifier* notifier) { MpdNotifier* notifier) {
DCHECK(notifier); DCHECK(notifier);
auto listener = base::MakeUnique<MpdNotifyMuxerListener>(notifier); auto listener = std::make_unique<MpdNotifyMuxerListener>(notifier);
listener->set_accessibilities(stream.dash_accessiblities); listener->set_accessibilities(stream.dash_accessiblities);
listener->set_roles(stream.dash_roles); listener->set_roles(stream.dash_roles);
return listener; return listener;
@ -60,11 +60,11 @@ std::list<std::unique_ptr<MuxerListener>> CreateHlsListenersInternal(
const std::vector<std::string>& characteristics = stream.hls_characteristics; const std::vector<std::string>& characteristics = stream.hls_characteristics;
if (name.empty()) { if (name.empty()) {
name = base::StringPrintf("stream_%d", stream_index); name = absl::StrFormat("stream_%d", stream_index);
} }
if (playlist_name.empty()) { if (playlist_name.empty()) {
playlist_name = base::StringPrintf("stream_%d.m3u8", stream_index); playlist_name = absl::StrFormat("stream_%d.m3u8", stream_index);
} }
const bool kIFramesOnly = true; const bool kIFramesOnly = true;
@ -125,7 +125,7 @@ std::unique_ptr<MuxerListener> MuxerListenerFactory::CreateListener(
multi_codec_listener->AddListener(std::move(combined_listener)); multi_codec_listener->AddListener(std::move(combined_listener));
} }
return std::move(multi_codec_listener); return multi_codec_listener;
} }
std::unique_ptr<MuxerListener> MuxerListenerFactory::CreateHlsListener( std::unique_ptr<MuxerListener> MuxerListenerFactory::CreateHlsListener(

View File

@ -9,17 +9,17 @@
#include <google/protobuf/util/message_differencer.h> #include <google/protobuf/util/message_differencer.h>
#include <math.h> #include <math.h>
#include "packager/base/logging.h" #include "absl/strings/escaping.h"
#include "packager/base/strings/string_number_conversions.h" #include "glog/logging.h"
#include "packager/base/strings/string_util.h"
#include "packager/media/base/audio_stream_info.h" #include "packager/media/base/audio_stream_info.h"
#include "packager/media/base/muxer_options.h" #include "packager/media/base/muxer_options.h"
#include "packager/media/base/protection_system_specific_info.h" #include "packager/media/base/protection_system_specific_info.h"
#include "packager/media/base/text_stream_info.h" #include "packager/media/base/text_stream_info.h"
#include "packager/media/base/video_stream_info.h" #include "packager/media/base/video_stream_info.h"
#include "packager/media/codecs/ec3_audio_util.h"
#include "packager/media/codecs/ac4_audio_util.h" #include "packager/media/codecs/ac4_audio_util.h"
#include "packager/media/codecs/ec3_audio_util.h"
#include "packager/mpd/base/media_info.pb.h" #include "packager/mpd/base/media_info.pb.h"
#include "packager/utils/bytes_to_string_view.h"
using ::google::protobuf::util::MessageDifferencer; using ::google::protobuf::util::MessageDifferencer;
@ -60,7 +60,7 @@ void SetMediaInfoContainerType(MuxerListener::ContainerType container_type,
media_info->set_container_type(MediaInfo::CONTAINER_TEXT); media_info->set_container_type(MediaInfo::CONTAINER_TEXT);
break; break;
default: default:
NOTREACHED() << "Unknown container type " << container_type; NOTIMPLEMENTED() << "Unknown container type " << container_type;
} }
} }
@ -309,8 +309,8 @@ void SetContentProtectionFields(
std::string CreateUUIDString(const std::vector<uint8_t>& data) { std::string CreateUUIDString(const std::vector<uint8_t>& data) {
DCHECK_EQ(16u, data.size()); DCHECK_EQ(16u, data.size());
std::string uuid = std::string uuid = absl::AsciiStrToLower(
base::ToLowerASCII(base::HexEncode(data.data(), data.size())); absl::BytesToHexString(byte_vector_to_string_view(data)));
uuid.insert(20, "-"); uuid.insert(20, "-");
uuid.insert(16, "-"); uuid.insert(16, "-");
uuid.insert(12, "-"); uuid.insert(12, "-");

View File

@ -10,7 +10,7 @@
#include <cmath> #include <cmath>
#include "packager/base/logging.h" #include "glog/logging.h"
#include "packager/file/file.h" #include "packager/file/file.h"
#include "packager/media/base/muxer_options.h" #include "packager/media/base/muxer_options.h"
#include "packager/media/base/protection_system_specific_info.h" #include "packager/media/base/protection_system_specific_info.h"
@ -34,6 +34,7 @@ void VodMediaInfoDumpMuxerListener::OnEncryptionInfoReady(
const std::vector<uint8_t>& default_key_id, const std::vector<uint8_t>& default_key_id,
const std::vector<uint8_t>& iv, const std::vector<uint8_t>& iv,
const std::vector<ProtectionSystemSpecificInfo>& key_system_info) { const std::vector<ProtectionSystemSpecificInfo>& key_system_info) {
UNUSED(iv);
LOG_IF(WARNING, !is_initial_encryption_info) LOG_IF(WARNING, !is_initial_encryption_info)
<< "Updating (non initial) encryption info is not supported by " << "Updating (non initial) encryption info is not supported by "
"this module."; "this module.";
@ -92,6 +93,8 @@ void VodMediaInfoDumpMuxerListener::OnNewSegment(const std::string& file_name,
int64_t start_time, int64_t start_time,
int64_t duration, int64_t duration,
uint64_t segment_file_size) { uint64_t segment_file_size) {
UNUSED(file_name);
UNUSED(start_time);
const double segment_duration_seconds = const double segment_duration_seconds =
static_cast<double>(duration) / media_info_->reference_time_scale(); static_cast<double>(duration) / media_info_->reference_time_scale();
@ -103,10 +106,16 @@ void VodMediaInfoDumpMuxerListener::OnNewSegment(const std::string& file_name,
void VodMediaInfoDumpMuxerListener::OnKeyFrame(int64_t timestamp, void VodMediaInfoDumpMuxerListener::OnKeyFrame(int64_t timestamp,
uint64_t start_byte_offset, uint64_t start_byte_offset,
uint64_t size) {} uint64_t size) {
UNUSED(timestamp);
UNUSED(start_byte_offset);
UNUSED(size);
}
void VodMediaInfoDumpMuxerListener::OnCueEvent(int64_t timestamp, void VodMediaInfoDumpMuxerListener::OnCueEvent(int64_t timestamp,
const std::string& cue_data) { const std::string& cue_data) {
UNUSED(timestamp);
UNUSED(cue_data);
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }

View File

@ -15,7 +15,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "packager/base/macros.h" #include "packager/macros.h"
#include "packager/media/base/muxer_options.h" #include "packager/media/base/muxer_options.h"
#include "packager/media/event/muxer_listener.h" #include "packager/media/event/muxer_listener.h"

View File

@ -4,6 +4,8 @@
// license that can be found in the LICENSE file or at // license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd // https://developers.google.com/open-source/licenses/bsd
#include "packager/media/event/vod_media_info_dump_muxer_listener.h"
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <google/protobuf/text_format.h> #include <google/protobuf/text_format.h>
#include <google/protobuf/util/message_differencer.h> #include <google/protobuf/util/message_differencer.h>
@ -11,14 +13,12 @@
#include <vector> #include <vector>
#include "packager/base/files/file_path.h"
#include "packager/base/files/file_util.h"
#include "packager/file/file.h" #include "packager/file/file.h"
#include "packager/file/file_test_util.h"
#include "packager/media/base/fourccs.h" #include "packager/media/base/fourccs.h"
#include "packager/media/base/muxer_options.h" #include "packager/media/base/muxer_options.h"
#include "packager/media/base/video_stream_info.h" #include "packager/media/base/video_stream_info.h"
#include "packager/media/event/muxer_listener_test_helper.h" #include "packager/media/event/muxer_listener_test_helper.h"
#include "packager/media/event/vod_media_info_dump_muxer_listener.h"
#include "packager/mpd/base/media_info.pb.h" #include "packager/mpd/base/media_info.pb.h"
namespace { namespace {
@ -67,21 +67,17 @@ class VodMediaInfoDumpMuxerListenerTest : public ::testing::Test {
~VodMediaInfoDumpMuxerListenerTest() override {} ~VodMediaInfoDumpMuxerListenerTest() override {}
void SetUp() override { void SetUp() override {
ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path_)); temp_file_path_ = generate_unique_temp_path();
DLOG(INFO) << "Created temp file: " << temp_file_path_.value(); DLOG(INFO) << "Created temp file: " << temp_file_path_;
listener_.reset(new VodMediaInfoDumpMuxerListener(temp_file_path_
.AsUTF8Unsafe(),false));
listener_.reset(new VodMediaInfoDumpMuxerListener(temp_file_path_, false));
} }
void SetSegmentListFlag() { void SetSegmentListFlag() {
listener_->set_use_segment_list(true); listener_->set_use_segment_list(true);
} }
void TearDown() override { void TearDown() override { delete_file(temp_file_path_); }
base::DeleteFile(temp_file_path_, false);
}
void FireOnMediaStartWithDefaultMuxerOptions( void FireOnMediaStartWithDefaultMuxerOptions(
const StreamInfo& stream_info, const StreamInfo& stream_info,
@ -92,8 +88,8 @@ class VodMediaInfoDumpMuxerListenerTest : public ::testing::Test {
if (enable_encryption) { if (enable_encryption) {
std::vector<uint8_t> bogus_default_key_id( std::vector<uint8_t> bogus_default_key_id(
kBogusDefaultKeyId, kBogusDefaultKeyId,
kBogusDefaultKeyId + arraysize(kBogusDefaultKeyId)); kBogusDefaultKeyId + std::size(kBogusDefaultKeyId));
std::vector<uint8_t> bogus_iv(kBogusIv, kBogusIv + arraysize(kBogusIv)); std::vector<uint8_t> bogus_iv(kBogusIv, kBogusIv + std::size(kBogusIv));
listener_->OnEncryptionInfoReady(kInitialEncryptionInfo, FOURCC_cenc, listener_->OnEncryptionInfoReady(kInitialEncryptionInfo, FOURCC_cenc,
bogus_default_key_id, bogus_iv, bogus_default_key_id, bogus_iv,
@ -114,7 +110,7 @@ class VodMediaInfoDumpMuxerListenerTest : public ::testing::Test {
} }
protected: protected:
base::FilePath temp_file_path_; std::string temp_file_path_;
std::unique_ptr<VodMediaInfoDumpMuxerListener> listener_; std::unique_ptr<VodMediaInfoDumpMuxerListener> listener_;
private: private:
@ -151,8 +147,7 @@ TEST_F(VodMediaInfoDumpMuxerListenerTest, UnencryptedStream_Normal) {
"container_type: 1\n" "container_type: 1\n"
"media_file_name: 'test_output_file_name.mp4'\n" "media_file_name: 'test_output_file_name.mp4'\n"
"media_duration_seconds: 10.5\n"; "media_duration_seconds: 10.5\n";
EXPECT_THAT(temp_file_path_.AsUTF8Unsafe(), EXPECT_THAT(temp_file_path_, FileContentEqualsProto(kExpectedProtobufOutput));
FileContentEqualsProto(kExpectedProtobufOutput));
} }
TEST_F(VodMediaInfoDumpMuxerListenerTest, EncryptedStream_Normal) { TEST_F(VodMediaInfoDumpMuxerListenerTest, EncryptedStream_Normal) {
@ -195,8 +190,7 @@ TEST_F(VodMediaInfoDumpMuxerListenerTest, EncryptedStream_Normal) {
" protection_scheme: 'cenc'\n" " protection_scheme: 'cenc'\n"
"}\n"; "}\n";
EXPECT_THAT(temp_file_path_.AsUTF8Unsafe(), EXPECT_THAT(temp_file_path_, FileContentEqualsProto(kExpectedProtobufOutput));
FileContentEqualsProto(kExpectedProtobufOutput));
} }
// Verify that VideoStreamInfo with non-0 pixel_{width,height} is set in the // Verify that VideoStreamInfo with non-0 pixel_{width,height} is set in the
@ -234,8 +228,7 @@ TEST_F(VodMediaInfoDumpMuxerListenerTest, CheckPixelWidthAndHeightSet) {
"media_file_name: 'test_output_file_name.mp4'\n" "media_file_name: 'test_output_file_name.mp4'\n"
"media_duration_seconds: 10.5\n"; "media_duration_seconds: 10.5\n";
EXPECT_THAT(temp_file_path_.AsUTF8Unsafe(), EXPECT_THAT(temp_file_path_, FileContentEqualsProto(kExpectedProtobufOutput));
FileContentEqualsProto(kExpectedProtobufOutput));
} }
TEST_F(VodMediaInfoDumpMuxerListenerTest, CheckBandwidth) { TEST_F(VodMediaInfoDumpMuxerListenerTest, CheckBandwidth) {
@ -276,8 +269,7 @@ TEST_F(VodMediaInfoDumpMuxerListenerTest, CheckBandwidth) {
"container_type: 1\n" "container_type: 1\n"
"media_file_name: 'test_output_file_name.mp4'\n" "media_file_name: 'test_output_file_name.mp4'\n"
"media_duration_seconds: 10.5\n"; "media_duration_seconds: 10.5\n";
EXPECT_THAT(temp_file_path_.AsUTF8Unsafe(), EXPECT_THAT(temp_file_path_, FileContentEqualsProto(kExpectedProtobufOutput));
FileContentEqualsProto(kExpectedProtobufOutput));
} }
// Equivalent tests with segment list flag on which writes subsegment ranges // Equivalent tests with segment list flag on which writes subsegment ranges
@ -318,8 +310,7 @@ TEST_F(VodMediaInfoDumpMuxerListenerTest, UnencryptedStream_Normal_SegmentList)
" begin: 222\n" " begin: 222\n"
" end: 9999\n" " end: 9999\n"
"}\n"; "}\n";
EXPECT_THAT(temp_file_path_.AsUTF8Unsafe(), EXPECT_THAT(temp_file_path_, FileContentEqualsProto(kExpectedProtobufOutput));
FileContentEqualsProto(kExpectedProtobufOutput));
} }
} // namespace media } // namespace media

View File

@ -11,10 +11,11 @@
#define MPD_BASE_MPD_NOTIFIER_H_ #define MPD_BASE_MPD_NOTIFIER_H_
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include "packager/base/macros.h" #include "packager/macros.h"
#include "packager/mpd/base/mpd_options.h" #include "packager/mpd/base/mpd_options.h"
namespace shaka { namespace shaka {
@ -52,6 +53,7 @@ class MpdNotifier {
/// @return true on success, false otherwise. This may fail if the container /// @return true on success, false otherwise. This may fail if the container
/// specified by @a container_id does not exist. /// specified by @a container_id does not exist.
virtual bool NotifyAvailabilityTimeOffset(uint32_t container_id) { virtual bool NotifyAvailabilityTimeOffset(uint32_t container_id) {
UNUSED(container_id);
return true; return true;
} }
@ -70,7 +72,10 @@ class MpdNotifier {
/// NotifyNewContainer(). /// NotifyNewContainer().
/// @return true on success, false otherwise. This may fail if the container /// @return true on success, false otherwise. This may fail if the container
/// specified by @a container_id does not exist. /// specified by @a container_id does not exist.
virtual bool NotifySegmentDuration(uint32_t container_id) { return true; } virtual bool NotifySegmentDuration(uint32_t container_id) {
UNUSED(container_id);
return true;
}
/// Notifies MpdBuilder that there is a new segment ready. For live, this /// Notifies MpdBuilder that there is a new segment ready. For live, this
/// is usually a new segment, for VOD this is usually a subsegment, for low /// is usually a new segment, for VOD this is usually a subsegment, for low
@ -102,6 +107,9 @@ class MpdNotifier {
virtual bool NotifyCompletedSegment(uint32_t container_id, virtual bool NotifyCompletedSegment(uint32_t container_id,
int64_t duration, int64_t duration,
uint64_t size) { uint64_t size) {
UNUSED(container_id);
UNUSED(duration);
UNUSED(size);
return true; return true;
} }

View File

@ -71,6 +71,8 @@ function(add_proto_library NAME)
if(MSVC) if(MSVC)
# Integer truncation warnings # Integer truncation warnings
target_compile_options(${NAME} PUBLIC /wd4244 /wd4267) target_compile_options(${NAME} PUBLIC /wd4244 /wd4267)
# Unused parameter warnings
target_compile_options(${NAME} PUBLIC /wd4100)
else() else()
target_compile_options(${NAME} PUBLIC -Wno-shorten-64-to-32) target_compile_options(${NAME} PUBLIC -Wno-shorten-64-to-32)
target_compile_options(${NAME} PUBLIC -Wno-unused-parameter) target_compile_options(${NAME} PUBLIC -Wno-unused-parameter)

View File

@ -35,6 +35,7 @@ else()
# Disable a warning about sprintf on macOS. # Disable a warning about sprintf on macOS.
add_compile_options(-Wno-deprecated-declarations) add_compile_options(-Wno-deprecated-declarations)
add_compile_options(-Wno-unused-but-set-variable)
endif() endif()
# With these set in scope of this folder, load the library's own CMakeLists.txt. # With these set in scope of this folder, load the library's own CMakeLists.txt.

View File

@ -14,4 +14,9 @@ set(ENABLE_TESTING OFF)
set(GEN_FILES OFF) set(GEN_FILES OFF)
# With these set in scope of this folder, load the library's own CMakeLists.txt. # With these set in scope of this folder, load the library's own CMakeLists.txt.
if(NOT MSVC)
add_compile_options(-Wno-unused-but-set-variable)
endif()
add_subdirectory(source) add_subdirectory(source)

View File

@ -32,6 +32,8 @@ if(MSVC)
/wd4146 # sign comparison /wd4146 # sign comparison
# src/google/protobuf/generated_message_tctable_lite.cc # src/google/protobuf/generated_message_tctable_lite.cc
/wd4141 # multiple inline keywords /wd4141 # multiple inline keywords
# src/google/protobuf/util/message_differencer.h
/wd4100 # unreferenced formal parameter
) )
else() else()
add_compile_options( add_compile_options(