NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / media / filters / in_memory_url_protocol.cc
blob85fa290e501988e480598f4f65f66dc28c45aa40
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/filters/in_memory_url_protocol.h"
7 namespace media {
9 InMemoryUrlProtocol::InMemoryUrlProtocol(const uint8* data, int64 size,
10 bool streaming)
11 : data_(data),
12 size_(size >= 0 ? size : 0),
13 position_(0),
14 streaming_(streaming) {
17 InMemoryUrlProtocol::~InMemoryUrlProtocol() {}
19 int InMemoryUrlProtocol::Read(int size, uint8* data) {
20 int available_bytes = size_ - position_;
21 if (size > available_bytes)
22 size = available_bytes;
24 memcpy(data, data_ + position_, size);
25 position_ += size;
26 return size;
29 bool InMemoryUrlProtocol::GetPosition(int64* position_out) {
30 if (!position_out)
31 return false;
33 *position_out = position_;
34 return true;
37 bool InMemoryUrlProtocol::SetPosition(int64 position) {
38 if (position < 0 || position > size_)
39 return false;
40 position_ = position;
41 return true;
44 bool InMemoryUrlProtocol::GetSize(int64* size_out) {
45 if (!size_out)
46 return false;
48 *size_out = size_;
49 return true;
52 bool InMemoryUrlProtocol::IsStreaming() {
53 return streaming_;
56 } // namespace media