• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GOOGLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
24  */
25 
26 #include "MockWebRTCDTMFSenderHandler.h"
27 
28 #include "public/platform/WebMediaStreamSource.h"
29 #include "public/platform/WebRTCDTMFSenderHandlerClient.h"
30 #include "public/testing/WebTestDelegate.h"
31 #include <assert.h>
32 
33 using namespace blink;
34 
35 namespace WebTestRunner {
36 
37 class DTMFSenderToneTask : public WebMethodTask<MockWebRTCDTMFSenderHandler> {
38 public:
DTMFSenderToneTask(MockWebRTCDTMFSenderHandler * object,WebRTCDTMFSenderHandlerClient * client)39     DTMFSenderToneTask(MockWebRTCDTMFSenderHandler* object, WebRTCDTMFSenderHandlerClient* client)
40         : WebMethodTask<MockWebRTCDTMFSenderHandler>(object)
41         , m_client(client)
42     {
43     }
44 
runIfValid()45     virtual void runIfValid() OVERRIDE
46     {
47         WebString tones = m_object->currentToneBuffer();
48         m_object->clearToneBuffer();
49         m_client->didPlayTone(tones);
50     }
51 
52 private:
53     WebRTCDTMFSenderHandlerClient* m_client;
54 };
55 
56 /////////////////////
57 
MockWebRTCDTMFSenderHandler(const WebMediaStreamTrack & track,WebTestDelegate * delegate)58 MockWebRTCDTMFSenderHandler::MockWebRTCDTMFSenderHandler(const WebMediaStreamTrack& track, WebTestDelegate* delegate)
59     : m_client(0)
60     , m_track(track)
61     , m_delegate(delegate)
62 {
63 }
64 
setClient(WebRTCDTMFSenderHandlerClient * client)65 void MockWebRTCDTMFSenderHandler::setClient(WebRTCDTMFSenderHandlerClient* client)
66 {
67     m_client = client;
68 }
69 
currentToneBuffer()70 WebString MockWebRTCDTMFSenderHandler::currentToneBuffer()
71 {
72     return m_toneBuffer;
73 }
74 
canInsertDTMF()75 bool MockWebRTCDTMFSenderHandler::canInsertDTMF()
76 {
77     assert(m_client && !m_track.isNull());
78     return m_track.source().type() == WebMediaStreamSource::TypeAudio && m_track.isEnabled() && m_track.source().readyState() == WebMediaStreamSource::ReadyStateLive;
79 }
80 
insertDTMF(const WebString & tones,long duration,long interToneGap)81 bool MockWebRTCDTMFSenderHandler::insertDTMF(const WebString& tones, long duration, long interToneGap)
82 {
83     assert(m_client);
84     if (!canInsertDTMF())
85         return false;
86 
87     m_toneBuffer = tones;
88     m_delegate->postTask(new DTMFSenderToneTask(this, m_client));
89     m_delegate->postTask(new DTMFSenderToneTask(this, m_client));
90     return true;
91 }
92 
93 }
94