2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2015 Google LLC. All rights reserved.
|
2015-12-22 00:33:55 +00:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_FORMATS_WEBM_SEGMENTER_TEST_UTILS_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_WEBM_SEGMENTER_TEST_UTILS_H_
|
2015-12-22 00:33:55 +00:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/file/file_closer.h>
|
|
|
|
#include <packager/file/file_test_util.h>
|
|
|
|
#include <packager/file/memory_file.h>
|
|
|
|
#include <packager/media/base/media_sample.h>
|
|
|
|
#include <packager/media/base/muxer_options.h>
|
|
|
|
#include <packager/media/base/stream_info.h>
|
|
|
|
#include <packager/media/base/video_stream_info.h>
|
|
|
|
#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/status.h>
|
|
|
|
#include <packager/status/status_test_util.h>
|
2015-12-22 00:33:55 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2015-12-22 00:33:55 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class SegmentTestBase : public ::testing::Test {
|
2016-01-07 22:50:40 +00:00
|
|
|
public:
|
|
|
|
enum KeyFrameFlag {
|
|
|
|
kKeyFrame,
|
|
|
|
kNotKeyFrame,
|
|
|
|
};
|
|
|
|
enum SideDataFlag {
|
|
|
|
kGenerateSideData,
|
|
|
|
kNoSideData,
|
|
|
|
};
|
|
|
|
|
2015-12-22 00:33:55 +00:00
|
|
|
protected:
|
|
|
|
SegmentTestBase();
|
|
|
|
|
|
|
|
void SetUp() override;
|
|
|
|
void TearDown() override;
|
|
|
|
|
|
|
|
/// Creates a Segmenter of the given type and initializes it.
|
|
|
|
template <typename S>
|
2016-08-17 17:41:40 +00:00
|
|
|
void CreateAndInitializeSegmenter(
|
|
|
|
const MuxerOptions& options,
|
2017-09-12 17:24:24 +00:00
|
|
|
const StreamInfo& info,
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<webm::Segmenter>* result) const {
|
|
|
|
std::unique_ptr<S> segmenter(new S(options));
|
2015-12-22 00:33:55 +00:00
|
|
|
|
2017-03-11 02:49:55 +00:00
|
|
|
ASSERT_OK(segmenter->Initialize(info, nullptr /* progress_listener */,
|
|
|
|
nullptr /* muxer_listener */));
|
2016-08-17 17:41:40 +00:00
|
|
|
*result = std::move(segmenter);
|
2015-12-22 00:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a new media sample.
|
2017-01-24 00:55:02 +00:00
|
|
|
std::shared_ptr<MediaSample> CreateSample(KeyFrameFlag key_frame_flag,
|
2021-08-04 18:56:44 +00:00
|
|
|
int64_t duration,
|
2017-01-24 00:55:02 +00:00
|
|
|
SideDataFlag side_data_flag);
|
2015-12-22 00:33:55 +00:00
|
|
|
/// Creates a Muxer options object for testing.
|
|
|
|
MuxerOptions CreateMuxerOptions() const;
|
|
|
|
/// Creates a video stream info object for testing.
|
2021-08-04 18:56:44 +00:00
|
|
|
VideoStreamInfo* CreateVideoStreamInfo(int32_t time_scale) const;
|
2015-12-22 00:33:55 +00:00
|
|
|
|
|
|
|
/// Gets the file name of the current output file.
|
|
|
|
std::string OutputFileName() const;
|
|
|
|
/// Gets the file name of the given template file.
|
|
|
|
std::string TemplateFileName(int number) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// A helper class used to determine the number of clusters and frames for a
|
|
|
|
// given WebM file.
|
|
|
|
class ClusterParser : private WebMParserClient {
|
|
|
|
public:
|
|
|
|
ClusterParser();
|
|
|
|
~ClusterParser() override;
|
|
|
|
|
|
|
|
// Make sure to use ASSERT_NO_FATAL_FAILURE.
|
|
|
|
void PopulateFromCluster(const std::string& file_name);
|
|
|
|
void PopulateFromSegment(const std::string& file_name);
|
|
|
|
|
2017-05-13 00:02:12 +00:00
|
|
|
size_t GetFrameCountForCluster(size_t cluster_index) const;
|
|
|
|
int64_t GetFrameTimecode(size_t cluster_index, size_t frame_index) const;
|
2015-12-22 00:33:55 +00:00
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t cluster_count() const;
|
2015-12-22 00:33:55 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// WebMParserClient overrides.
|
|
|
|
WebMParserClient* OnListStart(int id) override;
|
|
|
|
bool OnListEnd(int id) override;
|
|
|
|
bool OnUInt(int id, int64_t val) override;
|
|
|
|
bool OnFloat(int id, double val) override;
|
|
|
|
bool OnBinary(int id, const uint8_t* data, int size) override;
|
|
|
|
bool OnString(int id, const std::string& str) override;
|
|
|
|
|
|
|
|
private:
|
2017-05-13 00:02:12 +00:00
|
|
|
int64_t cluster_timecode_ = -1;
|
|
|
|
// frame_timecodes_[cluster_index][frame_index].
|
|
|
|
std::vector<std::vector<int64_t>> frame_timecodes_;
|
|
|
|
bool in_cluster_ = false;
|
2015-12-22 00:33:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
2021-08-04 18:56:44 +00:00
|
|
|
void set_cur_timestamp(int64_t timestamp) { cur_timestamp_ = timestamp; }
|
2017-05-13 00:02:12 +00:00
|
|
|
|
2015-12-22 00:33:55 +00:00
|
|
|
std::string output_file_name_;
|
|
|
|
std::string segment_template_;
|
2021-08-04 18:56:44 +00:00
|
|
|
int64_t cur_timestamp_;
|
2015-12-22 00:33:55 +00:00
|
|
|
bool single_segment_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2015-12-22 00:33:55 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#endif // PACKAGER_MEDIA_FORMATS_WEBM_SEGMENTER_TEST_UTILS_H_
|