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_stream_parser.h" | 5 #include "media/webm/webm_stream_parser.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "media/ffmpeg/ffmpeg_common.h" | 9 #include "media/ffmpeg/ffmpeg_common.h" |
10 #include "media/filters/ffmpeg_glue.h" | 10 #include "media/filters/ffmpeg_glue.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 return false; | 228 return false; |
229 | 229 |
230 byte_queue_.Push(buf, size); | 230 byte_queue_.Push(buf, size); |
231 | 231 |
232 int result = 0; | 232 int result = 0; |
233 int bytes_parsed = 0; | 233 int bytes_parsed = 0; |
234 const uint8* cur = NULL; | 234 const uint8* cur = NULL; |
235 int cur_size = 0; | 235 int cur_size = 0; |
236 | 236 |
237 byte_queue_.Peek(&cur, &cur_size); | 237 byte_queue_.Peek(&cur, &cur_size); |
238 do { | 238 while (cur_size > 0) { |
| 239 State oldState = state_; |
239 switch (state_) { | 240 switch (state_) { |
240 case kParsingHeaders: | 241 case kParsingHeaders: |
241 result = ParseInfoAndTracks(cur, cur_size); | 242 result = ParseInfoAndTracks(cur, cur_size); |
242 break; | 243 break; |
243 | 244 |
244 case kParsingClusters: | 245 case kParsingClusters: |
245 result = ParseCluster(cur, cur_size); | 246 result = ParseCluster(cur, cur_size); |
246 break; | 247 break; |
247 | 248 |
248 case kWaitingForInit: | 249 case kWaitingForInit: |
249 case kError: | 250 case kError: |
250 return false; | 251 return false; |
251 } | 252 } |
252 | 253 |
253 if (result < 0) { | 254 if (result < 0) { |
254 ChangeState(kError); | 255 ChangeState(kError); |
255 return false; | 256 return false; |
256 } | 257 } |
257 | 258 |
| 259 if (state_ == oldState && result == 0) |
| 260 break; |
| 261 |
| 262 DCHECK_GE(result, 0); |
258 cur += result; | 263 cur += result; |
259 cur_size -= result; | 264 cur_size -= result; |
260 bytes_parsed += result; | 265 bytes_parsed += result; |
261 } while (result > 0 && cur_size > 0); | 266 } |
262 | 267 |
263 byte_queue_.Pop(bytes_parsed); | 268 byte_queue_.Pop(bytes_parsed); |
264 return true; | 269 return true; |
265 } | 270 } |
266 | 271 |
267 void WebMStreamParser::ChangeState(State new_state) { | 272 void WebMStreamParser::ChangeState(State new_state) { |
268 DVLOG(1) << "ChangeState() : " << state_ << " -> " << new_state; | 273 DVLOG(1) << "ChangeState() : " << state_ << " -> " << new_state; |
269 state_ = new_state; | 274 state_ = new_state; |
270 } | 275 } |
271 | 276 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 if (!audio_buffers.empty() && !audio_cb_.Run(audio_buffers)) | 425 if (!audio_buffers.empty() && !audio_cb_.Run(audio_buffers)) |
421 return -1; | 426 return -1; |
422 | 427 |
423 if (!video_buffers.empty() && !video_cb_.Run(video_buffers)) | 428 if (!video_buffers.empty() && !video_cb_.Run(video_buffers)) |
424 return -1; | 429 return -1; |
425 | 430 |
426 return bytes_parsed; | 431 return bytes_parsed; |
427 } | 432 } |
428 | 433 |
429 } // namespace media | 434 } // namespace media |
OLD | NEW |