DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
segmenter_test_base.h
1 // Copyright 2015 Google Inc. 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 MEDIA_FORMATS_WEBM_SEGMENTER_TEST_UTILS_H_
8 #define MEDIA_FORMATS_WEBM_SEGMENTER_TEST_UTILS_H_
9 
10 #include <gtest/gtest.h>
11 
12 #include "packager/media/base/media_sample.h"
13 #include "packager/media/base/muxer_options.h"
14 #include "packager/media/base/status.h"
15 #include "packager/media/base/stream_info.h"
16 #include "packager/media/base/test/status_test_util.h"
17 #include "packager/media/base/video_stream_info.h"
18 #include "packager/media/file/file_closer.h"
19 #include "packager/media/file/file_test_util.h"
20 #include "packager/media/file/memory_file.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 
25 namespace shaka {
26 namespace media {
27 
28 class SegmentTestBase : public ::testing::Test {
29  public:
30  enum KeyFrameFlag {
31  kKeyFrame,
32  kNotKeyFrame,
33  };
34  enum SideDataFlag {
35  kGenerateSideData,
36  kNoSideData,
37  };
38 
39  protected:
41 
42  void SetUp() override;
43  void TearDown() override;
44 
46  template <typename S>
48  const MuxerOptions& options,
49  StreamInfo* info,
50  KeySource* key_source,
51  std::unique_ptr<webm::Segmenter>* result) const {
52  std::unique_ptr<S> segmenter(new S(options));
53 
54  std::unique_ptr<MkvWriter> writer(new MkvWriter());
55  ASSERT_OK(writer->Open(options.output_file_name));
56  ASSERT_OK(segmenter->Initialize(
57  std::move(writer), info, NULL /* progress_listener */,
58  NULL /* muxer_listener */, key_source, 0 /* max_sd_pixels */,
59  0 /* max_hd_pixels */, 0 /* max_uhd1_pixels */,
60  1 /* clear_lead_in_seconds */));
61  *result = std::move(segmenter);
62  }
63 
65  scoped_refptr<MediaSample> CreateSample(KeyFrameFlag key_frame_flag,
66  uint64_t duration,
67  SideDataFlag side_data_flag);
72 
74  std::string OutputFileName() const;
76  std::string TemplateFileName(int number) const;
77 
78  protected:
79  // A helper class used to determine the number of clusters and frames for a
80  // given WebM file.
81  class ClusterParser : private WebMParserClient {
82  public:
83  ClusterParser();
84  ~ClusterParser() override;
85 
86  // Make sure to use ASSERT_NO_FATAL_FAILURE.
87  void PopulateFromCluster(const std::string& file_name);
88  void PopulateFromSegment(const std::string& file_name);
89 
90  int GetFrameCountForCluster(size_t i) const;
91 
92  int cluster_count() const;
93 
94  private:
95  // WebMParserClient overrides.
96  WebMParserClient* OnListStart(int id) override;
97  bool OnListEnd(int id) override;
98  bool OnUInt(int id, int64_t val) override;
99  bool OnFloat(int id, double val) override;
100  bool OnBinary(int id, const uint8_t* data, int size) override;
101  bool OnString(int id, const std::string& str) override;
102 
103  private:
104  std::vector<int> cluster_sizes_;
105  bool in_cluster_;
106  };
107 
108  protected:
109  std::string output_file_name_;
110  std::string segment_template_;
111  uint64_t cur_time_timescale_;
112  bool single_segment_;
113 };
114 
115 } // namespace media
116 } // namespace shaka
117 
118 #endif // MEDIA_FORMATS_WEBM_SEGMENTER_TEST_UTILS_H_
Abstract class holds stream information.
Definition: stream_info.h:53
VideoStreamInfo * CreateVideoStreamInfo() const
Creates a video stream info object for testing.
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:18
std::string OutputFileName() const
Gets the file name of the current output file.
scoped_refptr< MediaSample > CreateSample(KeyFrameFlag key_frame_flag, uint64_t duration, SideDataFlag side_data_flag)
Creates a new media sample.
An implementation of IMkvWriter using our File type.
Definition: mkv_writer.h:21
void CreateAndInitializeSegmenter(const MuxerOptions &options, StreamInfo *info, KeySource *key_source, std::unique_ptr< webm::Segmenter > *result) const
Creates a Segmenter of the given type and initializes it.
MuxerOptions CreateMuxerOptions() const
Creates a Muxer options object for testing.
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:30
Holds video stream information.
std::string TemplateFileName(int number) const
Gets the file name of the given template file.