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/decryptor.h" | 10 #include "media/base/decryptor.h" |
11 #include "media/base/demuxer_stream.h" | |
12 #include "media/base/video_decoder.h" | 11 #include "media/base/video_decoder.h" |
| 12 #include "media/base/video_decoder_config.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 VideoDecoder implementation that can decrypt and decode |
24 // encrypted video buffers and return decrypted and decompressed video frames. | 24 // encrypted video buffers and return decrypted and decompressed video 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 class MEDIA_EXPORT DecryptingVideoDecoder : public VideoDecoder { | 27 class MEDIA_EXPORT DecryptingVideoDecoder : public VideoDecoder { |
28 public: | 28 public: |
29 DecryptingVideoDecoder( | 29 DecryptingVideoDecoder( |
30 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 30 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
31 const SetDecryptorReadyCB& set_decryptor_ready_cb); | 31 const SetDecryptorReadyCB& set_decryptor_ready_cb); |
32 virtual ~DecryptingVideoDecoder(); | 32 virtual ~DecryptingVideoDecoder(); |
33 | 33 |
34 // VideoDecoder implementation. | 34 // VideoDecoder implementation. |
35 virtual void Initialize(DemuxerStream* stream, | 35 virtual void Initialize(const VideoDecoderConfig& config, |
36 const PipelineStatusCB& status_cb, | 36 const PipelineStatusCB& status_cb, |
37 const StatisticsCB& statistics_cb) OVERRIDE; | 37 const StatisticsCB& statistics_cb) OVERRIDE; |
38 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 38 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 39 const ReadCB& read_cb) OVERRIDE; |
39 virtual void Reset(const base::Closure& closure) OVERRIDE; | 40 virtual void Reset(const base::Closure& closure) OVERRIDE; |
40 virtual void Stop(const base::Closure& closure) OVERRIDE; | 41 virtual void Stop(const base::Closure& closure) OVERRIDE; |
41 | 42 |
42 private: | 43 private: |
43 // For a detailed state diagram please see this link: http://goo.gl/8jAok | 44 // For a detailed state diagram please see this link: http://goo.gl/8jAok |
44 // TODO(xhwang): Add a ASCII state diagram in this file after this class | 45 // TODO(xhwang): Add a ASCII state diagram in this file after this class |
45 // stabilizes. | 46 // stabilizes. |
46 enum State { | 47 enum State { |
47 kUninitialized = 0, | 48 kUninitialized = 0, |
48 kDecryptorRequested, | 49 kDecryptorRequested, |
49 kPendingDecoderInit, | 50 kPendingDecoderInit, |
50 kIdle, | 51 kIdle, |
51 kPendingDemuxerRead, | |
52 kPendingDecode, | 52 kPendingDecode, |
53 kWaitingForKey, | 53 kWaitingForKey, |
54 kDecodeFinished, | 54 kDecodeFinished, |
55 kStopped, | 55 kStopped, |
56 kError | 56 kError |
57 }; | 57 }; |
58 | 58 |
59 // Callback for DecryptorHost::RequestDecryptor(). | 59 // Callback for DecryptorHost::RequestDecryptor(). |
60 void SetDecryptor(Decryptor* decryptor); | 60 void SetDecryptor(Decryptor* decryptor); |
61 | 61 |
62 // Callback for Decryptor::InitializeVideoDecoder() during initialization. | 62 // Callback for Decryptor::InitializeVideoDecoder() during initialization. |
63 void FinishInitialization(bool success); | 63 void FinishInitialization(bool success); |
64 | 64 |
65 void ReadFromDemuxerStream(); | |
66 | |
67 // Callback for DemuxerStream::Read(). | |
68 void DecryptAndDecodeBuffer(DemuxerStream::Status status, | |
69 const scoped_refptr<DecoderBuffer>& buffer); | |
70 | |
71 void DecodePendingBuffer(); | 65 void DecodePendingBuffer(); |
72 | 66 |
73 // Callback for Decryptor::DecryptAndDecodeVideo(). | 67 // Callback for Decryptor::DecryptAndDecodeVideo(). |
74 void DeliverFrame(int buffer_size, | 68 void DeliverFrame(int buffer_size, |
75 Decryptor::Status status, | 69 Decryptor::Status status, |
76 const scoped_refptr<VideoFrame>& frame); | 70 const scoped_refptr<VideoFrame>& frame); |
77 | 71 |
78 // Callback for the |decryptor_| to notify this object that a new key has been | 72 // Callback for the |decryptor_| to notify this object that a new key has been |
79 // added. | 73 // added. |
80 void OnKeyAdded(); | 74 void OnKeyAdded(); |
81 | 75 |
82 // Reset decoder and call |reset_cb_|. | 76 // Reset decoder and call |reset_cb_|. |
83 void DoReset(); | 77 void DoReset(); |
84 | 78 |
85 // Free decoder resources and call |stop_cb_|. | 79 // Free decoder resources and call |stop_cb_|. |
86 void DoStop(); | 80 void DoStop(); |
87 | 81 |
88 scoped_refptr<base::MessageLoopProxy> message_loop_; | 82 scoped_refptr<base::MessageLoopProxy> message_loop_; |
89 base::WeakPtrFactory<DecryptingVideoDecoder> weak_factory_; | 83 base::WeakPtrFactory<DecryptingVideoDecoder> weak_factory_; |
90 base::WeakPtr<DecryptingVideoDecoder> weak_this_; | 84 base::WeakPtr<DecryptingVideoDecoder> weak_this_; |
91 | 85 |
92 State state_; | 86 State state_; |
93 | 87 |
94 PipelineStatusCB init_cb_; | 88 PipelineStatusCB init_cb_; |
95 StatisticsCB statistics_cb_; | 89 StatisticsCB statistics_cb_; |
96 ReadCB read_cb_; | 90 ReadCB read_cb_; |
97 base::Closure reset_cb_; | 91 base::Closure reset_cb_; |
98 | 92 |
99 // Pointer to the demuxer stream that will feed us compressed buffers. | 93 VideoDecoderConfig config_; |
100 DemuxerStream* demuxer_stream_; | |
101 | 94 |
102 // Callback to request/cancel decryptor creation notification. | 95 // Callback to request/cancel decryptor creation notification. |
103 SetDecryptorReadyCB set_decryptor_ready_cb_; | 96 SetDecryptorReadyCB set_decryptor_ready_cb_; |
104 | 97 |
105 Decryptor* decryptor_; | 98 Decryptor* decryptor_; |
106 | 99 |
107 // The buffer returned by the demuxer that needs decrypting/decoding. | 100 // The buffer that needs decrypting/decoding. |
108 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_; | 101 scoped_refptr<media::DecoderBuffer> pending_buffer_to_decode_; |
109 | 102 |
110 // Indicates the situation where new key is added during pending decode | 103 // Indicates the situation where new key is added during pending decode |
111 // (in other words, this variable can only be set in state kPendingDecode). | 104 // (in other words, this variable can only be set in state kPendingDecode). |
112 // If this variable is true and kNoKey is returned then we need to try | 105 // If this variable is true and kNoKey is returned then we need to try |
113 // decrypting/decoding again in case the newly added key is the correct | 106 // decrypting/decoding again in case the newly added key is the correct |
114 // decryption key. | 107 // decryption key. |
115 bool key_added_while_decode_pending_; | 108 bool key_added_while_decode_pending_; |
116 | 109 |
117 // A unique ID to trace Decryptor::DecryptAndDecodeVideo() call and the | 110 // A unique ID to trace Decryptor::DecryptAndDecodeVideo() call and the |
118 // matching DecryptCB call (in DoDeliverFrame()). | 111 // matching DecryptCB call (in DoDeliverFrame()). |
119 uint32 trace_id_; | 112 uint32 trace_id_; |
120 | 113 |
121 DISALLOW_COPY_AND_ASSIGN(DecryptingVideoDecoder); | 114 DISALLOW_COPY_AND_ASSIGN(DecryptingVideoDecoder); |
122 }; | 115 }; |
123 | 116 |
124 } // namespace media | 117 } // namespace media |
125 | 118 |
126 #endif // MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_ | 119 #endif // MEDIA_FILTERS_DECRYPTING_VIDEO_DECODER_H_ |
OLD | NEW |