Commit 571a9008 authored by xians@chromium.org's avatar xians@chromium.org

Added interface to create one WebAudioSource for each CreateMediaStreamSource() call.

The new interface is called createWebAudioSourceFromMediaStreamTrack(), it is used to create one WebAudioSource for each CreateMediaStreamSource() call. By doing this, we avoid calling into the same source provider when there are multiple WebAudio audioContexts.

Note that the code in this is not hooked up to anything. We need to implement the interface in Chrome then hook the code up in AudioContext.cpp

NOTRY=true

BUG=354468

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

git-svn-id: svn://svn.chromium.org/blink/trunk@169859 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4bd9b3c0
......@@ -185,6 +185,11 @@ void MediaStreamTrack::stop()
m_stopped = true;
}
PassOwnPtr<AudioSourceProvider> MediaStreamTrack::createWebAudioSource()
{
return MediaStreamCenter::instance().createWebAudioSourceFromMediaStreamTrack(component());
}
void MediaStreamTrack::addObserver(MediaStreamTrack::Observer* observer)
{
RELEASE_ASSERT(!m_isIteratingObservers);
......
......@@ -32,6 +32,7 @@
#include "modules/mediastream/SourceInfo.h"
#include "platform/mediastream/MediaStreamDescriptor.h"
#include "platform/mediastream/MediaStreamSource.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/RefPtr.h"
#include "wtf/Vector.h"
......@@ -39,6 +40,7 @@
namespace WebCore {
class AudioSourceProvider;
class ExceptionState;
class MediaStreamComponent;
class MediaStreamTrackSourcesCallback;
......@@ -85,6 +87,8 @@ public:
// ActiveDOMObject
virtual void stop() OVERRIDE;
PassOwnPtr<AudioSourceProvider> createWebAudioSource();
private:
MediaStreamTrack(ExecutionContext*, MediaStreamComponent*);
......
......@@ -679,6 +679,8 @@
'mediastream/MediaStreamSource.cpp',
'mediastream/MediaStreamSource.h',
'mediastream/MediaStreamTrackSourcesRequest.h',
'mediastream/MediaStreamWebAudioSource.cpp',
'mediastream/MediaStreamWebAudioSource.h',
'mediastream/RTCConfiguration.h',
'mediastream/RTCSessionDescriptionRequest.h',
'mediastream/RTCStatsRequest.h',
......
......@@ -35,11 +35,14 @@
#include "platform/mediastream/MediaStreamDescriptor.h"
#include "platform/mediastream/MediaStreamTrackSourcesRequest.h"
#include "platform/mediastream/MediaStreamWebAudioSource.h"
#include "public/platform/Platform.h"
#include "public/platform/WebAudioSourceProvider.h"
#include "public/platform/WebMediaStream.h"
#include "public/platform/WebMediaStreamCenter.h"
#include "public/platform/WebMediaStreamTrack.h"
#include "public/platform/WebMediaStreamTrackSourcesRequest.h"
#include "wtf/Assertions.h"
#include "wtf/MainThread.h"
#include "wtf/PassOwnPtr.h"
......@@ -112,6 +115,17 @@ void MediaStreamCenter::didCreateMediaStreamTrack(MediaStreamComponent* track)
m_private->didCreateMediaStreamTrack(track);
}
PassOwnPtr<AudioSourceProvider> MediaStreamCenter::createWebAudioSourceFromMediaStreamTrack(MediaStreamComponent* track)
{
ASSERT_UNUSED(track, track);
#if ENABLE(WEB_AUDIO)
if (m_private)
return MediaStreamWebAudioSource::create(adoptPtr(m_private->createWebAudioSourceFromMediaStreamTrack(track)));
#endif
return nullptr;
}
void MediaStreamCenter::stopLocalMediaStream(const blink::WebMediaStream& webStream)
{
MediaStreamDescriptor* stream = webStream;
......
/*
* Copyright (C) 2011 Ericsson AB. All rights reserved.
* Copyright (C) 2012 Google Inc. All rights reserved.
* Copyright 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
......@@ -47,6 +46,7 @@ class WebMediaStreamTrack;
namespace WebCore {
class AudioSourceProvider;
class MediaStreamComponent;
class MediaStreamDescriptor;
class MediaStreamTrackSourcesRequest;
......@@ -63,6 +63,7 @@ public:
void didCreateMediaStreamTrack(MediaStreamComponent*);
void didSetMediaStreamTrackEnabled(MediaStreamComponent*);
bool didStopMediaStreamTrack(MediaStreamComponent*);
PassOwnPtr<AudioSourceProvider> createWebAudioSourceFromMediaStreamTrack(MediaStreamComponent*);
void didCreateMediaStream(MediaStreamDescriptor*);
bool didAddMediaStreamTrack(MediaStreamDescriptor*, MediaStreamComponent*);
......
/*
* Copyright 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.
* 3. Neither the name of Google Inc. nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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 THE COPYRIGHT
* OWNER 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"
#if ENABLE(WEB_AUDIO)
#include "platform/mediastream/MediaStreamWebAudioSource.h"
#include "platform/audio/AudioBus.h"
#include "public/platform/WebAudioSourceProvider.h"
namespace WebCore {
MediaStreamWebAudioSource::MediaStreamWebAudioSource(PassOwnPtr<blink::WebAudioSourceProvider> provider)
: m_webAudioSourceProvider(provider)
{
}
MediaStreamWebAudioSource::~MediaStreamWebAudioSource()
{
}
void MediaStreamWebAudioSource::provideInput(AudioBus* bus, size_t framesToProcess)
{
ASSERT(bus);
if (!bus)
return;
if (!m_webAudioSourceProvider) {
bus->zero();
return;
}
// Wrap the AudioBus channel data using WebVector.
size_t n = bus->numberOfChannels();
blink::WebVector<float*> webAudioData(n);
for (size_t i = 0; i < n; ++i)
webAudioData[i] = bus->channel(i)->mutableData();
m_webAudioSourceProvider->provideInput(webAudioData, framesToProcess);
}
} // namespace WebCore
#endif // ENABLE(WEB_AUDIO)
/*
* Copyright 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.
* 3. Neither the name of Ericsson nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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 THE COPYRIGHT
* OWNER 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 MediaStreamWebAudioSource_h
#define MediaStreamWebAudioSource_h
#include "platform/audio/AudioSourceProvider.h"
#include "wtf/Noncopyable.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/ThreadingPrimitives.h"
namespace blink {
class WebAudioSourceProvider;
}
namespace WebCore {
class MediaStreamWebAudioSource : public AudioSourceProvider {
WTF_MAKE_NONCOPYABLE(MediaStreamWebAudioSource);
public:
static PassOwnPtr<MediaStreamWebAudioSource> create(PassOwnPtr<blink::WebAudioSourceProvider> provider) { return adoptPtr(new MediaStreamWebAudioSource(provider)); }
virtual ~MediaStreamWebAudioSource();
private:
explicit MediaStreamWebAudioSource(PassOwnPtr<blink::WebAudioSourceProvider>);
// WebCore::AudioSourceProvider implementation.
virtual void provideInput(WebCore::AudioBus*, size_t framesToProcess) OVERRIDE;
OwnPtr<blink::WebAudioSourceProvider> m_webAudioSourceProvider;
};
} // namespace WebCore
#endif // MediaStreamWebAudioSource_h
......@@ -34,14 +34,13 @@ class WebAudioSourceProviderClient;
// Abstract interface for a pull-model client.
class WebAudioSourceProvider {
public:
virtual ~WebAudioSourceProvider() { }
// provideInput() gets called repeatedly to render time-slices of a continuous audio stream.
virtual void provideInput(const WebVector<float*>& audioData, size_t numberOfFrames) = 0;
// If a client is set, we call it back when the audio format is available.
virtual void setClient(WebAudioSourceProviderClient*) { };
protected:
virtual ~WebAudioSourceProvider() { }
};
} // WebKit
......
......@@ -34,6 +34,7 @@
#include "WebVector.h"
namespace blink {
class WebAudioSourceProvider;
class WebMediaStream;
class WebMediaStreamTrack;
class WebMediaStreamTrackSourcesRequest;
......@@ -57,6 +58,9 @@ public:
virtual void didEnableMediaStreamTrack(const WebMediaStreamTrack&) { }
virtual void didDisableMediaStreamTrack(const WebMediaStreamTrack&) { }
virtual bool didStopMediaStreamTrack(const WebMediaStreamTrack&) { return false; }
// Caller must take the ownership of the returned |WebAudioSourceProvider| object.
virtual WebAudioSourceProvider* createWebAudioSourceFromMediaStreamTrack(const WebMediaStreamTrack&) { return 0; }
};
} // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment