Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/webm/webm_tracks_parser.h" | 5 #include "media/webm/webm_tracks_parser.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "media/base/buffers.h" | 9 #include "media/base/buffers.h" |
| 10 #include "media/webm/webm_constants.h" | 10 #include "media/webm/webm_constants.h" |
| 11 #include "media/webm/webm_content_encodings.h" | 11 #include "media/webm/webm_content_encodings.h" |
| 12 | 12 |
| 13 namespace media { | 13 namespace media { |
| 14 | 14 |
| 15 // Values for TrackType element. | 15 // Values for TrackType element. |
| 16 static const int kWebMTrackTypeVideo = 1; | 16 static const int kWebMTrackTypeVideo = 1; |
| 17 static const int kWebMTrackTypeAudio = 2; | 17 static const int kWebMTrackTypeAudio = 2; |
| 18 | 18 |
| 19 WebMTracksParser::WebMTracksParser() | 19 WebMTracksParser::WebMTracksParser() |
| 20 : track_type_(-1), | 20 : track_type_(-1), |
| 21 track_num_(-1), | 21 track_num_(-1), |
| 22 audio_track_num_(-1), | 22 audio_track_num_(-1), |
| 23 video_track_num_(-1) { | 23 video_track_num_(-1) { |
| 24 } | 24 } |
| 25 | 25 |
| 26 WebMTracksParser::~WebMTracksParser() {} | 26 WebMTracksParser::~WebMTracksParser() {} |
| 27 | 27 |
| 28 const std::string& WebMTracksParser::video_encryption_key_id() const { | |
| 29 if (!video_content_encodings_client_.get()) | |
| 30 return EmptyString(); | |
| 31 | |
| 32 DCHECK(!video_content_encodings_client_->content_encodings().empty()); | |
| 33 return video_content_encodings_client_->content_encodings()[0]-> | |
| 34 encryption_key_id(); | |
| 35 } | |
| 36 | |
| 37 int WebMTracksParser::Parse(const uint8* buf, int size) { | 28 int WebMTracksParser::Parse(const uint8* buf, int size) { |
| 38 track_type_ =-1; | 29 track_type_ =-1; |
| 39 track_num_ = -1; | 30 track_num_ = -1; |
| 40 audio_track_num_ = -1; | 31 audio_track_num_ = -1; |
| 41 video_track_num_ = -1; | 32 video_track_num_ = -1; |
| 42 | 33 |
| 43 WebMListParser parser(kWebMIdTracks, this); | 34 WebMListParser parser(kWebMIdTracks, this); |
| 44 int result = parser.Parse(buf, size); | 35 int result = parser.Parse(buf, size); |
| 45 | 36 |
| 46 if (result <= 0) | 37 if (result <= 0) |
| 47 return result; | 38 return result; |
| 48 | 39 |
| 49 // For now we do all or nothing parsing. | 40 // For now we do all or nothing parsing. |
| 50 return parser.IsParsingComplete() ? result : 0; | 41 return parser.IsParsingComplete() ? result : 0; |
| 51 } | 42 } |
| 52 | 43 |
| 53 | |
| 54 WebMParserClient* WebMTracksParser::OnListStart(int id) { | 44 WebMParserClient* WebMTracksParser::OnListStart(int id) { |
| 55 if (id == kWebMIdContentEncodings) { | 45 if (id == kWebMIdContentEncodings) { |
| 56 DCHECK(!track_content_encodings_client_.get()); | 46 DCHECK(!track_content_encodings_client_.get()); |
| 57 track_content_encodings_client_.reset(new WebMContentEncodingsClient); | 47 track_content_encodings_client_.reset(new WebMContentEncodingsClient); |
| 58 return track_content_encodings_client_->OnListStart(id); | 48 return track_content_encodings_client_->OnListStart(id); |
| 59 } | 49 } |
| 60 | 50 |
| 61 if (id == kWebMIdTrackEntry) { | 51 if (id == kWebMIdTrackEntry) { |
| 62 track_type_ = -1; | 52 track_type_ = -1; |
| 63 track_num_ = -1; | 53 track_num_ = -1; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 74 } | 64 } |
| 75 | 65 |
| 76 if (id == kWebMIdTrackEntry) { | 66 if (id == kWebMIdTrackEntry) { |
| 77 if (track_type_ == -1 || track_num_ == -1) { | 67 if (track_type_ == -1 || track_num_ == -1) { |
| 78 DVLOG(1) << "Missing TrackEntry data" | 68 DVLOG(1) << "Missing TrackEntry data" |
| 79 << " TrackType " << track_type_ | 69 << " TrackType " << track_type_ |
| 80 << " TrackNum " << track_num_; | 70 << " TrackNum " << track_num_; |
| 81 return false; | 71 return false; |
| 82 } | 72 } |
| 83 | 73 |
| 84 if (track_type_ == kWebMTrackTypeVideo) { | 74 if (track_type_ == kWebMTrackTypeVideo) { |
|
ddorwin
2012/10/11 05:18:22
Strange that video is processed first here. It see
xhwang
2012/10/11 16:36:10
Done.
| |
| 85 video_track_num_ = track_num_; | 75 video_track_num_ = track_num_; |
| 86 if (track_content_encodings_client_.get()) { | 76 if (track_content_encodings_client_.get()) { |
| 87 video_content_encodings_client_ = | 77 DCHECK(!track_content_encodings_client_->content_encodings().empty()); |
| 88 track_content_encodings_client_.Pass(); | 78 video_encryption_key_id_ = track_content_encodings_client_-> |
| 79 content_encodings()[0]->encryption_key_id(); | |
|
ddorwin
2012/10/11 05:18:22
Why is it the first encoding? Maybe we should comm
xhwang
2012/10/11 16:36:10
Added more comments and more checks. fgalligan@: p
| |
| 89 } | 80 } |
| 90 } else if (track_type_ == kWebMTrackTypeAudio) { | 81 } else if (track_type_ == kWebMTrackTypeAudio) { |
| 91 audio_track_num_ = track_num_; | 82 audio_track_num_ = track_num_; |
| 92 if (track_content_encodings_client_.get()) { | 83 if (track_content_encodings_client_.get()) { |
| 93 audio_content_encodings_client_ = | 84 DCHECK(!track_content_encodings_client_->content_encodings().empty()); |
| 94 track_content_encodings_client_.Pass(); | 85 audio_encryption_key_id_ = track_content_encodings_client_-> |
| 86 content_encodings()[0]->encryption_key_id(); | |
| 95 } | 87 } |
| 96 } else { | 88 } else { |
| 97 DVLOG(1) << "Unexpected TrackType " << track_type_; | 89 DVLOG(1) << "Unexpected TrackType " << track_type_; |
| 98 return false; | 90 return false; |
| 99 } | 91 } |
| 100 | 92 |
| 101 track_type_ = -1; | 93 track_type_ = -1; |
| 102 track_num_ = -1; | 94 track_num_ = -1; |
| 103 track_content_encodings_client_.reset(); | 95 track_content_encodings_client_.reset(); |
| 104 return true; | 96 return true; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 bool WebMTracksParser::OnString(int id, const std::string& str) { | 133 bool WebMTracksParser::OnString(int id, const std::string& str) { |
| 142 if (id == kWebMIdCodecID && str != "A_VORBIS" && str != "V_VP8") { | 134 if (id == kWebMIdCodecID && str != "A_VORBIS" && str != "V_VP8") { |
| 143 DVLOG(1) << "Unexpected CodecID " << str; | 135 DVLOG(1) << "Unexpected CodecID " << str; |
| 144 return false; | 136 return false; |
| 145 } | 137 } |
| 146 | 138 |
| 147 return true; | 139 return true; |
| 148 } | 140 } |
| 149 | 141 |
| 150 } // namespace media | 142 } // namespace media |
| OLD | NEW |