• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 : public DataSourceHost {
21  public:
22   // Sets the duration of the media in microseconds.
23   // Duration may be kInfiniteDuration() if the duration is not known.
24   virtual void SetDuration(base::TimeDelta duration) = 0;
25 
26   // Stops execution of the pipeline due to a fatal error.  Do not call this
27   // method with PIPELINE_OK.
28   virtual void OnDemuxerError(PipelineStatus error) = 0;
29 
30   // Add |text_stream| to the collection managed by the text renderer.
31   virtual void AddTextStream(DemuxerStream* text_stream,
32                              const TextTrackConfig& config) = 0;
33 
34   // Remove |text_stream| from the presentation.
35   virtual void RemoveTextStream(DemuxerStream* text_stream) = 0;
36 
37  protected:
38   virtual ~DemuxerHost();
39 };
40 
41 class MEDIA_EXPORT Demuxer {
42  public:
43   // A new potentially encrypted stream has been parsed.
44   // First parameter - The type of initialization data.
45   // Second parameter - The initialization data associated with the stream.
46   typedef base::Callback<void(const std::string& type,
47                               const std::vector<uint8>& init_data)> NeedKeyCB;
48 
49   Demuxer();
50   virtual ~Demuxer();
51 
52   // Completes initialization of the demuxer.
53   //
54   // The demuxer does not own |host| as it is guaranteed to outlive the
55   // lifetime of the demuxer. Don't delete it!
56   virtual void Initialize(DemuxerHost* host,
57                           const PipelineStatusCB& status_cb,
58                           bool enable_text_tracks) = 0;
59 
60   // Carry out any actions required to seek to the given time, executing the
61   // callback upon completion.
62   virtual void Seek(base::TimeDelta time,
63                     const PipelineStatusCB& status_cb) = 0;
64 
65   // Starts stopping this demuxer, executing the callback upon completion.
66   //
67   // After the callback completes the demuxer may be destroyed. It is illegal to
68   // call any method (including Stop()) after a demuxer has stopped.
69   virtual void Stop(const base::Closure& callback) = 0;
70 
71   // This method is called from the pipeline when the audio renderer
72   // is disabled. Demuxers can ignore the notification if they do not
73   // need to react to this event.
74   //
75   // TODO(acolwell): Change to generic DisableStream(DemuxerStream::Type).
76   // TODO(scherkus): this might not be needed http://crbug.com/234708
77   virtual void OnAudioRendererDisabled() = 0;
78 
79   // Returns the first stream of the given stream type (which is not allowed
80   // to be DemuxerStream::TEXT), or NULL if that type of stream is not present.
81   virtual DemuxerStream* GetStream(DemuxerStream::Type type) = 0;
82 
83   // Returns the starting time for the media file.
84   virtual base::TimeDelta GetStartTime() const = 0;
85 
86  private:
87   DISALLOW_COPY_AND_ASSIGN(Demuxer);
88 };
89 
90 }  // namespace media
91 
92 #endif  // MEDIA_BASE_DEMUXER_H_
93