Shaka Packager SDK
tracks_builder.h
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef PACKAGER_MEDIA_FORMATS_WEBM_TRACKS_BUILDER_H_
6 #define PACKAGER_MEDIA_FORMATS_WEBM_TRACKS_BUILDER_H_
7 
8 #include <cstdint>
9 #include <list>
10 #include <string>
11 #include <vector>
12 
13 #include <packager/macros/classes.h>
14 
15 namespace shaka {
16 namespace media {
17 
19  public:
20  // If |allow_invalid_values| is false, some AddTrack() parameters will be
21  // basically checked and will assert if out of valid range. |codec_id|,
22  // |name|, |language| and any device-specific constraints are not checked.
23  explicit TracksBuilder(bool allow_invalid_values);
24  TracksBuilder(); // Sets |allow_invalid_values| to false.
25  ~TracksBuilder();
26 
27  // Only a non-negative |default_duration| will result in a serialized
28  // kWebMIdDefaultDuration element. Note, 0 is allowed here for testing only
29  // if |allow_invalid_values_| is true, since it is an illegal value for
30  // DefaultDuration. Similar applies to |audio_channels|,
31  // |audio_sampling_frequency|, |video_pixel_width| and |video_pixel_height|.
32  void AddVideoTrack(int track_num,
33  uint64_t track_uid,
34  const std::string& codec_id,
35  const std::string& name,
36  const std::string& language,
37  int default_duration,
38  int video_pixel_width,
39  int video_pixel_height);
40  void AddAudioTrack(int track_num,
41  uint64_t track_uid,
42  const std::string& codec_id,
43  const std::string& name,
44  const std::string& language,
45  int default_duration,
46  int audio_channels,
47  double audio_sampling_frequency);
48  void AddTextTrack(int track_num,
49  uint64_t track_uid,
50  const std::string& codec_id,
51  const std::string& name,
52  const std::string& language);
53 
54  std::vector<uint8_t> Finish();
55 
56  private:
57  void AddTrackInternal(int track_num,
58  int track_type,
59  uint64_t track_uid,
60  const std::string& codec_id,
61  const std::string& name,
62  const std::string& language,
63  int default_duration,
64  int video_pixel_width,
65  int video_pixel_height,
66  int audio_channels,
67  double audio_sampling_frequency);
68  int GetTracksSize() const;
69  int GetTracksPayloadSize() const;
70  void WriteTracks(uint8_t* buffer, int buffer_size) const;
71 
72  class Track {
73  public:
74  Track(int track_num,
75  int track_type,
76  uint64_t track_uid,
77  const std::string& codec_id,
78  const std::string& name,
79  const std::string& language,
80  int default_duration,
81  int video_pixel_width,
82  int video_pixel_height,
83  int audio_channels,
84  double audio_sampling_frequency,
85  bool allow_invalid_values);
86 
87  int GetSize() const;
88  void Write(uint8_t** buf, int* buf_size) const;
89 
90  private:
91  int GetPayloadSize() const;
92  int GetVideoPayloadSize() const;
93  int GetAudioPayloadSize() const;
94 
95  int track_num_;
96  int track_type_;
97  int track_uid_;
98  std::string codec_id_;
99  std::string name_;
100  std::string language_;
101  int default_duration_;
102  int video_pixel_width_;
103  int video_pixel_height_;
104  int audio_channels_;
105  double audio_sampling_frequency_;
106  };
107 
108  typedef std::list<Track> TrackList;
109  TrackList tracks_;
110  bool allow_invalid_values_;
111 
112  DISALLOW_COPY_AND_ASSIGN(TracksBuilder);
113 };
114 
115 } // namespace media
116 } // namespace shaka
117 
118 #endif // PACKAGER_MEDIA_FORMATS_WEBM_TRACKS_BUILDER_H_
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66