Revert "[M120 Migration]Fix for crash during chrome exit"
[platform/framework/web/chromium-efl.git] / media / filters / memory_data_source.h
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.
4
5 #ifndef MEDIA_FILTERS_MEMORY_DATA_SOURCE_H_
6 #define MEDIA_FILTERS_MEMORY_DATA_SOURCE_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <atomic>
12 #include <string>
13
14 #include "media/base/data_source.h"
15
16 namespace media {
17
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 {
21  public:
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);
25
26   // Similar to the above, but takes ownership of the std::string.
27   explicit MemoryDataSource(std::string data);
28
29   MemoryDataSource(const MemoryDataSource&) = delete;
30   MemoryDataSource& operator=(const MemoryDataSource&) = delete;
31
32   ~MemoryDataSource() final;
33
34   // Implementation of DataSource.
35   void Read(int64_t position,
36             int size,
37             uint8_t* data,
38             DataSource::ReadCB read_cb) final;
39   void Stop() final;
40   void Abort() 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;
46
47  private:
48   const std::string data_string_;
49   const uint8_t* data_ = nullptr;
50   const size_t size_ = 0;
51
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};
56 };
57
58 }  // namespace media
59
60 #endif  // MEDIA_FILTERS_MEMORY_DATA_SOURCE_H_