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