1 // Copyright 2023 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_HLS_RENDITION_H_
6 #define MEDIA_FILTERS_HLS_RENDITION_H_
8 #include "base/time/time.h"
9 #include "media/base/media_export.h"
10 #include "media/base/ranges.h"
11 #include "media/filters/chunk_demuxer.h"
12 #include "media/filters/hls_data_source_provider.h"
13 #include "media/filters/hls_demuxer_status.h"
14 #include "media/filters/manifest_demuxer.h"
15 #include "media/formats/hls/media_playlist.h"
16 #include "media/formats/hls/media_segment.h"
21 class ManifestDemuxerEngineHost;
23 // Interface for `HlsRendition` to make data requests to avoid having to own or
24 // create data sources.
25 class MEDIA_EXPORT HlsRenditionHost {
27 virtual ~HlsRenditionHost() = 0;
29 // Lets a rendition read URL data from `uri`. Usually this will be a chunked
30 // read, but can be configured with `read_chunked`, since live video needs to
31 // download full manifests. Additionally, some manifests can specify a custom
32 // byte range, which can be forwarded as `range`.
33 virtual void ReadFromUrl(GURL uri,
35 absl::optional<hls::types::ByteRange> range,
36 HlsDataSourceProvider::ReadCb cb) = 0;
38 // Continue reading from a partially read stream.
39 virtual void ReadStream(std::unique_ptr<HlsDataSourceStream> stream,
40 HlsDataSourceProvider::ReadCb cb) = 0;
42 virtual hls::ParseStatus::Or<scoped_refptr<hls::MediaPlaylist>>
43 ParseMediaPlaylistFromStringSource(base::StringPiece source,
45 hls::types::DecimalInteger version) = 0;
48 class MEDIA_EXPORT HlsRendition {
50 virtual ~HlsRendition() = default;
52 // Checks the current playback time and starts any required network requests
53 // for more data, or clears out old data.
54 virtual void CheckState(base::TimeDelta media_time,
56 ManifestDemuxer::DelayCallback time_remaining_cb) = 0;
58 // Does any necessary seeking work, and returns true iff more data is needed
59 // as the seek was outside of a loaded range.
60 virtual ManifestDemuxer::SeekResponse Seek(base::TimeDelta seek_time) = 0;
62 // Lets the rendition know that any network requests which respond with an
63 // aborted status are not to be treated as errors until the seek is finished.
64 virtual void StartWaitingForSeek() = 0;
66 // Live renditions should return a nullopt for duration.
67 virtual absl::optional<base::TimeDelta> GetDuration() = 0;
69 // Stop the rendition, including canceling pending seeks. After stopping,
70 // `CheckState` and `Seek` should be no-ops.
71 virtual void Stop() = 0;
73 static HlsDemuxerStatus::Or<std::unique_ptr<HlsRendition>> CreateRendition(
74 ManifestDemuxerEngineHost* engine_host,
75 HlsRenditionHost* rendition_host,
77 scoped_refptr<hls::MediaPlaylist> playlist,
83 #endif // MEDIA_FILTERS_HLS_RENDITION_H_