Revert of Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320) (patchset...
[chromium-blink-merge.git] / media / formats / webm / tracks_builder.h
blobf7786fd70fb7a8bb608328359a8de4c74ca62856
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.
5 #ifndef MEDIA_FORMATS_WEBM_TRACKS_BUILDER_H_
6 #define MEDIA_FORMATS_WEBM_TRACKS_BUILDER_H_
8 #include <list>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
14 namespace media {
16 class TracksBuilder {
17 public:
18 // If |allow_invalid_values| is false, some AddTrack() parameters will be
19 // basically checked and will assert if out of valid range. |codec_id|,
20 // |name|, |language| and any device-specific constraints are not checked.
21 explicit TracksBuilder(bool allow_invalid_values);
22 TracksBuilder(); // Sets |allow_invalid_values| to false.
23 ~TracksBuilder();
25 // Only a non-negative |default_duration| will result in a serialized
26 // kWebMIdDefaultDuration element. Note, 0 is allowed here for testing only
27 // if |allow_invalid_values_| is true, since it is an illegal value for
28 // DefaultDuration. Similar applies to |audio_channels|,
29 // |audio_sampling_frequency|, |video_pixel_width| and |video_pixel_height|.
30 void AddVideoTrack(int track_num,
31 uint64 track_uid,
32 const std::string& codec_id,
33 const std::string& name,
34 const std::string& language,
35 int default_duration,
36 int video_pixel_width,
37 int video_pixel_height);
38 void AddAudioTrack(int track_num,
39 uint64 track_uid,
40 const std::string& codec_id,
41 const std::string& name,
42 const std::string& language,
43 int default_duration,
44 int audio_channels,
45 double audio_sampling_frequency);
46 void AddTextTrack(int track_num,
47 uint64 track_uid,
48 const std::string& codec_id,
49 const std::string& name,
50 const std::string& language);
52 std::vector<uint8> Finish();
54 private:
55 void AddTrackInternal(int track_num,
56 int track_type,
57 uint64 track_uid,
58 const std::string& codec_id,
59 const std::string& name,
60 const std::string& language,
61 int default_duration,
62 int video_pixel_width,
63 int video_pixel_height,
64 int audio_channels,
65 double audio_sampling_frequency);
66 int GetTracksSize() const;
67 int GetTracksPayloadSize() const;
68 void WriteTracks(uint8* buffer, int buffer_size) const;
70 class Track {
71 public:
72 Track(int track_num,
73 int track_type,
74 uint64 track_uid,
75 const std::string& codec_id,
76 const std::string& name,
77 const std::string& language,
78 int default_duration,
79 int video_pixel_width,
80 int video_pixel_height,
81 int audio_channels,
82 double audio_sampling_frequency,
83 bool allow_invalid_values);
85 int GetSize() const;
86 void Write(uint8** buf, int* buf_size) const;
87 private:
88 int GetPayloadSize() const;
89 int GetVideoPayloadSize() const;
90 int GetAudioPayloadSize() const;
92 int track_num_;
93 int track_type_;
94 int track_uid_;
95 std::string codec_id_;
96 std::string name_;
97 std::string language_;
98 int default_duration_;
99 int video_pixel_width_;
100 int video_pixel_height_;
101 int audio_channels_;
102 double audio_sampling_frequency_;
105 typedef std::list<Track> TrackList;
106 TrackList tracks_;
107 bool allow_invalid_values_;
109 DISALLOW_COPY_AND_ASSIGN(TracksBuilder);
112 } // namespace media
114 #endif // MEDIA_FORMATS_WEBM_TRACKS_BUILDER_H_