Skip to content

Commit

Permalink
feat: port media/event to CMake
Browse files Browse the repository at this point in the history
Co-authored-by: Cosmin Stejerean <cstejerean@meta.com>
  • Loading branch information
Carlos Bentzen and cosmin committed Jun 28, 2023
1 parent bf6296c commit 4b44a37
Show file tree
Hide file tree
Showing 19 changed files with 134 additions and 70 deletions.
6 changes: 6 additions & 0 deletions packager/file/file_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ std::string generate_unique_temp_path() {
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() {
Expand Down
1 change: 1 addition & 0 deletions packager/file/file_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace shaka {

// Generate a unique filename.
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
// destroyed. Useful in tests that use ASSERT to avoid leaving behind temp
Expand Down
1 change: 1 addition & 0 deletions packager/media/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Subdirectories with their own CMakeLists.txt, all of whose targets are built.
add_subdirectory(base)
add_subdirectory(codecs)
add_subdirectory(event)
add_subdirectory(formats)
add_subdirectory(origin)
add_subdirectory(replicator)
Expand Down
64 changes: 64 additions & 0 deletions packager/media/event/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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
# needs MockMpdNotifier from mpd/base
# 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_base_unittest
# file
# file_test_util
# media_base
# gmock
# gtest
# gtest_main
# test_data_util)
#

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_base_unittest COMMAND media_event_unittest)
2 changes: 1 addition & 1 deletion packager/media/event/combined_muxer_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CombinedMuxerListener : public MuxerListener {
uint64_t segment_file_size) override;
void OnCompletedSegment(int64_t duration,
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;
/// @}

Expand Down
3 changes: 2 additions & 1 deletion packager/media/event/hls_notify_muxer_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include "packager/media/event/hls_notify_muxer_listener.h"

#include <memory>
#include "packager/base/logging.h"

#include "glog/logging.h"
#include "packager/hls/base/hls_notifier.h"
#include "packager/media/base/muxer_options.h"
#include "packager/media/base/protection_system_specific_info.h"
Expand Down
6 changes: 3 additions & 3 deletions packager/media/event/hls_notify_muxer_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#define PACKAGER_MEDIA_EVENT_HLS_NOTIFY_MUXER_LISTENER_H_

#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "packager/base/optional.h"
#include "packager/media/event/event_info.h"
#include "packager/media/event/muxer_listener.h"
#include "packager/mpd/base/media_info.pb.h"
Expand Down Expand Up @@ -68,7 +68,7 @@ class HlsNotifyMuxerListener : public MuxerListener {
int64_t start_time,
int64_t duration,
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;
/// @}

Expand All @@ -84,7 +84,7 @@ class HlsNotifyMuxerListener : public MuxerListener {
const std::string ext_x_media_group_id_;
const std::vector<std::string> characteristics_;
hls::HlsNotifier* const hls_notifier_;
base::Optional<uint32_t> stream_id_;
std::optional<uint32_t> stream_id_;

bool must_notify_encryption_start_ = false;
// Cached encryption info before OnMediaStart() is called.
Expand Down
12 changes: 6 additions & 6 deletions packager/media/event/hls_notify_muxer_listener_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ TEST_F(HlsNotifyMuxerListenerTest, OnMediaStart) {
// OnEncryptionInfoReady() and OnMediaStart().
TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionStart) {
std::vector<uint8_t> system_id(kAnySystemId,
kAnySystemId + arraysize(kAnySystemId));
std::vector<uint8_t> pssh(kAnyData, kAnyData + arraysize(kAnyData));
kAnySystemId + std::size(kAnySystemId));
std::vector<uint8_t> pssh(kAnyData, kAnyData + std::size(kAnyData));
std::vector<uint8_t> key_id(16, 0x05);
std::vector<uint8_t> iv(16, 0x54);

Expand Down Expand Up @@ -211,8 +211,8 @@ TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionStart) {
// OnMediaStart().
TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionStartBeforeMediaStart) {
std::vector<uint8_t> system_id(kAnySystemId,
kAnySystemId + arraysize(kAnySystemId));
std::vector<uint8_t> pssh(kAnyData, kAnyData + arraysize(kAnyData));
kAnySystemId + std::size(kAnySystemId));
std::vector<uint8_t> pssh(kAnyData, kAnyData + std::size(kAnyData));
std::vector<uint8_t> key_id(16, 0x05);
std::vector<uint8_t> iv(16, 0x54);

Expand Down Expand Up @@ -278,8 +278,8 @@ TEST_F(HlsNotifyMuxerListenerTest, OnEncryptionInfoReady) {
MuxerListener::kContainerMpeg2ts);

std::vector<uint8_t> system_id(kAnySystemId,
kAnySystemId + arraysize(kAnySystemId));
std::vector<uint8_t> pssh(kAnyData, kAnyData + arraysize(kAnyData));
kAnySystemId + std::size(kAnySystemId));
std::vector<uint8_t> pssh(kAnyData, kAnyData + std::size(kAnyData));
std::vector<uint8_t> key_id(16, 0x05);
std::vector<uint8_t> iv(16, 0x54);

Expand Down
2 changes: 1 addition & 1 deletion packager/media/event/mpd_notify_muxer_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <cmath>

#include "packager/base/logging.h"
#include "glog/logging.h"
#include "packager/media/base/audio_stream_info.h"
#include "packager/media/base/protection_system_specific_info.h"
#include "packager/media/base/video_stream_info.h"
Expand Down
6 changes: 3 additions & 3 deletions packager/media/event/mpd_notify_muxer_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#define PACKAGER_MEDIA_EVENT_MPD_NOTIFY_MUXER_LISTENER_H_

#include <memory>
#include <optional>
#include <vector>

#include "packager/base/optional.h"
#include "packager/media/base/muxer_options.h"
#include "packager/media/event/event_info.h"
#include "packager/media/event/muxer_listener.h"
Expand Down Expand Up @@ -55,7 +55,7 @@ class MpdNotifyMuxerListener : public MuxerListener {
uint64_t segment_file_size) override;
void OnCompletedSegment(int64_t duration,
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;
/// @}

Expand All @@ -72,7 +72,7 @@ class MpdNotifyMuxerListener : public MuxerListener {
bool NotifyNewContainer();

MpdNotifier* const mpd_notifier_ = nullptr;
base::Optional<uint32_t> notification_id_;
std::optional<uint32_t> notification_id_;
std::unique_ptr<MediaInfo> media_info_;

std::vector<std::string> accessibilities_;
Expand Down
17 changes: 8 additions & 9 deletions packager/media/event/mpd_notify_muxer_listener_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <algorithm>
#include <vector>

#include "packager/base/stl_util.h"
#include "packager/media/base/video_stream_info.h"
#include "packager/media/event/muxer_listener_test_helper.h"
#include "packager/mpd/base/content_protection_element.h"
Expand Down Expand Up @@ -204,7 +203,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodEncryptedContent) {
CreateVideoStreamInfo(video_params);

const std::vector<uint8_t> default_key_id(
kDefaultKeyId, kDefaultKeyId + arraysize(kDefaultKeyId) - 1);
kDefaultKeyId, kDefaultKeyId + std::size(kDefaultKeyId) - 1);

const std::string kExpectedMediaInfo =
std::string(kExpectedDefaultMediaInfo) +
Expand All @@ -220,7 +219,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodEncryptedContent) {

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,
default_key_id, iv,
GetDefaultKeySystemInfo());
Expand All @@ -247,7 +246,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodEncryptedContentSegmentList) {
CreateVideoStreamInfo(video_params);

const std::vector<uint8_t> default_key_id(
kDefaultKeyId, kDefaultKeyId + arraysize(kDefaultKeyId) - 1);
kDefaultKeyId, kDefaultKeyId + std::size(kDefaultKeyId) - 1);

const std::string kExpectedMediaInfo =
std::string(kExpectedDefaultMediaInfoSubsegmentRange) +
Expand All @@ -263,7 +262,7 @@ TEST_F(MpdNotifyMuxerListenerTest, VodEncryptedContentSegmentList) {

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,
default_key_id, iv,
GetDefaultKeySystemInfo());
Expand Down Expand Up @@ -681,7 +680,7 @@ TEST_P(MpdNotifyMuxerListenerTest, LiveNoKeyRotation) {
const int64_t kDuration2 = 3787;
const uint64_t kSegmentFileSize2 = 83743u;
const std::vector<uint8_t> default_key_id(
kDefaultKeyId, kDefaultKeyId + arraysize(kDefaultKeyId) - 1);
kDefaultKeyId, kDefaultKeyId + std::size(kDefaultKeyId) - 1);

InSequence s;
EXPECT_CALL(*notifier_, NotifyEncryptionUpdate(_, _, _, _)).Times(0);
Expand All @@ -699,7 +698,7 @@ TEST_P(MpdNotifyMuxerListenerTest, LiveNoKeyRotation) {
if (GetParam() == MpdType::kDynamic)
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,
default_key_id, iv,
GetDefaultKeySystemInfo());
Expand Down Expand Up @@ -754,7 +753,7 @@ TEST_P(MpdNotifyMuxerListenerTest, LiveWithKeyRotation) {
const int64_t kDuration2 = 3787;
const uint64_t kSegmentFileSize2 = 83743u;
const std::vector<uint8_t> default_key_id(
kDefaultKeyId, kDefaultKeyId + arraysize(kDefaultKeyId) - 1);
kDefaultKeyId, kDefaultKeyId + std::size(kDefaultKeyId) - 1);

InSequence s;
EXPECT_CALL(*notifier_,
Expand All @@ -771,7 +770,7 @@ TEST_P(MpdNotifyMuxerListenerTest, LiveWithKeyRotation) {
if (GetParam() == MpdType::kDynamic)
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,
default_key_id, iv,
std::vector<ProtectionSystemSpecificInfo>());
Expand Down
11 changes: 5 additions & 6 deletions packager/media/event/multi_codec_muxer_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "packager/media/event/multi_codec_muxer_listener.h"

#include "packager/base/logging.h"
#include "packager/base/strings/string_split.h"
#include "absl/strings/str_split.h"
#include "glog/logging.h"
#include "packager/media/base/stream_info.h"

namespace shaka {
Expand All @@ -18,11 +18,10 @@ void MultiCodecMuxerListener::OnMediaStart(const MuxerOptions& muxer_options,
int32_t time_scale,
ContainerType container_type) {
size_t num_codecs = 0;
for (const std::string& codec_string :
base::SplitString(stream_info.codec_string(), ";", base::KEEP_WHITESPACE,
base::SPLIT_WANT_NONEMPTY)) {
for (const auto& codec_string :
absl::StrSplit(stream_info.codec_string(), ";", absl::SkipEmpty())) {
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++);
if (!current_muxer_listener) {
LOG(WARNING) << "'" << codec_string << "' is not handled.";
Expand Down
1 change: 1 addition & 0 deletions packager/media/event/muxer_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <string>
#include <vector>

#include "packager/macros.h"
#include "packager/media/base/fourccs.h"
#include "packager/media/base/range.h"

Expand Down
12 changes: 6 additions & 6 deletions packager/media/event/muxer_listener_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <list>

#include "packager/base/memory/ptr_util.h"
#include "packager/base/strings/stringprintf.h"
#include "absl/strings/str_format.h"
#include "glog/logging.h"
#include "packager/hls/base/hls_notifier.h"
#include "packager/media/event/combined_muxer_listener.h"
#include "packager/media/event/hls_notify_muxer_listener.h"
Expand Down Expand Up @@ -39,7 +39,7 @@ std::unique_ptr<MuxerListener> CreateMpdListenerInternal(
MpdNotifier* notifier) {
DCHECK(notifier);

auto listener = base::MakeUnique<MpdNotifyMuxerListener>(notifier);
auto listener = std::make_unique<MpdNotifyMuxerListener>(notifier);
listener->set_accessibilities(stream.dash_accessiblities);
listener->set_roles(stream.dash_roles);
return listener;
Expand All @@ -60,11 +60,11 @@ std::list<std::unique_ptr<MuxerListener>> CreateHlsListenersInternal(
const std::vector<std::string>& characteristics = stream.hls_characteristics;

if (name.empty()) {
name = base::StringPrintf("stream_%d", stream_index);
name = absl::StrFormat("stream_%d", stream_index);
}

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;
Expand Down Expand Up @@ -125,7 +125,7 @@ std::unique_ptr<MuxerListener> MuxerListenerFactory::CreateListener(
multi_codec_listener->AddListener(std::move(combined_listener));
}

return std::move(multi_codec_listener);
return multi_codec_listener;
}

std::unique_ptr<MuxerListener> MuxerListenerFactory::CreateHlsListener(
Expand Down
Loading

0 comments on commit 4b44a37

Please sign in to comment.