Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: media/formats/webm/webm_stream_parser.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/formats/webm/webm_stream_parser.h" 5 #include "media/formats/webm/webm_stream_parser.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 byte_queue_.Reset(); 61 byte_queue_.Reset();
62 if (cluster_parser_) 62 if (cluster_parser_)
63 cluster_parser_->Reset(); 63 cluster_parser_->Reset();
64 if (state_ == kParsingClusters) { 64 if (state_ == kParsingClusters) {
65 ChangeState(kParsingHeaders); 65 ChangeState(kParsingHeaders);
66 end_of_segment_cb_.Run(); 66 end_of_segment_cb_.Run();
67 } 67 }
68 } 68 }
69 69
70 bool WebMStreamParser::Parse(const uint8* buf, int size) { 70 bool WebMStreamParser::Parse(const uint8_t* buf, int size) {
71 DCHECK_NE(state_, kWaitingForInit); 71 DCHECK_NE(state_, kWaitingForInit);
72 72
73 if (state_ == kError) 73 if (state_ == kError)
74 return false; 74 return false;
75 75
76 byte_queue_.Push(buf, size); 76 byte_queue_.Push(buf, size);
77 77
78 int result = 0; 78 int result = 0;
79 int bytes_parsed = 0; 79 int bytes_parsed = 0;
80 const uint8* cur = NULL; 80 const uint8_t* cur = NULL;
81 int cur_size = 0; 81 int cur_size = 0;
82 82
83 byte_queue_.Peek(&cur, &cur_size); 83 byte_queue_.Peek(&cur, &cur_size);
84 while (cur_size > 0) { 84 while (cur_size > 0) {
85 State oldState = state_; 85 State oldState = state_;
86 switch (state_) { 86 switch (state_) {
87 case kParsingHeaders: 87 case kParsingHeaders:
88 result = ParseInfoAndTracks(cur, cur_size); 88 result = ParseInfoAndTracks(cur, cur_size);
89 break; 89 break;
90 90
(...skipping 22 matching lines...) Expand all
113 113
114 byte_queue_.Pop(bytes_parsed); 114 byte_queue_.Pop(bytes_parsed);
115 return true; 115 return true;
116 } 116 }
117 117
118 void WebMStreamParser::ChangeState(State new_state) { 118 void WebMStreamParser::ChangeState(State new_state) {
119 DVLOG(1) << "ChangeState() : " << state_ << " -> " << new_state; 119 DVLOG(1) << "ChangeState() : " << state_ << " -> " << new_state;
120 state_ = new_state; 120 state_ = new_state;
121 } 121 }
122 122
123 int WebMStreamParser::ParseInfoAndTracks(const uint8* data, int size) { 123 int WebMStreamParser::ParseInfoAndTracks(const uint8_t* data, int size) {
124 DVLOG(2) << "ParseInfoAndTracks()"; 124 DVLOG(2) << "ParseInfoAndTracks()";
125 DCHECK(data); 125 DCHECK(data);
126 DCHECK_GT(size, 0); 126 DCHECK_GT(size, 0);
127 127
128 const uint8* cur = data; 128 const uint8_t* cur = data;
129 int cur_size = size; 129 int cur_size = size;
130 int bytes_parsed = 0; 130 int bytes_parsed = 0;
131 131
132 int id; 132 int id;
133 int64 element_size; 133 int64_t element_size;
134 int result = WebMParseElementHeader(cur, cur_size, &id, &element_size); 134 int result = WebMParseElementHeader(cur, cur_size, &id, &element_size);
135 135
136 if (result <= 0) 136 if (result <= 0)
137 return result; 137 return result;
138 138
139 switch (id) { 139 switch (id) {
140 case kWebMIdEBMLHeader: 140 case kWebMIdEBMLHeader:
141 case kWebMIdSeekHead: 141 case kWebMIdSeekHead:
142 case kWebMIdVoid: 142 case kWebMIdVoid:
143 case kWebMIdCRC32: 143 case kWebMIdCRC32:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 194
195 if (result <= 0) 195 if (result <= 0)
196 return result; 196 return result;
197 197
198 bytes_parsed += result; 198 bytes_parsed += result;
199 199
200 double timecode_scale_in_us = info_parser.timecode_scale() / 1000.0; 200 double timecode_scale_in_us = info_parser.timecode_scale() / 1000.0;
201 InitParameters params(kInfiniteDuration()); 201 InitParameters params(kInfiniteDuration());
202 202
203 if (info_parser.duration() > 0) { 203 if (info_parser.duration() > 0) {
204 int64 duration_in_us = info_parser.duration() * timecode_scale_in_us; 204 int64_t duration_in_us = info_parser.duration() * timecode_scale_in_us;
205 params.duration = base::TimeDelta::FromMicroseconds(duration_in_us); 205 params.duration = base::TimeDelta::FromMicroseconds(duration_in_us);
206 } 206 }
207 207
208 params.timeline_offset = info_parser.date_utc(); 208 params.timeline_offset = info_parser.date_utc();
209 209
210 if (unknown_segment_size_ && (info_parser.duration() <= 0) && 210 if (unknown_segment_size_ && (info_parser.duration() <= 0) &&
211 !info_parser.date_utc().is_null()) { 211 !info_parser.date_utc().is_null()) {
212 params.liveness = DemuxerStream::LIVENESS_LIVE; 212 params.liveness = DemuxerStream::LIVENESS_LIVE;
213 } else if (info_parser.duration() >= 0) { 213 } else if (info_parser.duration() >= 0) {
214 params.liveness = DemuxerStream::LIVENESS_RECORDED; 214 params.liveness = DemuxerStream::LIVENESS_RECORDED;
(...skipping 25 matching lines...) Expand all
240 tracks_parser.audio_encryption_key_id(), 240 tracks_parser.audio_encryption_key_id(),
241 tracks_parser.video_encryption_key_id(), audio_config.codec(), 241 tracks_parser.video_encryption_key_id(), audio_config.codec(),
242 media_log_)); 242 media_log_));
243 243
244 if (!init_cb_.is_null()) 244 if (!init_cb_.is_null())
245 base::ResetAndReturn(&init_cb_).Run(params); 245 base::ResetAndReturn(&init_cb_).Run(params);
246 246
247 return bytes_parsed; 247 return bytes_parsed;
248 } 248 }
249 249
250 int WebMStreamParser::ParseCluster(const uint8* data, int size) { 250 int WebMStreamParser::ParseCluster(const uint8_t* data, int size) {
251 if (!cluster_parser_) 251 if (!cluster_parser_)
252 return -1; 252 return -1;
253 253
254 int bytes_parsed = cluster_parser_->Parse(data, size); 254 int bytes_parsed = cluster_parser_->Parse(data, size);
255 if (bytes_parsed < 0) 255 if (bytes_parsed < 0)
256 return bytes_parsed; 256 return bytes_parsed;
257 257
258 const BufferQueue& audio_buffers = cluster_parser_->GetAudioBuffers(); 258 const BufferQueue& audio_buffers = cluster_parser_->GetAudioBuffers();
259 const BufferQueue& video_buffers = cluster_parser_->GetVideoBuffers(); 259 const BufferQueue& video_buffers = cluster_parser_->GetVideoBuffers();
260 const TextBufferQueueMap& text_map = cluster_parser_->GetTextBuffers(); 260 const TextBufferQueueMap& text_map = cluster_parser_->GetTextBuffers();
261 261
262 bool cluster_ended = cluster_parser_->cluster_ended(); 262 bool cluster_ended = cluster_parser_->cluster_ended();
263 263
264 if ((!audio_buffers.empty() || !video_buffers.empty() || 264 if ((!audio_buffers.empty() || !video_buffers.empty() ||
265 !text_map.empty()) && 265 !text_map.empty()) &&
266 !new_buffers_cb_.Run(audio_buffers, video_buffers, text_map)) { 266 !new_buffers_cb_.Run(audio_buffers, video_buffers, text_map)) {
267 return -1; 267 return -1;
268 } 268 }
269 269
270 if (cluster_ended) { 270 if (cluster_ended) {
271 ChangeState(kParsingHeaders); 271 ChangeState(kParsingHeaders);
272 end_of_segment_cb_.Run(); 272 end_of_segment_cb_.Run();
273 } 273 }
274 274
275 return bytes_parsed; 275 return bytes_parsed;
276 } 276 }
277 277
278 void WebMStreamParser::OnEncryptedMediaInitData(const std::string& key_id) { 278 void WebMStreamParser::OnEncryptedMediaInitData(const std::string& key_id) {
279 std::vector<uint8> key_id_vector(key_id.begin(), key_id.end()); 279 std::vector<uint8_t> key_id_vector(key_id.begin(), key_id.end());
280 encrypted_media_init_data_cb_.Run(EmeInitDataType::WEBM, key_id_vector); 280 encrypted_media_init_data_cb_.Run(EmeInitDataType::WEBM, key_id_vector);
281 } 281 }
282 282
283 } // namespace media 283 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698