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

Issue #1047 (CMake port)

Co-authored-by: Joey Parrish <joeyparrish@users.noreply.github.com>
This commit is contained in:
Carlos Bentzen 2022-12-17 06:40:00 +01:00 committed by GitHub
parent e9bf0c6de4
commit 56d3304045
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 290 additions and 313 deletions

View File

@ -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://";
@ -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.

View File

@ -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.

View File

@ -10,3 +10,4 @@ add_subdirectory(origin)
add_subdirectory(replicator)
add_subdirectory(test)
add_subdirectory(codecs)
add_subdirectory(formats)

View File

@ -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"
@ -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;
@ -39,8 +40,8 @@ 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.
@ -48,8 +49,8 @@ class MediaParser {
/// @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
@ -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);

View File

@ -8,9 +8,6 @@
#include <memory>
#include <string>
#include "packager/base/callback.h"
#include "packager/base/time/time.h"
namespace shaka {
namespace media {
@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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 {

View File

@ -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 {

View File

@ -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,

View File

@ -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 {

View File

@ -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 {
@ -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

View File

@ -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;
@ -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

View File

@ -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 {

View File

@ -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 {
@ -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;
}

View File

@ -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 {

View File

@ -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,

View File

@ -9,9 +9,11 @@
#include <algorithm>
#include <limits>
#include "packager/base/logging.h"
#include "packager/third_party/libwebm/src/mkvmuxerutil.hpp"
#include "packager/third_party/libwebm/src/webmids.hpp"
#include "common/webmids.h"
#include "glog/logging.h"
#include "mkvmuxer/mkvmuxerutil.h"
using namespace mkvmuxer;
namespace shaka {
namespace media {
@ -20,18 +22,19 @@ namespace {
// Cluster, Cues, Info, Tracks.
const size_t kElementIdCount = 4u;
uint64_t EbmlMasterElementWithPayloadSize(mkvmuxer::MkvId id, uint64_t payload_size) {
uint64_t EbmlMasterElementWithPayloadSize(libwebm::MkvId id,
uint64_t payload_size) {
return EbmlMasterElementSize(id, payload_size) + payload_size;
}
uint64_t MaxSeekEntrySize() {
const uint64_t max_entry_payload_size =
EbmlElementSize(
mkvmuxer::kMkvSeekID,
libwebm::kMkvSeekID,
static_cast<mkvmuxer::uint64>(std::numeric_limits<uint32_t>::max())) +
EbmlElementSize(mkvmuxer::kMkvSeekPosition,
EbmlElementSize(libwebm::kMkvSeekPosition,
std::numeric_limits<mkvmuxer::uint64>::max());
return EbmlMasterElementWithPayloadSize(mkvmuxer::kMkvSeek,
return EbmlMasterElementWithPayloadSize(libwebm::kMkvSeek,
max_entry_payload_size);
}
@ -39,7 +42,7 @@ uint64_t MaxSeekEntrySize() {
SeekHead::SeekHead()
: total_void_size_(EbmlMasterElementWithPayloadSize(
mkvmuxer::kMkvSeekHead,
libwebm::kMkvSeekHead,
kElementIdCount * MaxSeekEntrySize())) {}
SeekHead::~SeekHead() {}
@ -52,17 +55,17 @@ bool SeekHead::Write(mkvmuxer::IMkvWriter* writer) {
uint64_t payload_size = 0;
for (const SeekHead::SeekElement& seek_element : seek_elements) {
payload_size +=
EbmlMasterElementWithPayloadSize(mkvmuxer::kMkvSeek, seek_element.size);
EbmlMasterElementWithPayloadSize(libwebm::kMkvSeek, seek_element.size);
}
const int64_t start_pos = writer->Position();
if (!WriteEbmlMasterElement(writer, mkvmuxer::kMkvSeekHead, payload_size))
if (!WriteEbmlMasterElement(writer, libwebm::kMkvSeekHead, payload_size))
return false;
for (const SeekHead::SeekElement& element : seek_elements) {
if (!WriteEbmlMasterElement(writer, mkvmuxer::kMkvSeek, element.size) ||
!WriteEbmlElement(writer, mkvmuxer::kMkvSeekID, element.id) ||
!WriteEbmlElement(writer, mkvmuxer::kMkvSeekPosition, element.position))
if (!WriteEbmlMasterElement(writer, libwebm::kMkvSeek, element.size) ||
!WriteEbmlElement(writer, libwebm::kMkvSeekID, element.id) ||
!WriteEbmlElement(writer, libwebm::kMkvSeekPosition, element.position))
return false;
}
@ -88,13 +91,13 @@ bool SeekHead::WriteVoid(mkvmuxer::IMkvWriter* writer) {
std::vector<SeekHead::SeekElement> SeekHead::CreateSeekElements() {
std::vector<SeekHead::SeekElement> seek_elements;
if (info_pos_ != 0)
seek_elements.emplace_back(mkvmuxer::kMkvInfo, info_pos_);
seek_elements.emplace_back(libwebm::kMkvInfo, info_pos_);
if (tracks_pos_ != 0)
seek_elements.emplace_back(mkvmuxer::kMkvTracks, tracks_pos_);
seek_elements.emplace_back(libwebm::kMkvTracks, tracks_pos_);
if (cues_pos_ != 0)
seek_elements.emplace_back(mkvmuxer::kMkvCues, cues_pos_);
seek_elements.emplace_back(libwebm::kMkvCues, cues_pos_);
if (cluster_pos_ != 0)
seek_elements.emplace_back(mkvmuxer::kMkvCluster, cluster_pos_);
seek_elements.emplace_back(libwebm::kMkvCluster, cluster_pos_);
DCHECK_LE(seek_elements.size(), kElementIdCount);
std::sort(seek_elements.begin(), seek_elements.end(),
@ -103,9 +106,8 @@ std::vector<SeekHead::SeekElement> SeekHead::CreateSeekElements() {
return left.position < right.position;
});
for (SeekHead::SeekElement& element : seek_elements) {
element.size =
EbmlElementSize(mkvmuxer::kMkvSeekID, element.id) +
EbmlElementSize(mkvmuxer::kMkvSeekPosition, element.position);
element.size = EbmlElementSize(libwebm::kMkvSeekID, element.id) +
EbmlElementSize(libwebm::kMkvSeekPosition, element.position);
}
return seek_elements;
}

View File

@ -8,9 +8,10 @@
#define PACKAGER_MEDIA_FORMATS_WEBM_SEEK_HEAD_H_
#include <stdint.h>
#include <vector>
#include "packager/third_party/libwebm/src/mkvmuxer.hpp"
#include "mkvmuxer/mkvmuxer.h"
namespace shaka {
namespace media {

View File

@ -6,7 +6,8 @@
#include "packager/media/formats/webm/segmenter.h"
#include "packager/base/time/time.h"
#include "common/webmids.h"
#include "mkvmuxer/mkvmuxerutil.h"
#include "packager/media/base/audio_stream_info.h"
#include "packager/media/base/media_handler.h"
#include "packager/media/base/media_sample.h"
@ -19,8 +20,6 @@
#include "packager/media/event/progress_listener.h"
#include "packager/media/formats/webm/encryptor.h"
#include "packager/media/formats/webm/webm_constants.h"
#include "packager/third_party/libwebm/src/mkvmuxerutil.hpp"
#include "packager/third_party/libwebm/src/webmids.hpp"
#include "packager/version/version.h"
using mkvmuxer::AudioTrack;
@ -194,8 +193,8 @@ Status Segmenter::AddSample(const MediaSample& source_sample) {
return Status::OK;
}
Status Segmenter::FinalizeSegment(int64_t start_timestamp,
int64_t duration_timestamp,
Status Segmenter::FinalizeSegment(int64_t /*start_timestamp*/,
int64_t /*duration_timestamp*/,
bool is_subsegment) {
if (is_subsegment)
new_subsegment_ = true;
@ -228,7 +227,7 @@ Status Segmenter::WriteSegmentHeader(uint64_t file_size, MkvWriter* writer) {
if (!WriteEbmlHeader(writer))
return error_status;
if (WriteID(writer, mkvmuxer::kMkvSegment) != 0)
if (WriteID(writer, libwebm::kMkvSegment) != 0)
return error_status;
const uint64_t segment_size_size = 8;

View File

@ -9,12 +9,11 @@
#include <memory>
#include "packager/base/optional.h"
#include "mkvmuxer/mkvmuxer.h"
#include "packager/media/base/range.h"
#include "packager/media/formats/webm/mkv_writer.h"
#include "packager/media/formats/webm/seek_head.h"
#include "packager/status.h"
#include "packager/third_party/libwebm/src/mkvmuxer.hpp"
#include "packager/status/status.h"
namespace shaka {
namespace media {

View File

@ -182,13 +182,13 @@ bool SegmentTestBase::ClusterParser::OnUInt(int id, int64_t val) {
return true;
}
bool SegmentTestBase::ClusterParser::OnFloat(int id, double val) {
bool SegmentTestBase::ClusterParser::OnFloat(int /*id*/, double /*val*/) {
return true;
}
bool SegmentTestBase::ClusterParser::OnBinary(int id,
const uint8_t* data,
int size) {
int /*size*/) {
if (in_cluster_ && (id == kWebMIdSimpleBlock || id == kWebMIdBlock)) {
if (cluster_timecode_ == -1) {
LOG(WARNING) << "Cluster timecode not yet available";
@ -201,7 +201,8 @@ bool SegmentTestBase::ClusterParser::OnBinary(int id,
return true;
}
bool SegmentTestBase::ClusterParser::OnString(int id, const std::string& str) {
bool SegmentTestBase::ClusterParser::OnString(int /*id*/,
const std::string& /*str*/) {
return true;
}

View File

@ -19,8 +19,8 @@
#include "packager/media/formats/webm/mkv_writer.h"
#include "packager/media/formats/webm/segmenter.h"
#include "packager/media/formats/webm/webm_parser.h"
#include "packager/status.h"
#include "packager/status_test_util.h"
#include "packager/status/status.h"
#include "packager/status/status_test_util.h"
namespace shaka {
namespace media {

View File

@ -6,9 +6,9 @@
#include "packager/media/formats/webm/single_segment_segmenter.h"
#include "mkvmuxer/mkvmuxer.h"
#include "packager/media/base/muxer_options.h"
#include "packager/media/event/muxer_listener.h"
#include "packager/third_party/libwebm/src/mkvmuxer.hpp"
namespace shaka {
namespace media {

View File

@ -7,11 +7,11 @@
#ifndef PACKAGER_MEDIA_FORMATS_WEBM_SINGLE_SEGMENT_SEGMENTER_H_
#define PACKAGER_MEDIA_FORMATS_WEBM_SINGLE_SEGMENT_SEGMENTER_H_
#include "packager/media/formats/webm/segmenter.h"
#include <memory>
#include "packager/media/formats/webm/mkv_writer.h"
#include "packager/status.h"
#include "packager/media/formats/webm/segmenter.h"
#include "packager/status/status.h"
namespace shaka {
namespace media {

View File

@ -59,9 +59,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,

View File

@ -4,7 +4,7 @@
#include "packager/media/formats/webm/tracks_builder.h"
#include "packager/base/logging.h"
#include "glog/logging.h"
#include "packager/media/formats/webm/webm_constants.h"
namespace shaka {

View File

@ -11,7 +11,7 @@
#include <string>
#include <vector>
#include "packager/base/macros.h"
#include "packager/macros.h"
namespace shaka {
namespace media {

View File

@ -8,13 +8,13 @@
#include <algorithm>
#include "common/webmids.h"
#include "mkvmuxer/mkvmuxer.h"
#include "mkvmuxer/mkvmuxerutil.h"
#include "packager/file/file_util.h"
#include "packager/media/base/media_sample.h"
#include "packager/media/base/muxer_options.h"
#include "packager/media/base/stream_info.h"
#include "packager/third_party/libwebm/src/mkvmuxer.hpp"
#include "packager/third_party/libwebm/src/mkvmuxerutil.hpp"
#include "packager/third_party/libwebm/src/webmids.hpp"
namespace shaka {
namespace media {
@ -141,7 +141,7 @@ bool TwoPassSingleSegmentSegmenter::CopyFileWithClusterRewrite(
File* source,
MkvWriter* dest,
uint64_t last_size) {
const int cluster_id_size = mkvmuxer::GetUIntSize(mkvmuxer::kMkvCluster);
const int cluster_id_size = mkvmuxer::GetUIntSize(libwebm::kMkvCluster);
const int cluster_size_size = 8; // The size of the Cluster size integer.
const int cluster_header_size = cluster_id_size + cluster_size_size;

View File

@ -12,7 +12,7 @@
#include "packager/media/formats/webm/mkv_writer.h"
#include "packager/media/formats/webm/single_segment_segmenter.h"
#include "packager/status.h"
#include "packager/status/status.h"
namespace shaka {
namespace media {

View File

@ -1,95 +0,0 @@
# Copyright 2015 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': 'webm',
'type': '<(component)',
'sources': [
'encryptor.cc',
'encryptor.h',
'mkv_writer.cc',
'mkv_writer.h',
'multi_segment_segmenter.cc',
'multi_segment_segmenter.h',
'seek_head.cc',
'seek_head.h',
'segmenter.cc',
'segmenter.h',
'single_segment_segmenter.cc',
'single_segment_segmenter.h',
'two_pass_single_segment_segmenter.cc',
'two_pass_single_segment_segmenter.h',
'webm_audio_client.cc',
'webm_audio_client.h',
'webm_cluster_parser.cc',
'webm_cluster_parser.h',
'webm_constants.cc',
'webm_constants.h',
'webm_content_encodings.cc',
'webm_content_encodings.h',
'webm_content_encodings_client.cc',
'webm_content_encodings_client.h',
'webm_crypto_helpers.cc',
'webm_crypto_helpers.h',
'webm_info_parser.cc',
'webm_info_parser.h',
'webm_parser.cc',
'webm_parser.h',
'webm_media_parser.cc',
'webm_media_parser.h',
'webm_muxer.cc',
'webm_muxer.h',
'webm_tracks_parser.cc',
'webm_tracks_parser.h',
'webm_video_client.cc',
'webm_video_client.h',
'webm_webvtt_parser.cc',
'webm_webvtt_parser.h'
],
'dependencies': [
'../../../third_party/boringssl/boringssl.gyp:boringssl',
'../../../third_party/gflags/gflags.gyp:gflags',
'../../../third_party/libwebm/libwebm.gyp:mkvmuxer',
'../../base/media_base.gyp:media_base',
'../../codecs/codecs.gyp:codecs'
],
},
{
'target_name': 'webm_unittest',
'type': '<(gtest_target_type)',
'sources': [
'cluster_builder.cc',
'cluster_builder.h',
'encrypted_segmenter_unittest.cc',
'encryptor_unittest.cc',
'multi_segment_segmenter_unittest.cc',
'segmenter_test_base.cc',
'segmenter_test_base.h',
'single_segment_segmenter_unittest.cc',
'tracks_builder.cc',
'tracks_builder.h',
'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',
],
'dependencies': [
'../../../file/file.gyp:file',
'../../../testing/gtest.gyp:gtest',
'../../../testing/gmock.gyp:gmock',
'../../../third_party/libwebm/libwebm.gyp:mkvmuxer',
'../../test/media_test.gyp:media_test_support',
'webm',
]
},
],
}

View File

@ -4,7 +4,7 @@
#include "packager/media/formats/webm/webm_audio_client.h"
#include "packager/base/logging.h"
#include "glog/logging.h"
#include "packager/media/formats/webm/webm_constants.h"
namespace {

View File

@ -7,8 +7,8 @@
#include <algorithm>
#include <vector>
#include "packager/base/logging.h"
#include "packager/base/sys_byteorder.h"
#include "absl/base/internal/endian.h"
#include "glog/logging.h"
#include "packager/media/base/decrypt_config.h"
#include "packager/media/base/timestamp.h"
#include "packager/media/codecs/vp8_parser.h"
@ -259,7 +259,7 @@ bool WebMClusterParser::OnBinary(int id, const uint8_t* data, int size) {
return true;
case kWebMIdBlockAdditional: {
uint64_t block_add_id = base::HostToNet64(block_add_id_);
uint64_t block_add_id = absl::big_endian::FromHost64(block_add_id_);
if (block_additional_data_) {
// TODO: Technically, more than 1 BlockAdditional is allowed as per
// matroska spec. But for now we don't have a use case to support
@ -310,7 +310,7 @@ bool WebMClusterParser::OnBlock(bool is_simple_block,
int size,
const uint8_t* additional,
int additional_size,
int64_t discard_padding,
int64_t /*discard_padding*/,
bool is_key_frame) {
DCHECK_GE(size, 0);
if (cluster_timecode_ == -1) {
@ -427,7 +427,7 @@ bool WebMClusterParser::OnBlock(bool is_simple_block,
? (block_duration * timecode_multiplier_)
: kNoTimestamp);
if (!init_cb_.is_null() && !initialized_) {
if (init_cb_ && !initialized_) {
std::vector<std::shared_ptr<StreamInfo>> streams;
if (audio_stream_info_)
streams.push_back(audio_stream_info_);
@ -470,11 +470,11 @@ bool WebMClusterParser::OnBlock(bool is_simple_block,
}
streams.push_back(video_stream_info_);
init_cb_.Run(streams);
init_cb_(streams);
initialized_ = true;
}
} else {
init_cb_.Run(streams);
init_cb_(streams);
initialized_ = true;
}
}
@ -553,7 +553,7 @@ bool WebMClusterParser::Track::ApplyDurationEstimateIfNeeded() {
// Don't use the applied duration as a future estimation (don't use
// EmitBufferHelp() here.)
if (!new_sample_cb_.Run(track_num_, last_added_buffer_missing_duration_))
if (!new_sample_cb_(track_num_, last_added_buffer_missing_duration_))
return false;
last_added_buffer_missing_duration_ = NULL;
return true;
@ -594,7 +594,7 @@ bool WebMClusterParser::Track::EmitBufferHelp(
}
}
return new_sample_cb_.Run(track_num_, buffer);
return new_sample_cb_(track_num_, buffer);
}
int64_t WebMClusterParser::Track::GetDurationEstimate() {

View File

@ -11,7 +11,6 @@
#include <set>
#include <string>
#include "packager/base/compiler_specific.h"
#include "packager/media/base/decryptor_source.h"
#include "packager/media/base/media_parser.h"
#include "packager/media/base/media_sample.h"
@ -140,7 +139,7 @@ class WebMClusterParser : public WebMParserClient {
/// Flush data currently in the parser and reset the parser so it can accept a
/// new cluster.
/// @return true on success, false otherwise.
bool Flush() WARN_UNUSED_RESULT;
[[nodiscard]] bool Flush();
/// Parses a WebM cluster element in |buf|.
/// @return -1 if the parse fails.

View File

@ -9,25 +9,26 @@
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <string>
#include <vector>
#include "packager/base/bind.h"
#include "packager/base/logging.h"
#include "packager/base/strings/string_number_conversions.h"
#include "absl/strings/str_format.h"
#include "glog/logging.h"
#include "packager/media/base/decrypt_config.h"
#include "packager/media/base/raw_key_source.h"
#include "packager/media/base/timestamp.h"
#include "packager/media/formats/webm/cluster_builder.h"
#include "packager/media/formats/webm/webm_constants.h"
using ::testing::_;
using ::testing::DoAll;
using ::testing::HasSubstr;
using ::testing::InSequence;
using ::testing::Mock;
using ::testing::Return;
using ::testing::SetArgPointee;
using ::testing::StrictMock;
using ::testing::Mock;
using ::testing::_;
namespace shaka {
namespace media {
@ -39,13 +40,13 @@ typedef std::map<uint32_t, BufferQueue> TextBufferQueueMap;
MATCHER_P(OpusPacketDurationTooHigh, actual_duration_ms, "") {
return CONTAINS_STRING(
arg, "Warning, demuxed Opus packet with encoded duration: " +
base::IntToString(actual_duration_ms) +
absl::StrFormat("%d", actual_duration_ms) +
"ms. Should be no greater than 120ms.");
}
MATCHER_P(WebMSimpleBlockDurationEstimated, estimated_duration_ms, "") {
return CONTAINS_STRING(arg, "Estimating WebM block duration to be " +
base::IntToString(estimated_duration_ms) +
absl::StrFormat("%d", estimated_duration_ms) +
"ms for the last (Simple)Block in the "
"Cluster for this Track. Use BlockGroups "
"with BlockDurations at the end of each "
@ -57,9 +58,9 @@ MATCHER_P2(WebMBlockDurationMismatchesOpusDuration,
opus_duration_ms,
"") {
return CONTAINS_STRING(
arg, "BlockDuration (" + base::IntToString(block_duration_ms) +
arg, "BlockDuration (" + absl::StrFormat("%d", block_duration_ms) +
"ms) differs significantly from encoded duration (" +
base::IntToString(opus_duration_ms) + "ms).");
absl::StrFormat("%d", opus_duration_ms) + "ms).");
}
namespace {
@ -184,7 +185,7 @@ class MockKeySource : public RawKeySource {
Status(const std::vector<uint8_t>& key_id, EncryptionKey* key));
};
std::unique_ptr<Cluster> CreateCluster(int timecode,
std::unique_ptr<Cluster> CreateCluster(int /*timecode*/,
const BlockInfo* block_info,
int block_count) {
ClusterBuilder cb;
@ -201,7 +202,7 @@ std::unique_ptr<Cluster> CreateCluster(int timecode,
data_length = block_info[i].data_length;
} else {
data = kDefaultBlockData;
data_length = arraysize(kDefaultBlockData);
data_length = std::size(kDefaultBlockData);
}
if (block_info[i].use_simple_block) {
@ -404,6 +405,7 @@ class WebMClusterParserTest : public testing::Test {
const std::string& audio_encryption_key_id,
const std::string& video_encryption_key_id, const Codec audio_codec,
const Codec video_codec, const MediaParser::InitCB& init_cb) {
using namespace std::placeholders;
audio_stream_info_->set_codec(audio_codec);
video_stream_info_->set_codec(video_codec);
return new WebMClusterParser(
@ -411,8 +413,7 @@ class WebMClusterParserTest : public testing::Test {
VPCodecConfigurationRecord(), audio_default_duration,
video_default_duration, text_tracks, ignored_tracks,
audio_encryption_key_id, video_encryption_key_id,
base::Bind(&WebMClusterParserTest::NewSampleEvent,
base::Unretained(this)),
std::bind(&WebMClusterParserTest::NewSampleEvent, this, _1, _2),
init_cb, &mock_key_source_);
}
@ -456,10 +457,11 @@ class WebMClusterParserTest : public testing::Test {
// Create a parser for test with custom video codec, also check for init
// events.
WebMClusterParser* CreateParserWithCodec(const Codec video_codec) {
using namespace std::placeholders;
return CreateParserHelper(
kNoTimestamp, kNoTimestamp, TextTracks(), std::set<int64_t>(),
std::string(), std::string(), kUnknownCodec, video_codec,
base::Bind(&WebMClusterParserTest::InitEvent, base::Unretained(this)));
std::bind(&WebMClusterParserTest::InitEvent, this, _1));
}
bool VerifyBuffers(const BlockInfo* block_info, int block_count) {
@ -542,8 +544,8 @@ TEST_F(WebMClusterParserTest, TracksWithSampleMissingDuration) {
7, // 4th audio ready, 5th audio held back with no duration
};
ASSERT_EQ(arraysize(kBlockInfo), arraysize(kExpectedBuffersOnPartialCluster));
int block_count = arraysize(kBlockInfo);
ASSERT_EQ(std::size(kBlockInfo), std::size(kExpectedBuffersOnPartialCluster));
int block_count = std::size(kBlockInfo);
// Iteratively create a cluster containing the first N+1 blocks and parse the
// cluster. Verify that the corresponding entry in
@ -572,7 +574,7 @@ TEST_F(WebMClusterParserTest, TracksWithSampleMissingDuration) {
TEST_F(WebMClusterParserTest, Reset) {
InSequence s;
int block_count = arraysize(kDefaultBlockInfo);
int block_count = std::size(kDefaultBlockInfo);
std::unique_ptr<Cluster> cluster(
CreateCluster(0, kDefaultBlockInfo, block_count));
@ -592,7 +594,7 @@ TEST_F(WebMClusterParserTest, Reset) {
}
TEST_F(WebMClusterParserTest, ParseClusterWithSingleCall) {
int block_count = arraysize(kDefaultBlockInfo);
int block_count = std::size(kDefaultBlockInfo);
std::unique_ptr<Cluster> cluster(
CreateCluster(0, kDefaultBlockInfo, block_count));
@ -602,7 +604,7 @@ TEST_F(WebMClusterParserTest, ParseClusterWithSingleCall) {
}
TEST_F(WebMClusterParserTest, ParseClusterWithMultipleCalls) {
int block_count = arraysize(kDefaultBlockInfo);
int block_count = std::size(kDefaultBlockInfo);
std::unique_ptr<Cluster> cluster(
CreateCluster(0, kDefaultBlockInfo, block_count));
@ -645,7 +647,7 @@ TEST_F(WebMClusterParserTest, ParseBlockGroup) {
{kAudioTrackNum, 0, 23, false, NULL, 0, true},
{kVideoTrackNum, 33, 34, false, NULL, 0, true},
};
int block_count = arraysize(kBlockInfo);
int block_count = std::size(kBlockInfo);
const uint8_t kClusterData[] = {
0x1F, 0x43, 0xB6, 0x75, 0x9B, // Cluster(size=27)
@ -659,7 +661,7 @@ TEST_F(WebMClusterParserTest, ParseBlockGroup) {
0xA1, 0x85, 0x82, 0x00, 0x21, 0x00, 0x55, // Block(size=5, track=2, ts=33)
0x9B, 0x81, 0x22, // BlockDuration(size=1, value=34)
};
const int kClusterSize = arraysize(kClusterData);
const int kClusterSize = std::size(kClusterData);
int result = parser_->Parse(kClusterData, kClusterSize);
EXPECT_EQ(kClusterSize, result);
@ -674,7 +676,7 @@ TEST_F(WebMClusterParserTest, ParseSimpleBlockAndBlockGroupMixture) {
{kAudioTrackNum, 46, 23, false, NULL, 0, false},
{kVideoTrackNum, 67, 33, false, NULL, 0, false},
};
int block_count = arraysize(kBlockInfo);
int block_count = std::size(kBlockInfo);
std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
int result = parser_->Parse(cluster->data(), cluster->size());
@ -696,7 +698,7 @@ TEST_F(WebMClusterParserTest, IgnoredTracks) {
{kAudioTrackNum, 46, 23, true, NULL, 0, false},
{kVideoTrackNum, 67, 34, true, NULL, 0, false},
};
int input_block_count = arraysize(kInputBlockInfo);
int input_block_count = std::size(kInputBlockInfo);
const BlockInfo kOutputBlockInfo[] = {
{kAudioTrackNum, 0, 23, true, NULL, 0, false},
@ -705,7 +707,7 @@ TEST_F(WebMClusterParserTest, IgnoredTracks) {
{kAudioTrackNum, 46, 23, true, NULL, 0, false},
{kVideoTrackNum, 67, 34, true, NULL, 0, false},
};
int output_block_count = arraysize(kOutputBlockInfo);
int output_block_count = std::size(kOutputBlockInfo);
std::unique_ptr<Cluster> cluster(
CreateCluster(0, kInputBlockInfo, input_block_count));
@ -735,7 +737,7 @@ TEST_F(WebMClusterParserTest, ParseTextTracks) {
{kTextTrackNum, 55, 44, false, NULL, 0, true},
{kVideoTrackNum, 67, 34, true, NULL, 0, false},
};
int input_block_count = arraysize(kInputBlockInfo);
int input_block_count = std::size(kInputBlockInfo);
std::unique_ptr<Cluster> cluster(
CreateCluster(0, kInputBlockInfo, input_block_count));
@ -759,7 +761,7 @@ TEST_F(WebMClusterParserTest, TextTracksSimpleBlock) {
const BlockInfo kInputBlockInfo[] = {
{kTextTrackNum, 33, 42, true, NULL, 0, false},
};
int input_block_count = arraysize(kInputBlockInfo);
int input_block_count = std::size(kInputBlockInfo);
std::unique_ptr<Cluster> cluster(
CreateCluster(0, kInputBlockInfo, input_block_count));
@ -795,7 +797,7 @@ TEST_F(WebMClusterParserTest, ParseMultipleTextTracks) {
{kVideoTrackNum, 67, 34, true, NULL, 0, false},
{kSubtitleTextTrackNum, 67, 33, false, NULL, 0, false},
};
int input_block_count = arraysize(kInputBlockInfo);
int input_block_count = std::size(kInputBlockInfo);
std::unique_ptr<Cluster> cluster(
CreateCluster(0, kInputBlockInfo, input_block_count));
@ -815,7 +817,7 @@ TEST_F(WebMClusterParserTest, ParseMultipleTextTracks) {
TEST_F(WebMClusterParserTest, ParseVP8) {
std::unique_ptr<Cluster> cluster(
CreateCluster(kVP8Frame, arraysize(kVP8Frame)));
CreateCluster(kVP8Frame, std::size(kVP8Frame)));
parser_.reset(CreateParserWithCodec(kCodecVP8));
EXPECT_EQ(cluster->size(), parser_->Parse(cluster->data(), cluster->size()));
@ -829,7 +831,7 @@ TEST_F(WebMClusterParserTest, ParseVP8) {
TEST_F(WebMClusterParserTest, ParseVP9) {
std::unique_ptr<Cluster> cluster(
CreateCluster(kVP9Frame, arraysize(kVP9Frame)));
CreateCluster(kVP9Frame, std::size(kVP9Frame)));
parser_.reset(CreateParserWithCodec(kCodecVP9));
EXPECT_EQ(cluster->size(), parser_->Parse(cluster->data(), cluster->size()));
@ -845,14 +847,14 @@ TEST_F(WebMClusterParserTest, ParseEncryptedBlock) {
const std::string video_key_id("video_key_id");
EncryptionKey encryption_key;
encryption_key.key.assign(kMockKey, kMockKey + arraysize(kMockKey));
encryption_key.key.assign(kMockKey, kMockKey + std::size(kMockKey));
EXPECT_CALL(
mock_key_source_,
GetKey(std::vector<uint8_t>(video_key_id.begin(), video_key_id.end()), _))
.WillOnce(DoAll(SetArgPointee<1>(encryption_key), Return(Status::OK)));
std::unique_ptr<Cluster> cluster(
CreateCluster(kEncryptedFrame, arraysize(kEncryptedFrame)));
CreateCluster(kEncryptedFrame, std::size(kEncryptedFrame)));
parser_.reset(CreateParserWithKeyIdsAndCodec(std::string(), video_key_id,
kUnknownCodec));
@ -864,7 +866,7 @@ TEST_F(WebMClusterParserTest, ParseEncryptedBlock) {
std::shared_ptr<MediaSample> buffer = video_buffers_[0];
EXPECT_EQ(std::vector<uint8_t>(
kExpectedDecryptedFrame,
kExpectedDecryptedFrame + arraysize(kExpectedDecryptedFrame)),
kExpectedDecryptedFrame + std::size(kExpectedDecryptedFrame)),
std::vector<uint8_t>(buffer->data(),
buffer->data() + buffer->data_size()));
}
@ -873,7 +875,7 @@ TEST_F(WebMClusterParserTest, ParseEncryptedBlockGetKeyFailed) {
EXPECT_CALL(mock_key_source_, GetKey(_, _)).WillOnce(Return(Status::UNKNOWN));
std::unique_ptr<Cluster> cluster(
CreateCluster(kEncryptedFrame, arraysize(kEncryptedFrame)));
CreateCluster(kEncryptedFrame, std::size(kEncryptedFrame)));
parser_.reset(CreateParserWithKeyIdsAndCodec(std::string(), "video_key_id",
kUnknownCodec));
@ -884,7 +886,7 @@ TEST_F(WebMClusterParserTest, ParseEncryptedBlockGetKeyFailed) {
TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) {
std::unique_ptr<Cluster> cluster(
CreateCluster(kEncryptedFrame, arraysize(kEncryptedFrame) - 2));
CreateCluster(kEncryptedFrame, std::size(kEncryptedFrame) - 2));
parser_.reset(CreateParserWithKeyIdsAndCodec(std::string(), "video_key_id",
kUnknownCodec));
@ -894,7 +896,7 @@ TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) {
TEST_F(WebMClusterParserTest, ParseClearFrameInEncryptedTrack) {
std::unique_ptr<Cluster> cluster(CreateCluster(
kClearFrameInEncryptedTrack, arraysize(kClearFrameInEncryptedTrack)));
kClearFrameInEncryptedTrack, std::size(kClearFrameInEncryptedTrack)));
parser_.reset(CreateParserWithKeyIdsAndCodec(std::string(), "video_key_id",
kUnknownCodec));
@ -906,7 +908,7 @@ TEST_F(WebMClusterParserTest, ParseClearFrameInEncryptedTrack) {
std::shared_ptr<MediaSample> buffer = video_buffers_[0];
EXPECT_EQ(std::vector<uint8_t>(
kExpectedClearFrame,
kExpectedClearFrame + arraysize(kExpectedClearFrame)),
kExpectedClearFrame + std::size(kExpectedClearFrame)),
std::vector<uint8_t>(buffer->data(),
buffer->data() + buffer->data_size()));
}
@ -916,7 +918,7 @@ TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) {
0x1F, 0x43, 0xB6, 0x75, 0x80, // CLUSTER (size = 0)
};
EXPECT_EQ(-1, parser_->Parse(kBuffer, arraysize(kBuffer)));
EXPECT_EQ(-1, parser_->Parse(kBuffer, std::size(kBuffer)));
// Verify init event not called.
ASSERT_EQ(0u, streams_from_init_event_.size());
}
@ -927,7 +929,7 @@ TEST_F(WebMClusterParserTest, ParseInvalidUnknownButActuallyZeroSizedCluster) {
0x1F, 0x43, 0xB6, 0x75, 0x85, // CLUSTER (size = 5)
};
EXPECT_EQ(-1, parser_->Parse(kBuffer, arraysize(kBuffer)));
EXPECT_EQ(-1, parser_->Parse(kBuffer, std::size(kBuffer)));
}
TEST_F(WebMClusterParserTest, ParseInvalidTextBlockGroupWithoutDuration) {
@ -944,7 +946,7 @@ TEST_F(WebMClusterParserTest, ParseInvalidTextBlockGroupWithoutDuration) {
const BlockInfo kBlockInfo[] = {
{kTextTrackNum, 33, -42, false, NULL, 0, false},
};
int block_count = arraysize(kBlockInfo);
int block_count = std::size(kBlockInfo);
std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
int result = parser_->Parse(cluster->data(), cluster->size());
EXPECT_LT(result, 0);
@ -970,7 +972,7 @@ TEST_F(WebMClusterParserTest, ParseWithDefaultDurationsSimpleBlocks) {
false},
};
int block_count = arraysize(kBlockInfo);
int block_count = std::size(kBlockInfo);
std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
// Now parse a whole cluster to verify that all the blocks will get parsed
@ -1004,7 +1006,7 @@ TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsSimpleBlocks) {
{kVideoTrackNum, 100, 35, true, NULL, 0, false},
};
int block_count1 = arraysize(kBlockInfo1);
int block_count1 = std::size(kBlockInfo1);
std::unique_ptr<Cluster> cluster1(
CreateCluster(0, kBlockInfo1, block_count1));
@ -1026,7 +1028,7 @@ TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsSimpleBlocks) {
{kVideoTrackNum, 135, kExpectedVideoEstimationInMs, true, NULL, 0, false},
};
int block_count2 = arraysize(kBlockInfo2);
int block_count2 = std::size(kBlockInfo2);
std::unique_ptr<Cluster> cluster2(
CreateCluster(0, kBlockInfo2, block_count2));
EXPECT_EQ(cluster2->size(),
@ -1058,7 +1060,7 @@ TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsBlockGroups) {
{kVideoTrackNum, 100, -35, false, NULL, 0, false},
};
int block_count1 = arraysize(kBlockInfo1);
int block_count1 = std::size(kBlockInfo1);
std::unique_ptr<Cluster> cluster1(
CreateCluster(0, kBlockInfo1, block_count1));
@ -1082,7 +1084,7 @@ TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsBlockGroups) {
false},
};
int block_count2 = arraysize(kBlockInfo2);
int block_count2 = std::size(kBlockInfo2);
std::unique_ptr<Cluster> cluster2(
CreateCluster(0, kBlockInfo2, block_count2));
EXPECT_EQ(cluster2->size(),
@ -1105,7 +1107,7 @@ TEST_F(WebMClusterParserTest,
true, NULL, 0, false},
};
int block_count = arraysize(kBlockInfo);
int block_count = std::size(kBlockInfo);
std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
int result = parser_->Parse(cluster->data(), cluster->size());
EXPECT_EQ(cluster->size(), result);
@ -1124,7 +1126,7 @@ TEST_F(WebMClusterParserTest,
false},
};
int block_count = arraysize(kBlockInfo);
int block_count = std::size(kBlockInfo);
std::unique_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count));
int result = parser_->Parse(cluster->data(), cluster->size());
EXPECT_EQ(cluster->size(), result);

View File

@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "packager/base/logging.h"
#include "packager/media/formats/webm/webm_content_encodings.h"
#include "glog/logging.h"
namespace shaka {
namespace media {

View File

@ -4,7 +4,7 @@
#include "packager/media/formats/webm/webm_content_encodings_client.h"
#include "packager/base/logging.h"
#include "glog/logging.h"
#include "packager/media/formats/webm/webm_constants.h"
namespace shaka {

View File

@ -8,7 +8,6 @@
#include <memory>
#include <vector>
#include "packager/base/callback.h"
#include "packager/media/formats/webm/webm_content_encodings.h"
#include "packager/media/formats/webm/webm_parser.h"

View File

@ -8,7 +8,7 @@
#include <string>
#include "packager/base/strings/string_number_conversions.h"
#include "absl/strings/numbers.h"
#include "packager/media/formats/webm/webm_constants.h"
#include "packager/media/formats/webm/webm_parser.h"

View File

@ -4,8 +4,8 @@
#include "packager/media/formats/webm/webm_crypto_helpers.h"
#include "packager/base/logging.h"
#include "packager/base/sys_byteorder.h"
#include "absl/base/internal/endian.h"
#include "glog/logging.h"
#include "packager/media/base/buffer_reader.h"
#include "packager/media/formats/webm/webm_constants.h"

View File

@ -4,7 +4,9 @@
#include "packager/media/formats/webm/webm_info_parser.h"
#include "packager/base/logging.h"
#include <ctime>
#include "glog/logging.h"
#include "packager/media/formats/webm/webm_constants.h"
namespace shaka {
@ -35,7 +37,9 @@ int WebMInfoParser::Parse(const uint8_t* buf, int size) {
return parser.IsParsingComplete() ? result : 0;
}
WebMParserClient* WebMInfoParser::OnListStart(int id) { return this; }
WebMParserClient* WebMInfoParser::OnListStart(int /*id*/) {
return this;
}
bool WebMInfoParser::OnListEnd(int id) {
if (id == kWebMIdInfo && timecode_scale_ == -1) {
@ -83,21 +87,22 @@ bool WebMInfoParser::OnBinary(int id, const uint8_t* data, int size) {
for (int i = 0; i < size; ++i)
date_in_nanoseconds = (date_in_nanoseconds << 8) | data[i];
base::Time::Exploded exploded_epoch;
exploded_epoch.year = 2001;
exploded_epoch.month = 1;
exploded_epoch.day_of_month = 1;
exploded_epoch.hour = 0;
exploded_epoch.minute = 0;
exploded_epoch.second = 0;
exploded_epoch.millisecond = 0;
date_utc_ = base::Time::FromUTCExploded(exploded_epoch) +
base::TimeDelta::FromMicroseconds(date_in_nanoseconds / 1000);
std::tm exploded_epoch;
exploded_epoch.tm_year = 2001;
exploded_epoch.tm_mon = 1;
exploded_epoch.tm_mday = 1;
exploded_epoch.tm_hour = 0;
exploded_epoch.tm_min = 0;
exploded_epoch.tm_sec = 0;
date_utc_ =
std::chrono::system_clock::from_time_t(std::mktime(&exploded_epoch)) +
std::chrono::microseconds(date_in_nanoseconds / 1000);
}
return true;
}
bool WebMInfoParser::OnString(int id, const std::string& str) {
bool WebMInfoParser::OnString(int /*id*/, const std::string& /*str*/) {
return true;
}

View File

@ -5,8 +5,8 @@
#ifndef PACKAGER_MEDIA_FORMATS_WEBM_WEBM_INFO_PARSER_H_
#define PACKAGER_MEDIA_FORMATS_WEBM_WEBM_INFO_PARSER_H_
#include "packager/base/compiler_specific.h"
#include "packager/base/time/time.h"
#include <chrono>
#include "packager/media/formats/webm/webm_parser.h"
namespace shaka {
@ -26,7 +26,7 @@ class WebMInfoParser : public WebMParserClient {
int64_t timecode_scale() const { return timecode_scale_; }
double duration() const { return duration_; }
base::Time date_utc() const { return date_utc_; }
std::chrono::system_clock::time_point date_utc() const { return date_utc_; }
private:
// WebMParserClient methods
@ -39,7 +39,7 @@ class WebMInfoParser : public WebMParserClient {
int64_t timecode_scale_;
double duration_;
base::Time date_utc_;
std::chrono::system_clock::time_point date_utc_;
DISALLOW_COPY_AND_ASSIGN(WebMInfoParser);
};

View File

@ -6,9 +6,7 @@
#include <string>
#include "packager/base/callback.h"
#include "packager/base/callback_helpers.h"
#include "packager/base/logging.h"
#include "glog/logging.h"
#include "packager/media/base/buffer_writer.h"
#include "packager/media/base/timestamp.h"
#include "packager/media/formats/webm/webm_cluster_parser.h"
@ -27,12 +25,12 @@ WebMMediaParser::~WebMMediaParser() {}
void WebMMediaParser::Init(const InitCB& init_cb,
const NewMediaSampleCB& new_media_sample_cb,
const NewTextSampleCB& new_text_sample_cb,
const NewTextSampleCB&,
KeySource* decryption_key_source) {
DCHECK_EQ(state_, kWaitingForInit);
DCHECK(init_cb_.is_null());
DCHECK(!init_cb.is_null());
DCHECK(!new_media_sample_cb.is_null());
DCHECK(!init_cb_);
DCHECK(init_cb);
DCHECK(new_media_sample_cb);
ChangeState(kParsingHeaders);
init_cb_ = init_cb;

View File

@ -5,8 +5,6 @@
#ifndef PACKAGER_MEDIA_FORMATS_WEBM_WEBM_MEDIA_PARSER_H_
#define PACKAGER_MEDIA_FORMATS_WEBM_WEBM_MEDIA_PARSER_H_
#include "packager/base/callback_forward.h"
#include "packager/base/compiler_specific.h"
#include "packager/media/base/byte_queue.h"
#include "packager/media/base/media_parser.h"
@ -26,8 +24,8 @@ class WebMMediaParser : public MediaParser {
const NewMediaSampleCB& new_media_sample_cb,
const NewTextSampleCB& new_text_sample_cb,
KeySource* decryption_key_source) override;
bool Flush() override WARN_UNUSED_RESULT;
bool Parse(const uint8_t* buf, int size) override WARN_UNUSED_RESULT;
[[nodiscard]] bool Flush() override;
[[nodiscard]] bool Parse(const uint8_t* buf, int size) override;
/// @}
private:

View File

@ -13,8 +13,7 @@
#include <limits>
#include "packager/base/logging.h"
#include "packager/base/numerics/safe_conversions.h"
#include "glog/logging.h"
#include "packager/media/formats/webm/webm_constants.h"
namespace shaka {
@ -385,7 +384,7 @@ static const ElementIdInfo kSimpleTagIds[] = {
};
#define LIST_ELEMENT_INFO(id, level, id_info) \
{ (id), (level), (id_info), arraysize(id_info) }
{ (id), (level), (id_info), std::size(id_info) }
static const ListElementInfo kListElementInfo[] = {
LIST_ELEMENT_INFO(kWebMIdCluster, 1, kClusterIds),
@ -557,7 +556,7 @@ static ElementType FindIdType(int id,
// Finds ListElementInfo for a specific ID.
static const ListElementInfo* FindListInfo(int id) {
for (size_t i = 0; i < arraysize(kListElementInfo); ++i) {
for (size_t i = 0; i < std::size(kListElementInfo); ++i) {
if (id == kListElementInfo[i].id_)
return &kListElementInfo[i];
}
@ -588,7 +587,7 @@ static int ParseUInt(const uint8_t* buf,
// We use int64_t in place of uint64_t everywhere for convenience. See this
// bug
// for more details: http://crbug.com/366750#c3
if (!base::IsValueInRangeForNumericType<int64_t>(value))
if (value > static_cast<uint64_t>(std::numeric_limits<int64_t>::max()))
return -1;
if (!client->OnUInt(id, value))
@ -705,22 +704,22 @@ bool WebMParserClient::OnListEnd(int id) {
return false;
}
bool WebMParserClient::OnUInt(int id, int64_t val) {
bool WebMParserClient::OnUInt(int id, int64_t /*val*/) {
DVLOG(1) << "Unexpected unsigned integer element with ID " << std::hex << id;
return false;
}
bool WebMParserClient::OnFloat(int id, double val) {
bool WebMParserClient::OnFloat(int id, double /*val*/) {
DVLOG(1) << "Unexpected float element with ID " << std::hex << id;
return false;
}
bool WebMParserClient::OnBinary(int id, const uint8_t* data, int size) {
bool WebMParserClient::OnBinary(int id, const uint8_t* /*data*/, int /*size*/) {
DVLOG(1) << "Unexpected binary element with ID " << std::hex << id;
return false;
}
bool WebMParserClient::OnString(int id, const std::string& str) {
bool WebMParserClient::OnString(int id, const std::string& /*str*/) {
DVLOG(1) << "Unexpected string element with ID " << std::hex << id;
return false;
}
@ -985,7 +984,7 @@ bool WebMListParser::IsSiblingOrAncestor(int id_a, int id_b) const {
if (id_a == kWebMIdCluster) {
// kWebMIdCluster siblings.
for (size_t i = 0; i < arraysize(kSegmentIds); i++) {
for (size_t i = 0; i < std::size(kSegmentIds); i++) {
if (kSegmentIds[i].id_ == id_b)
return true;
}

View File

@ -10,7 +10,7 @@
#include <string>
#include <vector>
#include "packager/base/macros.h"
#include "packager/macros.h"
namespace shaka {
namespace media {

View File

@ -342,7 +342,7 @@ TEST_F(WebMParserTest, ReservedIds) {
const uint8_t* kBuffers[] = {k1ByteReservedId, k2ByteReservedId,
k3ByteReservedId, k4ByteReservedId};
for (size_t i = 0; i < arraysize(kBuffers); i++) {
for (size_t i = 0; i < std::size(kBuffers); i++) {
int id;
int64_t element_size;
int buffer_size = 2 + static_cast<int>(i);
@ -370,7 +370,7 @@ TEST_F(WebMParserTest, ReservedSizes) {
k5ByteReservedSize, k6ByteReservedSize,
k7ByteReservedSize, k8ByteReservedSize};
for (size_t i = 0; i < arraysize(kBuffers); i++) {
for (size_t i = 0; i < std::size(kBuffers); i++) {
int id;
int64_t element_size;
int buffer_size = 2 + static_cast<int>(i);

View File

@ -4,9 +4,8 @@
#include "packager/media/formats/webm/webm_tracks_parser.h"
#include "packager/base/logging.h"
#include "packager/base/strings/string_number_conversions.h"
#include "packager/base/strings/string_util.h"
#include "absl/strings/str_format.h"
#include "glog/logging.h"
#include "packager/media/base/timestamp.h"
#include "packager/media/formats/webm/webm_constants.h"
#include "packager/media/formats/webm/webm_content_encodings.h"
@ -251,7 +250,7 @@ bool WebMTracksParser::OnListEnd(int id) {
DLOG(INFO) << "Ignoring text track " << track_num_;
ignored_tracks_.insert(track_num_);
} else {
std::string track_num = base::Int64ToString(track_num_);
std::string track_num = absl::StrFormat("%d", track_num_);
text_tracks_[track_num_] = TextTrackConfig(
text_track_kind, track_name_, track_language_, track_num);
}
@ -309,7 +308,7 @@ bool WebMTracksParser::OnUInt(int id, int64_t val) {
return true;
}
bool WebMTracksParser::OnFloat(int id, double val) {
bool WebMTracksParser::OnFloat(int /*id*/, double /*val*/) {
return true;
}

View File

@ -11,7 +11,6 @@
#include <string>
#include <vector>
#include "packager/base/time/time.h"
#include "packager/media/base/audio_stream_info.h"
#include "packager/media/base/text_track_config.h"
#include "packager/media/base/video_stream_info.h"

View File

@ -7,7 +7,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "packager/base/logging.h"
#include "glog/logging.h"
#include "packager/media/base/timestamp.h"
#include "packager/media/formats/webm/tracks_builder.h"
#include "packager/media/formats/webm/webm_constants.h"

View File

@ -4,7 +4,7 @@
#include "packager/media/formats/webm/webm_video_client.h"
#include "packager/base/logging.h"
#include "glog/logging.h"
#include "packager/media/base/video_util.h"
#include "packager/media/codecs/av1_codec_configuration_record.h"
#include "packager/media/codecs/vp_codec_configuration_record.h"
@ -254,12 +254,14 @@ bool WebMVideoClient::OnUInt(int id, int64_t val) {
return true;
}
bool WebMVideoClient::OnBinary(int id, const uint8_t* data, int size) {
bool WebMVideoClient::OnBinary(int /*id*/,
const uint8_t* /*data*/,
int /*size*/) {
// Accept binary fields we don't care about for now.
return true;
}
bool WebMVideoClient::OnFloat(int id, double val) {
bool WebMVideoClient::OnFloat(int /*id*/, double /*val*/) {
// Accept float fields we don't care about for now.
return true;
}

View File

@ -9,7 +9,7 @@
#include <string>
#include "packager/base/macros.h"
#include "packager/macros.h"
namespace shaka {
namespace media {

View File

@ -15,6 +15,10 @@ set(ENABLE_WEBMINFO OFF)
set(ENABLE_TESTS OFF)
set(ENABLE_IWYU OFF)
set(ENABLE_WEBM_PARSER OFF)
set(MSVC_RUNTIME "dll")
# With these set in scope of this folder, load the library's own CMakeLists.txt.
add_subdirectory(source)
# libwebm headers have relative include paths that only get resolved with this.
target_include_directories(webm PUBLIC source)