• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <ImsMediaDefine.h>
18 #include <ImsMediaTrace.h>
19 #include <DtmfSenderNode.h>
20 #include <ImsMediaTimer.h>
21 #include <AudioConfig.h>
22 
DtmfSenderNode(BaseSessionCallback * callback)23 DtmfSenderNode::DtmfSenderNode(BaseSessionCallback* callback) :
24         BaseNode(callback)
25 {
26     mNextTime = 0;
27     mPrevTime = 0;
28     mPtime = 20;
29 }
30 
~DtmfSenderNode()31 DtmfSenderNode::~DtmfSenderNode() {}
32 
GetNodeId()33 kBaseNodeId DtmfSenderNode::GetNodeId()
34 {
35     return kNodeIdDtmfSender;
36 }
37 
Start()38 ImsMediaResult DtmfSenderNode::Start()
39 {
40     IMLOGD0("[Start]");
41     mNextTime = 0;
42     mNodeState = kNodeStateRunning;
43     return RESULT_SUCCESS;
44 }
45 
Stop()46 void DtmfSenderNode::Stop()
47 {
48     IMLOGD0("[Stop]");
49     mNextTime = 0;
50     ClearDataQueue();
51     mNodeState = kNodeStateStopped;
52 }
53 
IsRunTime()54 bool DtmfSenderNode::IsRunTime()
55 {
56     return false;
57 }
58 
IsSourceNode()59 bool DtmfSenderNode::IsSourceNode()
60 {
61     return false;
62 }
63 
SetConfig(void * config)64 void DtmfSenderNode::SetConfig(void* config)
65 {
66     AudioConfig* pConfig = reinterpret_cast<AudioConfig*>(config);
67 
68     if (pConfig != nullptr)
69     {
70         mPtime = pConfig->getPtimeMillis();
71     }
72 }
73 
IsSameConfig(void * config)74 bool DtmfSenderNode::IsSameConfig(void* config)
75 {
76     if (config == nullptr)
77     {
78         return true;
79     }
80 
81     AudioConfig* pConfig = reinterpret_cast<AudioConfig*>(config);
82     return (mPtime == pConfig->getPtimeMillis());
83 }
84 
ProcessData()85 void DtmfSenderNode::ProcessData()
86 {
87     ImsMediaSubType subtype;
88     uint8_t* data;
89     uint32_t size;
90     uint32_t timestamp;
91     bool bMark;
92     uint32_t currTime;
93 
94     if (!GetData(&subtype, &data, &size, &timestamp, &bMark, nullptr))
95     {
96         return;
97     }
98 
99     currTime = ImsMediaTimer::GetTimeInMilliSeconds();
100 
101     if (mNextTime && !(currTime >= mNextTime || currTime < mPrevTime || mNextTime < mPrevTime))
102     {
103         mPrevTime = currTime;
104         return;
105     }
106 
107     if (subtype == MEDIASUBTYPE_DTMFSTART)
108     {
109         SendDataToRearNode(subtype, data, size, currTime, bMark, 0);
110         DeleteData();
111         mNextTime = currTime;
112 
113         // send the first dtmf packet
114         if (GetData(&subtype, &data, &size, &timestamp, &bMark, nullptr, nullptr) &&
115                 subtype == MEDIASUBTYPE_DTMF_PAYLOAD)
116         {
117             SendDataToRearNode(subtype, data, size, currTime, bMark, 0);
118             DeleteData();
119             mNextTime += mPtime;
120         }
121     }
122     else
123     {
124         SendDataToRearNode(subtype, data, size, currTime, bMark, 0);
125         DeleteData();
126         mNextTime += mPtime;
127     }
128 
129     mPrevTime = currTime;
130 }
131