[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 | |||||
8 | #include "base/memory/ref_counted.h" | ||||
[email protected] | 236119c | 2011-12-16 17:14:25 | [diff] [blame] | 9 | #include "base/time.h" |
10 | #include "media/base/data_source.h" | ||||
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 11 | #include "media/base/demuxer_stream.h" |
12 | #include "media/base/media_export.h" | ||||
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 13 | #include "media/base/pipeline_status.h" |
14 | |||||
15 | namespace media { | ||||
16 | |||||
[email protected] | 236119c | 2011-12-16 17:14:25 | [diff] [blame] | 17 | class MEDIA_EXPORT DemuxerHost : public DataSourceHost { |
18 | public: | ||||
19 | virtual ~DemuxerHost(); | ||||
20 | |||||
21 | // Get the duration of the media in microseconds. If the duration has not | ||||
22 | // been determined yet, then returns 0. | ||||
23 | virtual void SetDuration(base::TimeDelta duration) = 0; | ||||
24 | |||||
25 | // Set the approximate amount of playable data buffered so far in micro- | ||||
26 | // seconds. | ||||
27 | virtual void SetBufferedTime(base::TimeDelta buffered_time) = 0; | ||||
28 | |||||
29 | // Sets the byte offset at which the client is requesting the video. | ||||
30 | virtual void SetCurrentReadPosition(int64 offset) = 0; | ||||
31 | |||||
32 | // Stops execution of the pipeline due to a fatal error. Do not call this | ||||
33 | // method with PIPELINE_OK. | ||||
34 | virtual void OnDemuxerError(PipelineStatus error) = 0; | ||||
35 | }; | ||||
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 36 | |
[email protected] | d09ef25 | 2012-04-05 04:31:30 | [diff] [blame^] | 37 | class MEDIA_EXPORT Demuxer : public base::RefCountedThreadSafe<Demuxer> { |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 38 | public: |
[email protected] | 236119c | 2011-12-16 17:14:25 | [diff] [blame] | 39 | Demuxer(); |
40 | |||||
[email protected] | 9bfe9b8 | 2012-04-02 17:56:27 | [diff] [blame] | 41 | // Completes initialization of the demuxer. |
42 | // | ||||
[email protected] | d09ef25 | 2012-04-05 04:31:30 | [diff] [blame^] | 43 | // The demuxer does not own |host| as it is guaranteed to outlive the |
44 | // lifetime of the demuxer. Don't delete it! | ||||
45 | virtual void Initialize(DemuxerHost* host, | ||||
46 | const PipelineStatusCB& status_cb) = 0; | ||||
[email protected] | 9bfe9b8 | 2012-04-02 17:56:27 | [diff] [blame] | 47 | |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 48 | // The pipeline playback rate has been changed. Demuxers may implement this |
49 | // method if they need to respond to this call. | ||||
50 | virtual void SetPlaybackRate(float playback_rate); | ||||
51 | |||||
52 | // Carry out any actions required to seek to the given time, executing the | ||||
53 | // callback upon completion. | ||||
[email protected] | a4dae8e | 2012-03-15 23:35:31 | [diff] [blame] | 54 | virtual void Seek(base::TimeDelta time, const PipelineStatusCB& status_cb); |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 55 | |
56 | // The pipeline is being stopped either as a result of an error or because | ||||
57 | // the client called Stop(). | ||||
[email protected] | adabb627 | 2011-09-29 22:36:38 | [diff] [blame] | 58 | virtual void Stop(const base::Closure& callback); |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 59 | |
60 | // This method is called from the pipeline when the audio renderer | ||||
61 | // is disabled. Demuxers can ignore the notification if they do not | ||||
62 | // need to react to this event. | ||||
63 | // | ||||
64 | // TODO(acolwell): Change to generic DisableStream(DemuxerStream::Type). | ||||
65 | virtual void OnAudioRendererDisabled(); | ||||
66 | |||||
67 | // Returns the given stream type, or NULL if that type is not present. | ||||
68 | virtual scoped_refptr<DemuxerStream> GetStream(DemuxerStream::Type type) = 0; | ||||
69 | |||||
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 70 | // Returns the starting time for the media file. |
71 | virtual base::TimeDelta GetStartTime() const = 0; | ||||
72 | |||||
[email protected] | 7b268b7a | 2011-11-18 19:52:08 | [diff] [blame] | 73 | // Returns the content bitrate. May be obtained from container or |
74 | // approximated. Returns 0 if it is unknown. | ||||
75 | virtual int GetBitrate() = 0; | ||||
76 | |||||
[email protected] | 62fce1c | 2011-12-01 22:44:55 | [diff] [blame] | 77 | // Returns true if the source is from a local file or stream (such as a |
78 | // webcam stream), false otherwise. | ||||
[email protected] | 9bfe9b8 | 2012-04-02 17:56:27 | [diff] [blame] | 79 | // |
80 | // TODO(scherkus): See http://crbug.com/120426 on why we should remove this. | ||||
[email protected] | 62fce1c | 2011-12-01 22:44:55 | [diff] [blame] | 81 | virtual bool IsLocalSource() = 0; |
82 | |||||
83 | // Returns true if seeking is possible; false otherwise. | ||||
84 | virtual bool IsSeekable() = 0; | ||||
85 | |||||
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 86 | protected: |
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 87 | friend class base::RefCountedThreadSafe<Demuxer>; |
88 | virtual ~Demuxer(); | ||||
89 | |||||
90 | private: | ||||
[email protected] | a2b5c47 | 2011-09-13 20:24:10 | [diff] [blame] | 91 | DISALLOW_COPY_AND_ASSIGN(Demuxer); |
92 | }; | ||||
93 | |||||
94 | } // namespace media | ||||
95 | |||||
96 | #endif // MEDIA_BASE_DEMUXER_H_ |