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(const LogCB& log_cb) |
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 log_cb_(log_cb) { |
24 } | 25 } |
25 | 26 |
26 WebMTracksParser::~WebMTracksParser() {} | 27 WebMTracksParser::~WebMTracksParser() {} |
27 | 28 |
28 int WebMTracksParser::Parse(const uint8* buf, int size) { | 29 int WebMTracksParser::Parse(const uint8* buf, int size) { |
29 track_type_ =-1; | 30 track_type_ =-1; |
30 track_num_ = -1; | 31 track_num_ = -1; |
31 audio_track_num_ = -1; | 32 audio_track_num_ = -1; |
32 video_track_num_ = -1; | 33 video_track_num_ = -1; |
33 | 34 |
34 WebMListParser parser(kWebMIdTracks, this); | 35 WebMListParser parser(kWebMIdTracks, this); |
35 int result = parser.Parse(buf, size); | 36 int result = parser.Parse(buf, size); |
36 | 37 |
37 if (result <= 0) | 38 if (result <= 0) |
38 return result; | 39 return result; |
39 | 40 |
40 // For now we do all or nothing parsing. | 41 // For now we do all or nothing parsing. |
41 return parser.IsParsingComplete() ? result : 0; | 42 return parser.IsParsingComplete() ? result : 0; |
42 } | 43 } |
43 | 44 |
44 WebMParserClient* WebMTracksParser::OnListStart(int id) { | 45 WebMParserClient* WebMTracksParser::OnListStart(int id) { |
45 if (id == kWebMIdContentEncodings) { | 46 if (id == kWebMIdContentEncodings) { |
46 DCHECK(!track_content_encodings_client_.get()); | 47 DCHECK(!track_content_encodings_client_.get()); |
47 track_content_encodings_client_.reset(new WebMContentEncodingsClient); | 48 track_content_encodings_client_.reset( |
| 49 new WebMContentEncodingsClient(log_cb_)); |
48 return track_content_encodings_client_->OnListStart(id); | 50 return track_content_encodings_client_->OnListStart(id); |
49 } | 51 } |
50 | 52 |
51 if (id == kWebMIdTrackEntry) { | 53 if (id == kWebMIdTrackEntry) { |
52 track_type_ = -1; | 54 track_type_ = -1; |
53 track_num_ = -1; | 55 track_num_ = -1; |
54 return this; | 56 return this; |
55 } | 57 } |
56 | 58 |
57 return this; | 59 return this; |
58 } | 60 } |
59 | 61 |
60 bool WebMTracksParser::OnListEnd(int id) { | 62 bool WebMTracksParser::OnListEnd(int id) { |
61 if (id == kWebMIdContentEncodings) { | 63 if (id == kWebMIdContentEncodings) { |
62 DCHECK(track_content_encodings_client_.get()); | 64 DCHECK(track_content_encodings_client_.get()); |
63 return track_content_encodings_client_->OnListEnd(id); | 65 return track_content_encodings_client_->OnListEnd(id); |
64 } | 66 } |
65 | 67 |
66 if (id == kWebMIdTrackEntry) { | 68 if (id == kWebMIdTrackEntry) { |
67 if (track_type_ == -1 || track_num_ == -1) { | 69 if (track_type_ == -1 || track_num_ == -1) { |
68 DVLOG(1) << "Missing TrackEntry data" | 70 MEDIA_LOG(log_cb_) << "Missing TrackEntry data for " |
69 << " TrackType " << track_type_ | 71 << " TrackType " << track_type_ |
70 << " TrackNum " << track_num_; | 72 << " TrackNum " << track_num_; |
71 return false; | 73 return false; |
72 } | 74 } |
73 | 75 |
74 if (track_type_ != kWebMTrackTypeAudio && | 76 if (track_type_ != kWebMTrackTypeAudio && |
75 track_type_ != kWebMTrackTypeVideo) { | 77 track_type_ != kWebMTrackTypeVideo) { |
76 DVLOG(1) << "Unexpected TrackType " << track_type_; | 78 MEDIA_LOG(log_cb_) << "Unexpected TrackType " << track_type_; |
77 return false; | 79 return false; |
78 } | 80 } |
79 | 81 |
80 std::string encryption_key_id; | 82 std::string encryption_key_id; |
81 if (track_content_encodings_client_.get()) { | 83 if (track_content_encodings_client_.get()) { |
82 DCHECK(!track_content_encodings_client_->content_encodings().empty()); | 84 DCHECK(!track_content_encodings_client_->content_encodings().empty()); |
83 // If we have multiple ContentEncoding in one track. Always choose the | 85 // If we have multiple ContentEncoding in one track. Always choose the |
84 // key id in the first ContentEncoding as the key id of the track. | 86 // key id in the first ContentEncoding as the key id of the track. |
85 encryption_key_id = track_content_encodings_client_-> | 87 encryption_key_id = track_content_encodings_client_-> |
86 content_encodings()[0]->encryption_key_id(); | 88 content_encodings()[0]->encryption_key_id(); |
(...skipping 24 matching lines...) Expand all Loading... |
111 dst = &track_num_; | 113 dst = &track_num_; |
112 break; | 114 break; |
113 case kWebMIdTrackType: | 115 case kWebMIdTrackType: |
114 dst = &track_type_; | 116 dst = &track_type_; |
115 break; | 117 break; |
116 default: | 118 default: |
117 return true; | 119 return true; |
118 } | 120 } |
119 | 121 |
120 if (*dst != -1) { | 122 if (*dst != -1) { |
121 DVLOG(1) << "Multiple values for id " << std::hex << id << " specified"; | 123 MEDIA_LOG(log_cb_) << "Multiple values for id " << std::hex << id |
| 124 << " specified"; |
122 return false; | 125 return false; |
123 } | 126 } |
124 | 127 |
125 *dst = val; | 128 *dst = val; |
126 return true; | 129 return true; |
127 } | 130 } |
128 | 131 |
129 bool WebMTracksParser::OnFloat(int id, double val) { | 132 bool WebMTracksParser::OnFloat(int id, double val) { |
130 return true; | 133 return true; |
131 } | 134 } |
132 | 135 |
133 bool WebMTracksParser::OnBinary(int id, const uint8* data, int size) { | 136 bool WebMTracksParser::OnBinary(int id, const uint8* data, int size) { |
134 return true; | 137 return true; |
135 } | 138 } |
136 | 139 |
137 bool WebMTracksParser::OnString(int id, const std::string& str) { | 140 bool WebMTracksParser::OnString(int id, const std::string& str) { |
138 if (id == kWebMIdCodecID && str != "A_VORBIS" && str != "V_VP8") { | 141 if (id == kWebMIdCodecID && str != "A_VORBIS" && str != "V_VP8") { |
139 DVLOG(1) << "Unexpected CodecID " << str; | 142 MEDIA_LOG(log_cb_) << "Unexpected CodecID " << str; |
140 return false; | 143 return false; |
141 } | 144 } |
142 | 145 |
143 return true; | 146 return true; |
144 } | 147 } |
145 | 148 |
146 } // namespace media | 149 } // namespace media |
OLD | NEW |