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