Index: media/filters/buffer_url_protocol.cc |
diff --git a/media/filters/buffer_url_protocol.cc b/media/filters/buffer_url_protocol.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d1970cdb63c493c8986e3769584999130f11da4c |
--- /dev/null |
+++ b/media/filters/buffer_url_protocol.cc |
@@ -0,0 +1,55 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "media/filters/buffer_url_protocol.h" |
+ |
+namespace media { |
+ |
+BufferUrlProtocol::BufferUrlProtocol(const uint8* buf, int size, |
+ bool streaming) |
+ : buf_(buf), |
+ size_(size), |
+ offset_(0), |
+ streaming_(streaming) { |
+} |
+ |
+BufferUrlProtocol::~BufferUrlProtocol() {} |
+ |
+int BufferUrlProtocol::Read(int size, uint8* data) { |
+ int bytes_to_copy = size; |
+ int bytes_left = size_ - offset_; |
+ |
+ if (bytes_to_copy > bytes_left) |
+ bytes_to_copy = bytes_left; |
+ |
+ if (bytes_to_copy == 0) |
+ return 0; |
+ |
+ memcpy(data, buf_ + offset_, bytes_to_copy); |
+ offset_ += bytes_to_copy; |
+ |
+ return bytes_to_copy; |
+} |
+ |
+bool BufferUrlProtocol::GetPosition(int64* position_out) { |
+ *position_out = offset_; |
+ return true; |
+} |
+ |
+bool BufferUrlProtocol::SetPosition(int64 position) { |
+ if (position < 0 || position >= size_) |
+ return false; |
+ |
+ offset_ = position; |
+ return true; |
+} |
+ |
+bool BufferUrlProtocol::GetSize(int64* size_out) { |
+ *size_out = size_; |
+ return true; |
+} |
+ |
+bool BufferUrlProtocol::IsStreaming() { return streaming_; } |
+ |
+} // namespace media |