Skip to content

Commit

Permalink
MediaStream API: Patch #1 of implementing navigator.getMediaDevices
Browse files Browse the repository at this point in the history
The deprecated MediaStreamTrack.getSources()  will be removed later.
This patch contains almost everything except .idl files which means that this is "dead" code which will not affect anything.
Patch 2 will introduce mock support for getMediaDevices.
And finally the third patch will add tests and idl files.

BUG=338511

Review URL: https://codereview.chromium.org/135363004

git-svn-id: svn://svn.chromium.org/blink/trunk@166370 bbb929c8-8fbe-4397-9dbb-9b2b20218538
  • Loading branch information
[email protected] committed Feb 4, 2014
1 parent 3f17e66 commit f3dea58
Show file tree
Hide file tree
Showing 19 changed files with 748 additions and 3 deletions.
74 changes: 74 additions & 0 deletions Source/modules/mediastream/MediaDeviceInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2014 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "modules/mediastream/MediaDeviceInfo.h"

#include "wtf/text/WTFString.h"

namespace WebCore {

PassRefPtr<MediaDeviceInfo> MediaDeviceInfo::create(const blink::WebMediaDeviceInfo& webMediaDeviceInfo)
{
ASSERT(!webMediaDeviceInfo.isNull());
return adoptRef(new MediaDeviceInfo(webMediaDeviceInfo));
}

MediaDeviceInfo::MediaDeviceInfo(const blink::WebMediaDeviceInfo& webMediaDeviceInfo)
: m_webMediaDeviceInfo(webMediaDeviceInfo)
{
}

String MediaDeviceInfo::deviceId() const
{
return m_webMediaDeviceInfo.deviceId();
}

String MediaDeviceInfo::kind() const
{
switch (m_webMediaDeviceInfo.kind()) {
case blink::WebMediaDeviceInfo::MediaDeviceKindAudioInput:
return "audioinput";
case blink::WebMediaDeviceInfo::MediaDeviceKindAudioOutput:
return "audiooutput";
case blink::WebMediaDeviceInfo::MediaDeviceKindVideoInput:
return "videoinput";
}

ASSERT_NOT_REACHED();
return String();
}

String MediaDeviceInfo::label() const
{
return m_webMediaDeviceInfo.label();
}

String MediaDeviceInfo::groupId() const
{
return m_webMediaDeviceInfo.groupId();
}

} // namespace WebCore
55 changes: 55 additions & 0 deletions Source/modules/mediastream/MediaDeviceInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2014 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef MediaDeviceInfo_h
#define MediaDeviceInfo_h

#include "public/platform/WebMediaDeviceInfo.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/Vector.h"

namespace WebCore {

class MediaDeviceInfo : public RefCounted<MediaDeviceInfo> {
public:
static PassRefPtr<MediaDeviceInfo> create(const blink::WebMediaDeviceInfo&);

String deviceId() const;
String kind() const;
String label() const;
String groupId() const;

private:
explicit MediaDeviceInfo(const blink::WebMediaDeviceInfo&);

blink::WebMediaDeviceInfo m_webMediaDeviceInfo;
};

typedef Vector<RefPtr<MediaDeviceInfo> > MediaDeviceInfoVector;

} // namespace WebCore

#endif // MediaDeviceInfo_h
41 changes: 41 additions & 0 deletions Source/modules/mediastream/MediaDeviceInfoCallback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2014 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef MediaDeviceInfoCallback_h
#define MediaDeviceInfoCallback_h

#include "modules/mediastream/MediaDeviceInfo.h"

namespace WebCore {

class MediaDeviceInfoCallback {
public:
virtual ~MediaDeviceInfoCallback() { }
virtual void handleEvent(const MediaDeviceInfoVector&) = 0;
};

} // namespace WebCore

#endif // MediaDeviceInfoCallback_h
83 changes: 83 additions & 0 deletions Source/modules/mediastream/MediaDevicesRequest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (C) 2014 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"

#include "modules/mediastream/MediaDevicesRequest.h"

#include "bindings/v8/ExceptionState.h"
#include "core/dom/Document.h"
#include "modules/mediastream/UserMediaController.h"

namespace WebCore {

PassRefPtr<MediaDevicesRequest> MediaDevicesRequest::create(ExecutionContext* context, UserMediaController* controller, PassOwnPtr<MediaDeviceInfoCallback> callback, ExceptionState& exceptionState)
{
RefPtr<MediaDevicesRequest> request = adoptRef(new MediaDevicesRequest(context, controller, callback));
request->suspendIfNeeded();
return request.release();
}

MediaDevicesRequest::MediaDevicesRequest(ExecutionContext* context, UserMediaController* controller, PassOwnPtr<MediaDeviceInfoCallback> callback)
: ActiveDOMObject(context)
, m_controller(controller)
, m_callback(callback)
{
}

MediaDevicesRequest::~MediaDevicesRequest()
{
}

Document* MediaDevicesRequest::ownerDocument()
{
if (ExecutionContext* context = executionContext()) {
return toDocument(context);
}

return 0;
}

void MediaDevicesRequest::start()
{
if (m_controller)
m_controller->requestMediaDevices(this);
}

void MediaDevicesRequest::succeed(const MediaDeviceInfoVector& mediaDevices)
{
if (!executionContext() || !m_callback)
return;

m_callback->handleEvent(mediaDevices);
}

void MediaDevicesRequest::stop()
{
m_callback.clear();
m_controller = 0;
}

} // namespace WebCore
68 changes: 68 additions & 0 deletions Source/modules/mediastream/MediaDevicesRequest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2014 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef MediaDevicesRequest_h
#define MediaDevicesRequest_h

#include "core/dom/ActiveDOMObject.h"
#include "modules/mediastream/MediaDeviceInfo.h"
#include "modules/mediastream/MediaDeviceInfoCallback.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"

namespace WebCore {

class Document;
class ExceptionState;
class MediaStreamDescriptor;
class UserMediaController;

class MediaDevicesRequest FINAL : public RefCounted<MediaDevicesRequest>, public ActiveDOMObject {
public:
static PassRefPtr<MediaDevicesRequest> create(ExecutionContext*, UserMediaController*, PassOwnPtr<MediaDeviceInfoCallback>, ExceptionState&);
virtual ~MediaDevicesRequest();

MediaDeviceInfoCallback* callback() const { return m_callback.get(); }
Document* ownerDocument();

void start();

void succeed(const MediaDeviceInfoVector&);

// ActiveDOMObject
virtual void stop() OVERRIDE;

private:
MediaDevicesRequest(ExecutionContext*, UserMediaController*, PassOwnPtr<MediaDeviceInfoCallback>);

UserMediaController* m_controller;

OwnPtr<MediaDeviceInfoCallback> m_callback;
};

} // namespace WebCore

#endif // MediaDevicesRequest_h
19 changes: 19 additions & 0 deletions Source/modules/mediastream/NavigatorMediaStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "core/frame/Frame.h"
#include "core/frame/Navigator.h"
#include "core/page/Page.h"
#include "modules/mediastream/MediaDeviceInfoCallback.h"
#include "modules/mediastream/MediaDevicesRequest.h"
#include "modules/mediastream/NavigatorUserMediaErrorCallback.h"
#include "modules/mediastream/NavigatorUserMediaSuccessCallback.h"
#include "modules/mediastream/UserMediaController.h"
Expand Down Expand Up @@ -65,4 +67,21 @@ void NavigatorMediaStream::webkitGetUserMedia(Navigator* navigator, const Dictio
request->start();
}

void NavigatorMediaStream::getMediaDevices(Navigator* navigator, PassOwnPtr<MediaDeviceInfoCallback> callback, ExceptionState& exceptionState)
{
UserMediaController* userMedia = UserMediaController::from(navigator->frame() ? navigator->frame()->page() : 0);
if (!userMedia) {
exceptionState.throwDOMException(NotSupportedError, "Not implemented.");
return;
}

RefPtr<MediaDevicesRequest> request = MediaDevicesRequest::create(navigator->frame()->document(), userMedia, callback, exceptionState);
if (!request) {
exceptionState.throwDOMException(NotSupportedError, "Not implemented.");
return;
}

request->start();
}

} // namespace WebCore
3 changes: 3 additions & 0 deletions Source/modules/mediastream/NavigatorMediaStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace WebCore {

class Dictionary;
class ExceptionState;
class MediaDeviceInfoCallback;
class Navigator;
class NavigatorUserMediaErrorCallback;
class NavigatorUserMediaSuccessCallback;
Expand All @@ -35,6 +36,8 @@ class NavigatorMediaStream {
public:
static void webkitGetUserMedia(Navigator*, const Dictionary&, PassOwnPtr<NavigatorUserMediaSuccessCallback>, PassOwnPtr<NavigatorUserMediaErrorCallback>, ExceptionState&);

static void getMediaDevices(Navigator*, PassOwnPtr<MediaDeviceInfoCallback>, ExceptionState&);

private:
NavigatorMediaStream();
~NavigatorMediaStream();
Expand Down
3 changes: 3 additions & 0 deletions Source/modules/mediastream/UserMediaClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifndef UserMediaClient_h
#define UserMediaClient_h

#include "modules/mediastream/MediaDevicesRequest.h"
#include "modules/mediastream/UserMediaRequest.h"
#include "wtf/text/WTFString.h"

Expand All @@ -42,6 +43,8 @@ class UserMediaClient {
public:
virtual void requestUserMedia(PassRefPtr<UserMediaRequest>) = 0;
virtual void cancelUserMediaRequest(UserMediaRequest*) = 0;
virtual void requestMediaDevices(PassRefPtr<MediaDevicesRequest>) = 0;
virtual void cancelMediaDevicesRequest(MediaDevicesRequest*) = 0;

protected:
virtual ~UserMediaClient() { }
Expand Down
Loading

0 comments on commit f3dea58

Please sign in to comment.