OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include <cstring> | 5 #include <cstring> |
6 #include <map> | 6 #include <map> |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 void ConfigureInputBuffer( | 68 void ConfigureInputBuffer( |
69 const pp::Buffer_Dev& encrypted_buffer, | 69 const pp::Buffer_Dev& encrypted_buffer, |
70 const PP_EncryptedBlockInfo& encrypted_block_info, | 70 const PP_EncryptedBlockInfo& encrypted_block_info, |
71 std::vector<cdm::SubsampleEntry>* subsamples, | 71 std::vector<cdm::SubsampleEntry>* subsamples, |
72 cdm::InputBuffer* input_buffer) { | 72 cdm::InputBuffer* input_buffer) { |
73 PP_DCHECK(subsamples); | 73 PP_DCHECK(subsamples); |
74 PP_DCHECK(!encrypted_buffer.is_null()); | 74 PP_DCHECK(!encrypted_buffer.is_null()); |
75 | 75 |
76 input_buffer->data = static_cast<uint8_t*>(encrypted_buffer.data()); | 76 input_buffer->data = static_cast<uint8_t*>(encrypted_buffer.data()); |
77 input_buffer->data_size = encrypted_block_info.data_size; | 77 input_buffer->data_size = encrypted_block_info.data_size; |
78 PP_DCHECK(encrypted_buffer.size() >= | 78 PP_DCHECK(encrypted_buffer.size() >= input_buffer->data_size); |
79 static_cast<uint32_t>(input_buffer->data_size)); | |
80 input_buffer->data_offset = encrypted_block_info.data_offset; | 79 input_buffer->data_offset = encrypted_block_info.data_offset; |
81 | 80 |
82 PP_DCHECK(encrypted_block_info.key_id_size <= | 81 PP_DCHECK(encrypted_block_info.key_id_size <= |
83 arraysize(encrypted_block_info.key_id)); | 82 arraysize(encrypted_block_info.key_id)); |
84 input_buffer->key_id_size = encrypted_block_info.key_id_size; | 83 input_buffer->key_id_size = encrypted_block_info.key_id_size; |
85 input_buffer->key_id = input_buffer->key_id_size > 0 ? | 84 input_buffer->key_id = input_buffer->key_id_size > 0 ? |
86 encrypted_block_info.key_id : NULL; | 85 encrypted_block_info.key_id : NULL; |
87 | 86 |
88 PP_DCHECK(encrypted_block_info.iv_size <= arraysize(encrypted_block_info.iv)); | 87 PP_DCHECK(encrypted_block_info.iv_size <= arraysize(encrypted_block_info.iv)); |
89 input_buffer->iv_size = encrypted_block_info.iv_size; | 88 input_buffer->iv_size = encrypted_block_info.iv_size; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 static PpbBuffer* Create(const pp::Buffer_Dev& buffer, uint32_t buffer_id) { | 222 static PpbBuffer* Create(const pp::Buffer_Dev& buffer, uint32_t buffer_id) { |
224 PP_DCHECK(buffer.data()); | 223 PP_DCHECK(buffer.data()); |
225 PP_DCHECK(buffer.size()); | 224 PP_DCHECK(buffer.size()); |
226 PP_DCHECK(buffer_id); | 225 PP_DCHECK(buffer_id); |
227 return new PpbBuffer(buffer, buffer_id); | 226 return new PpbBuffer(buffer, buffer_id); |
228 } | 227 } |
229 | 228 |
230 // cdm::Buffer implementation. | 229 // cdm::Buffer implementation. |
231 virtual void Destroy() OVERRIDE { delete this; } | 230 virtual void Destroy() OVERRIDE { delete this; } |
232 | 231 |
233 virtual int32_t Capacity() const OVERRIDE { return buffer_.size(); } | 232 virtual uint32_t Capacity() const OVERRIDE { return buffer_.size(); } |
234 | 233 |
235 virtual uint8_t* Data() OVERRIDE { | 234 virtual uint8_t* Data() OVERRIDE { |
236 return static_cast<uint8_t*>(buffer_.data()); | 235 return static_cast<uint8_t*>(buffer_.data()); |
237 } | 236 } |
238 | 237 |
239 virtual void SetSize(int32_t size) OVERRIDE { | 238 virtual void SetSize(uint32_t size) OVERRIDE { |
240 PP_DCHECK(size >= 0); | |
241 PP_DCHECK(size < Capacity()); | 239 PP_DCHECK(size < Capacity()); |
242 if (size < 0 || size > Capacity()) { | 240 if (size > Capacity()) { |
243 size_ = 0; | 241 size_ = 0; |
244 return; | 242 return; |
245 } | 243 } |
246 | 244 |
247 size_ = size; | 245 size_ = size; |
248 } | 246 } |
249 | 247 |
250 virtual int32_t Size() const OVERRIDE { return size_; } | 248 virtual uint32_t Size() const OVERRIDE { return size_; } |
251 | 249 |
252 pp::Buffer_Dev buffer_dev() const { return buffer_; } | 250 pp::Buffer_Dev buffer_dev() const { return buffer_; } |
253 | 251 |
254 uint32_t buffer_id() const { return buffer_id_; } | 252 uint32_t buffer_id() const { return buffer_id_; } |
255 | 253 |
256 private: | 254 private: |
257 PpbBuffer(pp::Buffer_Dev buffer, uint32_t buffer_id) | 255 PpbBuffer(pp::Buffer_Dev buffer, uint32_t buffer_id) |
258 : buffer_(buffer), | 256 : buffer_(buffer), |
259 buffer_id_(buffer_id), | 257 buffer_id_(buffer_id), |
260 size_(0) {} | 258 size_(0) {} |
261 virtual ~PpbBuffer() {} | 259 virtual ~PpbBuffer() {} |
262 | 260 |
263 pp::Buffer_Dev buffer_; | 261 pp::Buffer_Dev buffer_; |
264 uint32_t buffer_id_; | 262 uint32_t buffer_id_; |
265 int32_t size_; | 263 uint32_t size_; |
266 | 264 |
267 DISALLOW_COPY_AND_ASSIGN(PpbBuffer); | 265 DISALLOW_COPY_AND_ASSIGN(PpbBuffer); |
268 }; | 266 }; |
269 | 267 |
270 class PpbBufferAllocator { | 268 class PpbBufferAllocator { |
271 public: | 269 public: |
272 explicit PpbBufferAllocator(pp::Instance* instance) | 270 explicit PpbBufferAllocator(pp::Instance* instance) |
273 : instance_(instance), | 271 : instance_(instance), |
274 next_buffer_id_(1) {} | 272 next_buffer_id_(1) {} |
275 ~PpbBufferAllocator() {} | 273 ~PpbBufferAllocator() {} |
276 | 274 |
277 cdm::Buffer* Allocate(int32_t capacity); | 275 cdm::Buffer* Allocate(uint32_t capacity); |
278 | 276 |
279 // Releases the buffer with |buffer_id|. A buffer can be recycled after | 277 // Releases the buffer with |buffer_id|. A buffer can be recycled after |
280 // it is released. | 278 // it is released. |
281 void Release(uint32_t buffer_id); | 279 void Release(uint32_t buffer_id); |
282 | 280 |
283 private: | 281 private: |
284 typedef std::map<uint32_t, pp::Buffer_Dev> AllocatedBufferMap; | 282 typedef std::map<uint32_t, pp::Buffer_Dev> AllocatedBufferMap; |
285 typedef std::multimap<int, std::pair<uint32_t, pp::Buffer_Dev> > | 283 typedef std::multimap<uint32_t, std::pair<uint32_t, pp::Buffer_Dev> > |
286 FreeBufferMap; | 284 FreeBufferMap; |
287 | 285 |
288 // Always pad new allocated buffer so that we don't need to reallocate | 286 // Always pad new allocated buffer so that we don't need to reallocate |
289 // buffers frequently if requested sizes fluctuate slightly. | 287 // buffers frequently if requested sizes fluctuate slightly. |
290 static const int kBufferPadding = 512; | 288 static const uint32_t kBufferPadding = 512; |
291 | 289 |
292 // Maximum number of free buffers we can keep when allocating new buffers. | 290 // Maximum number of free buffers we can keep when allocating new buffers. |
293 static const int kFreeLimit = 3; | 291 static const uint32_t kFreeLimit = 3; |
294 | 292 |
295 pp::Buffer_Dev AllocateNewBuffer(int capacity); | 293 pp::Buffer_Dev AllocateNewBuffer(uint32_t capacity); |
296 | 294 |
297 pp::Instance* const instance_; | 295 pp::Instance* const instance_; |
298 uint32_t next_buffer_id_; | 296 uint32_t next_buffer_id_; |
299 AllocatedBufferMap allocated_buffers_; | 297 AllocatedBufferMap allocated_buffers_; |
300 FreeBufferMap free_buffers_; | 298 FreeBufferMap free_buffers_; |
301 | 299 |
302 DISALLOW_COPY_AND_ASSIGN(PpbBufferAllocator); | 300 DISALLOW_COPY_AND_ASSIGN(PpbBufferAllocator); |
303 }; | 301 }; |
304 | 302 |
305 cdm::Buffer* PpbBufferAllocator::Allocate(int32_t capacity) { | 303 cdm::Buffer* PpbBufferAllocator::Allocate(uint32_t capacity) { |
306 PP_DCHECK(IsMainThread()); | 304 PP_DCHECK(IsMainThread()); |
307 | 305 |
308 if (capacity <= 0) | 306 if (!capacity) |
309 return NULL; | 307 return NULL; |
310 | 308 |
311 pp::Buffer_Dev buffer; | 309 pp::Buffer_Dev buffer; |
312 uint32_t buffer_id = 0; | 310 uint32_t buffer_id = 0; |
313 | 311 |
314 // Reuse a buffer in the free list if there is one that fits |capacity|. | 312 // Reuse a buffer in the free list if there is one that fits |capacity|. |
315 // Otherwise, create a new one. | 313 // Otherwise, create a new one. |
316 FreeBufferMap::iterator found = free_buffers_.lower_bound(capacity); | 314 FreeBufferMap::iterator found = free_buffers_.lower_bound(capacity); |
317 if (found == free_buffers_.end()) { | 315 if (found == free_buffers_.end()) { |
318 // TODO(xhwang): Report statistics about how many new buffers are allocated. | 316 // TODO(xhwang): Report statistics about how many new buffers are allocated. |
(...skipping 20 matching lines...) Expand all Loading... |
339 if (found == allocated_buffers_.end()) | 337 if (found == allocated_buffers_.end()) |
340 return; | 338 return; |
341 | 339 |
342 pp::Buffer_Dev& buffer = found->second; | 340 pp::Buffer_Dev& buffer = found->second; |
343 free_buffers_.insert( | 341 free_buffers_.insert( |
344 std::make_pair(buffer.size(), std::make_pair(buffer_id, buffer))); | 342 std::make_pair(buffer.size(), std::make_pair(buffer_id, buffer))); |
345 | 343 |
346 allocated_buffers_.erase(found); | 344 allocated_buffers_.erase(found); |
347 } | 345 } |
348 | 346 |
349 pp::Buffer_Dev PpbBufferAllocator::AllocateNewBuffer(int32_t capacity) { | 347 pp::Buffer_Dev PpbBufferAllocator::AllocateNewBuffer(uint32_t capacity) { |
350 // Destroy the smallest buffer before allocating a new bigger buffer if the | 348 // Destroy the smallest buffer before allocating a new bigger buffer if the |
351 // number of free buffers exceeds a limit. This mechanism helps avoid ending | 349 // number of free buffers exceeds a limit. This mechanism helps avoid ending |
352 // up with too many small buffers, which could happen if the size to be | 350 // up with too many small buffers, which could happen if the size to be |
353 // allocated keeps increasing. | 351 // allocated keeps increasing. |
354 if (free_buffers_.size() >= static_cast<uint32_t>(kFreeLimit)) | 352 if (free_buffers_.size() >= kFreeLimit) |
355 free_buffers_.erase(free_buffers_.begin()); | 353 free_buffers_.erase(free_buffers_.begin()); |
356 | 354 |
357 // Creation of pp::Buffer_Dev is expensive! It involves synchronous IPC calls. | 355 // Creation of pp::Buffer_Dev is expensive! It involves synchronous IPC calls. |
358 // That's why we try to avoid AllocateNewBuffer() as much as we can. | 356 // That's why we try to avoid AllocateNewBuffer() as much as we can. |
359 return pp::Buffer_Dev(instance_, capacity + kBufferPadding); | 357 return pp::Buffer_Dev(instance_, capacity + kBufferPadding); |
360 } | 358 } |
361 | 359 |
362 class DecryptedBlockImpl : public cdm::DecryptedBlock { | 360 class DecryptedBlockImpl : public cdm::DecryptedBlock { |
363 public: | 361 public: |
364 DecryptedBlockImpl() : buffer_(NULL), timestamp_(0) {} | 362 DecryptedBlockImpl() : buffer_(NULL), timestamp_(0) {} |
(...skipping 28 matching lines...) Expand all Loading... |
393 | 391 |
394 virtual void SetSize(cdm::Size size) OVERRIDE { size_ = size; } | 392 virtual void SetSize(cdm::Size size) OVERRIDE { size_ = size; } |
395 virtual cdm::Size Size() const OVERRIDE { return size_; } | 393 virtual cdm::Size Size() const OVERRIDE { return size_; } |
396 | 394 |
397 virtual void SetFrameBuffer(cdm::Buffer* frame_buffer) OVERRIDE { | 395 virtual void SetFrameBuffer(cdm::Buffer* frame_buffer) OVERRIDE { |
398 frame_buffer_ = static_cast<PpbBuffer*>(frame_buffer); | 396 frame_buffer_ = static_cast<PpbBuffer*>(frame_buffer); |
399 } | 397 } |
400 virtual cdm::Buffer* FrameBuffer() OVERRIDE { return frame_buffer_; } | 398 virtual cdm::Buffer* FrameBuffer() OVERRIDE { return frame_buffer_; } |
401 | 399 |
402 virtual void SetPlaneOffset(cdm::VideoFrame::VideoPlane plane, | 400 virtual void SetPlaneOffset(cdm::VideoFrame::VideoPlane plane, |
403 int32_t offset) OVERRIDE { | 401 uint32_t offset) OVERRIDE { |
404 PP_DCHECK(0 <= plane && plane < kMaxPlanes); | 402 PP_DCHECK(plane < kMaxPlanes); |
405 PP_DCHECK(offset >= 0); | |
406 plane_offsets_[plane] = offset; | 403 plane_offsets_[plane] = offset; |
407 } | 404 } |
408 virtual int32_t PlaneOffset(VideoPlane plane) OVERRIDE { | 405 virtual uint32_t PlaneOffset(VideoPlane plane) OVERRIDE { |
409 PP_DCHECK(0 <= plane && plane < kMaxPlanes); | 406 PP_DCHECK(plane < kMaxPlanes); |
410 return plane_offsets_[plane]; | 407 return plane_offsets_[plane]; |
411 } | 408 } |
412 | 409 |
413 virtual void SetStride(VideoPlane plane, int32_t stride) OVERRIDE { | 410 virtual void SetStride(VideoPlane plane, uint32_t stride) OVERRIDE { |
414 PP_DCHECK(0 <= plane && plane < kMaxPlanes); | 411 PP_DCHECK(plane < kMaxPlanes); |
415 strides_[plane] = stride; | 412 strides_[plane] = stride; |
416 } | 413 } |
417 virtual int32_t Stride(VideoPlane plane) OVERRIDE { | 414 virtual uint32_t Stride(VideoPlane plane) OVERRIDE { |
418 PP_DCHECK(0 <= plane && plane < kMaxPlanes); | 415 PP_DCHECK(plane < kMaxPlanes); |
419 return strides_[plane]; | 416 return strides_[plane]; |
420 } | 417 } |
421 | 418 |
422 virtual void SetTimestamp(int64_t timestamp) OVERRIDE { | 419 virtual void SetTimestamp(int64_t timestamp) OVERRIDE { |
423 timestamp_ = timestamp; | 420 timestamp_ = timestamp; |
424 } | 421 } |
425 virtual int64_t Timestamp() const OVERRIDE { return timestamp_; } | 422 virtual int64_t Timestamp() const OVERRIDE { return timestamp_; } |
426 | 423 |
427 private: | 424 private: |
428 // The video buffer format. | 425 // The video buffer format. |
429 cdm::VideoFormat format_; | 426 cdm::VideoFormat format_; |
430 | 427 |
431 // Width and height of the video frame. | 428 // Width and height of the video frame. |
432 cdm::Size size_; | 429 cdm::Size size_; |
433 | 430 |
434 // The video frame buffer. | 431 // The video frame buffer. |
435 PpbBuffer* frame_buffer_; | 432 PpbBuffer* frame_buffer_; |
436 | 433 |
437 // Array of data pointers to each plane in the video frame buffer. | 434 // Array of data pointers to each plane in the video frame buffer. |
438 int32_t plane_offsets_[kMaxPlanes]; | 435 uint32_t plane_offsets_[kMaxPlanes]; |
439 | 436 |
440 // Array of strides for each plane, typically greater or equal to the width | 437 // Array of strides for each plane, typically greater or equal to the width |
441 // of the surface divided by the horizontal sampling period. Note that | 438 // of the surface divided by the horizontal sampling period. Note that |
442 // strides can be negative. | 439 // strides can be negative. |
443 int32_t strides_[kMaxPlanes]; | 440 uint32_t strides_[kMaxPlanes]; |
444 | 441 |
445 // Presentation timestamp in microseconds. | 442 // Presentation timestamp in microseconds. |
446 int64_t timestamp_; | 443 int64_t timestamp_; |
447 | 444 |
448 DISALLOW_COPY_AND_ASSIGN(VideoFrameImpl); | 445 DISALLOW_COPY_AND_ASSIGN(VideoFrameImpl); |
449 }; | 446 }; |
450 | 447 |
451 VideoFrameImpl::VideoFrameImpl() | 448 VideoFrameImpl::VideoFrameImpl() |
452 : format_(cdm::kUnknownVideoFormat), | 449 : format_(cdm::kUnknownVideoFormat), |
453 frame_buffer_(NULL), | 450 frame_buffer_(NULL), |
454 timestamp_(0) { | 451 timestamp_(0) { |
455 for (int32_t i = 0; i < kMaxPlanes; ++i) { | 452 for (uint32_t i = 0; i < kMaxPlanes; ++i) { |
456 plane_offsets_[i] = 0; | 453 plane_offsets_[i] = 0; |
457 strides_[i] = 0; | 454 strides_[i] = 0; |
458 } | 455 } |
459 } | 456 } |
460 | 457 |
461 VideoFrameImpl::~VideoFrameImpl() { | 458 VideoFrameImpl::~VideoFrameImpl() { |
462 if (frame_buffer_) | 459 if (frame_buffer_) |
463 frame_buffer_->Destroy(); | 460 frame_buffer_->Destroy(); |
464 } | 461 } |
465 | 462 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 virtual void DeinitializeDecoder(PP_DecryptorStreamType decoder_type, | 531 virtual void DeinitializeDecoder(PP_DecryptorStreamType decoder_type, |
535 uint32_t request_id) OVERRIDE; | 532 uint32_t request_id) OVERRIDE; |
536 virtual void ResetDecoder(PP_DecryptorStreamType decoder_type, | 533 virtual void ResetDecoder(PP_DecryptorStreamType decoder_type, |
537 uint32_t request_id) OVERRIDE; | 534 uint32_t request_id) OVERRIDE; |
538 virtual void DecryptAndDecode( | 535 virtual void DecryptAndDecode( |
539 PP_DecryptorStreamType decoder_type, | 536 PP_DecryptorStreamType decoder_type, |
540 pp::Buffer_Dev encrypted_buffer, | 537 pp::Buffer_Dev encrypted_buffer, |
541 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; | 538 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; |
542 | 539 |
543 // cdm::Host_1 implementation. | 540 // cdm::Host_1 implementation. |
544 virtual cdm::Buffer* Allocate(int32_t capacity) OVERRIDE; | 541 virtual cdm::Buffer* Allocate(uint32_t capacity) OVERRIDE; |
545 virtual void SetTimer(int64_t delay_ms, void* context) OVERRIDE; | 542 virtual void SetTimer(int64_t delay_ms, void* context) OVERRIDE; |
546 virtual double GetCurrentWallTimeInSeconds() OVERRIDE; | 543 virtual double GetCurrentWallTimeInSeconds() OVERRIDE; |
547 virtual void SendKeyMessage( | 544 virtual void SendKeyMessage( |
548 const char* session_id, int32_t session_id_length, | 545 const char* session_id, uint32_t session_id_length, |
549 const char* message, int32_t message_length, | 546 const char* message, uint32_t message_length, |
550 const char* default_url, int32_t default_url_length) OVERRIDE; | 547 const char* default_url, uint32_t default_url_length) OVERRIDE; |
551 virtual void SendKeyError(const char* session_id, | 548 virtual void SendKeyError(const char* session_id, |
552 int32_t session_id_length, | 549 uint32_t session_id_length, |
553 cdm::MediaKeyError error_code, | 550 cdm::MediaKeyError error_code, |
554 uint32_t system_code) OVERRIDE; | 551 uint32_t system_code) OVERRIDE; |
555 virtual void GetPrivateData(int32_t* instance, | 552 virtual void GetPrivateData(int32_t* instance, |
556 GetPrivateInterface* get_interface) OVERRIDE; | 553 GetPrivateInterface* get_interface) OVERRIDE; |
557 | 554 |
558 // cdm::Host_2 implementation. | 555 // cdm::Host_2 implementation. |
559 virtual bool CanChallengePlatform() OVERRIDE; | 556 virtual bool CanChallengePlatform() OVERRIDE; |
560 virtual void SendPlatformChallenge( | 557 virtual void SendPlatformChallenge( |
561 const char* service_id, int32_t service_id_length, | 558 const char* service_id, uint32_t service_id_length, |
562 const char* challenge, int32_t challenge_length) OVERRIDE; | 559 const char* challenge, uint32_t challenge_length) OVERRIDE; |
563 virtual void EnableOutputProtection( | 560 virtual void EnableOutputProtection( |
564 uint32_t desired_protection_mask) OVERRIDE; | 561 uint32_t desired_protection_mask) OVERRIDE; |
565 virtual void QueryOutputProtectionStatus() OVERRIDE; | 562 virtual void QueryOutputProtectionStatus() OVERRIDE; |
566 | 563 |
567 private: | 564 private: |
568 struct SessionInfo { | 565 struct SessionInfo { |
569 SessionInfo(const std::string& key_system_in, | 566 SessionInfo(const std::string& key_system_in, |
570 const std::string& session_id_in) | 567 const std::string& session_id_in) |
571 : key_system(key_system_in), | 568 : key_system(key_system_in), |
572 session_id(session_id_in) {} | 569 session_id(session_id_in) {} |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 void CdmWrapper::AddKey(const std::string& session_id, | 746 void CdmWrapper::AddKey(const std::string& session_id, |
750 pp::VarArrayBuffer key, | 747 pp::VarArrayBuffer key, |
751 pp::VarArrayBuffer init_data) { | 748 pp::VarArrayBuffer init_data) { |
752 PP_DCHECK(cdm_); // Initialize() should have succeeded. | 749 PP_DCHECK(cdm_); // Initialize() should have succeeded. |
753 if (!cdm_) { | 750 if (!cdm_) { |
754 SendUnknownKeyError(key_system_, session_id); | 751 SendUnknownKeyError(key_system_, session_id); |
755 return; | 752 return; |
756 } | 753 } |
757 | 754 |
758 const uint8_t* key_ptr = static_cast<const uint8_t*>(key.Map()); | 755 const uint8_t* key_ptr = static_cast<const uint8_t*>(key.Map()); |
759 int key_size = key.ByteLength(); | 756 uint32_t key_size = key.ByteLength(); |
760 const uint8_t* init_data_ptr = static_cast<const uint8_t*>(init_data.Map()); | 757 const uint8_t* init_data_ptr = static_cast<const uint8_t*>(init_data.Map()); |
761 int init_data_size = init_data.ByteLength(); | 758 uint32_t init_data_size = init_data.ByteLength(); |
762 PP_DCHECK(!init_data_ptr == !init_data_size); | 759 PP_DCHECK(!init_data_ptr == !init_data_size); |
763 | 760 |
764 if (!key_ptr || key_size <= 0) { | 761 if (!key_ptr || !key_size) { |
765 SendUnknownKeyError(key_system_, session_id); | 762 SendUnknownKeyError(key_system_, session_id); |
766 return; | 763 return; |
767 } | 764 } |
768 | 765 |
769 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(), | 766 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(), |
770 key_ptr, key_size, | 767 key_ptr, key_size, |
771 init_data_ptr, init_data_size); | 768 init_data_ptr, init_data_size); |
772 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); | 769 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); |
773 if (status != cdm::kSuccess) { | 770 if (status != cdm::kSuccess) { |
774 SendUnknownKeyError(key_system_, session_id); | 771 SendUnknownKeyError(key_system_, session_id); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 cdm::Status status = cdm::kSessionError; | 829 cdm::Status status = cdm::kSessionError; |
833 if (cdm_) { | 830 if (cdm_) { |
834 cdm::AudioDecoderConfig cdm_decoder_config; | 831 cdm::AudioDecoderConfig cdm_decoder_config; |
835 cdm_decoder_config.codec = | 832 cdm_decoder_config.codec = |
836 PpAudioCodecToCdmAudioCodec(decoder_config.codec); | 833 PpAudioCodecToCdmAudioCodec(decoder_config.codec); |
837 cdm_decoder_config.channel_count = decoder_config.channel_count; | 834 cdm_decoder_config.channel_count = decoder_config.channel_count; |
838 cdm_decoder_config.bits_per_channel = decoder_config.bits_per_channel; | 835 cdm_decoder_config.bits_per_channel = decoder_config.bits_per_channel; |
839 cdm_decoder_config.samples_per_second = decoder_config.samples_per_second; | 836 cdm_decoder_config.samples_per_second = decoder_config.samples_per_second; |
840 cdm_decoder_config.extra_data = | 837 cdm_decoder_config.extra_data = |
841 static_cast<uint8_t*>(extra_data_buffer.data()); | 838 static_cast<uint8_t*>(extra_data_buffer.data()); |
842 cdm_decoder_config.extra_data_size = | 839 cdm_decoder_config.extra_data_size = extra_data_buffer.size(); |
843 static_cast<int32_t>(extra_data_buffer.size()); | |
844 status = cdm_->InitializeAudioDecoder(cdm_decoder_config); | 840 status = cdm_->InitializeAudioDecoder(cdm_decoder_config); |
845 } | 841 } |
846 | 842 |
847 CallOnMain(callback_factory_.NewCallback( | 843 CallOnMain(callback_factory_.NewCallback( |
848 &CdmWrapper::DecoderInitializeDone, | 844 &CdmWrapper::DecoderInitializeDone, |
849 PP_DECRYPTORSTREAMTYPE_AUDIO, | 845 PP_DECRYPTORSTREAMTYPE_AUDIO, |
850 decoder_config.request_id, | 846 decoder_config.request_id, |
851 status == cdm::kSuccess)); | 847 status == cdm::kSuccess)); |
852 } | 848 } |
853 | 849 |
854 void CdmWrapper::InitializeVideoDecoder( | 850 void CdmWrapper::InitializeVideoDecoder( |
855 const PP_VideoDecoderConfig& decoder_config, | 851 const PP_VideoDecoderConfig& decoder_config, |
856 pp::Buffer_Dev extra_data_buffer) { | 852 pp::Buffer_Dev extra_data_buffer) { |
857 PP_DCHECK(cdm_); // Initialize() should have succeeded. | 853 PP_DCHECK(cdm_); // Initialize() should have succeeded. |
858 | 854 |
859 cdm::Status status = cdm::kSessionError; | 855 cdm::Status status = cdm::kSessionError; |
860 if (cdm_) { | 856 if (cdm_) { |
861 cdm::VideoDecoderConfig cdm_decoder_config; | 857 cdm::VideoDecoderConfig cdm_decoder_config; |
862 cdm_decoder_config.codec = | 858 cdm_decoder_config.codec = |
863 PpVideoCodecToCdmVideoCodec(decoder_config.codec); | 859 PpVideoCodecToCdmVideoCodec(decoder_config.codec); |
864 cdm_decoder_config.profile = | 860 cdm_decoder_config.profile = |
865 PpVCProfileToCdmVCProfile(decoder_config.profile); | 861 PpVCProfileToCdmVCProfile(decoder_config.profile); |
866 cdm_decoder_config.format = | 862 cdm_decoder_config.format = |
867 PpDecryptedFrameFormatToCdmVideoFormat(decoder_config.format); | 863 PpDecryptedFrameFormatToCdmVideoFormat(decoder_config.format); |
868 cdm_decoder_config.coded_size.width = decoder_config.width; | 864 cdm_decoder_config.coded_size.width = decoder_config.width; |
869 cdm_decoder_config.coded_size.height = decoder_config.height; | 865 cdm_decoder_config.coded_size.height = decoder_config.height; |
870 cdm_decoder_config.extra_data = | 866 cdm_decoder_config.extra_data = |
871 static_cast<uint8_t*>(extra_data_buffer.data()); | 867 static_cast<uint8_t*>(extra_data_buffer.data()); |
872 cdm_decoder_config.extra_data_size = | 868 cdm_decoder_config.extra_data_size = extra_data_buffer.size(); |
873 static_cast<int32_t>(extra_data_buffer.size()); | |
874 status = cdm_->InitializeVideoDecoder(cdm_decoder_config); | 869 status = cdm_->InitializeVideoDecoder(cdm_decoder_config); |
875 } | 870 } |
876 | 871 |
877 CallOnMain(callback_factory_.NewCallback( | 872 CallOnMain(callback_factory_.NewCallback( |
878 &CdmWrapper::DecoderInitializeDone, | 873 &CdmWrapper::DecoderInitializeDone, |
879 PP_DECRYPTORSTREAMTYPE_VIDEO, | 874 PP_DECRYPTORSTREAMTYPE_VIDEO, |
880 decoder_config.request_id, | 875 decoder_config.request_id, |
881 status == cdm::kSuccess)); | 876 status == cdm::kSuccess)); |
882 } | 877 } |
883 | 878 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 encrypted_block_info.tracking_info)); | 947 encrypted_block_info.tracking_info)); |
953 return; | 948 return; |
954 } | 949 } |
955 | 950 |
956 default: | 951 default: |
957 PP_NOTREACHED(); | 952 PP_NOTREACHED(); |
958 return; | 953 return; |
959 } | 954 } |
960 } | 955 } |
961 | 956 |
962 cdm::Buffer* CdmWrapper::Allocate(int32_t capacity) { | 957 cdm::Buffer* CdmWrapper::Allocate(uint32_t capacity) { |
963 return allocator_.Allocate(capacity); | 958 return allocator_.Allocate(capacity); |
964 } | 959 } |
965 | 960 |
966 void CdmWrapper::SetTimer(int64_t delay_ms, void* context) { | 961 void CdmWrapper::SetTimer(int64_t delay_ms, void* context) { |
967 // NOTE: doesn't really need to run on the main thread; could just as well run | 962 // NOTE: doesn't really need to run on the main thread; could just as well run |
968 // on a helper thread if |cdm_| were thread-friendly and care was taken. We | 963 // on a helper thread if |cdm_| were thread-friendly and care was taken. We |
969 // only use CallOnMainThread() here to get delayed-execution behavior. | 964 // only use CallOnMainThread() here to get delayed-execution behavior. |
970 pp::Module::Get()->core()->CallOnMainThread( | 965 pp::Module::Get()->core()->CallOnMainThread( |
971 delay_ms, | 966 delay_ms, |
972 callback_factory_.NewCallback(&CdmWrapper::TimerExpired, context), | 967 callback_factory_.NewCallback(&CdmWrapper::TimerExpired, context), |
973 PP_OK); | 968 PP_OK); |
974 } | 969 } |
975 | 970 |
976 void CdmWrapper::TimerExpired(int32_t result, void* context) { | 971 void CdmWrapper::TimerExpired(int32_t result, void* context) { |
977 PP_DCHECK(result == PP_OK); | 972 PP_DCHECK(result == PP_OK); |
978 cdm_->TimerExpired(context); | 973 cdm_->TimerExpired(context); |
979 } | 974 } |
980 | 975 |
981 double CdmWrapper::GetCurrentWallTimeInSeconds() { | 976 double CdmWrapper::GetCurrentWallTimeInSeconds() { |
982 return pp::Module::Get()->core()->GetTime(); | 977 return pp::Module::Get()->core()->GetTime(); |
983 } | 978 } |
984 | 979 |
985 void CdmWrapper::SendKeyMessage( | 980 void CdmWrapper::SendKeyMessage( |
986 const char* session_id, int32_t session_id_length, | 981 const char* session_id, uint32_t session_id_length, |
987 const char* message, int32_t message_length, | 982 const char* message, uint32_t message_length, |
988 const char* default_url, int32_t default_url_length) { | 983 const char* default_url, uint32_t default_url_length) { |
989 PP_DCHECK(!key_system_.empty()); | 984 PP_DCHECK(!key_system_.empty()); |
990 PostOnMain(callback_factory_.NewCallback( | 985 PostOnMain(callback_factory_.NewCallback( |
991 &CdmWrapper::KeyMessage, | 986 &CdmWrapper::KeyMessage, |
992 SessionInfo(key_system_, | 987 SessionInfo(key_system_, |
993 std::string(session_id, session_id_length)), | 988 std::string(session_id, session_id_length)), |
994 std::vector<uint8>(message, message + message_length), | 989 std::vector<uint8>(message, message + message_length), |
995 std::string(default_url, default_url_length))); | 990 std::string(default_url, default_url_length))); |
996 } | 991 } |
997 | 992 |
998 void CdmWrapper::SendKeyError(const char* session_id, | 993 void CdmWrapper::SendKeyError(const char* session_id, |
999 int32_t session_id_length, | 994 uint32_t session_id_length, |
1000 cdm::MediaKeyError error_code, | 995 cdm::MediaKeyError error_code, |
1001 uint32_t system_code) { | 996 uint32_t system_code) { |
1002 SendKeyErrorInternal(key_system_, | 997 SendKeyErrorInternal(key_system_, |
1003 std::string(session_id, session_id_length), | 998 std::string(session_id, session_id_length), |
1004 error_code, | 999 error_code, |
1005 system_code); | 1000 system_code); |
1006 } | 1001 } |
1007 | 1002 |
1008 void CdmWrapper::GetPrivateData(int32_t* instance, | 1003 void CdmWrapper::GetPrivateData(int32_t* instance, |
1009 GetPrivateInterface* get_interface) { | 1004 GetPrivateInterface* get_interface) { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 bool CdmWrapper::IsValidVideoFrame(const LinkedVideoFrame& video_frame) { | 1199 bool CdmWrapper::IsValidVideoFrame(const LinkedVideoFrame& video_frame) { |
1205 if (!video_frame.get() || | 1200 if (!video_frame.get() || |
1206 !video_frame->FrameBuffer() || | 1201 !video_frame->FrameBuffer() || |
1207 (video_frame->Format() != cdm::kI420 && | 1202 (video_frame->Format() != cdm::kI420 && |
1208 video_frame->Format() != cdm::kYv12)) { | 1203 video_frame->Format() != cdm::kYv12)) { |
1209 return false; | 1204 return false; |
1210 } | 1205 } |
1211 | 1206 |
1212 PpbBuffer* ppb_buffer = static_cast<PpbBuffer*>(video_frame->FrameBuffer()); | 1207 PpbBuffer* ppb_buffer = static_cast<PpbBuffer*>(video_frame->FrameBuffer()); |
1213 | 1208 |
1214 for (int i = 0; i < cdm::VideoFrame::kMaxPlanes; ++i) { | 1209 for (uint32_t i = 0; i < cdm::VideoFrame::kMaxPlanes; ++i) { |
1215 int plane_height = (i == cdm::VideoFrame::kYPlane) ? | 1210 int plane_height = (i == cdm::VideoFrame::kYPlane) ? |
1216 video_frame->Size().height : (video_frame->Size().height + 1) / 2; | 1211 video_frame->Size().height : (video_frame->Size().height + 1) / 2; |
1217 cdm::VideoFrame::VideoPlane plane = | 1212 cdm::VideoFrame::VideoPlane plane = |
1218 static_cast<cdm::VideoFrame::VideoPlane>(i); | 1213 static_cast<cdm::VideoFrame::VideoPlane>(i); |
1219 if (ppb_buffer->Size() < video_frame->PlaneOffset(plane) + | 1214 if (ppb_buffer->Size() < video_frame->PlaneOffset(plane) + |
1220 plane_height * video_frame->Stride(plane)) { | 1215 plane_height * video_frame->Stride(plane)) { |
1221 return false; | 1216 return false; |
1222 } | 1217 } |
1223 } | 1218 } |
1224 | 1219 |
1225 return true; | 1220 return true; |
1226 } | 1221 } |
1227 | 1222 |
1228 bool CdmWrapper::CanChallengePlatform() { | 1223 bool CdmWrapper::CanChallengePlatform() { |
1229 #if defined(OS_CHROMEOS) | 1224 #if defined(OS_CHROMEOS) |
1230 return can_challenge_platform_; | 1225 return can_challenge_platform_; |
1231 #else | 1226 #else |
1232 return false; | 1227 return false; |
1233 #endif | 1228 #endif |
1234 } | 1229 } |
1235 | 1230 |
1236 void CdmWrapper::SendPlatformChallenge( | 1231 void CdmWrapper::SendPlatformChallenge( |
1237 const char* service_id, int32_t service_id_length, | 1232 const char* service_id, uint32_t service_id_length, |
1238 const char* challenge, int32_t challenge_length) { | 1233 const char* challenge, uint32_t challenge_length) { |
1239 #if defined(OS_CHROMEOS) | 1234 #if defined(OS_CHROMEOS) |
1240 PP_DCHECK(!challenge_in_progress_); | 1235 PP_DCHECK(!challenge_in_progress_); |
1241 | 1236 |
1242 // Ensure member variables set by the callback are in a clean state. | 1237 // Ensure member variables set by the callback are in a clean state. |
1243 signed_data_output_ = pp::Var(); | 1238 signed_data_output_ = pp::Var(); |
1244 signed_data_signature_output_ = pp::Var(); | 1239 signed_data_signature_output_ = pp::Var(); |
1245 platform_key_certificate_output_ = pp::Var(); | 1240 platform_key_certificate_output_ = pp::Var(); |
1246 | 1241 |
1247 pp::VarArrayBuffer challenge_var(challenge_length); | 1242 pp::VarArrayBuffer challenge_var(challenge_length); |
1248 uint8_t* var_data = static_cast<uint8_t*>(challenge_var.Map()); | 1243 uint8_t* var_data = static_cast<uint8_t*>(challenge_var.Map()); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 return; | 1311 return; |
1317 } | 1312 } |
1318 | 1313 |
1319 pp::VarArrayBuffer signed_data_var(signed_data_output_); | 1314 pp::VarArrayBuffer signed_data_var(signed_data_output_); |
1320 pp::VarArrayBuffer signed_data_signature_var(signed_data_signature_output_); | 1315 pp::VarArrayBuffer signed_data_signature_var(signed_data_signature_output_); |
1321 std::string platform_key_certificate_string = | 1316 std::string platform_key_certificate_string = |
1322 platform_key_certificate_output_.AsString(); | 1317 platform_key_certificate_output_.AsString(); |
1323 | 1318 |
1324 cdm::PlatformChallengeResponse response = { | 1319 cdm::PlatformChallengeResponse response = { |
1325 static_cast<uint8_t*>(signed_data_var.Map()), | 1320 static_cast<uint8_t*>(signed_data_var.Map()), |
1326 static_cast<int32_t>(signed_data_var.ByteLength()), | 1321 signed_data_var.ByteLength(), |
1327 | 1322 |
1328 static_cast<uint8_t*>(signed_data_signature_var.Map()), | 1323 static_cast<uint8_t*>(signed_data_signature_var.Map()), |
1329 static_cast<int32_t>(signed_data_signature_var.ByteLength()), | 1324 signed_data_signature_var.ByteLength(), |
1330 | 1325 |
1331 reinterpret_cast<const uint8_t*>(platform_key_certificate_string.c_str()), | 1326 reinterpret_cast<const uint8_t*>(platform_key_certificate_string.c_str()), |
1332 static_cast<int32_t>(platform_key_certificate_string.length()) | 1327 static_cast<uint32_t>(platform_key_certificate_string.length()) |
1333 }; | 1328 }; |
1334 cdm_->OnPlatformChallengeResponse(response); | 1329 cdm_->OnPlatformChallengeResponse(response); |
1335 | 1330 |
1336 signed_data_var.Unmap(); | 1331 signed_data_var.Unmap(); |
1337 signed_data_signature_var.Unmap(); | 1332 signed_data_signature_var.Unmap(); |
1338 } | 1333 } |
1339 | 1334 |
1340 void CdmWrapper::EnableProtectionDone(int32_t result) { | 1335 void CdmWrapper::EnableProtectionDone(int32_t result) { |
1341 // Does nothing since clients must call QueryOutputProtectionStatus() to | 1336 // Does nothing since clients must call QueryOutputProtectionStatus() to |
1342 // inspect the protection status on a regular basis. | 1337 // inspect the protection status on a regular basis. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 } // namespace media | 1388 } // namespace media |
1394 | 1389 |
1395 namespace pp { | 1390 namespace pp { |
1396 | 1391 |
1397 // Factory function for your specialization of the Module object. | 1392 // Factory function for your specialization of the Module object. |
1398 Module* CreateModule() { | 1393 Module* CreateModule() { |
1399 return new media::CdmWrapperModule(); | 1394 return new media::CdmWrapperModule(); |
1400 } | 1395 } |
1401 | 1396 |
1402 } // namespace pp | 1397 } // namespace pp |
OLD | NEW |