1 // Copyright (c) 2012 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_WEBM_WEBM_TRACKS_PARSER_H_
6 #define MEDIA_WEBM_WEBM_TRACKS_PARSER_H_
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "media/base/audio_decoder_config.h"
16 #include "media/base/media_log.h"
17 #include "media/base/text_track.h"
18 #include "media/base/video_decoder_config.h"
19 #include "media/webm/webm_audio_client.h"
20 #include "media/webm/webm_content_encodings_client.h"
21 #include "media/webm/webm_parser.h"
22 #include "media/webm/webm_video_client.h"
26 // Parser for WebM Tracks element.
27 class MEDIA_EXPORT WebMTracksParser
: public WebMParserClient
{
29 explicit WebMTracksParser(const LogCB
& log_cb
, bool ignore_text_tracks
);
30 virtual ~WebMTracksParser();
32 // Parses a WebM Tracks element in |buf|.
34 // Returns -1 if the parse fails.
35 // Returns 0 if more data is needed.
36 // Returns the number of bytes parsed on success.
37 int Parse(const uint8
* buf
, int size
);
39 int64
audio_track_num() const { return audio_track_num_
; }
40 int64
video_track_num() const { return video_track_num_
; }
41 const std::set
<int64
>& ignored_tracks() const { return ignored_tracks_
; }
43 const std::string
& audio_encryption_key_id() const {
44 return audio_encryption_key_id_
;
47 const AudioDecoderConfig
& audio_decoder_config() {
48 return audio_decoder_config_
;
51 const std::string
& video_encryption_key_id() const {
52 return video_encryption_key_id_
;
55 const VideoDecoderConfig
& video_decoder_config() {
56 return video_decoder_config_
;
59 struct TextTrackInfo
{
65 typedef std::map
<int64
, TextTrackInfo
> TextTracks
;
67 const TextTracks
& text_tracks() const {
72 // WebMParserClient implementation.
73 virtual WebMParserClient
* OnListStart(int id
) OVERRIDE
;
74 virtual bool OnListEnd(int id
) OVERRIDE
;
75 virtual bool OnUInt(int id
, int64 val
) OVERRIDE
;
76 virtual bool OnFloat(int id
, double val
) OVERRIDE
;
77 virtual bool OnBinary(int id
, const uint8
* data
, int size
) OVERRIDE
;
78 virtual bool OnString(int id
, const std::string
& str
) OVERRIDE
;
82 std::string track_name_
;
83 std::string track_language_
;
84 std::string codec_id_
;
85 std::vector
<uint8
> codec_private_
;
86 scoped_ptr
<WebMContentEncodingsClient
> track_content_encodings_client_
;
88 int64 audio_track_num_
;
89 int64 video_track_num_
;
90 bool ignore_text_tracks_
;
91 TextTracks text_tracks_
;
92 std::set
<int64
> ignored_tracks_
;
93 std::string audio_encryption_key_id_
;
94 std::string video_encryption_key_id_
;
97 WebMAudioClient audio_client_
;
98 AudioDecoderConfig audio_decoder_config_
;
100 WebMVideoClient video_client_
;
101 VideoDecoderConfig video_decoder_config_
;
103 DISALLOW_COPY_AND_ASSIGN(WebMTracksParser
);
108 #endif // MEDIA_WEBM_WEBM_TRACKS_PARSER_H_