| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /* |
| 6 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 7 * |
| 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions are |
| 10 * met: |
| 11 * |
| 12 * * Redistributions of source code must retain the above copyright |
| 13 * notice, this list of conditions and the following disclaimer. |
| 14 * * Redistributions in binary form must reproduce the above |
| 15 * copyright notice, this list of conditions and the following disclaimer |
| 16 * in the documentation and/or other materials provided with the |
| 17 * distribution. |
| 18 * * Neither the name of Google Inc. nor the names of its |
| 19 * contributors may be used to endorse or promote products derived from |
| 20 * this software without specific prior written permission. |
| 21 * |
| 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 */ |
| 34 |
| 35 #include "content/test/layout_tests/runner/MockWebMediaStreamCenter.h" |
| 36 |
| 37 #include "third_party/WebKit/public/platform/WebAudioDestinationConsumer.h" |
| 38 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| 39 #include "third_party/WebKit/public/platform/WebMediaStreamCenterClient.h" |
| 40 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 41 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 42 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h
" |
| 43 #include "third_party/WebKit/public/platform/WebSourceInfo.h" |
| 44 #include "third_party/WebKit/public/platform/WebVector.h" |
| 45 |
| 46 using namespace blink; |
| 47 |
| 48 namespace WebTestRunner { |
| 49 |
| 50 MockWebMediaStreamCenter::MockWebMediaStreamCenter(WebMediaStreamCenterClient* c
lient) |
| 51 { |
| 52 } |
| 53 |
| 54 bool MockWebMediaStreamCenter::getMediaStreamTrackSources(const WebMediaStreamTr
ackSourcesRequest& request) |
| 55 { |
| 56 size_t size = 2; |
| 57 WebVector<WebSourceInfo> results(size); |
| 58 results[0].initialize("MockAudioDevice#1", WebSourceInfo::SourceKindAudio, "
Mock audio device", WebSourceInfo::VideoFacingModeNone); |
| 59 results[1].initialize("MockVideoDevice#1", WebSourceInfo::SourceKindVideo, "
Mock video device", WebSourceInfo::VideoFacingModeEnvironment); |
| 60 request.requestSucceeded(results); |
| 61 return true; |
| 62 } |
| 63 |
| 64 void MockWebMediaStreamCenter::didEnableMediaStreamTrack(const WebMediaStream&,
const WebMediaStreamTrack& track) |
| 65 { |
| 66 track.source().setReadyState(WebMediaStreamSource::ReadyStateLive); |
| 67 } |
| 68 |
| 69 void MockWebMediaStreamCenter::didDisableMediaStreamTrack(const WebMediaStream&,
const WebMediaStreamTrack& track) |
| 70 { |
| 71 track.source().setReadyState(WebMediaStreamSource::ReadyStateMuted); |
| 72 } |
| 73 |
| 74 bool MockWebMediaStreamCenter::didAddMediaStreamTrack(const WebMediaStream&, con
st WebMediaStreamTrack&) |
| 75 { |
| 76 return true; |
| 77 } |
| 78 |
| 79 bool MockWebMediaStreamCenter::didRemoveMediaStreamTrack(const WebMediaStream&,
const WebMediaStreamTrack&) |
| 80 { |
| 81 return true; |
| 82 } |
| 83 |
| 84 void MockWebMediaStreamCenter::didStopLocalMediaStream(const WebMediaStream& str
eam) |
| 85 { |
| 86 WebVector<WebMediaStreamTrack> tracks; |
| 87 stream.audioTracks(tracks); |
| 88 for (size_t i = 0; i < tracks.size(); ++i) |
| 89 tracks[i].source().setReadyState(WebMediaStreamSource::ReadyStateEnded); |
| 90 stream.videoTracks(tracks); |
| 91 for (size_t i = 0; i < tracks.size(); ++i) |
| 92 tracks[i].source().setReadyState(WebMediaStreamSource::ReadyStateEnded); |
| 93 } |
| 94 |
| 95 bool MockWebMediaStreamCenter::didStopMediaStreamTrack(const blink::WebMediaStre
amTrack& track) |
| 96 { |
| 97 track.source().setReadyState(WebMediaStreamSource::ReadyStateEnded); |
| 98 return true; |
| 99 } |
| 100 |
| 101 class MockWebAudioDestinationConsumer : public WebAudioDestinationConsumer { |
| 102 public: |
| 103 virtual ~MockWebAudioDestinationConsumer() { } |
| 104 virtual void setFormat(size_t numberOfChannels, float sampleRate) OVERRIDE {
} |
| 105 virtual void consumeAudio(const WebVector<const float*>&, size_t number_of_f
rames) OVERRIDE { } |
| 106 }; |
| 107 |
| 108 void MockWebMediaStreamCenter::didCreateMediaStream(WebMediaStream& stream) |
| 109 { |
| 110 WebVector<WebMediaStreamTrack> audioTracks; |
| 111 stream.audioTracks(audioTracks); |
| 112 for (size_t i = 0; i < audioTracks.size(); ++i) { |
| 113 WebMediaStreamSource source = audioTracks[i].source(); |
| 114 if (source.requiresAudioConsumer()) { |
| 115 MockWebAudioDestinationConsumer* consumer = new MockWebAudioDestinat
ionConsumer(); |
| 116 source.addAudioConsumer(consumer); |
| 117 source.removeAudioConsumer(consumer); |
| 118 delete consumer; |
| 119 } |
| 120 } |
| 121 } |
| 122 |
| 123 } |
| OLD | NEW |