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