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.
5 #ifndef MEDIA_BASE_DEMUXER_H_
6 #define MEDIA_BASE_DEMUXER_H_
8 #include "base/memory/ref_counted.h"
10 #include "media/base/data_source.h"
11 #include "media/base/demuxer_stream.h"
12 #include "media/base/media_export.h"
13 #include "media/base/pipeline_status.h"
17 class MEDIA_EXPORT DemuxerHost
: public DataSourceHost
{
19 virtual ~DemuxerHost();
21 // Sets the duration of the media in microseconds.
22 // Duration may be kInfiniteDuration() if the duration is not known.
23 virtual void SetDuration(base::TimeDelta duration
) = 0;
25 // Sets the byte offset at which the client is requesting the video.
26 virtual void SetCurrentReadPosition(int64 offset
) = 0;
28 // Stops execution of the pipeline due to a fatal error. Do not call this
29 // method with PIPELINE_OK.
30 virtual void OnDemuxerError(PipelineStatus error
) = 0;
33 class MEDIA_EXPORT Demuxer
: public base::RefCountedThreadSafe
<Demuxer
> {
37 // Completes initialization of the demuxer.
39 // The demuxer does not own |host| as it is guaranteed to outlive the
40 // lifetime of the demuxer. Don't delete it!
41 virtual void Initialize(DemuxerHost
* host
,
42 const PipelineStatusCB
& status_cb
) = 0;
44 // The pipeline playback rate has been changed. Demuxers may implement this
45 // method if they need to respond to this call.
46 virtual void SetPlaybackRate(float playback_rate
);
48 // Carry out any actions required to seek to the given time, executing the
49 // callback upon completion.
50 virtual void Seek(base::TimeDelta time
, const PipelineStatusCB
& status_cb
);
52 // The pipeline is being stopped either as a result of an error or because
53 // the client called Stop().
54 virtual void Stop(const base::Closure
& callback
);
56 // This method is called from the pipeline when the audio renderer
57 // is disabled. Demuxers can ignore the notification if they do not
58 // need to react to this event.
60 // TODO(acolwell): Change to generic DisableStream(DemuxerStream::Type).
61 virtual void OnAudioRendererDisabled();
63 // Returns the given stream type, or NULL if that type is not present.
64 virtual scoped_refptr
<DemuxerStream
> GetStream(DemuxerStream::Type type
) = 0;
66 // Returns the starting time for the media file.
67 virtual base::TimeDelta
GetStartTime() const = 0;
69 // Returns the content bitrate. May be obtained from container or
70 // approximated. Returns 0 if it is unknown.
71 virtual int GetBitrate() = 0;
74 friend class base::RefCountedThreadSafe
<Demuxer
>;
78 DISALLOW_COPY_AND_ASSIGN(Demuxer
);
83 #endif // MEDIA_BASE_DEMUXER_H_