1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 8 #include <vector> 9 10 #include "base/time/time.h" 11 #include "media/base/data_source.h" 12 #include "media/base/demuxer_stream.h" 13 #include "media/base/media_export.h" 14 #include "media/base/pipeline_status.h" 15 16 namespace media { 17 18 class TextTrackConfig; 19 20 class MEDIA_EXPORT DemuxerHost { 21 public: 22 // Notify the host that time range [start,end] has been buffered. 23 virtual void AddBufferedTimeRange(base::TimeDelta start, 24 base::TimeDelta end) = 0; 25 26 // Sets the duration of the media in microseconds. 27 // Duration may be kInfiniteDuration() if the duration is not known. 28 virtual void SetDuration(base::TimeDelta duration) = 0; 29 30 // Stops execution of the pipeline due to a fatal error. Do not call this 31 // method with PIPELINE_OK. 32 virtual void OnDemuxerError(PipelineStatus error) = 0; 33 34 // Add |text_stream| to the collection managed by the text renderer. 35 virtual void AddTextStream(DemuxerStream* text_stream, 36 const TextTrackConfig& config) = 0; 37 38 // Remove |text_stream| from the presentation. 39 virtual void RemoveTextStream(DemuxerStream* text_stream) = 0; 40 41 protected: 42 virtual ~DemuxerHost(); 43 }; 44 45 class MEDIA_EXPORT Demuxer { 46 public: 47 enum Liveness { 48 LIVENESS_UNKNOWN, 49 LIVENESS_RECORDED, 50 LIVENESS_LIVE, 51 }; 52 53 // A new potentially encrypted stream has been parsed. 54 // First parameter - The type of initialization data. 55 // Second parameter - The initialization data associated with the stream. 56 typedef base::Callback<void(const std::string& type, 57 const std::vector<uint8>& init_data)> NeedKeyCB; 58 59 Demuxer(); 60 virtual ~Demuxer(); 61 62 // Completes initialization of the demuxer. 63 // 64 // The demuxer does not own |host| as it is guaranteed to outlive the 65 // lifetime of the demuxer. Don't delete it! 66 virtual void Initialize(DemuxerHost* host, 67 const PipelineStatusCB& status_cb, 68 bool enable_text_tracks) = 0; 69 70 // Carry out any actions required to seek to the given time, executing the 71 // callback upon completion. 72 virtual void Seek(base::TimeDelta time, 73 const PipelineStatusCB& status_cb) = 0; 74 75 // Starts stopping this demuxer, executing the callback upon completion. 76 // 77 // After the callback completes the demuxer may be destroyed. It is illegal to 78 // call any method (including Stop()) after a demuxer has stopped. 79 virtual void Stop(const base::Closure& callback) = 0; 80 81 // Returns the first stream of the given stream type (which is not allowed 82 // to be DemuxerStream::TEXT), or NULL if that type of stream is not present. 83 virtual DemuxerStream* GetStream(DemuxerStream::Type type) = 0; 84 85 // Returns the starting time for the media file. 86 virtual base::TimeDelta GetStartTime() const = 0; 87 88 // Returns Time represented by presentation timestamp 0. 89 // If the timstamps are not associated with a Time, then 90 // a null Time is returned. 91 virtual base::Time GetTimelineOffset() const = 0; 92 93 // Returns liveness of the stream, i.e. whether it is recorded or live. 94 virtual Liveness GetLiveness() const = 0; 95 96 private: 97 DISALLOW_COPY_AND_ASSIGN(Demuxer); 98 }; 99 100 } // namespace media 101 102 #endif // MEDIA_BASE_DEMUXER_H_ 103