1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_FILTERS_MEMORY_DATA_SOURCE_H_
6 #define MEDIA_FILTERS_MEMORY_DATA_SOURCE_H_
14 #include "media/base/data_source.h"
18 // Basic data source that treats the URL as a file path, and uses the file
19 // system to read data for a media pipeline.
20 class MEDIA_EXPORT MemoryDataSource final : public DataSource {
22 // Construct MemoryDataSource with |data| and |size|. The data is guaranteed
23 // to be valid during the lifetime of MemoryDataSource.
24 MemoryDataSource(const uint8_t* data, size_t size);
26 // Similar to the above, but takes ownership of the std::string.
27 explicit MemoryDataSource(std::string data);
29 MemoryDataSource(const MemoryDataSource&) = delete;
30 MemoryDataSource& operator=(const MemoryDataSource&) = delete;
32 ~MemoryDataSource() final;
34 // Implementation of DataSource.
35 void Read(int64_t position,
38 DataSource::ReadCB read_cb) final;
41 [[nodiscard]] bool GetSize(int64_t* size_out) final;
42 bool IsStreaming() final;
43 void SetBitrate(int bitrate) final;
44 bool PassedTimingAllowOriginCheck() final;
45 bool WouldTaintOrigin() final;
48 const std::string data_string_;
49 const uint8_t* data_ = nullptr;
50 const size_t size_ = 0;
52 // Stop may be called from the render thread while this class is being used by
53 // the media thread. It's harmless if we fulfill a read after Stop() has been
54 // called, so an atomic without a lock is safe.
55 std::atomic<bool> is_stopped_{false};
60 #endif // MEDIA_FILTERS_MEMORY_DATA_SOURCE_H_