OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_DECRYPTING_VIDEO_DECODER_H_ | 5 #ifndef MEDIA_FILTERS_DECRYPTING_AUDIO_DECODER_H_ |
6 #define MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_ | 6 #define MEDIA_FILTERS_DECRYPTING_AUDIO_DECODER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "media/base/audio_decoder.h" | |
10 #include "media/base/decryptor.h" | 11 #include "media/base/decryptor.h" |
11 #include "media/base/demuxer_stream.h" | 12 #include "media/base/demuxer_stream.h" |
12 #include "media/base/video_decoder.h" | |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 class MessageLoopProxy; | 15 class MessageLoopProxy; |
16 } | 16 } |
17 | 17 |
18 namespace media { | 18 namespace media { |
19 | 19 |
20 class DecoderBuffer; | 20 class DecoderBuffer; |
21 class Decryptor; | 21 class Decryptor; |
22 | 22 |
23 // Decryptor-based VideoDecoder implementation that can decrypt and decode | 23 // Decryptor-based AudioDecoder implementation that can decrypt and decode |
24 // encrypted video buffers and return decrypted and decompressed video frames. | 24 // encrypted audio buffers and return decrypted and decompressed audio frames. |
25 // All public APIs and callbacks are trampolined to the |message_loop_| so | 25 // All public APIs and callbacks are trampolined to the |message_loop_| so |
26 // that no locks are required for thread safety. | 26 // that no locks are required for thread safety. |
27 // | 27 // |
28 // TODO(xhwang): For now, DecryptingVideoDecoder relies on the decryptor to do | 28 // TODO(xhwang): For now, DecryptingAudioDecoder relies on the decryptor to do |
29 // both decryption and video decoding. Add the path to use the decryptor for | 29 // both decryption and audio decoding. Add the path to use the decryptor for |
30 // decryption only and use other VideoDecoder implementations within | 30 // decryption only and use other AudioDecoder implementations within |
31 // DecryptingVideoDecoder for video decoding. | 31 // DecryptingAudioDecoder for audio decoding. |
32 class MEDIA_EXPORT DecryptingVideoDecoder : public VideoDecoder { | 32 class MEDIA_EXPORT DecryptingAudioDecoder : public AudioDecoder { |
33 public: | 33 public: |
34 // Callback to get a message loop. | 34 // Callback to get a message loop. |
35 typedef base::Callback< | 35 typedef base::Callback< |
36 scoped_refptr<base::MessageLoopProxy>()> MessageLoopFactoryCB; | 36 scoped_refptr<base::MessageLoopProxy>()> MessageLoopFactoryCB; |
37 // Callback to notify decryptor creation. | 37 // Callback to notify decryptor creation. |
38 typedef base::Callback<void(Decryptor*)> DecryptorNotificationCB; | 38 typedef base::Callback<void(Decryptor*)> DecryptorNotificationCB; |
39 // Callback to request/cancel decryptor creation notification. | 39 // Callback to request/cancel decryptor creation notification. |
40 // Calling this callback with a non-null callback registers decryptor creation | 40 // Calling this callback with a non-null callback registers decryptor creation |
41 // notification. When the decryptor is created, notification will be sent | 41 // notification. When the decryptor is created, notification will be sent |
42 // through the provided callback. | 42 // through the provided callback. |
43 // Calling this callback with a null callback cancels previously registered | 43 // Calling this callback with a null callback cancels previously registered |
44 // decryptor creation notification. Any previously provided callback will be | 44 // decryptor creation notification. Any previously provided callback will be |
45 // fired immediately with NULL. | 45 // fired immediately with NULL. |
46 typedef base::Callback<void(const DecryptorNotificationCB&)> | 46 typedef base::Callback<void(const DecryptorNotificationCB&)> |
47 RequestDecryptorNotificationCB; | 47 RequestDecryptorNotificationCB; |
48 | 48 |
49 DecryptingVideoDecoder( | 49 DecryptingAudioDecoder( |
50 const MessageLoopFactoryCB& message_loop_factory_cb, | 50 const MessageLoopFactoryCB& message_loop_factory_cb, |
51 const RequestDecryptorNotificationCB& request_decryptor_notification_cb); | 51 const RequestDecryptorNotificationCB& request_decryptor_notification_cb); |
52 | 52 |
53 // VideoDecoder implementation. | 53 // AudioDecoder implementation. |
54 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream, | 54 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream, |
55 const PipelineStatusCB& status_cb, | 55 const PipelineStatusCB& status_cb, |
56 const StatisticsCB& statistics_cb) OVERRIDE; | 56 const StatisticsCB& statistics_cb) OVERRIDE; |
57 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 57 virtual void Read(const ReadCB& read_cb) OVERRIDE; |
58 virtual void Reset(const base::Closure& closure) OVERRIDE; | 58 virtual void Reset(const base::Closure& closure) OVERRIDE; |
59 virtual void Stop(const base::Closure& closure) OVERRIDE; | 59 virtual int bits_per_channel() OVERRIDE; |
60 virtual ChannelLayout channel_layout() OVERRIDE; | |
61 virtual int samples_per_second() OVERRIDE; | |
62 | |
63 // TODO(xhwang): Either remove Stop() here or add Stop() to AudioDecoder | |
64 // interface. Figure out the right teardown process. | |
65 void Stop(const base::Closure& closure); | |
xhwang
2012/10/18 02:14:10
scherkus: currently nobody is gonna call this Stop
| |
60 | 66 |
61 protected: | 67 protected: |
62 virtual ~DecryptingVideoDecoder(); | 68 virtual ~DecryptingAudioDecoder(); |
63 | 69 |
64 private: | 70 private: |
65 // For a detailed state diagram please see this link: http://goo.gl/8jAok | 71 // For a detailed state diagram please see this link: http://goo.gl/8jAok |
66 // TODO(xhwang): Add a ASCII state diagram in this file after this class | 72 // TODO(xhwang): Add a ASCII state diagram in this file after this class |
67 // stabilizes. | 73 // stabilizes. |
68 enum DecoderState { | 74 enum DecoderState { |
69 kUninitialized = 0, | 75 kUninitialized = 0, |
70 kDecryptorRequested, | 76 kDecryptorRequested, |
71 kPendingDecoderInit, | 77 kPendingDecoderInit, |
72 kIdle, | 78 kIdle, |
73 kPendingDemuxerRead, | 79 kPendingDemuxerRead, |
74 kPendingDecode, | 80 kPendingDecode, |
75 kWaitingForKey, | 81 kWaitingForKey, |
76 kDecodeFinished, | 82 kDecodeFinished, |
77 kStopped | 83 kStopped |
78 }; | 84 }; |
79 | 85 |
80 // Carries out the initialization operation scheduled by Initialize(). | 86 // Carries out the initialization operation scheduled by Initialize(). |
81 void DoInitialize(const scoped_refptr<DemuxerStream>& stream, | 87 void DoInitialize(const scoped_refptr<DemuxerStream>& stream, |
82 const PipelineStatusCB& status_cb, | 88 const PipelineStatusCB& status_cb, |
83 const StatisticsCB& statistics_cb); | 89 const StatisticsCB& statistics_cb); |
84 | 90 |
85 // Callback for DecryptorHost::RequestDecryptor(). | 91 // Callback for DecryptorHost::RequestDecryptor(). |
86 void SetDecryptor(Decryptor* decryptor); | 92 void SetDecryptor(Decryptor* decryptor); |
87 | 93 |
88 // Callback for Decryptor::InitializeVideoDecoder(). | 94 // Callback for Decryptor::InitializeAudioDecoder(). |
89 void FinishInitialization(bool success); | 95 void FinishInitialization(bool success); |
90 | 96 |
91 // Carries out the buffer reading operation scheduled by Read(). | 97 // Carries out the buffer reading operation scheduled by Read(). |
92 void DoRead(const ReadCB& read_cb); | 98 void DoRead(const ReadCB& read_cb); |
93 | 99 |
94 void ReadFromDemuxerStream(); | 100 void ReadFromDemuxerStream(); |
95 | 101 |
96 // Callback for DemuxerStream::Read(). | 102 // Callback for DemuxerStream::Read(). |
97 void DecryptAndDecodeBuffer(DemuxerStream::Status status, | 103 void DecryptAndDecodeBuffer(DemuxerStream::Status status, |
98 const scoped_refptr<DecoderBuffer>& buffer); | 104 const scoped_refptr<DecoderBuffer>& buffer); |
99 | 105 |
100 // Carries out the buffer decrypting/decoding operation scheduled by | 106 // Carries out the buffer decrypting/decoding operation scheduled by |
101 // DecryptAndDecodeBuffer(). | 107 // DecryptAndDecodeBuffer(). |
102 void DoDecryptAndDecodeBuffer(DemuxerStream::Status status, | 108 void DoDecryptAndDecodeBuffer(DemuxerStream::Status status, |
103 const scoped_refptr<DecoderBuffer>& buffer); | 109 const scoped_refptr<DecoderBuffer>& buffer); |
104 | 110 |
105 void DecodePendingBuffer(); | 111 void DecodePendingBuffer(); |
106 | 112 |
107 // Callback for Decryptor::DecryptAndDecodeVideo(). | 113 // Callback for Decryptor::DecryptAndDecodeAudio(). |
108 void DeliverFrame(int buffer_size, | 114 void DeliverFrame(int buffer_size, |
109 Decryptor::Status status, | 115 Decryptor::Status status, |
110 const scoped_refptr<VideoFrame>& frame); | 116 const Decryptor::AudioBuffers& frames); |
111 | 117 |
112 // Carries out the frame delivery operation scheduled by DeliverFrame(). | 118 // Carries out the frame delivery operation scheduled by DeliverFrame(). |
113 void DoDeliverFrame(int buffer_size, | 119 void DoDeliverFrame(int buffer_size, |
114 Decryptor::Status status, | 120 Decryptor::Status status, |
115 const scoped_refptr<VideoFrame>& frame); | 121 const Decryptor::AudioBuffers& frames); |
116 | 122 |
117 // Callback for the |decryptor_| to notify the DecryptingVideoDecoder that | 123 // Callback for the |decryptor_| to notify the DecryptingAudioDecoder that |
118 // a new key has been added. | 124 // a new key has been added. |
119 void OnKeyAdded(); | 125 void OnKeyAdded(); |
120 | 126 |
121 // Reset decoder and call |reset_cb_|. | 127 // Reset decoder and call |reset_cb_|. |
122 void DoReset(); | 128 void DoReset(); |
123 | 129 |
124 // Free decoder resources and call |stop_cb_|. | 130 // Free decoder resources and call |stop_cb_|. |
125 void DoStop(); | 131 void DoStop(); |
126 | 132 |
127 // This is !is_null() iff Initialize() hasn't been called. | 133 // This is !is_null() iff Initialize() hasn't been called. |
128 MessageLoopFactoryCB message_loop_factory_cb_; | 134 MessageLoopFactoryCB message_loop_factory_cb_; |
129 | 135 |
130 scoped_refptr<base::MessageLoopProxy> message_loop_; | 136 scoped_refptr<base::MessageLoopProxy> message_loop_; |
131 | 137 |
132 // Current state of the DecryptingVideoDecoder. | 138 // Current state of the DecryptingAudioDecoder. |
133 DecoderState state_; | 139 DecoderState state_; |
134 | 140 |
135 PipelineStatusCB init_cb_; | 141 PipelineStatusCB init_cb_; |
136 StatisticsCB statistics_cb_; | 142 StatisticsCB statistics_cb_; |
137 ReadCB read_cb_; | 143 ReadCB read_cb_; |
138 base::Closure reset_cb_; | 144 base::Closure reset_cb_; |
139 base::Closure stop_cb_; | 145 base::Closure stop_cb_; |
140 | 146 |
141 // Pointer to the demuxer stream that will feed us compressed buffers. | 147 // Pointer to the demuxer stream that will feed us compressed buffers. |
142 scoped_refptr<DemuxerStream> demuxer_stream_; | 148 scoped_refptr<DemuxerStream> demuxer_stream_; |
143 | 149 |
144 // Callback to request/cancel decryptor creation notification. | 150 // Callback to request/cancel decryptor creation notification. |
145 RequestDecryptorNotificationCB request_decryptor_notification_cb_; | 151 RequestDecryptorNotificationCB request_decryptor_notification_cb_; |
146 | 152 |
147 Decryptor* decryptor_; | 153 Decryptor* decryptor_; |
148 | 154 |
149 // The buffer returned by the demuxer that needs decrypting/decoding. | 155 // The buffer returned by the demuxer that needs decrypting/decoding. |
150 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_; | 156 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_; |
151 | 157 |
152 // Indicates the situation where new key is added during pending decode | 158 // Indicates the situation where new key is added during pending decode |
153 // (in other words, this variable can only be set in state kPendingDecode). | 159 // (in other words, this variable can only be set in state kPendingDecode). |
154 // If this variable is true and kNoKey is returned then we need to try | 160 // If this variable is true and kNoKey is returned then we need to try |
155 // decrypting/decoding again in case the newly added key is the correct | 161 // decrypting/decoding again in case the newly added key is the correct |
156 // decryption key. | 162 // decryption key. |
157 bool key_added_while_pending_decode_; | 163 bool key_added_while_pending_decode_; |
158 | 164 |
159 DISALLOW_COPY_AND_ASSIGN(DecryptingVideoDecoder); | 165 Decryptor::AudioBuffers queued_audio_frames_; |
166 | |
167 // Decoded audio format. | |
168 int bits_per_channel_; | |
169 ChannelLayout channel_layout_; | |
170 int samples_per_second_; | |
171 | |
172 DISALLOW_COPY_AND_ASSIGN(DecryptingAudioDecoder); | |
160 }; | 173 }; |
161 | 174 |
162 } // namespace media | 175 } // namespace media |
163 | 176 |
164 #endif // MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_ | 177 #endif // MEDIA_FILTERS_DECRYPTING_AUDIO_DECODER_H_ |
OLD | NEW |