[MD settings] moving attached() code
[chromium-blink-merge.git] / media / formats / webm / webm_tracks_parser.h
blobd5513b520dac0f05a33acba26f6f5474209f5f2a
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_WEBM_TRACKS_PARSER_H_
6 #define MEDIA_FORMATS_WEBM_WEBM_TRACKS_PARSER_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/time/time.h"
16 #include "media/base/audio_decoder_config.h"
17 #include "media/base/media_log.h"
18 #include "media/base/text_track_config.h"
19 #include "media/base/video_decoder_config.h"
20 #include "media/formats/webm/webm_audio_client.h"
21 #include "media/formats/webm/webm_content_encodings_client.h"
22 #include "media/formats/webm/webm_parser.h"
23 #include "media/formats/webm/webm_video_client.h"
25 namespace media {
27 // Parser for WebM Tracks element.
28 class MEDIA_EXPORT WebMTracksParser : public WebMParserClient {
29 public:
30 WebMTracksParser(const scoped_refptr<MediaLog>& media_log,
31 bool ignore_text_tracks);
32 ~WebMTracksParser() override;
34 // Parses a WebM Tracks element in |buf|.
36 // Returns -1 if the parse fails.
37 // Returns 0 if more data is needed.
38 // Returns the number of bytes parsed on success.
39 int Parse(const uint8* buf, int size);
41 int64 audio_track_num() const { return audio_track_num_; }
42 int64 video_track_num() const { return video_track_num_; }
44 // If TrackEntry DefaultDuration field existed for the associated audio or
45 // video track, returns that value converted from ns to base::TimeDelta with
46 // precision not greater than |timecode_scale_in_us|. Defaults to
47 // kNoTimestamp().
48 base::TimeDelta GetAudioDefaultDuration(
49 const double timecode_scale_in_us) const;
50 base::TimeDelta GetVideoDefaultDuration(
51 const double timecode_scale_in_us) const;
53 const std::set<int64>& ignored_tracks() const { return ignored_tracks_; }
55 const std::string& audio_encryption_key_id() const {
56 return audio_encryption_key_id_;
59 const AudioDecoderConfig& audio_decoder_config() {
60 return audio_decoder_config_;
63 const std::string& video_encryption_key_id() const {
64 return video_encryption_key_id_;
67 const VideoDecoderConfig& video_decoder_config() {
68 return video_decoder_config_;
71 typedef std::map<int, TextTrackConfig> TextTracks;
73 const TextTracks& text_tracks() const {
74 return text_tracks_;
77 private:
78 // WebMParserClient implementation.
79 WebMParserClient* OnListStart(int id) override;
80 bool OnListEnd(int id) override;
81 bool OnUInt(int id, int64 val) override;
82 bool OnFloat(int id, double val) override;
83 bool OnBinary(int id, const uint8* data, int size) override;
84 bool OnString(int id, const std::string& str) override;
86 int64 track_type_;
87 int64 track_num_;
88 std::string track_name_;
89 std::string track_language_;
90 std::string codec_id_;
91 std::vector<uint8> codec_private_;
92 int64 seek_preroll_;
93 int64 codec_delay_;
94 int64 default_duration_;
95 scoped_ptr<WebMContentEncodingsClient> track_content_encodings_client_;
97 int64 audio_track_num_;
98 int64 audio_default_duration_;
99 int64 video_track_num_;
100 int64 video_default_duration_;
101 bool ignore_text_tracks_;
102 TextTracks text_tracks_;
103 std::set<int64> ignored_tracks_;
104 std::string audio_encryption_key_id_;
105 std::string video_encryption_key_id_;
106 scoped_refptr<MediaLog> media_log_;
108 WebMAudioClient audio_client_;
109 AudioDecoderConfig audio_decoder_config_;
111 WebMVideoClient video_client_;
112 VideoDecoderConfig video_decoder_config_;
114 DISALLOW_COPY_AND_ASSIGN(WebMTracksParser);
117 } // namespace media
119 #endif // MEDIA_FORMATS_WEBM_WEBM_TRACKS_PARSER_H_