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