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; | |
60 | 62 |
61 protected: | 63 protected: |
62 virtual ~DecryptingVideoDecoder(); | 64 virtual ~DecryptingAudioDecoder(); |
63 | 65 |
64 private: | 66 private: |
65 // For a detailed state diagram please see this link: http://goo.gl/8jAok | 67 // 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 | 68 // TODO(xhwang): Add a ASCII state diagram in this file after this class |
67 // stabilizes. | 69 // stabilizes. |
70 // TODO(xhwang): Update this diagram for DecryptingAudioDecoder. | |
68 enum DecoderState { | 71 enum DecoderState { |
69 kUninitialized = 0, | 72 kUninitialized = 0, |
70 kDecryptorRequested, | 73 kDecryptorRequested, |
71 kPendingDecoderInit, | 74 kPendingDecoderInit, |
72 kIdle, | 75 kIdle, |
73 kPendingDemuxerRead, | 76 kPendingDemuxerRead, |
74 kPendingDecode, | 77 kPendingDecode, |
75 kWaitingForKey, | 78 kWaitingForKey, |
76 kDecodeFinished, | 79 kDecodeFinished, |
77 kStopped | |
78 }; | 80 }; |
79 | 81 |
80 // Carries out the initialization operation scheduled by Initialize(). | 82 // Carries out the initialization operation scheduled by Initialize(). |
81 void DoInitialize(const scoped_refptr<DemuxerStream>& stream, | 83 void DoInitialize(const scoped_refptr<DemuxerStream>& stream, |
82 const PipelineStatusCB& status_cb, | 84 const PipelineStatusCB& status_cb, |
83 const StatisticsCB& statistics_cb); | 85 const StatisticsCB& statistics_cb); |
84 | 86 |
85 // Callback for DecryptorHost::RequestDecryptor(). | 87 // Callback for DecryptorHost::RequestDecryptor(). |
86 void SetDecryptor(Decryptor* decryptor); | 88 void SetDecryptor(Decryptor* decryptor); |
87 | 89 |
88 // Callback for Decryptor::InitializeVideoDecoder(). | 90 // Callback for Decryptor::InitializeAudioDecoder(). |
89 void FinishInitialization(bool success); | 91 void FinishInitialization(bool success); |
90 | 92 |
91 // Carries out the buffer reading operation scheduled by Read(). | 93 // Carries out the buffer reading operation scheduled by Read(). |
92 void DoRead(const ReadCB& read_cb); | 94 void DoRead(const ReadCB& read_cb); |
93 | 95 |
94 void ReadFromDemuxerStream(); | 96 void ReadFromDemuxerStream(); |
95 | 97 |
96 // Callback for DemuxerStream::Read(). | 98 // Callback for DemuxerStream::Read(). |
97 void DecryptAndDecodeBuffer(DemuxerStream::Status status, | 99 void DecryptAndDecodeBuffer(DemuxerStream::Status status, |
98 const scoped_refptr<DecoderBuffer>& buffer); | 100 const scoped_refptr<DecoderBuffer>& buffer); |
99 | 101 |
100 // Carries out the buffer decrypting/decoding operation scheduled by | 102 // Carries out the buffer decrypting/decoding operation scheduled by |
101 // DecryptAndDecodeBuffer(). | 103 // DecryptAndDecodeBuffer(). |
102 void DoDecryptAndDecodeBuffer(DemuxerStream::Status status, | 104 void DoDecryptAndDecodeBuffer(DemuxerStream::Status status, |
103 const scoped_refptr<DecoderBuffer>& buffer); | 105 const scoped_refptr<DecoderBuffer>& buffer); |
104 | 106 |
105 void DecodePendingBuffer(); | 107 void DecodePendingBuffer(); |
106 | 108 |
107 // Callback for Decryptor::DecryptAndDecodeVideo(). | 109 // Callback for Decryptor::DecryptAndDecodeAudio(). |
108 void DeliverFrame(int buffer_size, | 110 void DeliverFrame(int buffer_size, |
109 Decryptor::Status status, | 111 Decryptor::Status status, |
110 const scoped_refptr<VideoFrame>& frame); | 112 const Decryptor::AudioBuffers& frames); |
111 | 113 |
112 // Carries out the frame delivery operation scheduled by DeliverFrame(). | 114 // Carries out the frame delivery operation scheduled by DeliverFrame(). |
113 void DoDeliverFrame(int buffer_size, | 115 void DoDeliverFrame(int buffer_size, |
114 Decryptor::Status status, | 116 Decryptor::Status status, |
115 const scoped_refptr<VideoFrame>& frame); | 117 const Decryptor::AudioBuffers& frames); |
116 | 118 |
117 // Callback for the |decryptor_| to notify the DecryptingVideoDecoder that | 119 // Callback for the |decryptor_| to notify the DecryptingAudioDecoder that |
118 // a new key has been added. | 120 // a new key has been added. |
119 void OnKeyAdded(); | 121 void OnKeyAdded(); |
120 | 122 |
121 // Reset decoder and call |reset_cb_|. | 123 // Reset decoder and call |reset_cb_|. |
122 void DoReset(); | 124 void DoReset(); |
123 | 125 |
124 // Free decoder resources and call |stop_cb_|. | |
125 void DoStop(); | |
126 | |
127 // This is !is_null() iff Initialize() hasn't been called. | 126 // This is !is_null() iff Initialize() hasn't been called. |
128 MessageLoopFactoryCB message_loop_factory_cb_; | 127 MessageLoopFactoryCB message_loop_factory_cb_; |
129 | 128 |
130 scoped_refptr<base::MessageLoopProxy> message_loop_; | 129 scoped_refptr<base::MessageLoopProxy> message_loop_; |
131 | 130 |
132 // Current state of the DecryptingVideoDecoder. | 131 // Current state of the DecryptingAudioDecoder. |
133 DecoderState state_; | 132 DecoderState state_; |
134 | 133 |
135 PipelineStatusCB init_cb_; | 134 PipelineStatusCB init_cb_; |
136 StatisticsCB statistics_cb_; | 135 StatisticsCB statistics_cb_; |
137 ReadCB read_cb_; | 136 ReadCB read_cb_; |
138 base::Closure reset_cb_; | 137 base::Closure reset_cb_; |
139 | 138 |
140 // Pointer to the demuxer stream that will feed us compressed buffers. | 139 // Pointer to the demuxer stream that will feed us compressed buffers. |
141 scoped_refptr<DemuxerStream> demuxer_stream_; | 140 scoped_refptr<DemuxerStream> demuxer_stream_; |
142 | 141 |
143 // Callback to request/cancel decryptor creation notification. | 142 // Callback to request/cancel decryptor creation notification. |
144 RequestDecryptorNotificationCB request_decryptor_notification_cb_; | 143 RequestDecryptorNotificationCB request_decryptor_notification_cb_; |
145 | 144 |
146 Decryptor* decryptor_; | 145 Decryptor* decryptor_; |
147 | 146 |
148 // The buffer returned by the demuxer that needs decrypting/decoding. | 147 // The buffer returned by the demuxer that needs decrypting/decoding. |
149 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_; | 148 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_; |
150 | 149 |
151 // Indicates the situation where new key is added during pending decode | 150 // Indicates the situation where new key is added during pending decode |
152 // (in other words, this variable can only be set in state kPendingDecode). | 151 // (in other words, this variable can only be set in state kPendingDecode). |
153 // If this variable is true and kNoKey is returned then we need to try | 152 // If this variable is true and kNoKey is returned then we need to try |
154 // decrypting/decoding again in case the newly added key is the correct | 153 // decrypting/decoding again in case the newly added key is the correct |
155 // decryption key. | 154 // decryption key. |
156 bool key_added_while_pending_decode_; | 155 bool key_added_while_pending_decode_; |
157 | 156 |
158 DISALLOW_COPY_AND_ASSIGN(DecryptingVideoDecoder); | 157 Decryptor::AudioBuffers queued_audio_frames_; |
scherkus (not reviewing)
2012/10/19 02:12:58
sorry just for noticing this... why are we queuing
xhwang
2012/10/19 02:19:45
This is the same as "queued_audio_" in FFAD. We ma
| |
158 | |
159 // Decoded audio format. | |
160 int bits_per_channel_; | |
161 ChannelLayout channel_layout_; | |
162 int samples_per_second_; | |
163 | |
164 DISALLOW_COPY_AND_ASSIGN(DecryptingAudioDecoder); | |
159 }; | 165 }; |
160 | 166 |
161 } // namespace media | 167 } // namespace media |
162 | 168 |
163 #endif // MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_ | 169 #endif // MEDIA_FILTERS_DECRYPTING_AUDIO_DECODER_H_ |
OLD | NEW |