[email protected] | a4dae8e | 2012-03-15 23:35:31 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 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_BASE_DEMUXER_H_ |
| 6 | #define MEDIA_BASE_DEMUXER_H_ |
| 7 | |
avi | 1323b9c2 | 2015-12-23 06:22:36 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | 322d22c | 2013-08-26 18:50:41 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
avi | a82b9b5 | 2015-12-19 04:27:08 | [diff] [blame] | 12 | #include "base/macros.h" |
[email protected] | 7e72e7b | 2013-06-28 05:40:10 | [diff] [blame] | 13 | #include "base/time/time.h" |
[email protected] | 236119c | 2011-12-16 17:14:25 | [diff] [blame] | 14 | #include "media/base/data_source.h" |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 15 | #include "media/base/demuxer_stream.h" |
xhwang | 1c5668e | 2014-09-10 02:42:04 | [diff] [blame] | 16 | #include "media/base/demuxer_stream_provider.h" |
jrummell | cf78967c | 2015-04-03 05:03:58 | [diff] [blame] | 17 | #include "media/base/eme_constants.h" |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 18 | #include "media/base/media_export.h" |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 19 | #include "media/base/pipeline_status.h" |
servolk | 21e682e | 2016-01-14 22:38:23 | [diff] [blame^] | 20 | #include "media/base/ranges.h" |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 21 | |
| 22 | namespace media { |
| 23 | |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 24 | class TextTrackConfig; |
| 25 | |
[email protected] | a61ce5a9 | 2014-04-03 18:54:39 | [diff] [blame] | 26 | class MEDIA_EXPORT DemuxerHost { |
[email protected] | 236119c | 2011-12-16 17:14:25 | [diff] [blame] | 27 | public: |
servolk | 21e682e | 2016-01-14 22:38:23 | [diff] [blame^] | 28 | // Notify the host that buffered time ranges have changed. Note that buffered |
| 29 | // time ranges can grow (when new media data is appended), but they can also |
| 30 | // shrink (when buffering reaches limit capacity and some buffered data |
| 31 | // becomes evicted, e.g. due to MSE GC algorithm, or by explicit removal of |
| 32 | // ranges directed by MSE web app). |
| 33 | virtual void OnBufferedTimeRangesChanged( |
| 34 | const Ranges<base::TimeDelta>& ranges) = 0; |
[email protected] | a61ce5a9 | 2014-04-03 18:54:39 | [diff] [blame] | 35 | |
[email protected] | 60bf922 | 2012-05-26 00:31:34 | [diff] [blame] | 36 | // Sets the duration of the media in microseconds. |
| 37 | // Duration may be kInfiniteDuration() if the duration is not known. |
[email protected] | 236119c | 2011-12-16 17:14:25 | [diff] [blame] | 38 | virtual void SetDuration(base::TimeDelta duration) = 0; |
| 39 | |
[email protected] | 236119c | 2011-12-16 17:14:25 | [diff] [blame] | 40 | // Stops execution of the pipeline due to a fatal error. Do not call this |
| 41 | // method with PIPELINE_OK. |
| 42 | virtual void OnDemuxerError(PipelineStatus error) = 0; |
[email protected] | 512d03f | 2012-06-26 01:06:06 | [diff] [blame] | 43 | |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 44 | // Add |text_stream| to the collection managed by the text renderer. |
| 45 | virtual void AddTextStream(DemuxerStream* text_stream, |
| 46 | const TextTrackConfig& config) = 0; |
| 47 | |
| 48 | // Remove |text_stream| from the presentation. |
| 49 | virtual void RemoveTextStream(DemuxerStream* text_stream) = 0; |
| 50 | |
[email protected] | 512d03f | 2012-06-26 01:06:06 | [diff] [blame] | 51 | protected: |
| 52 | virtual ~DemuxerHost(); |
[email protected] | 236119c | 2011-12-16 17:14:25 | [diff] [blame] | 53 | }; |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 54 | |
xhwang | 1c5668e | 2014-09-10 02:42:04 | [diff] [blame] | 55 | class MEDIA_EXPORT Demuxer : public DemuxerStreamProvider { |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 56 | public: |
[email protected] | 322d22c | 2013-08-26 18:50:41 | [diff] [blame] | 57 | // A new potentially encrypted stream has been parsed. |
| 58 | // First parameter - The type of initialization data. |
| 59 | // Second parameter - The initialization data associated with the stream. |
jrummell | cf78967c | 2015-04-03 05:03:58 | [diff] [blame] | 60 | typedef base::Callback<void(EmeInitDataType type, |
Avi Drissman | 97785ea | 2015-12-19 01:11:31 | [diff] [blame] | 61 | const std::vector<uint8_t>& init_data)> |
xhwang | e8c4181a | 2014-12-06 08:10:01 | [diff] [blame] | 62 | EncryptedMediaInitDataCB; |
[email protected] | 322d22c | 2013-08-26 18:50:41 | [diff] [blame] | 63 | |
[email protected] | 236119c | 2011-12-16 17:14:25 | [diff] [blame] | 64 | Demuxer(); |
dcheng | c24565478f | 2014-10-21 12:23:27 | [diff] [blame] | 65 | ~Demuxer() override; |
[email protected] | 236119c | 2011-12-16 17:14:25 | [diff] [blame] | 66 | |
xhwang | a9ca9db | 2015-06-11 23:52:39 | [diff] [blame] | 67 | // Returns the name of the demuxer for logging purpose. |
| 68 | virtual std::string GetDisplayName() const = 0; |
| 69 | |
[email protected] | 9bfe9b8 | 2012-04-02 17:56:27 | [diff] [blame] | 70 | // Completes initialization of the demuxer. |
| 71 | // |
[email protected] | d09ef25 | 2012-04-05 04:31:30 | [diff] [blame] | 72 | // The demuxer does not own |host| as it is guaranteed to outlive the |
dalecurtis | 21b12829 | 2015-01-21 11:09:24 | [diff] [blame] | 73 | // lifetime of the demuxer. Don't delete it! |status_cb| must only be run |
| 74 | // after this method has returned. |
[email protected] | d09ef25 | 2012-04-05 04:31:30 | [diff] [blame] | 75 | virtual void Initialize(DemuxerHost* host, |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 76 | const PipelineStatusCB& status_cb, |
| 77 | bool enable_text_tracks) = 0; |
[email protected] | 9bfe9b8 | 2012-04-02 17:56:27 | [diff] [blame] | 78 | |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 79 | // Carry out any actions required to seek to the given time, executing the |
| 80 | // callback upon completion. |
[email protected] | 7c63c2e | 2013-10-10 20:00:45 | [diff] [blame] | 81 | virtual void Seek(base::TimeDelta time, |
| 82 | const PipelineStatusCB& status_cb) = 0; |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 83 | |
xhwang | fcdacaf | 2014-09-02 18:08:35 | [diff] [blame] | 84 | // Stops this demuxer. |
[email protected] | 8b75455 | 2013-08-22 00:31:05 | [diff] [blame] | 85 | // |
xhwang | fcdacaf | 2014-09-02 18:08:35 | [diff] [blame] | 86 | // After this call the demuxer may be destroyed. It is illegal to call any |
| 87 | // method (including Stop()) after a demuxer has stopped. |
| 88 | virtual void Stop() = 0; |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 89 | |
dalecurtis | b9ec078cf | 2014-09-16 22:23:21 | [diff] [blame] | 90 | // Returns the starting time for the media file; it's always positive. |
| 91 | virtual base::TimeDelta GetStartTime() const = 0; |
| 92 | |
[email protected] | db66d009 | 2014-04-16 07:15:12 | [diff] [blame] | 93 | // Returns Time represented by presentation timestamp 0. |
| 94 | // If the timstamps are not associated with a Time, then |
| 95 | // a null Time is returned. |
| 96 | virtual base::Time GetTimelineOffset() const = 0; |
| 97 | |
wdzierzanowski | 9836863 | 2015-12-04 09:22:01 | [diff] [blame] | 98 | // Returns the memory usage in bytes for the demuxer. |
dalecurtis | 83266c7 | 2015-10-29 18:43:20 | [diff] [blame] | 99 | virtual int64_t GetMemoryUsage() const = 0; |
| 100 | |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 101 | private: |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 102 | DISALLOW_COPY_AND_ASSIGN(Demuxer); |
| 103 | }; |
| 104 | |
| 105 | } // namespace media |
| 106 | |
| 107 | #endif // MEDIA_BASE_DEMUXER_H_ |