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 <cstddef>
11#include <cstdint>
12#include <memory>
13#include <string>
14#include <vector>
15
16#include <gtest/gtest.h>
17
18#include <packager/media/base/media_sample.h>
19#include <packager/media/base/muxer_options.h>
20#include <packager/media/base/stream_info.h>
21#include <packager/media/base/video_stream_info.h>
22#include <packager/media/formats/webm/segmenter.h>
23#include <packager/media/formats/webm/webm_parser.h>
24#include <packager/status/status_test_util.h>
25
26namespace shaka {
27namespace media {
28
29class SegmentTestBase : public ::testing::Test {
30 public:
31 enum KeyFrameFlag {
32 kKeyFrame,
33 kNotKeyFrame,
34 };
35 enum SideDataFlag {
36 kGenerateSideData,
37 kNoSideData,
38 };
39
40 protected:
42
43 void SetUp() override;
44 void TearDown() override;
45
47 template <typename S>
49 const MuxerOptions& options,
50 const StreamInfo& info,
51 std::unique_ptr<webm::Segmenter>* result) const {
52 std::unique_ptr<S> segmenter(new S(options));
53
54 ASSERT_OK(segmenter->Initialize(info, nullptr /* progress_listener */,
55 nullptr /* muxer_listener */));
56 *result = std::move(segmenter);
57 }
58
60 std::shared_ptr<MediaSample> CreateSample(KeyFrameFlag key_frame_flag,
61 int64_t duration,
62 SideDataFlag side_data_flag);
66 VideoStreamInfo* CreateVideoStreamInfo(int32_t time_scale) const;
67
69 std::string OutputFileName() const;
71 std::string TemplateFileName(int number) const;
72
73 protected:
74 // A helper class used to determine the number of clusters and frames for a
75 // given WebM file.
77 public:
79 ~ClusterParser() override;
80
81 // Make sure to use ASSERT_NO_FATAL_FAILURE.
82 void PopulateFromCluster(const std::string& file_name);
83 void PopulateFromSegment(const std::string& file_name);
84
85 size_t GetFrameCountForCluster(size_t cluster_index) const;
86 int64_t GetFrameTimecode(size_t cluster_index, size_t frame_index) const;
87
88 size_t cluster_count() const;
89
90 private:
91 // WebMParserClient overrides.
92 WebMParserClient* OnListStart(int id) override;
93 bool OnListEnd(int id) override;
94 bool OnUInt(int id, int64_t val) override;
95 bool OnFloat(int id, double val) override;
96 bool OnBinary(int id, const uint8_t* data, int size) override;
97 bool OnString(int id, const std::string& str) override;
98
99 private:
100 int64_t cluster_timecode_ = -1;
101 // frame_timecodes_[cluster_index][frame_index].
102 std::vector<std::vector<int64_t>> frame_timecodes_;
103 bool in_cluster_ = false;
104 };
105
106 protected:
107 void set_cur_timestamp(int64_t timestamp) { cur_timestamp_ = timestamp; }
108
109 std::string output_file_name_;
110 std::string segment_template_;
111 int64_t cur_timestamp_;
112 bool single_segment_;
113};
114
115} // namespace media
116} // namespace shaka
117
118#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:73
Holds video stream information.
All the methods that are virtual are virtual for mocking.
This structure contains the list of configuration options for Muxer.