DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs 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/video_stream_info.h"
15 #include "packager/media/base/status.h"
16 #include "packager/media/base/stream_info.h"
17 #include "packager/media/base/test/status_test_util.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 edash_packager {
26 namespace media {
27 
28 class SegmentTestBase : public ::testing::Test {
29  protected:
31 
32  void SetUp() override;
33  void TearDown() override;
34 
36  template <typename S>
38  StreamInfo* info,
39  scoped_ptr<webm::Segmenter>* result) const {
40  scoped_ptr<S> segmenter(new S(options));
41 
42  scoped_ptr<MkvWriter> writer(new MkvWriter());
43  ASSERT_OK(writer->Open(this->output_file_name_));
44  ASSERT_OK(segmenter->Initialize(writer.Pass(), info, NULL, NULL, NULL));
45  *result = segmenter.Pass();
46  }
47 
49  scoped_refptr<MediaSample> CreateSample(bool is_key_frame, uint64_t duration);
54 
56  std::string OutputFileName() const;
58  std::string TemplateFileName(int number) const;
59 
60  protected:
61  // A helper class used to determine the number of clusters and frames for a
62  // given WebM file.
63  class ClusterParser : private WebMParserClient {
64  public:
65  ClusterParser();
66  ~ClusterParser() override;
67 
68  // Make sure to use ASSERT_NO_FATAL_FAILURE.
69  void PopulateFromCluster(const std::string& file_name);
70  void PopulateFromSegment(const std::string& file_name);
71 
72  int GetFrameCountForCluster(size_t i) const;
73 
74  int cluster_count() const;
75 
76  private:
77  // WebMParserClient overrides.
78  WebMParserClient* OnListStart(int id) override;
79  bool OnListEnd(int id) override;
80  bool OnUInt(int id, int64_t val) override;
81  bool OnFloat(int id, double val) override;
82  bool OnBinary(int id, const uint8_t* data, int size) override;
83  bool OnString(int id, const std::string& str) override;
84 
85  private:
86  std::vector<int> cluster_sizes_;
87  bool in_cluster_;
88  };
89 
90  protected:
91  std::string output_file_name_;
92  std::string segment_template_;
93  uint64_t cur_time_timescale_;
94  bool single_segment_;
95 };
96 
97 } // namespace media
98 } // namespace edash_packager
99 
100 #endif // MEDIA_FORMATS_WEBM_SEGMENTER_TEST_UTILS_H_
An implementation of IMkvWriter using our File type.
Definition: mkv_writer.h:21
std::string OutputFileName() const
Gets the file name of the current output file.
Abstract class holds stream information.
Definition: stream_info.h:26
void CreateAndInitializeSegmenter(const MuxerOptions &options, StreamInfo *info, scoped_ptr< webm::Segmenter > *result) const
Creates a Segmenter of the given type and initializes it.
scoped_refptr< MediaSample > CreateSample(bool is_key_frame, uint64_t duration)
Creates a new media sample.
std::string TemplateFileName(int number) const
Gets the file name of the given template file.
VideoStreamInfo * CreateVideoStreamInfo() const
Creates a video stream info object for testing.
MuxerOptions CreateMuxerOptions() const
Creates a Muxer options object for testing.
Holds video stream information.
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:18