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

Side by Side Diff: Source/modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.cpp

Issue 1188203002: Implementation of setSinkId() for HTMLMediaElement. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix missing #include and broken previous upload Created 5 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "config.h" 5 #include "config.h"
6 #include "modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.h" 6 #include "modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.h"
7 7
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "bindings/core/v8/ScriptState.h" 9 #include "bindings/core/v8/ScriptState.h"
10 #include "core/dom/ExecutionContext.h" 10 #include "core/dom/ExecutionContext.h"
11 #include "modules/audio_output_devices/SetSinkIdCallbacks.h"
11 #include "platform/Logging.h" 12 #include "platform/Logging.h"
12 13
13 namespace blink { 14 namespace blink {
14 15
15 HTMLMediaElementAudioOutputDevice::HTMLMediaElementAudioOutputDevice() 16 HTMLMediaElementAudioOutputDevice::HTMLMediaElementAudioOutputDevice()
16 : m_sinkId("") 17 : m_sinkId("")
17 { 18 {
18 } 19 }
19 20
20 String HTMLMediaElementAudioOutputDevice::sinkId(HTMLMediaElement& element) 21 String HTMLMediaElementAudioOutputDevice::sinkId(HTMLMediaElement& element)
21 { 22 {
22 WTF_LOG(Media, __FUNCTION__); 23 WTF_LOG(Media, __FUNCTION__);
23 HTMLMediaElementAudioOutputDevice& aodElement = HTMLMediaElementAudioOutputD evice::from(element); 24 HTMLMediaElementAudioOutputDevice& aodElement = HTMLMediaElementAudioOutputD evice::from(element);
24 return aodElement.m_sinkId; 25 return aodElement.m_sinkId;
25 } 26 }
26 27
27 ScriptPromise HTMLMediaElementAudioOutputDevice::setSinkId(ScriptState* scriptSt ate, HTMLMediaElement& element, const String& newSinkId) 28 ScriptPromise HTMLMediaElementAudioOutputDevice::setSinkId(ScriptState* scriptSt ate, HTMLMediaElement& element, const String& sinkId)
28 { 29 {
29 WTF_LOG(Media, __FUNCTION__); 30 WTF_LOG(Media, __FUNCTION__);
30 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError, "Operation not supported")); 31 WebMediaPlayer* webMediaPlayer = element.webMediaPlayer();
32 if (!webMediaPlayer)
33 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "No media player available"));
34
35 // According to spec, "id-multimedia" is equivalent to ""
36 String newSinkId = (sinkId == "id-multimedia") ? "" : sinkId;
Mike West 2015/06/17 11:44:37 The spec isn't terribly clear here. https://w3c.gi
Guido Urdaneta 2015/06/17 12:25:15 You are right. I just removed support for id-multi
37 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
38 ScriptPromise promise = resolver->promise();
Mike West 2015/06/17 11:44:37 Nit: Could you just return `resolver->promise()` r
Guido Urdaneta 2015/06/17 12:25:15 Done.
39 HTMLMediaElementAudioOutputDevice& aodElement = HTMLMediaElementAudioOutputD evice::from(element);
40 if (newSinkId == aodElement.m_sinkId)
41 resolver->resolve();
42 else
43 webMediaPlayer->setSinkId(newSinkId, new SetSinkIdCallbacks(resolver, el ement, newSinkId));
44
45 return promise;
31 } 46 }
32 47
33 const char* HTMLMediaElementAudioOutputDevice::supplementName() 48 const char* HTMLMediaElementAudioOutputDevice::supplementName()
34 { 49 {
35 return "HTMLMediaElementAudioOutputDevice"; 50 return "HTMLMediaElementAudioOutputDevice";
36 } 51 }
37 52
38 HTMLMediaElementAudioOutputDevice& HTMLMediaElementAudioOutputDevice::from(HTMLM ediaElement& element) 53 HTMLMediaElementAudioOutputDevice& HTMLMediaElementAudioOutputDevice::from(HTMLM ediaElement& element)
39 { 54 {
40 HTMLMediaElementAudioOutputDevice* supplement = static_cast<HTMLMediaElement AudioOutputDevice*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supple mentName())); 55 HTMLMediaElementAudioOutputDevice* supplement = static_cast<HTMLMediaElement AudioOutputDevice*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supple mentName()));
41 if (!supplement) { 56 if (!supplement) {
42 supplement = new HTMLMediaElementAudioOutputDevice(); 57 supplement = new HTMLMediaElementAudioOutputDevice();
43 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement)); 58 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement));
44 } 59 }
45 return *supplement; 60 return *supplement;
46 } 61 }
47 62
48 DEFINE_TRACE(HTMLMediaElementAudioOutputDevice) 63 DEFINE_TRACE(HTMLMediaElementAudioOutputDevice)
49 { 64 {
50 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); 65 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor);
51 } 66 }
52 67
53 } // namespace blink 68 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698