| 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_VIDEO_DECODER_H_ |
| 6 #define MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_ | 6 #define MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "media/base/cdm_context.h" |
| 10 #include "media/base/decryptor.h" | 11 #include "media/base/decryptor.h" |
| 11 #include "media/base/video_decoder.h" | 12 #include "media/base/video_decoder.h" |
| 12 #include "media/base/video_decoder_config.h" | 13 #include "media/base/video_decoder_config.h" |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 class SingleThreadTaskRunner; | 16 class SingleThreadTaskRunner; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace media { | 19 namespace media { |
| 19 | 20 |
| 20 class DecoderBuffer; | 21 class DecoderBuffer; |
| 21 class Decryptor; | 22 class Decryptor; |
| 22 class MediaLog; | 23 class MediaLog; |
| 23 | 24 |
| 24 // Decryptor-based VideoDecoder implementation that can decrypt and decode | 25 // Decryptor-based VideoDecoder implementation that can decrypt and decode |
| 25 // encrypted video buffers and return decrypted and decompressed video frames. | 26 // encrypted video buffers and return decrypted and decompressed video frames. |
| 26 // All public APIs and callbacks are trampolined to the |task_runner_| so | 27 // All public APIs and callbacks are trampolined to the |task_runner_| so |
| 27 // that no locks are required for thread safety. | 28 // that no locks are required for thread safety. |
| 28 class MEDIA_EXPORT DecryptingVideoDecoder : public VideoDecoder { | 29 class MEDIA_EXPORT DecryptingVideoDecoder : public VideoDecoder { |
| 29 public: | 30 public: |
| 30 DecryptingVideoDecoder( | 31 DecryptingVideoDecoder( |
| 31 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 32 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 32 const scoped_refptr<MediaLog>& media_log, | 33 const scoped_refptr<MediaLog>& media_log, |
| 33 const SetDecryptorReadyCB& set_decryptor_ready_cb, | 34 const SetCdmReadyCB& set_cdm_ready_cb, |
| 34 const base::Closure& waiting_for_decryption_key_cb); | 35 const base::Closure& waiting_for_decryption_key_cb); |
| 35 ~DecryptingVideoDecoder() override; | 36 ~DecryptingVideoDecoder() override; |
| 36 | 37 |
| 37 // VideoDecoder implementation. | 38 // VideoDecoder implementation. |
| 38 std::string GetDisplayName() const override; | 39 std::string GetDisplayName() const override; |
| 39 void Initialize(const VideoDecoderConfig& config, | 40 void Initialize(const VideoDecoderConfig& config, |
| 40 bool low_delay, | 41 bool low_delay, |
| 41 const InitCB& init_cb, | 42 const InitCB& init_cb, |
| 42 const OutputCB& output_cb) override; | 43 const OutputCB& output_cb) override; |
| 43 void Decode(const scoped_refptr<DecoderBuffer>& buffer, | 44 void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 54 kUninitialized = 0, | 55 kUninitialized = 0, |
| 55 kDecryptorRequested, | 56 kDecryptorRequested, |
| 56 kPendingDecoderInit, | 57 kPendingDecoderInit, |
| 57 kIdle, | 58 kIdle, |
| 58 kPendingDecode, | 59 kPendingDecode, |
| 59 kWaitingForKey, | 60 kWaitingForKey, |
| 60 kDecodeFinished, | 61 kDecodeFinished, |
| 61 kError | 62 kError |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 // Callback for DecryptorHost::RequestDecryptor(). |decryptor_attached_cb| is | 65 // Callback to set CDM. |cdm_attached_cb| is called when the decryptor in the |
| 65 // called when the decryptor has been completely attached to the pipeline. | 66 // CDM has been completely attached to the pipeline. |
| 66 void SetDecryptor(Decryptor* decryptor, | 67 void SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb); |
| 67 const DecryptorAttachedCB& decryptor_attached_cb); | |
| 68 | 68 |
| 69 // Callback for Decryptor::InitializeVideoDecoder() during initialization. | 69 // Callback for Decryptor::InitializeVideoDecoder() during initialization. |
| 70 void FinishInitialization(bool success); | 70 void FinishInitialization(bool success); |
| 71 | 71 |
| 72 void DecodePendingBuffer(); | 72 void DecodePendingBuffer(); |
| 73 | 73 |
| 74 // Callback for Decryptor::DecryptAndDecodeVideo(). | 74 // Callback for Decryptor::DecryptAndDecodeVideo(). |
| 75 void DeliverFrame(int buffer_size, | 75 void DeliverFrame(int buffer_size, |
| 76 Decryptor::Status status, | 76 Decryptor::Status status, |
| 77 const scoped_refptr<VideoFrame>& frame); | 77 const scoped_refptr<VideoFrame>& frame); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 90 State state_; | 90 State state_; |
| 91 | 91 |
| 92 InitCB init_cb_; | 92 InitCB init_cb_; |
| 93 OutputCB output_cb_; | 93 OutputCB output_cb_; |
| 94 DecodeCB decode_cb_; | 94 DecodeCB decode_cb_; |
| 95 base::Closure reset_cb_; | 95 base::Closure reset_cb_; |
| 96 base::Closure waiting_for_decryption_key_cb_; | 96 base::Closure waiting_for_decryption_key_cb_; |
| 97 | 97 |
| 98 VideoDecoderConfig config_; | 98 VideoDecoderConfig config_; |
| 99 | 99 |
| 100 // Callback to request/cancel decryptor creation notification. | 100 // Callback to request/cancel CDM ready notification. |
| 101 SetDecryptorReadyCB set_decryptor_ready_cb_; | 101 SetCdmReadyCB set_cdm_ready_cb_; |
| 102 | 102 |
| 103 Decryptor* decryptor_; | 103 Decryptor* decryptor_; |
| 104 | 104 |
| 105 // The buffer that needs decrypting/decoding. | 105 // The buffer that needs decrypting/decoding. |
| 106 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_; | 106 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_; |
| 107 | 107 |
| 108 // Indicates the situation where new key is added during pending decode | 108 // Indicates the situation where new key is added during pending decode |
| 109 // (in other words, this variable can only be set in state kPendingDecode). | 109 // (in other words, this variable can only be set in state kPendingDecode). |
| 110 // If this variable is true and kNoKey is returned then we need to try | 110 // If this variable is true and kNoKey is returned then we need to try |
| 111 // decrypting/decoding again in case the newly added key is the correct | 111 // decrypting/decoding again in case the newly added key is the correct |
| 112 // decryption key. | 112 // decryption key. |
| 113 bool key_added_while_decode_pending_; | 113 bool key_added_while_decode_pending_; |
| 114 | 114 |
| 115 // A unique ID to trace Decryptor::DecryptAndDecodeVideo() call and the | 115 // A unique ID to trace Decryptor::DecryptAndDecodeVideo() call and the |
| 116 // matching DecryptCB call (in DoDeliverFrame()). | 116 // matching DecryptCB call (in DoDeliverFrame()). |
| 117 uint32 trace_id_; | 117 uint32 trace_id_; |
| 118 | 118 |
| 119 base::WeakPtr<DecryptingVideoDecoder> weak_this_; | 119 base::WeakPtr<DecryptingVideoDecoder> weak_this_; |
| 120 base::WeakPtrFactory<DecryptingVideoDecoder> weak_factory_; | 120 base::WeakPtrFactory<DecryptingVideoDecoder> weak_factory_; |
| 121 | 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(DecryptingVideoDecoder); | 122 DISALLOW_COPY_AND_ASSIGN(DecryptingVideoDecoder); |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 } // namespace media | 125 } // namespace media |
| 126 | 126 |
| 127 #endif // MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_ | 127 #endif // MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_ |
| OLD | NEW |