OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/callback.h" | 5 #include "base/callback.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 329 } |
330 | 330 |
331 int FFmpegDemuxer::Read(int size, uint8* data) { | 331 int FFmpegDemuxer::Read(int size, uint8* data) { |
332 DCHECK(data_source_); | 332 DCHECK(data_source_); |
333 | 333 |
334 // If read has ever failed, return with an error. | 334 // If read has ever failed, return with an error. |
335 // TODO(hclam): use a more meaningful constant as error. | 335 // TODO(hclam): use a more meaningful constant as error. |
336 if (read_has_failed_) | 336 if (read_has_failed_) |
337 return AVERROR_IO; | 337 return AVERROR_IO; |
338 | 338 |
339 // If the read position exceeds the size of the data source. We should return | 339 // Even though FFmpeg defines AVERROR_EOF, it's not to be used with I/O |
340 // end-of-file directly. | 340 // routines. Instead return 0 for any read at or past EOF. |
341 int64 file_size; | 341 int64 file_size; |
342 if (data_source_->GetSize(&file_size) && read_position_ >= file_size) | 342 if (data_source_->GetSize(&file_size) && read_position_ >= file_size) |
343 return AVERROR_EOF; | 343 return 0; |
344 | 344 |
345 // Asynchronous read from data source. | 345 // Asynchronous read from data source. |
346 data_source_->Read(read_position_, size, data, | 346 data_source_->Read(read_position_, size, data, |
347 NewCallback(this, &FFmpegDemuxer::OnReadCompleted)); | 347 NewCallback(this, &FFmpegDemuxer::OnReadCompleted)); |
348 | 348 |
349 // TODO(hclam): The method is called on the demuxer thread and this method | 349 // TODO(hclam): The method is called on the demuxer thread and this method |
350 // call will block the thread. We need to implemented an additional thread to | 350 // call will block the thread. We need to implemented an additional thread to |
351 // let FFmpeg demuxer methods to run on. | 351 // let FFmpeg demuxer methods to run on. |
352 size_t last_read_bytes = WaitForRead(); | 352 size_t last_read_bytes = WaitForRead(); |
353 if (last_read_bytes == DataSource::kReadError) { | 353 if (last_read_bytes == DataSource::kReadError) { |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 read_event_.Wait(); | 620 read_event_.Wait(); |
621 return last_read_bytes_; | 621 return last_read_bytes_; |
622 } | 622 } |
623 | 623 |
624 void FFmpegDemuxer::SignalReadCompleted(size_t size) { | 624 void FFmpegDemuxer::SignalReadCompleted(size_t size) { |
625 last_read_bytes_ = size; | 625 last_read_bytes_ = size; |
626 read_event_.Signal(); | 626 read_event_.Signal(); |
627 } | 627 } |
628 | 628 |
629 } // namespace media | 629 } // namespace media |
OLD | NEW |