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
media / filters / hls_data_source_provider_impl.h [blame]
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_FILTERS_HLS_DATA_SOURCE_PROVIDER_IMPL_H_
#define MEDIA_FILTERS_HLS_DATA_SOURCE_PROVIDER_IMPL_H_
#include <memory>
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/tick_clock.h"
#include "base/types/pass_key.h"
#include "media/base/data_source.h"
#include "media/base/media_export.h"
#include "media/base/media_log.h"
#include "media/filters/hls_data_source_provider.h"
namespace media {
class MEDIA_EXPORT HlsDataSourceProviderImpl : public HlsDataSourceProvider {
public:
// An instance of DataSourceFactory allows separation of DataSource creation
// and DataSourceStream buffer management for easier testing.
class DataSourceFactory {
public:
using DataSourceCb = base::OnceCallback<void(std::unique_ptr<DataSource>)>;
virtual ~DataSourceFactory() = default;
virtual void CreateDataSource(GURL uri,
bool ignore_cache,
DataSourceCb cb) = 0;
};
~HlsDataSourceProviderImpl() override;
explicit HlsDataSourceProviderImpl(
std::unique_ptr<DataSourceFactory> factory);
// HlsDataSourceProvider implementation
void ReadFromCombinedUrlQueue(SegmentQueue segments,
ReadCb callback) override;
void ReadFromExistingStream(std::unique_ptr<HlsDataSourceStream> stream,
ReadCb callback) override;
void AbortPendingReads(base::OnceClosure cb) override;
private:
void UpdateStreamMetadata(HlsDataSourceStream::StreamId,
HlsDataSourceStream& stream);
void OnDataSourceCreated(std::unique_ptr<HlsDataSourceStream> stream,
ReadCb callback,
std::unique_ptr<DataSource> data_source);
void OnStreamReleased(HlsDataSourceStream::StreamId stream_id);
void DataSourceInitialized(std::unique_ptr<HlsDataSourceStream> stream,
ReadCb callback,
bool success);
std::unique_ptr<DataSourceFactory> data_source_factory_;
HlsDataSourceStream::StreamId::Generator stream_id_generator_;
base::flat_map<HlsDataSourceStream::StreamId, std::unique_ptr<DataSource>>
data_source_map_;
bool would_taint_origin_ = false;
SEQUENCE_CHECKER(sequence_checker_);
base::WeakPtrFactory<HlsDataSourceProviderImpl> weak_factory_{this};
};
} // namespace media
#endif // MEDIA_FILTERS_HLS_DATA_SOURCE_PROVIDER_IMPL_H_