Shaka Packager SDK
Loading...
Searching...
No Matches
segmenter_test_base.h
1// Copyright 2015 Google LLC. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6
7#ifndef PACKAGER_MEDIA_FORMATS_WEBM_SEGMENTER_TEST_UTILS_H_
8#define PACKAGER_MEDIA_FORMATS_WEBM_SEGMENTER_TEST_UTILS_H_
9
10#include <cstdint>
11
12#include <gtest/gtest.h>
13
14#include <packager/file/file_closer.h>
15#include <packager/file/file_test_util.h>
16#include <packager/file/memory_file.h>
17#include <packager/media/base/media_sample.h>
18#include <packager/media/base/muxer_options.h>
19#include <packager/media/base/stream_info.h>
20#include <packager/media/base/video_stream_info.h>
21#include <packager/media/formats/webm/mkv_writer.h>
22#include <packager/media/formats/webm/segmenter.h>
23#include <packager/media/formats/webm/webm_parser.h>
24#include <packager/status.h>
25#include <packager/status/status_test_util.h>
26
27namespace shaka {
28namespace media {
29
30class SegmentTestBase : public ::testing::Test {
31 public:
32 enum KeyFrameFlag {
33 kKeyFrame,
34 kNotKeyFrame,
35 };
36 enum SideDataFlag {
37 kGenerateSideData,
38 kNoSideData,
39 };
40
41 protected:
43
44 void SetUp() override;
45 void TearDown() override;
46
48 template <typename S>
50 const MuxerOptions& options,
51 const StreamInfo& info,
52 std::unique_ptr<webm::Segmenter>* result) const {
53 std::unique_ptr<S> segmenter(new S(options));
54
55 ASSERT_OK(segmenter->Initialize(info, nullptr /* progress_listener */,
56 nullptr /* muxer_listener */));
57 *result = std::move(segmenter);
58 }
59
61 std::shared_ptr<MediaSample> CreateSample(KeyFrameFlag key_frame_flag,
62 int64_t duration,
63 SideDataFlag side_data_flag);
67 VideoStreamInfo* CreateVideoStreamInfo(int32_t time_scale) const;
68
70 std::string OutputFileName() const;
72 std::string TemplateFileName(int number) const;
73
74 protected:
75 // A helper class used to determine the number of clusters and frames for a
76 // given WebM file.
78 public:
80 ~ClusterParser() override;
81
82 // Make sure to use ASSERT_NO_FATAL_FAILURE.
83 void PopulateFromCluster(const std::string& file_name);
84 void PopulateFromSegment(const std::string& file_name);
85
86 size_t GetFrameCountForCluster(size_t cluster_index) const;
87 int64_t GetFrameTimecode(size_t cluster_index, size_t frame_index) const;
88
89 size_t cluster_count() const;
90
91 private:
92 // WebMParserClient overrides.
93 WebMParserClient* OnListStart(int id) override;
94 bool OnListEnd(int id) override;
95 bool OnUInt(int id, int64_t val) override;
96 bool OnFloat(int id, double val) override;
97 bool OnBinary(int id, const uint8_t* data, int size) override;
98 bool OnString(int id, const std::string& str) override;
99
100 private:
101 int64_t cluster_timecode_ = -1;
102 // frame_timecodes_[cluster_index][frame_index].
103 std::vector<std::vector<int64_t>> frame_timecodes_;
104 bool in_cluster_ = false;
105 };
106
107 protected:
108 void set_cur_timestamp(int64_t timestamp) { cur_timestamp_ = timestamp; }
109
110 std::string output_file_name_;
111 std::string segment_template_;
112 int64_t cur_timestamp_;
113 bool single_segment_;
114};
115
116} // namespace media
117} // namespace shaka
118
119#endif // PACKAGER_MEDIA_FORMATS_WEBM_SEGMENTER_TEST_UTILS_H_
std::string TemplateFileName(int number) const
Gets the file name of the given template file.
VideoStreamInfo * CreateVideoStreamInfo(int32_t time_scale) const
Creates a video stream info object for testing.
MuxerOptions CreateMuxerOptions() const
Creates a Muxer options object for testing.
void CreateAndInitializeSegmenter(const MuxerOptions &options, const StreamInfo &info, std::unique_ptr< webm::Segmenter > *result) const
Creates a Segmenter of the given type and initializes it.
std::string OutputFileName() const
Gets the file name of the current output file.
std::shared_ptr< MediaSample > CreateSample(KeyFrameFlag key_frame_flag, int64_t duration, SideDataFlag side_data_flag)
Creates a new media sample.
Abstract class holds stream information.
Definition stream_info.h:72
Holds video stream information.
All the methods that are virtual are virtual for mocking.
This structure contains the list of configuration options for Muxer.