85fa290e501988e480598f4f65f66dc28c45aa40
[platform/framework/web/crosswalk.git] / src / media / filters / in_memory_url_protocol.cc
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 namespace media {
8
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) {
15 }
16
17 InMemoryUrlProtocol::~InMemoryUrlProtocol() {}
18
19 int 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
29 bool InMemoryUrlProtocol::GetPosition(int64* position_out) {
30   if (!position_out)
31     return false;
32
33   *position_out = position_;
34   return true;
35 }
36
37 bool InMemoryUrlProtocol::SetPosition(int64 position) {
38   if (position < 0 || position > size_)
39     return false;
40   position_ = position;
41   return true;
42 }
43
44 bool InMemoryUrlProtocol::GetSize(int64* size_out) {
45   if (!size_out)
46     return false;
47
48   *size_out = size_;
49   return true;
50 }
51
52 bool InMemoryUrlProtocol::IsStreaming() {
53   return streaming_;
54 }
55
56 }  // namespace media