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

Side by Side Diff: webkit/media/webmediaplayer_impl.cc

Issue 10020053: Initial implementation of Encrypted Media Extensions in Chrome. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 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
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/webmediaplayer_impl.h" 5 #include "webkit/media/webmediaplayer_impl.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/message_loop_proxy.h" 13 #include "base/message_loop_proxy.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/string_number_conversions.h"
15 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
16 #include "media/audio/null_audio_sink.h" 17 #include "media/audio/null_audio_sink.h"
17 #include "media/base/filter_collection.h" 18 #include "media/base/filter_collection.h"
18 #include "media/base/limits.h" 19 #include "media/base/limits.h"
19 #include "media/base/media_log.h" 20 #include "media/base/media_log.h"
20 #include "media/base/media_switches.h" 21 #include "media/base/media_switches.h"
21 #include "media/base/pipeline.h" 22 #include "media/base/pipeline.h"
22 #include "media/base/video_frame.h" 23 #include "media/base/video_frame.h"
23 #include "media/filters/audio_renderer_impl.h" 24 #include "media/filters/audio_renderer_impl.h"
24 #include "media/filters/video_renderer_base.h" 25 #include "media/filters/video_renderer_base.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
30 #include "v8/include/v8.h" 32 #include "v8/include/v8.h"
31 #include "webkit/media/buffered_data_source.h" 33 #include "webkit/media/buffered_data_source.h"
32 #include "webkit/media/filter_helpers.h" 34 #include "webkit/media/filter_helpers.h"
35 #include "webkit/media/supported_key_systems.h"
33 #include "webkit/media/webmediaplayer_delegate.h" 36 #include "webkit/media/webmediaplayer_delegate.h"
34 #include "webkit/media/webmediaplayer_proxy.h" 37 #include "webkit/media/webmediaplayer_proxy.h"
35 #include "webkit/media/webvideoframe_impl.h" 38 #include "webkit/media/webvideoframe_impl.h"
36 39
37 using WebKit::WebCanvas; 40 using WebKit::WebCanvas;
38 using WebKit::WebRect; 41 using WebKit::WebRect;
39 using WebKit::WebSize; 42 using WebKit::WebSize;
40 using media::NetworkEvent; 43 using media::NetworkEvent;
41 using media::PipelineStatus; 44 using media::PipelineStatus;
42 45
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 case WebKit::WebMediaPlayer::EosDecodeError: 664 case WebKit::WebMediaPlayer::EosDecodeError:
662 pipeline_status = media::PIPELINE_ERROR_DECODE; 665 pipeline_status = media::PIPELINE_ERROR_DECODE;
663 break; 666 break;
664 default: 667 default:
665 NOTIMPLEMENTED(); 668 NOTIMPLEMENTED();
666 } 669 }
667 670
668 proxy_->DemuxerEndOfStream(pipeline_status); 671 proxy_->DemuxerEndOfStream(pipeline_status);
669 } 672 }
670 673
674 WebKit::WebMediaPlayer::MediaKeyException
675 WebMediaPlayerImpl::generateKeyRequest(const WebKit::WebString& keySystem,
scherkus (not reviewing) 2012/04/12 20:18:41 chromium style unix_hacker here + below
ddorwin 2012/04/12 23:41:23 Done.
676 const unsigned char* initData,
677 unsigned initDataLength) {
678 if (!SupportedKeySystems::isKeySystemSupported(keySystem))
679 return WebKit::WebMediaPlayer::KeySystemNotSupported;
680
681 // Every request call creates a unique ID.
scherkus (not reviewing) 2012/04/12 20:18:41 how unique is unique supposed to be? unique per p
ddorwin 2012/04/12 23:41:23 Whatever is necessary for the CDM to "associate ca
682 // Increment the ID here to avoid race conditions in task threads.
scherkus (not reviewing) 2012/04/12 20:18:41 which race conditions are you referring to? if it
ddorwin 2012/04/12 23:41:23 For now (see above), per-page uniqueness is fine.
683 static uint32_t nextAvailableSessionId = 1;
scherkus (not reviewing) 2012/04/12 20:18:41 unix_hacker style
ddorwin 2012/04/12 23:41:23 Done.
684 uint32_t sessionId = nextAvailableSessionId++;
685
686 MessageLoop::current()->PostTask(
scherkus (not reviewing) 2012/04/12 20:18:41 nit: our preferred style for PostTask is: PostTas
ddorwin 2012/04/12 23:41:23 Done.
687 FROM_HERE,
688 base::Bind(&WebMediaPlayerImpl::generateKeyRequestTask,
689 AsWeakPtr(),
690 keySystem,
691 initData,
692 initDataLength,
693 sessionId));
694
695 return WebKit::WebMediaPlayer::NoError;
696 }
697
698 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey(
699 const WebKit::WebString& keySystem,
700 const unsigned char* key,
701 unsigned keyLength,
702 const unsigned char* initData,
703 unsigned initDataLength,
704 const WebKit::WebString& sessionId) {
705 if (!SupportedKeySystems::isKeySystemSupported(keySystem))
706 return WebKit::WebMediaPlayer::KeySystemNotSupported;
707
708 MessageLoop::current()->PostTask(
709 FROM_HERE,
710 base::Bind(&WebMediaPlayerImpl::addKeyTask,
711 AsWeakPtr(),
712 keySystem,
713 key,
714 keyLength,
715 initData,
716 initDataLength,
717 sessionId));
718
719 return WebKit::WebMediaPlayer::NoError;
720 }
721
722 WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest(
723 const WebKit::WebString& keySystem,
724 const WebKit::WebString& sessionId) {
725 if (!SupportedKeySystems::isKeySystemSupported(keySystem))
726 return WebKit::WebMediaPlayer::KeySystemNotSupported;
727
728 MessageLoop::current()->PostTask(
729 FROM_HERE,
730 base::Bind(&WebMediaPlayerImpl::cancelKeyRequestTask,
731 AsWeakPtr(),
732 keySystem,
733 sessionId));
734
735 return WebKit::WebMediaPlayer::NoError;
736 }
737
671 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { 738 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() {
672 Destroy(); 739 Destroy();
673 main_loop_ = NULL; 740 main_loop_ = NULL;
674 } 741 }
675 742
676 void WebMediaPlayerImpl::Repaint() { 743 void WebMediaPlayerImpl::Repaint() {
677 DCHECK_EQ(main_loop_, MessageLoop::current()); 744 DCHECK_EQ(main_loop_, MessageLoop::current());
678 GetClient()->repaint(); 745 GetClient()->repaint();
679 } 746 }
680 747
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 WebKit::WebAudioSourceProvider* WebMediaPlayerImpl::audioSourceProvider() { 980 WebKit::WebAudioSourceProvider* WebMediaPlayerImpl::audioSourceProvider() {
914 return audio_source_provider_; 981 return audio_source_provider_;
915 } 982 }
916 983
917 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { 984 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() {
918 DCHECK_EQ(main_loop_, MessageLoop::current()); 985 DCHECK_EQ(main_loop_, MessageLoop::current());
919 incremented_externally_allocated_memory_ = true; 986 incremented_externally_allocated_memory_ = true;
920 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); 987 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory);
921 } 988 }
922 989
990 void WebMediaPlayerImpl::generateKeyRequestTask(
scherkus (not reviewing) 2012/04/12 20:18:41 you don't need any of these methods considering t
ddorwin 2012/04/12 23:41:23 I kept the first two functions but removed the thi
991 const WebKit::WebString& keySystem,
992 const unsigned char* initData,
993 unsigned initDataLength,
994 uint32_t sessionId) {
995 WebKit::WebString sessionIdSring(base::UintToString16(sessionId));
scherkus (not reviewing) 2012/04/12 20:18:41 Sring -> String?
ddorwin 2012/04/12 23:41:23 Done.
996
997 DVLOG(1) << "generateKeyRequest: " << keySystem.utf8().data() << ": "
998 << std::string(reinterpret_cast<const char*>(initData),
999 static_cast<size_t>(initDataLength)).c_str() << ": "
1000 << sessionIdSring.utf8().data();
1001
1002 // TODO(ddorwin): Generate a key request in the decrypter and fire
1003 // keyMessage when it completes.
1004 // For now, just fire the event with the initData as the request.
1005 const unsigned char* message = initData;
1006 unsigned messageLength = initDataLength;
1007
1008 GetClient()->keyMessage(keySystem, sessionIdSring, message, messageLength);
1009 }
1010
1011 void WebMediaPlayerImpl::addKeyTask(
1012 const WebKit::WebString& keySystem,
1013 const unsigned char* key,
1014 unsigned keyLength,
1015 const unsigned char* initData,
1016 unsigned initDataLength,
1017 const WebKit::WebString& sessionId) {
1018 DVLOG(1) << "addKey: " << keySystem.utf8().data() << ": "
1019 << std::string(reinterpret_cast<const char*>(key),
1020 static_cast<size_t>(keyLength)).c_str() << ": "
scherkus (not reviewing) 2012/04/12 20:18:41 why c_str()?
ddorwin 2012/04/12 23:41:23 Done.
1021 << std::string(reinterpret_cast<const char*>(initData),
1022 static_cast<size_t>(initDataLength)).c_str()
1023 << "[" << sessionId.utf8().data() << "]";
1024
1025 // TODO(ddorwin): Add the key to the decrypter and fire keyAdded when it
1026 // completes. Check the key length there.
1027 // Temporarily, fire an error for invalid key length so we can test the error
1028 // event and fire the keyAdded event in all other cases.
1029 const int kSupportedKeyLengthBits = 128;
1030 const int kBitsPerByte = 8;
1031 const unsigned int kSupportedKeyLengthBytes =
1032 kSupportedKeyLengthBits / kBitsPerByte;
1033 if (keyLength != kSupportedKeyLengthBytes) {
scherkus (not reviewing) 2012/04/12 20:18:41 these constants seemed overly verbose for temporar
ddorwin 2012/04/12 23:41:23 Done.
1034 DLOG(ERROR) << "invalid key length: " << keyLength;
1035 GetClient()->keyError(keySystem, sessionId,
1036 WebKit::WebMediaPlayerClient::UnknownError, 0);
1037 return;
1038 }
1039
1040 GetClient()->keyAdded(keySystem, sessionId);
1041 }
1042
1043 void WebMediaPlayerImpl::cancelKeyRequestTask(
scherkus (not reviewing) 2012/04/12 20:18:41 remove -- add this method when we have an impl
ddorwin 2012/04/12 23:41:23 Done.
1044 const WebKit::WebString& keySystem,
1045 const WebKit::WebString& sessionId) {
1046 DVLOG(1) << "cancelKeyRequest: " << keySystem.utf8().data() << ": "
1047 << "[" << sessionId.utf8().data() << "]";
1048 // TODO(ddorwin): Cancel the key request in the decrypter.
1049 }
1050
923 } // namespace webkit_media 1051 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698