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. 4 5#include "media/filters/in_memory_url_protocol.h" 6 7namespace media { 8 9InMemoryUrlProtocol::InMemoryUrlProtocol(const uint8* data, int64 size, 10 bool streaming) 11 : data_(data), 12 size_(size >= 0 ? size : 0), 13 position_(0), 14 streaming_(streaming) { 15} 16 17InMemoryUrlProtocol::~InMemoryUrlProtocol() {} 18 19int InMemoryUrlProtocol::Read(int size, uint8* data) { 20 int available_bytes = size_ - position_; 21 if (size > available_bytes) 22 size = available_bytes; 23 24 memcpy(data, data_ + position_, size); 25 position_ += size; 26 return size; 27} 28 29bool InMemoryUrlProtocol::GetPosition(int64* position_out) { 30 if (!position_out) 31 return false; 32 33 *position_out = position_; 34 return true; 35} 36 37bool InMemoryUrlProtocol::SetPosition(int64 position) { 38 if (position < 0 || position >= size_) 39 return false; 40 position_ = position; 41 return true; 42} 43 44bool InMemoryUrlProtocol::GetSize(int64* size_out) { 45 if (!size_out) 46 return false; 47 48 *size_out = size_; 49 return true; 50} 51 52bool InMemoryUrlProtocol::IsStreaming() { 53 return streaming_; 54} 55 56} // namespace media 57