OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_FILTERS_DECODER_STREAM_H_ | 5 #ifndef MEDIA_FILTERS_DECODER_STREAM_H_ |
6 #define MEDIA_FILTERS_DECODER_STREAM_H_ | 6 #define MEDIA_FILTERS_DECODER_STREAM_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "media/base/audio_decoder.h" |
14 #include "media/base/decryptor.h" | 15 #include "media/base/decryptor.h" |
15 #include "media/base/demuxer_stream.h" | 16 #include "media/base/demuxer_stream.h" |
16 #include "media/base/media_export.h" | 17 #include "media/base/media_export.h" |
17 #include "media/base/pipeline_status.h" | 18 #include "media/base/pipeline_status.h" |
18 #include "media/filters/decoder_selector.h" | 19 #include "media/filters/decoder_selector.h" |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 class SingleThreadTaskRunner; | 22 class SingleThreadTaskRunner; |
22 } | 23 } |
23 | 24 |
24 namespace media { | 25 namespace media { |
25 | 26 |
26 class DecryptingDemuxerStream; | 27 class DecryptingDemuxerStream; |
27 | 28 |
28 // Wraps a DemuxerStream and a list of Decoders and provides decoded | 29 // Wraps a DemuxerStream and a list of Decoders and provides decoded |
29 // output to its client (e.g. Audio/VideoRendererImpl). | 30 // output to its client (e.g. Audio/VideoRendererImpl). |
30 template<DemuxerStream::Type StreamType> | 31 template<DemuxerStream::Type StreamType> |
31 class MEDIA_EXPORT DecoderStream { | 32 class MEDIA_EXPORT DecoderStream { |
32 public: | 33 public: |
33 typedef DecoderStreamTraits<StreamType> StreamTraits; | 34 typedef DecoderStreamTraits<StreamType> StreamTraits; |
34 typedef typename StreamTraits::DecoderType Decoder; | 35 typedef typename StreamTraits::DecoderType Decoder; |
35 typedef typename StreamTraits::OutputType Output; | 36 typedef typename StreamTraits::OutputType Output; |
36 typedef typename StreamTraits::StreamInitCB InitCB; | 37 typedef typename StreamTraits::StreamInitCB InitCB; |
| 38 typedef typename Decoder::Status DecoderStatus; |
37 | 39 |
38 enum Status { | 40 enum Status { |
39 OK, // Everything went as planned. | 41 OK, // Everything went as planned. |
40 ABORTED, // Read aborted due to Reset() during pending read. | 42 ABORTED, // Read aborted due to Reset() during pending read. |
41 DEMUXER_READ_ABORTED, // Demuxer returned aborted read. | 43 DEMUXER_READ_ABORTED, // Demuxer returned aborted read. |
42 DECODE_ERROR, // Decoder returned decode error. | 44 DECODE_ERROR, // Decoder returned decode error. |
43 DECRYPT_ERROR // Decoder returned decrypt error. | 45 DECRYPT_ERROR // Decoder returned decrypt error. |
44 }; | 46 }; |
45 | 47 |
46 // Indicates completion of a DecoderStream read. | 48 // Indicates completion of a DecoderStream read. |
(...skipping 26 matching lines...) Expand all Loading... |
73 | 75 |
74 // Stops the decoder, fires any existing pending read callback or reset | 76 // Stops the decoder, fires any existing pending read callback or reset |
75 // callback and calls |closure| on completion. Note that |closure| is always | 77 // callback and calls |closure| on completion. Note that |closure| is always |
76 // called asynchronously. The DecoderStream cannot be used anymore after | 78 // called asynchronously. The DecoderStream cannot be used anymore after |
77 // it is stopped. This method can be called at any time but not during another | 79 // it is stopped. This method can be called at any time but not during another |
78 // pending Stop(). | 80 // pending Stop(). |
79 void Stop(const base::Closure& closure); | 81 void Stop(const base::Closure& closure); |
80 | 82 |
81 // Returns true if the decoder currently has the ability to decode and return | 83 // Returns true if the decoder currently has the ability to decode and return |
82 // an Output. | 84 // an Output. |
| 85 // TODO(rileya): Remove the need for this by refactoring Decoder queueing |
| 86 // behavior. |
83 bool CanReadWithoutStalling() const; | 87 bool CanReadWithoutStalling() const; |
84 | 88 |
| 89 // TODO(rileya): Remove this once channel_layout/bits_per_channel/etc getters |
| 90 // have been removed from AudioDecoder and plumbed elsewhere. |
| 91 Decoder* decoder() { return decoder_.get(); } |
| 92 |
85 private: | 93 private: |
86 enum State { | 94 enum State { |
87 STATE_UNINITIALIZED, | 95 STATE_UNINITIALIZED, |
88 STATE_INITIALIZING, | 96 STATE_INITIALIZING, |
89 STATE_NORMAL, // Includes idle, pending decoder decode/reset/stop. | 97 STATE_NORMAL, // Includes idle, pending decoder decode/reset/stop. |
90 STATE_FLUSHING_DECODER, | 98 STATE_FLUSHING_DECODER, |
91 STATE_PENDING_DEMUXER_READ, | 99 STATE_PENDING_DEMUXER_READ, |
92 STATE_REINITIALIZING_DECODER, | 100 STATE_REINITIALIZING_DECODER, |
93 STATE_STOPPED, | 101 STATE_STOPPED, |
94 STATE_ERROR | 102 STATE_ERROR |
95 }; | 103 }; |
96 | 104 |
97 // Called when |decoder_selector| selected the |selected_decoder|. | 105 // Called when |decoder_selector| selected the |selected_decoder|. |
98 // |decrypting_demuxer_stream| was also populated if a DecryptingDemuxerStream | 106 // |decrypting_demuxer_stream| was also populated if a DecryptingDemuxerStream |
99 // is created to help decrypt the encrypted stream. | 107 // is created to help decrypt the encrypted stream. |
100 void OnDecoderSelected( | 108 void OnDecoderSelected( |
101 scoped_ptr<Decoder> selected_decoder, | 109 scoped_ptr<Decoder> selected_decoder, |
102 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream); | 110 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream); |
103 | 111 |
104 // Satisfy pending |read_cb_| with |status| and |output|. | 112 // Satisfy pending |read_cb_| with |status| and |output|. |
105 void SatisfyRead(Status status, const scoped_refptr<Output>& output); | 113 void SatisfyRead(Status status, |
| 114 const scoped_refptr<Output>& output); |
106 | 115 |
107 // Abort pending |read_cb_|. | 116 // Abort pending |read_cb_|. |
108 void AbortRead(); | 117 void AbortRead(); |
109 | 118 |
110 // Decodes |buffer| and returns the result via OnDecodeOutputReady(). | 119 // Decodes |buffer| and returns the result via OnDecodeOutputReady(). |
111 void Decode(const scoped_refptr<DecoderBuffer>& buffer); | 120 void Decode(const scoped_refptr<DecoderBuffer>& buffer); |
112 | 121 |
113 // Flushes the decoder with an EOS buffer to retrieve internally buffered | 122 // Flushes the decoder with an EOS buffer to retrieve internally buffered |
114 // decoder output. | 123 // decoder output. |
115 void FlushDecoder(); | 124 void FlushDecoder(); |
116 | 125 |
117 // Callback for Decoder::Decode(). | 126 // Callback for Decoder::Decode(). |
118 void OnDecodeOutputReady(int buffer_size, | 127 void OnDecodeOutputReady(int buffer_size, |
119 typename Decoder::Status status, | 128 DecoderStatus status, |
120 const scoped_refptr<Output>& output); | 129 const scoped_refptr<Output>& output); |
121 | 130 |
122 // Reads a buffer from |stream_| and returns the result via OnBufferReady(). | 131 // Reads a buffer from |stream_| and returns the result via OnBufferReady(). |
123 void ReadFromDemuxerStream(); | 132 void ReadFromDemuxerStream(); |
124 | 133 |
125 // Callback for DemuxerStream::Read(). | 134 // Callback for DemuxerStream::Read(). |
126 void OnBufferReady(DemuxerStream::Status status, | 135 void OnBufferReady(DemuxerStream::Status status, |
127 const scoped_refptr<DecoderBuffer>& buffer); | 136 const scoped_refptr<DecoderBuffer>& buffer); |
128 | 137 |
129 void ReinitializeDecoder(); | 138 void ReinitializeDecoder(); |
(...skipping 25 matching lines...) Expand all Loading... |
155 | 164 |
156 // These two will be set by DecoderSelector::SelectDecoder(). | 165 // These two will be set by DecoderSelector::SelectDecoder(). |
157 scoped_ptr<Decoder> decoder_; | 166 scoped_ptr<Decoder> decoder_; |
158 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; | 167 scoped_ptr<DecryptingDemuxerStream> decrypting_demuxer_stream_; |
159 | 168 |
160 // This is required so the VideoFrameStream can access private members in | 169 // This is required so the VideoFrameStream can access private members in |
161 // FinishInitialization() and ReportStatistics(). | 170 // FinishInitialization() and ReportStatistics(). |
162 DISALLOW_IMPLICIT_CONSTRUCTORS(DecoderStream); | 171 DISALLOW_IMPLICIT_CONSTRUCTORS(DecoderStream); |
163 }; | 172 }; |
164 | 173 |
| 174 template <> |
| 175 bool DecoderStream<DemuxerStream::AUDIO>::CanReadWithoutStalling() const; |
| 176 |
165 typedef DecoderStream<DemuxerStream::VIDEO> VideoFrameStream; | 177 typedef DecoderStream<DemuxerStream::VIDEO> VideoFrameStream; |
| 178 typedef DecoderStream<DemuxerStream::AUDIO> AudioBufferStream; |
166 | 179 |
167 } // namespace media | 180 } // namespace media |
168 | 181 |
169 #endif // MEDIA_FILTERS_DECODER_STREAM_H_ | 182 #endif // MEDIA_FILTERS_DECODER_STREAM_H_ |
OLD | NEW |