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. 4 5 #ifndef MEDIA_WEBM_WEBM_TRACKS_PARSER_H_ 6 #define MEDIA_WEBM_WEBM_TRACKS_PARSER_H_ 7 8 #include <map> 9 #include <set> 10 #include <string> 11 #include <vector> 12 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_config.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" 23 24 namespace media { 25 26 // Parser for WebM Tracks element. 27 class MEDIA_EXPORT WebMTracksParser : public WebMParserClient { 28 public: 29 explicit WebMTracksParser(const LogCB& log_cb, bool ignore_text_tracks); 30 virtual ~WebMTracksParser(); 31 32 // Parses a WebM Tracks element in |buf|. 33 // 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); 38 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_; } 42 43 const std::string& audio_encryption_key_id() const { 44 return audio_encryption_key_id_; 45 } 46 47 const AudioDecoderConfig& audio_decoder_config() { 48 return audio_decoder_config_; 49 } 50 51 const std::string& video_encryption_key_id() const { 52 return video_encryption_key_id_; 53 } 54 55 const VideoDecoderConfig& video_decoder_config() { 56 return video_decoder_config_; 57 } 58 59 typedef std::map<int, TextTrackConfig> TextTracks; 60 61 const TextTracks& text_tracks() const { 62 return text_tracks_; 63 } 64 65 private: 66 // WebMParserClient implementation. 67 virtual WebMParserClient* OnListStart(int id) OVERRIDE; 68 virtual bool OnListEnd(int id) OVERRIDE; 69 virtual bool OnUInt(int id, int64 val) OVERRIDE; 70 virtual bool OnFloat(int id, double val) OVERRIDE; 71 virtual bool OnBinary(int id, const uint8* data, int size) OVERRIDE; 72 virtual bool OnString(int id, const std::string& str) OVERRIDE; 73 74 int64 track_type_; 75 int64 track_num_; 76 int64 track_uid_; 77 std::string track_name_; 78 std::string track_language_; 79 std::string codec_id_; 80 std::vector<uint8> codec_private_; 81 int64 seek_preroll_; 82 int64 codec_delay_; 83 scoped_ptr<WebMContentEncodingsClient> track_content_encodings_client_; 84 85 int64 audio_track_num_; 86 int64 video_track_num_; 87 bool ignore_text_tracks_; 88 TextTracks text_tracks_; 89 std::set<int64> ignored_tracks_; 90 std::string audio_encryption_key_id_; 91 std::string video_encryption_key_id_; 92 LogCB log_cb_; 93 94 WebMAudioClient audio_client_; 95 AudioDecoderConfig audio_decoder_config_; 96 97 WebMVideoClient video_client_; 98 VideoDecoderConfig video_decoder_config_; 99 100 DISALLOW_COPY_AND_ASSIGN(WebMTracksParser); 101 }; 102 103 } // namespace media 104 105 #endif // MEDIA_WEBM_WEBM_TRACKS_PARSER_H_ 106