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 #include "content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.h" | |
6 | |
7 #include <assert.h> | |
8 | |
9 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | |
10 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | |
11 #include "third_party/WebKit/public/platform/WebRTCDTMFSenderHandlerClient.h" | |
12 | |
13 using namespace blink; | |
14 | |
15 namespace content { | |
16 | |
17 class DTMFSenderToneTask : public WebMethodTask<MockWebRTCDTMFSenderHandler> { | |
18 public: | |
19 DTMFSenderToneTask(MockWebRTCDTMFSenderHandler* object, | |
20 WebRTCDTMFSenderHandlerClient* client) | |
21 : WebMethodTask<MockWebRTCDTMFSenderHandler>(object), client_(client) {} | |
22 | |
23 virtual void runIfValid() OVERRIDE { | |
24 WebString tones = m_object->currentToneBuffer(); | |
25 m_object->ClearToneBuffer(); | |
26 client_->didPlayTone(tones); | |
27 } | |
28 | |
29 private: | |
30 WebRTCDTMFSenderHandlerClient* client_; | |
31 }; | |
32 | |
33 ///////////////////// | |
34 | |
35 MockWebRTCDTMFSenderHandler::MockWebRTCDTMFSenderHandler( | |
36 const WebMediaStreamTrack& track, | |
37 WebTestDelegate* delegate) | |
38 : client_(0), track_(track), delegate_(delegate) { | |
39 } | |
40 | |
41 void MockWebRTCDTMFSenderHandler::setClient( | |
42 WebRTCDTMFSenderHandlerClient* client) { | |
43 client_ = client; | |
44 } | |
45 | |
46 WebString MockWebRTCDTMFSenderHandler::currentToneBuffer() { | |
47 return tone_buffer_; | |
48 } | |
49 | |
50 bool MockWebRTCDTMFSenderHandler::canInsertDTMF() { | |
51 assert(client_ && !track_.isNull()); | |
jochen (gone - plz use gerrit)
2014/06/03 12:55:00
DCHECK
Nikhil
2014/06/04 05:33:55
Done.
| |
52 return track_.source().type() == WebMediaStreamSource::TypeAudio && | |
53 track_.isEnabled() && | |
54 track_.source().readyState() == WebMediaStreamSource::ReadyStateLive; | |
55 } | |
56 | |
57 bool MockWebRTCDTMFSenderHandler::insertDTMF(const WebString& tones, | |
58 long duration, | |
59 long inter_tone_gap) { | |
60 assert(client_); | |
61 if (!canInsertDTMF()) | |
62 return false; | |
63 | |
64 tone_buffer_ = tones; | |
65 delegate_->postTask(new DTMFSenderToneTask(this, client_)); | |
66 delegate_->postTask(new DTMFSenderToneTask(this, client_)); | |
67 return true; | |
68 } | |
69 | |
70 } // namespace content | |
OLD | NEW |