-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_data_source.h
74 lines (57 loc) · 1.97 KB
/
resource_data_source.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) 2017 YuTeh Shen
//
#ifndef CHROMIUM_MEDIA_LIB_RESOURCE_DATA_SOURCE_H_
#define CHROMIUM_MEDIA_LIB_RESOURCE_DATA_SOURCE_H_
#include <memory>
#include "base/bind.h"
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/synchronization/lock.h"
#include "chromium_media_lib/read_operation.h"
#include "chromium_media_lib/resource_multibuffer.h"
#include "media/base/data_source.h"
#include "url/gurl.h"
namespace media {
class ResourceDataSource : public DataSource, public ResourceMultiBufferClient {
public:
ResourceDataSource(
const GURL& url,
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
~ResourceDataSource() override;
typedef base::Callback<void(bool)> InitializeCB;
void Initialize(const InitializeCB& init_cb);
// DataSource implementation.
// Called from demuxer thread.
void Stop() override;
void Abort() override;
void Read(int64_t position,
int size,
uint8_t* data,
const DataSource::ReadCB& read_cb) override;
bool GetSize(int64_t* size_out) override;
bool IsStreaming() override;
void SetBitrate(int bitrate) override;
// ResourceMultiBufferClient
void DidInitialize() override;
void OnUpdateState() override;
private:
void ReadTask();
private:
const scoped_refptr<base::SingleThreadTaskRunner> render_task_runner_;
const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
GURL url_;
base::Lock lock_;
bool stop_signal_received_;
int64_t total_bytes_;
InitializeCB init_cb_;
ResourceMultiBuffer multibuffer_;
std::unique_ptr<ReadOperation> read_op_;
base::WeakPtr<ResourceDataSource> weak_ptr_;
base::WeakPtrFactory<ResourceDataSource> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ResourceDataSource);
};
} // namespace media
#endif // CHROMIUM_MEDIA_LIB_RESOURCE_DATA_SOURCE_H_