Skip to content

Commit

Permalink
feat: port media/event to CMake (#1222)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Joey Parrish <[email protected]>
  • Loading branch information
3 people authored Jul 13, 2023
1 parent 3a551f4 commit 8d3b2c6
Show file tree
Hide file tree
Showing 24 changed files with 167 additions and 154 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 @@ -8,6 +8,7 @@
add_subdirectory(base)
add_subdirectory(codecs)
add_subdirectory(chunking)
add_subdirectory(event)
add_subdirectory(formats)
add_subdirectory(origin)
add_subdirectory(replicator)
Expand Down
54 changes: 54 additions & 0 deletions packager/media/event/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 3 additions & 1 deletion packager/media/event/combined_muxer_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ 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
7 changes: 5 additions & 2 deletions 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 Expand Up @@ -46,6 +47,7 @@ void HlsNotifyMuxerListener::OnEncryptionInfoReady(
const std::vector<uint8_t>& key_id,
const std::vector<uint8_t>& iv,
const std::vector<ProtectionSystemSpecificInfo>& key_system_infos) {
UNUSED(is_initial_encryption_info);
if (!stream_id_) {
next_key_id_ = key_id;
next_iv_ = iv;
Expand Down Expand Up @@ -147,6 +149,7 @@ void HlsNotifyMuxerListener::OnSampleDurationReady(int32_t sample_duration) {

void HlsNotifyMuxerListener::OnMediaEnd(const MediaRanges& media_ranges,
float duration_seconds) {
UNUSED(duration_seconds);
DCHECK(media_info_);
// 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
Expand Down Expand Up @@ -263,7 +266,7 @@ void HlsNotifyMuxerListener::OnKeyFrame(int64_t timestamp,

void HlsNotifyMuxerListener::OnCueEvent(int64_t timestamp,
const std::string& cue_data) {
// Not using |cue_data| at this moment.
UNUSED(cue_data);
if (!media_info_->has_segment_template()) {
EventInfo event_info;
event_info.type = EventInfoType::kCue;
Expand Down
8 changes: 5 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,9 @@ 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 +86,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
80 changes: 0 additions & 80 deletions packager/media/event/media_event.gyp

This file was deleted.

9 changes: 7 additions & 2 deletions 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 All @@ -34,6 +34,7 @@ void MpdNotifyMuxerListener::OnEncryptionInfoReady(
const std::vector<uint8_t>& key_id,
const std::vector<uint8_t>& iv,
const std::vector<ProtectionSystemSpecificInfo>& key_system_info) {
UNUSED(iv);
if (is_initial_encryption_info) {
LOG_IF(WARNING, is_encrypted_)
<< "Updating initial encryption information.";
Expand Down Expand Up @@ -191,6 +192,7 @@ void MpdNotifyMuxerListener::OnNewSegment(const std::string& file_name,
int64_t start_time,
int64_t duration,
uint64_t segment_file_size) {
UNUSED(file_name);
if (mpd_notifier_->dash_profile() == DashProfile::kLive) {
mpd_notifier_->NotifyNewSegment(notification_id_.value(), start_time,
duration, segment_file_size);
Expand All @@ -214,11 +216,14 @@ void MpdNotifyMuxerListener::OnKeyFrame(int64_t timestamp,
uint64_t start_byte_offset,
uint64_t size) {
// NO-OP for DASH.
UNUSED(timestamp);
UNUSED(start_byte_offset);
UNUSED(size);
}

void MpdNotifyMuxerListener::OnCueEvent(int64_t timestamp,
const std::string& cue_data) {
// Not using |cue_data| at this moment.
UNUSED(cue_data);
if (mpd_notifier_->dash_profile() == DashProfile::kLive) {
mpd_notifier_->NotifyCueEvent(notification_id_.value(), timestamp);
} else {
Expand Down
8 changes: 5 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,9 @@ 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 +74,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
Loading

0 comments on commit 8d3b2c6

Please sign in to comment.