OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 | 27 |
28 #include "MockWebRTCDTMFSenderHandler.h" | 28 #include <public/WebSourceInfo.h> |
29 | 29 |
30 #include "WebTestDelegate.h" | 30 #include "wtf/PassRefPtr.h" |
31 #include <assert.h> | 31 #include "wtf/RefCounted.h" |
32 #include <public/WebMediaStreamSource.h> | 32 #include <public/WebString.h> |
33 #include <public/WebRTCDTMFSenderHandlerClient.h> | |
34 | 33 |
35 using namespace WebKit; | 34 namespace WebKit { |
36 | 35 |
37 namespace WebTestRunner { | 36 class WebSourceInfoPrivate : public RefCounted<WebSourceInfoPrivate> { |
37 public: | |
38 static PassRefPtr<WebSourceInfoPrivate> create(const WebString& id, WebSourc eInfo::SourceKind, const WebString& label, WebSourceInfo::VideoFacingMode); | |
39 virtual ~WebSourceInfoPrivate(); | |
38 | 40 |
39 class DTMFSenderToneTask : public WebMethodTask<MockWebRTCDTMFSenderHandler> { | 41 WebString id() const { return m_id; } |
abarth-chromium
2013/05/31 17:30:08
These can return const WebString&
Tommy Widenflycht
2013/06/05 11:51:38
Done.
| |
40 public: | 42 WebSourceInfo::SourceKind kind() const { return m_kind; } |
41 DTMFSenderToneTask(MockWebRTCDTMFSenderHandler* object, WebRTCDTMFSenderHand lerClient* client) | 43 WebString label() const { return m_label; } |
42 : WebMethodTask<MockWebRTCDTMFSenderHandler>(object) | 44 WebSourceInfo::VideoFacingMode facing() const { return m_facing; } |
43 , m_client(client) | |
44 { | |
45 } | |
46 | |
47 virtual void runIfValid() OVERRIDE | |
48 { | |
49 WebString tones = m_object->currentToneBuffer(); | |
50 m_object->clearToneBuffer(); | |
51 m_client->didPlayTone(tones); | |
52 } | |
53 | 45 |
54 private: | 46 private: |
55 WebRTCDTMFSenderHandlerClient* m_client; | 47 WebSourceInfoPrivate(const WebString& id, WebSourceInfo::SourceKind, const W ebString& label, WebSourceInfo::VideoFacingMode); |
48 | |
49 WebString m_id; | |
50 WebSourceInfo::SourceKind m_kind; | |
51 WebString m_label; | |
52 WebSourceInfo::VideoFacingMode m_facing; | |
56 }; | 53 }; |
57 | 54 |
58 ///////////////////// | 55 PassRefPtr<WebSourceInfoPrivate> WebSourceInfoPrivate::create(const WebString& i d, WebSourceInfo::SourceKind kind, const WebString& label, WebSourceInfo::VideoF acingMode facing) |
56 { | |
57 return adoptRef(new WebSourceInfoPrivate(id, kind, label, facing)); | |
58 } | |
59 | 59 |
60 MockWebRTCDTMFSenderHandler::MockWebRTCDTMFSenderHandler(const WebMediaStreamTra ck& track, WebTestDelegate* delegate) | 60 WebSourceInfoPrivate::WebSourceInfoPrivate(const WebString& id, WebSourceInfo::S ourceKind kind, const WebString& label, WebSourceInfo::VideoFacingMode facing) |
61 : m_client(0) | 61 : m_id(id) |
62 , m_track(track) | 62 , m_kind(kind) |
63 , m_delegate(delegate) | 63 , m_label(label) |
64 , m_facing(facing) | |
64 { | 65 { |
65 } | 66 } |
66 | 67 |
67 void MockWebRTCDTMFSenderHandler::setClient(WebRTCDTMFSenderHandlerClient* clien t) | 68 WebSourceInfoPrivate::~WebSourceInfoPrivate() |
68 { | 69 { |
69 m_client = client; | |
70 } | 70 } |
71 | 71 |
72 WebString MockWebRTCDTMFSenderHandler::currentToneBuffer() | 72 void WebSourceInfo::assign(const WebSourceInfo& other) |
73 { | 73 { |
74 return m_toneBuffer; | 74 m_private = other.m_private; |
75 } | 75 } |
76 | 76 |
77 bool MockWebRTCDTMFSenderHandler::canInsertDTMF() | 77 void WebSourceInfo::reset() |
78 { | 78 { |
79 assert(m_client && !m_track.isNull()); | 79 m_private.reset(); |
80 return m_track.source().type() == WebMediaStreamSource::TypeAudio && m_track .isEnabled() && m_track.source().readyState() == WebMediaStreamSource::ReadyStat eLive; | |
81 } | 80 } |
82 | 81 |
83 bool MockWebRTCDTMFSenderHandler::insertDTMF(const WebString& tones, long durati on, long interToneGap) | 82 void WebSourceInfo::initialize(const WebString& id, WebSourceInfo::SourceKind ki nd, const WebString& label, WebSourceInfo::VideoFacingMode facing) |
84 { | 83 { |
85 assert(m_client); | 84 m_private = WebSourceInfoPrivate::create(id, kind, label, facing); |
86 if (!canInsertDTMF()) | |
87 return false; | |
88 | |
89 m_toneBuffer = tones; | |
90 m_delegate->postTask(new DTMFSenderToneTask(this, m_client)); | |
91 m_delegate->postTask(new DTMFSenderToneTask(this, m_client)); | |
92 return true; | |
93 } | 85 } |
94 | 86 |
87 WebString WebSourceInfo::id() const | |
88 { | |
89 ASSERT(!m_private.isNull()); | |
90 return m_private->id(); | |
95 } | 91 } |
92 | |
93 WebSourceInfo::SourceKind WebSourceInfo::kind() const | |
94 { | |
95 ASSERT(!m_private.isNull()); | |
96 return m_private->kind(); | |
97 } | |
98 | |
99 WebString WebSourceInfo::label() const | |
100 { | |
101 ASSERT(!m_private.isNull()); | |
102 return m_private->label(); | |
103 } | |
104 | |
105 WebSourceInfo::VideoFacingMode WebSourceInfo::facing() const | |
106 { | |
107 ASSERT(!m_private.isNull()); | |
108 return m_private->facing(); | |
109 } | |
110 | |
111 } // namespace WebKit | |
112 | |
OLD | NEW |