• 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_STREAM_H_
6 #define MEDIA_BASE_DEMUXER_STREAM_H_
7 
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "media/base/media_export.h"
11 
12 namespace media {
13 
14 class AudioDecoderConfig;
15 class DecoderBuffer;
16 class VideoDecoderConfig;
17 
18 class MEDIA_EXPORT DemuxerStream {
19  public:
20   enum Type {
21     UNKNOWN,
22     AUDIO,
23     VIDEO,
24     TEXT,
25     NUM_TYPES,  // Always keep this entry as the last one!
26   };
27 
28   // Status returned in the Read() callback.
29   //  kOk : Indicates the second parameter is Non-NULL and contains media data
30   //        or the end of the stream.
31   //  kAborted : Indicates an aborted Read(). This can happen if the
32   //             DemuxerStream gets flushed and doesn't have any more data to
33   //             return. The second parameter MUST be NULL when this status is
34   //             returned.
35   //  kConfigChange : Indicates that the AudioDecoderConfig or
36   //                  VideoDecoderConfig for the stream has changed.
37   //                  The DemuxerStream expects an audio_decoder_config() or
38   //                  video_decoder_config() call before Read() will start
39   //                  returning DecoderBuffers again. The decoder will need this
40   //                  new configuration to properly decode the buffers read
41   //                  from this point forward. The second parameter MUST be NULL
42   //                  when this status is returned.
43   //                  This will only be returned if SupportsConfigChanges()
44   //                  returns 'true' for this DemuxerStream.
45   enum Status {
46     kOk,
47     kAborted,
48     kConfigChanged,
49   };
50 
51   // Request a buffer to returned via the provided callback.
52   //
53   // The first parameter indicates the status of the read.
54   // The second parameter is non-NULL and contains media data
55   // or the end of the stream if the first parameter is kOk. NULL otherwise.
56   typedef base::Callback<void(Status,
57                               const scoped_refptr<DecoderBuffer>&)>ReadCB;
58   virtual void Read(const ReadCB& read_cb) = 0;
59 
60   // Returns the audio decoder configuration. It is an error to call this method
61   // if type() != AUDIO.
62   virtual AudioDecoderConfig audio_decoder_config() = 0;
63 
64   // Returns the video decoder configuration. It is an error to call this method
65   // if type() != VIDEO.
66   virtual VideoDecoderConfig video_decoder_config() = 0;
67 
68   // Returns the type of stream.
69   virtual Type type() = 0;
70 
71   virtual void EnableBitstreamConverter() = 0;
72 
73   // Whether or not this DemuxerStream allows midstream configuration changes.
74   //
75   // A DemuxerStream that returns 'true' to this may return the 'kConfigChange'
76   // status from a Read() call. In this case the client is expected to be
77   // capable of taking appropriate action to handle config changes. Otherwise
78   // audio_decoder_config() and video_decoder_config()'s return values are
79   // guaranteed to remain constant, and the client may make optimizations based
80   // on this.
81   virtual bool SupportsConfigChanges() = 0;
82 
83  protected:
84   // Only allow concrete implementations to get deleted.
85   virtual ~DemuxerStream();
86 };
87 
88 }  // namespace media
89 
90 #endif  // MEDIA_BASE_DEMUXER_STREAM_H_
91