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

Side by Side Diff: webkit/media/crypto/ppapi/clear_key_cdm.cc

Issue 11304010: Fix type punning error in (de)serializing audio frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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
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 #include "webkit/media/crypto/ppapi/clear_key_cdm.h" 5 #include "webkit/media/crypto/ppapi/clear_key_cdm.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 int64 duration_in_microseconds = last_duration_.InMicroseconds(); 485 int64 duration_in_microseconds = last_duration_.InMicroseconds();
486 DCHECK_GT(duration_in_microseconds, 0); 486 DCHECK_GT(duration_in_microseconds, 0);
487 487
488 int64 timestamp = last_timestamp_.InMicroseconds(); 488 int64 timestamp = last_timestamp_.InMicroseconds();
489 int64 bytes_per_sample = channel_count_ * bits_per_channel_ / 8; 489 int64 bytes_per_sample = channel_count_ * bits_per_channel_ / 8;
490 int64 frame_size = bytes_per_sample * samples_per_second_ * 490 int64 frame_size = bytes_per_sample * samples_per_second_ *
491 duration_in_microseconds / base::Time::kMicrosecondsPerSecond; 491 duration_in_microseconds / base::Time::kMicrosecondsPerSecond;
492 492
493 const int kHeaderSize = sizeof(timestamp) + sizeof(frame_size); 493 const int kHeaderSize = sizeof(timestamp) + sizeof(frame_size);
494 audio_frames->set_buffer(allocator_->Allocate(kHeaderSize + frame_size)); 494 audio_frames->set_buffer(allocator_->Allocate(kHeaderSize + frame_size));
495 int64* data = reinterpret_cast<int64*>(audio_frames->buffer()->data()); 495 uint8_t* data = audio_frames->buffer()->data();
496 *(data++) = timestamp; 496
497 *(data++) = frame_size; 497 memcpy(data, &timestamp, sizeof(timestamp));
498 data += sizeof(timestamp);
499 memcpy(data, &frame_size, sizeof(frame_size));
500 data += sizeof(frame_size);
498 // You won't hear anything because we have all zeros here. But the video 501 // You won't hear anything because we have all zeros here. But the video
499 // should play just fine! 502 // should play just fine!
500 memset(data, 0, frame_size); 503 memset(data, 0, frame_size);
501 } 504 }
502 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER 505 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER
503 506
504 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) 507 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER)
505 void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp, 508 void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp,
506 cdm::VideoFrame* video_frame) { 509 cdm::VideoFrame* video_frame) {
507 // Choose non-zero alignment and padding on purpose for testing. 510 // Choose non-zero alignment and padding on purpose for testing.
(...skipping 29 matching lines...) Expand all
537 540
538 static unsigned char color = 0; 541 static unsigned char color = 0;
539 color += 10; 542 color += 10;
540 543
541 memset(reinterpret_cast<void*>(video_frame->frame_buffer()->data()), 544 memset(reinterpret_cast<void*>(video_frame->frame_buffer()->data()),
542 color, frame_size); 545 color, frame_size);
543 } 546 }
544 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER 547 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER
545 548
546 } // namespace webkit_media 549 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698