summaryrefslogtreecommitdiffstats
path: root/media/base/demuxer.h
blob: f049f6f49cafa038d33d7ae50c7ed5ad2b0b5381 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_BASE_DEMUXER_H_
#define MEDIA_BASE_DEMUXER_H_

#include "base/memory/ref_counted.h"
#include "base/time.h"
#include "media/base/data_source.h"
#include "media/base/demuxer_stream.h"
#include "media/base/media_export.h"
#include "media/base/pipeline_status.h"
#include "media/base/preload.h"

namespace media {

class MEDIA_EXPORT DemuxerHost : public DataSourceHost {
 public:
  virtual ~DemuxerHost();

  // Get the duration of the media in microseconds.  If the duration has not
  // been determined yet, then returns 0.
  virtual void SetDuration(base::TimeDelta duration) = 0;

  // Set the approximate amount of playable data buffered so far in micro-
  // seconds.
  virtual void SetBufferedTime(base::TimeDelta buffered_time) = 0;

  // Sets the byte offset at which the client is requesting the video.
  virtual void SetCurrentReadPosition(int64 offset) = 0;

  // Stops execution of the pipeline due to a fatal error.  Do not call this
  // method with PIPELINE_OK.
  virtual void OnDemuxerError(PipelineStatus error) = 0;
};

class MEDIA_EXPORT Demuxer
    : public base::RefCountedThreadSafe<Demuxer> {
 public:
  Demuxer();

  // Sets the private member |host_|. This is the first method called by
  // the DemuxerHost after a demuxer is created.  The host holds a strong
  // reference to the demuxer.  The reference held by the host is guaranteed
  // to be released before the host object is destroyed by the pipeline.
  virtual void set_host(DemuxerHost* host);

  // The pipeline playback rate has been changed.  Demuxers may implement this
  // method if they need to respond to this call.
  virtual void SetPlaybackRate(float playback_rate);

  // Carry out any actions required to seek to the given time, executing the
  // callback upon completion.
  virtual void Seek(base::TimeDelta time, const PipelineStatusCB& callback);

  // The pipeline is being stopped either as a result of an error or because
  // the client called Stop().
  virtual void Stop(const base::Closure& callback);

  // This method is called from the pipeline when the audio renderer
  // is disabled. Demuxers can ignore the notification if they do not
  // need to react to this event.
  //
  // TODO(acolwell): Change to generic DisableStream(DemuxerStream::Type).
  virtual void OnAudioRendererDisabled();

  // Returns the given stream type, or NULL if that type is not present.
  virtual scoped_refptr<DemuxerStream> GetStream(DemuxerStream::Type type) = 0;

  // Alert the Demuxer that the video preload value has been changed.
  virtual void SetPreload(Preload preload) = 0;

  // Returns the starting time for the media file.
  virtual base::TimeDelta GetStartTime() const = 0;

  // Returns the content bitrate. May be obtained from container or
  // approximated. Returns 0 if it is unknown.
  virtual int GetBitrate() = 0;

  // Returns true if the source is from a local file or stream (such as a
  // webcam stream), false otherwise.
  virtual bool IsLocalSource() = 0;

  // Returns true if seeking is possible; false otherwise.
  virtual bool IsSeekable() = 0;

 protected:
  // Only allow derived objects access to the DemuxerHost. This is
  // kept out of the public interface because demuxers need to be
  // aware of all calls made to the host object so they can insure
  // the state presented to the host is always consistent with its own
  // state.
  DemuxerHost* host() { return host_; }

  friend class base::RefCountedThreadSafe<Demuxer>;
  virtual ~Demuxer();

 private:
  DemuxerHost* host_;

  DISALLOW_COPY_AND_ASSIGN(Demuxer);
};

}  // namespace media

#endif  // MEDIA_BASE_DEMUXER_H_