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

Unified Diff: media/base/seekable_buffer.cc

Issue 17315021: Refactored DataBuffer to use unix_hacker style methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor DataBuffer Created 7 years, 6 months 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 side-by-side diff with in-line comments
Download patch
Index: media/base/seekable_buffer.cc
diff --git a/media/base/seekable_buffer.cc b/media/base/seekable_buffer.cc
index 6ad3b02fd5bd494a85448d5f78d3cc6e941363af..57c09870df2bf19fe75d7f0b83dd84521cd1b3da 100644
--- a/media/base/seekable_buffer.cc
+++ b/media/base/seekable_buffer.cc
@@ -11,8 +11,7 @@
namespace media {
-SeekableBuffer::SeekableBuffer(int backward_capacity,
- int forward_capacity)
+SeekableBuffer::SeekableBuffer(int backward_capacity, int forward_capacity)
: current_buffer_offset_(0),
backward_capacity_(backward_capacity),
backward_bytes_(0),
@@ -22,8 +21,7 @@ SeekableBuffer::SeekableBuffer(int backward_capacity,
current_buffer_ = buffers_.begin();
}
-SeekableBuffer::~SeekableBuffer() {
-}
+SeekableBuffer::~SeekableBuffer() {}
void SeekableBuffer::Clear() {
buffers_.clear();
@@ -49,20 +47,19 @@ bool SeekableBuffer::GetCurrentChunk(const uint8** data, int* size) const {
int current_buffer_offset = current_buffer_offset_;
// Advance position if we are in the end of the current buffer.
while (current_buffer != buffers_.end() &&
- current_buffer_offset >= (*current_buffer)->GetDataSize()) {
+ current_buffer_offset >= (*current_buffer)->get_data_size()) {
++current_buffer;
current_buffer_offset = 0;
}
- if (current_buffer == buffers_.end())
- return false;
- *data = (*current_buffer)->GetData() + current_buffer_offset;
- *size = (*current_buffer)->GetDataSize() - current_buffer_offset;
+ if (current_buffer == buffers_.end()) return false;
+ *data = (*current_buffer)->get_data() + current_buffer_offset;
+ *size = (*current_buffer)->get_data_size() - current_buffer_offset;
return true;
}
bool SeekableBuffer::Append(const scoped_refptr<DataBuffer>& buffer_in) {
- if (buffers_.empty() && buffer_in->GetTimestamp() != kNoTimestamp()) {
- current_time_ = buffer_in->GetTimestamp();
+ if (buffers_.empty() && buffer_in->get_timestamp() != kNoTimestamp()) {
+ current_time_ = buffer_in->get_timestamp();
}
// Since the forward capacity is only used to check the criteria for buffer
@@ -77,19 +74,18 @@ bool SeekableBuffer::Append(const scoped_refptr<DataBuffer>& buffer_in) {
}
// Update the |forward_bytes_| counter since we have more bytes.
- forward_bytes_ += buffer_in->GetDataSize();
+ forward_bytes_ += buffer_in->get_data_size();
// Advise the user to stop append if the amount of forward bytes exceeds
// the forward capacity. A false return value means the user should stop
// appending more data to this buffer.
- if (forward_bytes_ >= forward_capacity_)
- return false;
+ if (forward_bytes_ >= forward_capacity_) return false;
return true;
}
bool SeekableBuffer::Append(const uint8* data, int size) {
if (size > 0) {
- scoped_refptr<DataBuffer> data_buffer = DataBuffer::CopyFrom(data, size);
+ scoped_refptr<DataBuffer> data_buffer = DataBuffer::copy_from(data, size);
return Append(data_buffer);
} else {
// Return true if we have forward capacity.
@@ -107,8 +103,7 @@ bool SeekableBuffer::Seek(int32 offset) {
bool SeekableBuffer::SeekForward(int size) {
// Perform seeking forward only if we have enough bytes in the queue.
- if (size > forward_bytes_)
- return false;
+ if (size > forward_bytes_) return false;
// Do a read of |size| bytes.
int taken = InternalRead(NULL, size, true, 0);
@@ -117,8 +112,7 @@ bool SeekableBuffer::SeekForward(int size) {
}
bool SeekableBuffer::SeekBackward(int size) {
- if (size > backward_bytes_)
- return false;
+ if (size > backward_bytes_) return false;
// Record the number of bytes taken.
int taken = 0;
// Loop until we taken enough bytes and rewind by the desired |size|.
@@ -150,13 +144,12 @@ bool SeekableBuffer::SeekBackward(int size) {
// The current buffer pointed by current iterator has been consumed. Move
// the iterator backward so it points to the previous buffer.
if (current_buffer_offset_ == 0) {
- if (current_buffer_ == buffers_.begin())
- break;
+ if (current_buffer_ == buffers_.begin()) break;
// Move the iterator backward.
--current_buffer_;
// Set the offset into the current buffer to be the buffer size as we
// are preparing for rewind for next iteration.
- current_buffer_offset_ = (*current_buffer_)->GetDataSize();
+ current_buffer_offset_ = (*current_buffer_)->get_data_size();
}
}
@@ -170,18 +163,16 @@ void SeekableBuffer::EvictBackwardBuffers() {
// Advances the iterator until we hit the current pointer.
while (backward_bytes_ > backward_capacity_) {
BufferQueue::iterator i = buffers_.begin();
- if (i == current_buffer_)
- break;
+ if (i == current_buffer_) break;
scoped_refptr<DataBuffer> buffer = *i;
- backward_bytes_ -= buffer->GetDataSize();
+ backward_bytes_ -= buffer->get_data_size();
DCHECK_GE(backward_bytes_, 0);
buffers_.erase(i);
}
}
-int SeekableBuffer::InternalRead(uint8* data, int size,
- bool advance_position,
+int SeekableBuffer::InternalRead(uint8* data, int size, bool advance_position,
int forward_offset) {
// Counts how many bytes are actually read from the buffer queue.
int taken = 0;
@@ -193,13 +184,12 @@ int SeekableBuffer::InternalRead(uint8* data, int size,
while (taken < size) {
// |current_buffer| is valid since the first time this buffer is appended
// with data.
- if (current_buffer == buffers_.end())
- break;
+ if (current_buffer == buffers_.end()) break;
scoped_refptr<DataBuffer> buffer = *current_buffer;
int remaining_bytes_in_buffer =
- buffer->GetDataSize() - current_buffer_offset;
+ buffer->get_data_size() - current_buffer_offset;
if (bytes_to_skip == 0) {
// Find the right amount to copy from the current buffer referenced by
@@ -209,7 +199,8 @@ int SeekableBuffer::InternalRead(uint8* data, int size,
// |data| is NULL if we are seeking forward, so there's no need to copy.
if (data)
- memcpy(data + taken, buffer->GetData() + current_buffer_offset, copied);
+ memcpy(data + taken, buffer->get_data() + current_buffer_offset,
+ copied);
// Increase total number of bytes copied, which regulates when to end this
// loop.
@@ -225,7 +216,7 @@ int SeekableBuffer::InternalRead(uint8* data, int size,
}
// The buffer has been consumed.
- if (current_buffer_offset == buffer->GetDataSize()) {
+ if (current_buffer_offset == buffer->get_data_size()) {
if (advance_position) {
// Next buffer may not have timestamp, so we need to update current
// timestamp before switching to the next buffer.
@@ -235,8 +226,7 @@ int SeekableBuffer::InternalRead(uint8* data, int size,
BufferQueue::iterator next = current_buffer;
++next;
// If we are at the last buffer, don't advance.
- if (next == buffers_.end())
- break;
+ if (next == buffers_.end()) break;
// Advances the iterator.
current_buffer = next;
@@ -265,12 +255,13 @@ int SeekableBuffer::InternalRead(uint8* data, int size,
void SeekableBuffer::UpdateCurrentTime(BufferQueue::iterator buffer,
int offset) {
// Garbage values are unavoidable, so this check will remain.
- if (buffer != buffers_.end() && (*buffer)->GetTimestamp() != kNoTimestamp()) {
- int64 time_offset = ((*buffer)->GetDuration().InMicroseconds() *
- offset) / (*buffer)->GetDataSize();
+ if (buffer != buffers_.end() &&
+ (*buffer)->get_timestamp() != kNoTimestamp()) {
+ int64 time_offset = ((*buffer)->get_duration().InMicroseconds() * offset) /
+ (*buffer)->get_data_size();
- current_time_ = (*buffer)->GetTimestamp() +
- base::TimeDelta::FromMicroseconds(time_offset);
+ current_time_ = (*buffer)->get_timestamp() +
+ base::TimeDelta::FromMicroseconds(time_offset);
}
}

Powered by Google App Engine
This is Rietveld 408576698