blob: 71cdc6d14a91518950aa7d1dc943568937dff761 [file] [log] [blame]
[email protected]a4dae8e2012-03-15 23:35:311// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a2b5c472011-09-13 20:24:102// 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_BASE_DEMUXER_H_
6#define MEDIA_BASE_DEMUXER_H_
7
avi1323b9c22015-12-23 06:22:368#include <stdint.h>
9
danakj6aaed6a2016-04-26 01:25:4410#include <memory>
[email protected]322d22c2013-08-26 18:50:4111#include <vector>
12
avia82b9b52015-12-19 04:27:0813#include "base/macros.h"
[email protected]7e72e7b2013-06-28 05:40:1014#include "base/time/time.h"
[email protected]236119c2011-12-16 17:14:2515#include "media/base/data_source.h"
[email protected]a2b5c472011-09-13 20:24:1016#include "media/base/demuxer_stream.h"
jrummellcf78967c2015-04-03 05:03:5817#include "media/base/eme_constants.h"
[email protected]a2b5c472011-09-13 20:24:1018#include "media/base/media_export.h"
servolkcfc91f152017-02-02 05:11:2319#include "media/base/media_resource.h"
servolkf25ceed2016-07-01 03:44:3820#include "media/base/media_track.h"
[email protected]a2b5c472011-09-13 20:24:1021#include "media/base/pipeline_status.h"
servolk21e682e2016-01-14 22:38:2322#include "media/base/ranges.h"
[email protected]a2b5c472011-09-13 20:24:1023
24namespace media {
25
[email protected]8a561062013-11-22 01:19:3126class TextTrackConfig;
servolk81e01e02016-03-05 03:29:1527class MediaTracks;
[email protected]8a561062013-11-22 01:19:3128
[email protected]a61ce5a92014-04-03 18:54:3929class MEDIA_EXPORT DemuxerHost {
[email protected]236119c2011-12-16 17:14:2530 public:
servolk21e682e2016-01-14 22:38:2331 // Notify the host that buffered time ranges have changed. Note that buffered
32 // time ranges can grow (when new media data is appended), but they can also
33 // shrink (when buffering reaches limit capacity and some buffered data
34 // becomes evicted, e.g. due to MSE GC algorithm, or by explicit removal of
35 // ranges directed by MSE web app).
36 virtual void OnBufferedTimeRangesChanged(
37 const Ranges<base::TimeDelta>& ranges) = 0;
[email protected]a61ce5a92014-04-03 18:54:3938
[email protected]60bf9222012-05-26 00:31:3439 // Sets the duration of the media in microseconds.
dalecurtis39a7f932016-07-19 18:34:5940 // Duration may be kInfiniteDuration if the duration is not known.
[email protected]236119c2011-12-16 17:14:2541 virtual void SetDuration(base::TimeDelta duration) = 0;
42
dalecurtis2ff781da2016-03-03 01:52:1343 // Stops execution of the pipeline due to a fatal error. Do not call this
44 // method with PIPELINE_OK. Stopping is not immediate so demuxers must be
45 // prepared to soft fail on subsequent calls. E.g., if Demuxer::Seek() is
46 // called after an unrecoverable error the provided PipelineStatusCB must be
47 // called with an error.
[email protected]236119c2011-12-16 17:14:2548 virtual void OnDemuxerError(PipelineStatus error) = 0;
[email protected]512d03f2012-06-26 01:06:0649
[email protected]8a561062013-11-22 01:19:3150 // Add |text_stream| to the collection managed by the text renderer.
51 virtual void AddTextStream(DemuxerStream* text_stream,
52 const TextTrackConfig& config) = 0;
53
54 // Remove |text_stream| from the presentation.
55 virtual void RemoveTextStream(DemuxerStream* text_stream) = 0;
56
[email protected]512d03f2012-06-26 01:06:0657 protected:
58 virtual ~DemuxerHost();
[email protected]236119c2011-12-16 17:14:2559};
[email protected]a2b5c472011-09-13 20:24:1060
servolkcfc91f152017-02-02 05:11:2361class MEDIA_EXPORT Demuxer : public MediaResource {
[email protected]a2b5c472011-09-13 20:24:1062 public:
[email protected]322d22c2013-08-26 18:50:4163 // A new potentially encrypted stream has been parsed.
64 // First parameter - The type of initialization data.
65 // Second parameter - The initialization data associated with the stream.
danakj6aaed6a2016-04-26 01:25:4466 using EncryptedMediaInitDataCB =
67 base::Callback<void(EmeInitDataType type,
68 const std::vector<uint8_t>& init_data)>;
[email protected]322d22c2013-08-26 18:50:4169
servolk81e01e02016-03-05 03:29:1570 // Notifies demuxer clients that media track configuration has been updated
servolkf25ceed2016-07-01 03:44:3871 // (e.g. the initial stream metadata has been parsed successfully, or a new
servolk81e01e02016-03-05 03:29:1572 // init segment has been parsed successfully in MSE case).
danakj6aaed6a2016-04-26 01:25:4473 using MediaTracksUpdatedCB =
74 base::Callback<void(std::unique_ptr<MediaTracks>)>;
servolk81e01e02016-03-05 03:29:1575
[email protected]236119c2011-12-16 17:14:2576 Demuxer();
dchengc24565478f2014-10-21 12:23:2777 ~Demuxer() override;
[email protected]236119c2011-12-16 17:14:2578
xhwanga9ca9db2015-06-11 23:52:3979 // Returns the name of the demuxer for logging purpose.
80 virtual std::string GetDisplayName() const = 0;
81
[email protected]9bfe9b82012-04-02 17:56:2782 // Completes initialization of the demuxer.
83 //
[email protected]d09ef252012-04-05 04:31:3084 // The demuxer does not own |host| as it is guaranteed to outlive the
dalecurtis21b128292015-01-21 11:09:2485 // lifetime of the demuxer. Don't delete it! |status_cb| must only be run
86 // after this method has returned.
[email protected]d09ef252012-04-05 04:31:3087 virtual void Initialize(DemuxerHost* host,
[email protected]8a561062013-11-22 01:19:3188 const PipelineStatusCB& status_cb,
89 bool enable_text_tracks) = 0;
[email protected]9bfe9b82012-04-02 17:56:2790
dalecurtisf299e192016-08-30 19:54:1991 // Aborts any pending read operations that the demuxer is involved with; any
sandersd216002c2016-12-05 22:28:5892 // read aborted will be aborted with a status of kAborted. Future reads will
93 // also be aborted until Seek() is called.
dalecurtisf299e192016-08-30 19:54:1994 virtual void AbortPendingReads() = 0;
95
sandersdb5e21462016-03-09 01:49:0796 // Indicates that a new Seek() call is on its way. Implementations may abort
97 // pending reads and future Read() calls may return kAborted until Seek() is
98 // executed. |seek_time| is the presentation timestamp of the new Seek() call.
99 //
100 // In actual use, this call occurs on the main thread while Seek() is called
101 // on the media thread. StartWaitingForSeek() can be used to synchronize the
102 // two.
103 //
104 // StartWaitingForSeek() MUST be called before Seek().
105 virtual void StartWaitingForSeek(base::TimeDelta seek_time) = 0;
106
107 // Indicates that the current Seek() operation is obsoleted by a new one.
108 // Implementations can expect that StartWaitingForSeek() will be called
109 // when the current seek operation completes.
110 //
111 // Like StartWaitingForSeek(), CancelPendingSeek() is called on the main
112 // thread. Ordering with respect to the to-be-canceled Seek() is not
113 // guaranteed. Regardless of ordering, implementations may abort pending reads
114 // and may return kAborted from future Read() calls, until after
115 // StartWaitingForSeek() and the following Seek() call occurs.
116 //
117 // |seek_time| should match that passed to the next StartWaitingForSeek(), but
118 // may not if the seek target changes again before the current seek operation
119 // completes or is aborted.
120 virtual void CancelPendingSeek(base::TimeDelta seek_time) = 0;
121
[email protected]a2b5c472011-09-13 20:24:10122 // Carry out any actions required to seek to the given time, executing the
123 // callback upon completion.
[email protected]7c63c2e2013-10-10 20:00:45124 virtual void Seek(base::TimeDelta time,
125 const PipelineStatusCB& status_cb) = 0;
[email protected]a2b5c472011-09-13 20:24:10126
xhwangfcdacaf2014-09-02 18:08:35127 // Stops this demuxer.
[email protected]8b754552013-08-22 00:31:05128 //
xhwangfcdacaf2014-09-02 18:08:35129 // After this call the demuxer may be destroyed. It is illegal to call any
130 // method (including Stop()) after a demuxer has stopped.
131 virtual void Stop() = 0;
[email protected]a2b5c472011-09-13 20:24:10132
dalecurtisb9ec078cf2014-09-16 22:23:21133 // Returns the starting time for the media file; it's always positive.
134 virtual base::TimeDelta GetStartTime() const = 0;
135
[email protected]db66d0092014-04-16 07:15:12136 // Returns Time represented by presentation timestamp 0.
137 // If the timstamps are not associated with a Time, then
138 // a null Time is returned.
139 virtual base::Time GetTimelineOffset() const = 0;
140
wdzierzanowski98368632015-12-04 09:22:01141 // Returns the memory usage in bytes for the demuxer.
dalecurtis83266c72015-10-29 18:43:20142 virtual int64_t GetMemoryUsage() const = 0;
143
servolkf25ceed2016-07-01 03:44:38144 virtual void OnEnabledAudioTracksChanged(
145 const std::vector<MediaTrack::Id>& track_ids,
146 base::TimeDelta currTime) = 0;
147
148 // |track_ids| is either empty or contains a single video track id.
149 virtual void OnSelectedVideoTrackChanged(
150 const std::vector<MediaTrack::Id>& track_ids,
151 base::TimeDelta currTime) = 0;
152
[email protected]a2b5c472011-09-13 20:24:10153 private:
[email protected]a2b5c472011-09-13 20:24:10154 DISALLOW_COPY_AND_ASSIGN(Demuxer);
155};
156
157} // namespace media
158
159#endif // MEDIA_BASE_DEMUXER_H_