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 #ifndef MEDIA_FILTERS_IN_MEMORY_URL_PROTOCOL_H_
6 #define MEDIA_FILTERS_IN_MEMORY_URL_PROTOCOL_H_
7 
8 #include <stdint.h>
9 
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "media/filters/ffmpeg_glue.h"
13 
14 namespace media {
15 
16 // Simple FFmpegURLProtocol that reads from a buffer.
17 // NOTE: This object does not copy the buffer so the
18 //       buffer pointer passed into the constructor
19 //       needs to remain valid for the entire lifetime of
20 //       this object.
21 class MEDIA_EXPORT InMemoryUrlProtocol : public FFmpegURLProtocol {
22  public:
23   InMemoryUrlProtocol(const uint8_t* buf, int64_t size, bool streaming);
24   virtual ~InMemoryUrlProtocol();
25 
26   // FFmpegURLProtocol methods.
27   int Read(int size, uint8_t* data) override;
28   bool GetPosition(int64_t* position_out) override;
29   bool SetPosition(int64_t position) override;
30   bool GetSize(int64_t* size_out) override;
31   bool IsStreaming() override;
32 
33  private:
34   const uint8_t* data_;
35   int64_t size_;
36   int64_t position_;
37   bool streaming_;
38 
39   DISALLOW_IMPLICIT_CONSTRUCTORS(InMemoryUrlProtocol);
40 };
41 
42 }  // namespace media
43 
44 #endif  // MEDIA_FILTERS_IN_MEMORY_URL_PROTOCOL_H_
45