This source file includes following definitions.
- read_position_
- Abort
- Read
- GetPosition
- SetPosition
- GetSize
- IsStreaming
- SignalReadCompleted
#include "media/filters/blocking_url_protocol.h"
#include "base/bind.h"
#include "media/base/data_source.h"
#include "media/ffmpeg/ffmpeg_common.h"
namespace media {
BlockingUrlProtocol::BlockingUrlProtocol(
DataSource* data_source,
const base::Closure& error_cb)
: data_source_(data_source),
error_cb_(error_cb),
aborted_(true, false),
read_complete_(false, false),
last_read_bytes_(0),
read_position_(0) {
}
BlockingUrlProtocol::~BlockingUrlProtocol() {}
void BlockingUrlProtocol::Abort() {
aborted_.Signal();
}
int BlockingUrlProtocol::Read(int size, uint8* data) {
if (aborted_.IsSignaled())
return AVERROR(EIO);
int64 file_size;
if (data_source_->GetSize(&file_size) && read_position_ >= file_size)
return 0;
data_source_->Read(read_position_, size, data, base::Bind(
&BlockingUrlProtocol::SignalReadCompleted, base::Unretained(this)));
base::WaitableEvent* events[] = { &aborted_, &read_complete_ };
size_t index = base::WaitableEvent::WaitMany(events, arraysize(events));
if (events[index] == &aborted_)
return AVERROR(EIO);
if (last_read_bytes_ == DataSource::kReadError) {
aborted_.Signal();
error_cb_.Run();
return AVERROR(EIO);
}
read_position_ += last_read_bytes_;
return last_read_bytes_;
}
bool BlockingUrlProtocol::GetPosition(int64* position_out) {
*position_out = read_position_;
return true;
}
bool BlockingUrlProtocol::SetPosition(int64 position) {
int64 file_size;
if ((data_source_->GetSize(&file_size) && position > file_size) ||
position < 0) {
return false;
}
read_position_ = position;
return true;
}
bool BlockingUrlProtocol::GetSize(int64* size_out) {
return data_source_->GetSize(size_out);
}
bool BlockingUrlProtocol::IsStreaming() {
return data_source_->IsStreaming();
}
void BlockingUrlProtocol::SignalReadCompleted(int size) {
last_read_bytes_ = size;
read_complete_.Signal();
}
}