Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: port media/formats/webm to CMake #1147

Merged
merged 6 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions packager/file/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ ABSL_FLAG(uint64_t,
1ULL << 16,
"Size of the block size used for threaded I/O, in bytes.");

// Needed for Windows weirdness which somewhere defines CopyFile as CopyFileW.
#ifdef CopyFile
#undef CopyFile
#endif // CopyFile

namespace shaka {

const char* kCallbackFilePrefix = "callback://";
Expand Down Expand Up @@ -360,17 +355,17 @@ bool File::Copy(const char* from_file_name, const char* to_file_name) {
return true;
}

int64_t File::CopyFile(File* source, File* destination) {
return CopyFile(source, destination, kWholeFile);
int64_t File::Copy(File* source, File* destination) {
return Copy(source, destination, kWholeFile);
}

int64_t File::CopyFile(File* source, File* destination, int64_t max_copy) {
int64_t File::Copy(File* source, File* destination, int64_t max_copy) {
DCHECK(source);
DCHECK(destination);
if (max_copy < 0)
max_copy = std::numeric_limits<int64_t>::max();

VLOG(2) << "File::CopyFile from " << source->file_name() << " to "
VLOG(2) << "File::Copy from " << source->file_name() << " to "
<< destination->file_name();

const int64_t kBufferSize = 0x40000; // 256KB.
Expand Down
4 changes: 2 additions & 2 deletions packager/file/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ class SHAKA_EXPORT File {
/// @param source The file to copy from.
/// @param destination The file to copy to.
/// @return Number of bytes written, or a value < 0 on error.
static int64_t CopyFile(File* source, File* destination);
static int64_t Copy(File* source, File* destination);

/// Copies the contents from source to destination.
/// @param source The file to copy from.
/// @param destination The file to copy to.
/// @param max_copy The maximum number of bytes to copy; < 0 to copy to EOF.
/// @return Number of bytes written, or a value < 0 on error.
static int64_t CopyFile(File* source, File* destination, int64_t max_copy);
static int64_t Copy(File* source, File* destination, int64_t max_copy);

/// @param file_name is the name of the file to be checked.
/// @return true if `file_name` is a local and regular file.
Expand Down
1 change: 1 addition & 0 deletions packager/media/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ add_subdirectory(origin)
add_subdirectory(replicator)
add_subdirectory(test)
add_subdirectory(codecs)
add_subdirectory(formats)
17 changes: 9 additions & 8 deletions packager/media/base/media_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#ifndef PACKAGER_MEDIA_BASE_MEDIA_PARSER_H_
#define PACKAGER_MEDIA_BASE_MEDIA_PARSER_H_

#include <functional>
#include <memory>
#include <string>
#include <vector>
#include "packager/base/callback.h"

#include "packager/macros.h"
#include "packager/media/base/container_names.h"

Expand All @@ -30,7 +31,7 @@ class MediaParser {
/// Called upon completion of parser initialization.
/// @param stream_info contains the stream info of all the elementary streams
/// within this file.
typedef base::Callback<void(
typedef std::function<void(
const std::vector<std::shared_ptr<StreamInfo> >& stream_info)>
InitCB;

Expand All @@ -39,17 +40,17 @@ class MediaParser {
/// @param media_sample is the new media sample.
/// @return true if the sample is accepted, false if something was wrong
/// with the sample and a parsing error should be signaled.
typedef base::Callback<bool(uint32_t track_id,
std::shared_ptr<MediaSample> media_sample)>
typedef std::function<bool(uint32_t track_id,
std::shared_ptr<MediaSample> media_sample)>
NewMediaSampleCB;

/// Called when a new text sample has been parsed.
/// @param track_id is the track id of the new sample.
/// @param text_sample is the new text sample.
/// @return true if the sample is accepted, false if something was wrong
/// with the sample and a parsing error should be signaled.
typedef base::Callback<bool(uint32_t track_id,
std::shared_ptr<TextSample> text_sample)>
typedef std::function<bool(uint32_t track_id,
std::shared_ptr<TextSample> text_sample)>
NewTextSampleCB;

/// Initialize the parser with necessary callbacks. Must be called before any
Expand All @@ -70,11 +71,11 @@ class MediaParser {
/// Flush data currently in the parser and put the parser in a state where it
/// can receive data for a new seek point.
/// @return true if successful, false otherwise.
virtual bool Flush() WARN_UNUSED_RESULT = 0;
[[nodiscard]] virtual bool Flush() = 0;

/// Should be called when there is new data to parse.
/// @return true if successful.
virtual bool Parse(const uint8_t* buf, int size) WARN_UNUSED_RESULT = 0;
[[nodiscard]] virtual bool Parse(const uint8_t* buf, int size) = 0;

private:
DISALLOW_COPY_AND_ASSIGN(MediaParser);
Expand Down
9 changes: 3 additions & 6 deletions packager/media/base/text_track.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
#include <memory>
#include <string>

#include "packager/base/callback.h"
#include "packager/base/time/time.h"

namespace shaka {
namespace media {

Expand All @@ -33,9 +30,9 @@ class TextTrack {
const std::string& settings) = 0;
};

typedef base::Callback<std::unique_ptr<TextTrack>(TextKind kind,
const std::string& label,
const std::string& language)>
typedef std::function<std::unique_ptr<TextTrack>(TextKind kind,
const std::string& label,
const std::string& language)>
AddTextTrackCB;

} // namespace media
Expand Down
8 changes: 8 additions & 0 deletions packager/media/formats/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 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

# Subdirectories with their own CMakeLists.txt, all of whose targets are built.
add_subdirectory(webm)
60 changes: 60 additions & 0 deletions packager/media/formats/webm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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(formats_webm STATIC
encryptor.cc
mkv_writer.cc
multi_segment_segmenter.cc
seek_head.cc
segmenter.cc
single_segment_segmenter.cc
two_pass_single_segment_segmenter.cc
webm_audio_client.cc
webm_cluster_parser.cc
webm_constants.cc
webm_content_encodings.cc
webm_content_encodings_client.cc
webm_crypto_helpers.cc
webm_info_parser.cc
webm_parser.cc
webm_media_parser.cc
webm_muxer.cc
webm_tracks_parser.cc
webm_video_client.cc
webm_webvtt_parser.cc
)

target_link_libraries(formats_webm
webm
file
media_base
codecs
)

add_executable(webm_unittest
cluster_builder.cc
encrypted_segmenter_unittest.cc
encryptor_unittest.cc
multi_segment_segmenter_unittest.cc
segmenter_test_base.cc
single_segment_segmenter_unittest.cc
tracks_builder.cc
webm_cluster_parser_unittest.cc
webm_content_encodings_client_unittest.cc
webm_parser_unittest.cc
webm_tracks_parser_unittest.cc
webm_webvtt_parser_unittest.cc
)

target_link_libraries(webm_unittest
formats_webm
gmock
gtest
gtest_main
test_data_util
)

add_test(NAME webm_unittest COMMAND webm_unittest)
2 changes: 1 addition & 1 deletion packager/media/formats/webm/cluster_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "packager/media/formats/webm/cluster_builder.h"

#include "packager/base/logging.h"
#include "glog/logging.h"
#include "packager/media/formats/webm/webm_constants.h"

namespace shaka {
Expand Down
3 changes: 2 additions & 1 deletion packager/media/formats/webm/cluster_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#define PACKAGER_MEDIA_FORMATS_WEBM_CLUSTER_BUILDER_H_

#include <stdint.h>

#include <memory>

#include "packager/base/macros.h"
#include "packager/macros.h"

namespace shaka {
namespace media {
Expand Down
4 changes: 2 additions & 2 deletions packager/media/formats/webm/encrypted_segmenter_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ const uint8_t kBasicSupportData[] = {
0x2a, 0xd7, 0xb1, 0x83, 0x0f, 0x42, 0x40,
// Duration: float(5000)
0x44, 0x89, 0x84, 0x45, 0x9c, 0x40, 0x00,
// MuxingApp: 'libwebm-0.2.1.0'
// MuxingApp: 'libwebm-0.3.0.0'
0x4d, 0x80, 0x8f, 0x6c, 0x69, 0x62, 0x77, 0x65, 0x62, 0x6d, 0x2d, 0x30,
0x2e, 0x32, 0x2e, 0x31, 0x2e, 0x30,
0x2e, 0x33, 0x2e, 0x30, 0x2e, 0x30,
// WritingApp: 'https://github.com/shaka-project/shaka-packager version test'
0x57, 0x41, 0xbc,
0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68,
Expand Down
4 changes: 2 additions & 2 deletions packager/media/formats/webm/encryptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#include <vector>

#include "packager/status.h"
#include "packager/third_party/libwebm/src/mkvmuxer.hpp"
#include "mkvmuxer/mkvmuxer.h"
#include "packager/status/status.h"

namespace shaka {
namespace media {
Expand Down
20 changes: 11 additions & 9 deletions packager/media/formats/webm/encryptor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
#include "packager/media/formats/webm/encryptor.h"

#include <gtest/gtest.h>

#include <memory>

#include "packager/media/base/media_sample.h"
#include "packager/media/formats/webm/webm_constants.h"
#include "packager/status_test_util.h"
#include "packager/status/status_test_util.h"

namespace shaka {
namespace media {
Expand Down Expand Up @@ -139,14 +141,14 @@ namespace {
EncryptionTestCase kEncryptionTestCases[] = {
// Special case with no subsamples.
{nullptr, 0, nullptr, 0},
{kSubsamples1, arraysize(kSubsamples1), kSubsamplePartitionData1,
arraysize(kSubsamplePartitionData1)},
{kSubsamples2, arraysize(kSubsamples2), kSubsamplePartitionData2,
arraysize(kSubsamplePartitionData2)},
{kSubsamples3, arraysize(kSubsamples3), kSubsamplePartitionData3,
arraysize(kSubsamplePartitionData3)},
{kSubsamples4, arraysize(kSubsamples4), kSubsamplePartitionData4,
arraysize(kSubsamplePartitionData4)},
{kSubsamples1, std::size(kSubsamples1), kSubsamplePartitionData1,
std::size(kSubsamplePartitionData1)},
{kSubsamples2, std::size(kSubsamples2), kSubsamplePartitionData2,
std::size(kSubsamplePartitionData2)},
{kSubsamples3, std::size(kSubsamples3), kSubsamplePartitionData3,
std::size(kSubsamplePartitionData3)},
{kSubsamples4, std::size(kSubsamples4), kSubsamplePartitionData4,
std::size(kSubsamplePartitionData4)},
};
} // namespace

Expand Down
6 changes: 3 additions & 3 deletions packager/media/formats/webm/mkv_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int64_t MkvWriter::WriteFromFile(File* source) {
int64_t MkvWriter::WriteFromFile(File* source, int64_t max_copy) {
DCHECK(file_);

const int64_t size = File::CopyFile(source, file_.get(), max_copy);
const int64_t size = File::Copy(source, file_.get(), max_copy);
if (size < 0)
return size;

Expand All @@ -90,8 +90,8 @@ bool MkvWriter::Seekable() const {
return seekable_;
}

void MkvWriter::ElementStartNotify(mkvmuxer::uint64 element_id,
mkvmuxer::int64 position) {}
void MkvWriter::ElementStartNotify(mkvmuxer::uint64 /*element_id*/,
mkvmuxer::int64 /*position*/) {}

} // namespace media
} // namespace shaka
4 changes: 2 additions & 2 deletions packager/media/formats/webm/mkv_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <memory>
#include <string>

#include "mkvmuxer/mkvmuxer.h"
#include "packager/file/file_closer.h"
#include "packager/status.h"
#include "packager/third_party/libwebm/src/mkvmuxer.hpp"
#include "packager/status/status.h"

namespace shaka {
namespace media {
Expand Down
12 changes: 6 additions & 6 deletions packager/media/formats/webm/multi_segment_segmenter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

#include "packager/media/formats/webm/multi_segment_segmenter.h"

#include "mkvmuxer/mkvmuxer.h"
#include "packager/media/base/muxer_options.h"
#include "packager/media/base/muxer_util.h"
#include "packager/media/base/stream_info.h"
#include "packager/media/event/muxer_listener.h"
#include "packager/status_macros.h"
#include "packager/third_party/libwebm/src/mkvmuxer.hpp"
#include "packager/status/status_macros.h"

namespace shaka {
namespace media {
Expand Down Expand Up @@ -58,13 +58,13 @@ Status MultiSegmentSegmenter::FinalizeSegment(int64_t start_timestamp,
return Status::OK;
}

bool MultiSegmentSegmenter::GetInitRangeStartAndEnd(uint64_t* start,
uint64_t* end) {
bool MultiSegmentSegmenter::GetInitRangeStartAndEnd(uint64_t* /*start*/,
uint64_t* /*end*/) {
return false;
}

bool MultiSegmentSegmenter::GetIndexRangeStartAndEnd(uint64_t* start,
uint64_t* end) {
bool MultiSegmentSegmenter::GetIndexRangeStartAndEnd(uint64_t* /*start*/,
uint64_t* /*end*/) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion packager/media/formats/webm/multi_segment_segmenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "packager/media/formats/webm/mkv_writer.h"
#include "packager/media/formats/webm/segmenter.h"
#include "packager/status.h"
#include "packager/status/status.h"

namespace shaka {
namespace media {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const uint8_t kBasicSupportDataInit[] = {
0x15, 0x49, 0xa9, 0x66, 0xd8,
// TimecodeScale: 1000000
0x2a, 0xd7, 0xb1, 0x83, 0x0f, 0x42, 0x40,
// MuxingApp: 'libwebm-0.2.1.0'
// MuxingApp: 'libwebm-0.3.0.0'
0x4d, 0x80, 0x8f, 0x6c, 0x69, 0x62, 0x77, 0x65, 0x62, 0x6d, 0x2d, 0x30,
0x2e, 0x32, 0x2e, 0x31, 0x2e, 0x30,
0x2e, 0x33, 0x2e, 0x30, 0x2e, 0x30,
// WritingApp: 'https://github.com/shaka-project/shaka-packager version test'
0x57, 0x41, 0xbc,
0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68,
Expand Down
Loading