[M120 Migration][hbbtv] Audio tracks count notification
[platform/framework/web/chromium-efl.git] / media / filters / hls_rendition.h
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.
4
5 #ifndef MEDIA_FILTERS_HLS_RENDITION_H_
6 #define MEDIA_FILTERS_HLS_RENDITION_H_
7
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"
17
18 namespace media {
19
20 // Forward declare.
21 class ManifestDemuxerEngineHost;
22
23 // Interface for `HlsRendition` to make data requests to avoid having to own or
24 // create data sources.
25 class MEDIA_EXPORT HlsRenditionHost {
26  public:
27   virtual ~HlsRenditionHost() = 0;
28
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,
34                            bool read_chunked,
35                            absl::optional<hls::types::ByteRange> range,
36                            HlsDataSourceProvider::ReadCb cb) = 0;
37
38   // Continue reading from a partially read stream.
39   virtual void ReadStream(std::unique_ptr<HlsDataSourceStream> stream,
40                           HlsDataSourceProvider::ReadCb cb) = 0;
41
42   virtual hls::ParseStatus::Or<scoped_refptr<hls::MediaPlaylist>>
43   ParseMediaPlaylistFromStringSource(base::StringPiece source,
44                                      GURL uri,
45                                      hls::types::DecimalInteger version) = 0;
46 };
47
48 class MEDIA_EXPORT HlsRendition {
49  public:
50   virtual ~HlsRendition() = default;
51
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,
55                           double playback_rate,
56                           ManifestDemuxer::DelayCallback time_remaining_cb) = 0;
57
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;
61
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;
65
66   // Live renditions should return a nullopt for duration.
67   virtual absl::optional<base::TimeDelta> GetDuration() = 0;
68
69   // Stop the rendition, including canceling pending seeks. After stopping,
70   // `CheckState` and `Seek` should be no-ops.
71   virtual void Stop() = 0;
72
73   static HlsDemuxerStatus::Or<std::unique_ptr<HlsRendition>> CreateRendition(
74       ManifestDemuxerEngineHost* engine_host,
75       HlsRenditionHost* rendition_host,
76       std::string role,
77       scoped_refptr<hls::MediaPlaylist> playlist,
78       GURL uri);
79 };
80
81 }  // namespace media
82
83 #endif  // MEDIA_FILTERS_HLS_RENDITION_H_