Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1229)

Side by Side Diff: media/cdm/ppapi/cdm_wrapper.h

Issue 26155003: Add CdmWrapper to support multiple CDM versions in CdmAdapter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_CDM_PPAPI_CDM_WRAPPER_H_
6 #define MEDIA_CDM_PPAPI_CDM_WRAPPER_H_
7
8 #include "base/basictypes.h"
9 #include "media/cdm/ppapi/api/content_decryption_module.h"
10 #include "media/cdm/ppapi/cdm_helpers.h"
11 #include "ppapi/cpp/logging.h"
12
13 namespace media {
14
15 // CdmWrapper wraps different versions of ContentDecryptionModule interfaces and
16 // exposes a common interface to the caller.
17 //
18 // The caller should call CdmWrapper::Create() to create a CDM instance.
19 // CdmWrapper will first try to create a CDM instance that supports the latest
20 // CDM interface (i.e. ContentDecryptionModule). If such an instance cannot be
ddorwin 2013/10/18 22:17:01 not i.e. - it is exactly this type.
xhwang 2013/10/18 23:03:52 Done.
21 // created (e.g. an older CDM was loaded), CdmWrapper will try to create a CDM
22 // that supports an older version of CDM interface (e.g.
23 // ContentDecryptionModule_*). Internally CdmWrapper converts the CdmWrapper
24 // calls to corresponding ContentDecryptionModule calls.
25 //
26 // Note that CdmWrapper interface always reflects the latest state of content
27 // decryption related PPAPI APIs (e.g. pp::ContentDecryptor_Private).
28 //
29 // Since this file is highly templated and default implementations are short
30 // (just a shim layer in most cases), everything is done in this header file.
31 class CdmWrapper {
32 public:
33 static CdmWrapper* Create(const char* key_system,
34 int key_system_size,
35 GetCdmHostFunc get_cdm_host_func,
36 void* user_data);
37
38 virtual ~CdmWrapper() {};
39
40 virtual cdm::Status GenerateKeyRequest(const char* type,
41 int type_size,
42 const uint8_t* init_data,
43 int init_data_size) = 0;
44 virtual cdm::Status AddKey(const char* session_id,
45 int session_id_size,
46 const uint8_t* key,
47 int key_size,
48 const uint8_t* key_id,
49 int key_id_size) = 0;
50 virtual cdm::Status CancelKeyRequest(const char* session_id,
51 int session_id_size) = 0;
52 virtual void TimerExpired(void* context) = 0;
53 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer,
54 cdm::DecryptedBlock* decrypted_buffer) = 0;
55 virtual cdm::Status InitializeAudioDecoder(
56 const cdm::AudioDecoderConfig& audio_decoder_config) = 0;
57 virtual cdm::Status InitializeVideoDecoder(
58 const cdm::VideoDecoderConfig& video_decoder_config) = 0;
59 virtual void DeinitializeDecoder(cdm::StreamType decoder_type) = 0;
60 virtual void ResetDecoder(cdm::StreamType decoder_type) = 0;
61 virtual cdm::Status DecryptAndDecodeFrame(
62 const cdm::InputBuffer& encrypted_buffer,
63 cdm::VideoFrame* video_frame) = 0;
64 virtual cdm::Status DecryptAndDecodeSamples(
65 const cdm::InputBuffer& encrypted_buffer,
66 cdm::AudioFrames* audio_frames) = 0;
67
68 protected:
69 CdmWrapper() {};
70
71 private:
72 DISALLOW_COPY_AND_ASSIGN(CdmWrapper);
73 };
74
75 // Template class that does the CdmWrapper -> CdmType conversion. Default
76 // implementations are provided. Any methods that need special treatment should
77 // be specialized.
78 // TODO(xhwang): Remove CdmVersion template parameter after we roll CDM DEPS.
ddorwin 2013/10/18 22:17:01 CDM.h DEPS?
xhwang 2013/10/18 23:03:52 Done.
79 template <class CdmType, int CdmVersion>
ddorwin 2013/10/18 22:17:01 CdmType is a bit misleading. CdmInterface? CdmVers
xhwang 2013/10/18 23:03:52 Done.
80 class CdmWrapperImpl : public CdmWrapper {
81 public:
82 static CdmWrapper* Create(const char* key_system,
83 int key_system_size,
84 GetCdmHostFunc get_cdm_host_func,
85 void* user_data) {
86 void* cdm_instance = ::CreateCdmInstance(CdmVersion,
87 key_system, key_system_size, get_cdm_host_func, user_data);
88 if (!cdm_instance)
89 return NULL;
90
91 return new CdmWrapperImpl<CdmType, CdmVersion>(
92 static_cast<CdmType*>(cdm_instance));
93 }
94
95 virtual ~CdmWrapperImpl() {
96 if (cdm_)
ddorwin 2013/10/18 22:17:01 Always true.
xhwang 2013/10/18 23:03:52 Done.
97 cdm_->Destroy();
98 }
99
100 virtual cdm::Status GenerateKeyRequest(const char* type,
101 int type_size,
102 const uint8_t* init_data,
103 int init_data_size) OVERRIDE {
104 return cdm_->GenerateKeyRequest(type, type_size, init_data, init_data_size);
105 }
106
107 virtual cdm::Status AddKey(const char* session_id,
108 int session_id_size,
109 const uint8_t* key,
110 int key_size,
111 const uint8_t* key_id,
112 int key_id_size) OVERRIDE {
113 return cdm_->AddKey(
114 session_id, session_id_size, key, key_size, key_id, key_id_size);
115 }
116
117 virtual cdm::Status CancelKeyRequest(const char* session_id,
118 int session_id_size) OVERRIDE {
119 return cdm_->CancelKeyRequest(session_id, session_id_size);
120 }
121
122 virtual void TimerExpired(void* context) OVERRIDE {
123 cdm_->TimerExpired(context);
124 }
125
126 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer,
127 cdm::DecryptedBlock* decrypted_buffer) OVERRIDE {
128 return cdm_->Decrypt(encrypted_buffer, decrypted_buffer);
129 }
130
131 virtual cdm::Status InitializeAudioDecoder(
132 const cdm::AudioDecoderConfig& audio_decoder_config) OVERRIDE {
133 return cdm_->InitializeAudioDecoder(audio_decoder_config);
134 }
135
136 virtual cdm::Status InitializeVideoDecoder(
137 const cdm::VideoDecoderConfig& video_decoder_config) OVERRIDE {
138 return cdm_->InitializeVideoDecoder(video_decoder_config);
139 }
140
141 virtual void DeinitializeDecoder(cdm::StreamType decoder_type) OVERRIDE {
142 cdm_->DeinitializeDecoder(decoder_type);
143 }
144
145 virtual void ResetDecoder(cdm::StreamType decoder_type) OVERRIDE {
146 cdm_->ResetDecoder(decoder_type);
147 }
148
149 virtual cdm::Status DecryptAndDecodeFrame(
150 const cdm::InputBuffer& encrypted_buffer,
151 cdm::VideoFrame* video_frame) OVERRIDE {
152 return cdm_->DecryptAndDecodeFrame(encrypted_buffer, video_frame);
153 }
154
155 virtual cdm::Status DecryptAndDecodeSamples(
156 const cdm::InputBuffer& encrypted_buffer,
157 cdm::AudioFrames* audio_frames) OVERRIDE {
158 return cdm_->DecryptAndDecodeSamples(encrypted_buffer, audio_frames);
159 }
160
161 private:
162 CdmWrapperImpl(CdmType* cdm) : cdm_(cdm) {
163 PP_DCHECK(cdm_);
164 }
165
166 CdmType* cdm_;
167
168 DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl);
169 };
170
171 // Specializations for old ContentDecryptionModule interfaces.
172 // For example:
173
174 // template <> cdm::Status CdmAdapterImpl<cdm::ContentDecryptionModule_1>::
175 // DecryptAndDecodeSamples(const cdm::InputBuffer& encrypted_buffer,
176 // cdm::AudioFrames* audio_frames) {
177 // AudioFramesImpl audio_frames_1;
178 // cdm::Status status =
179 // cdm_->DecryptAndDecodeSamples(encrypted_buffer, &audio_frames_1);
180 // if (status != cdm::kSuccess)
181 // return status;
182 //
183 // audio_frames->SetFrameBuffer(audio_frames_1.PassFrameBuffer());
184 // audio_frames->SetFormat(cdm::kAudioFormatS16);
185 // return cdm::kSuccess;
186 // }
187
188 CdmWrapper* CdmWrapper::Create(const char* key_system,
189 int key_system_size,
190 GetCdmHostFunc get_cdm_host_func,
191 void* user_data) {
192 // Try to create the CDM using the latest CDM interface version.
193 CdmWrapper* cdm_wrapper =
194 CdmWrapperImpl<cdm::ContentDecryptionModule, cdm::kCdmInterfaceVersion>::
195 Create(key_system, key_system_size, get_cdm_host_func, user_data);
196
197 // Try to see if the CDM supports older version(s) of CDM interface(s).
198 // For example:
199 //
200 // if (cdm_wrapper)
201 // return cdm_wrapper;
202 //
203 // cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule_1>::Create(
204 // key_system, key_system_size, get_cdm_host_func, user_data);
205
206 return cdm_wrapper;
207 }
208
209 } // namespace media
210
211 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698