• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2022 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 #ifndef DTMFENCODERNODE_H_INCLUDED
18 #define DTMFENCODERNODE_H_INCLUDED
19 
20 #include <ImsMediaDefine.h>
21 #include <BaseNode.h>
22 #include <IImsMediaThread.h>
23 #include <ImsMediaCondition.h>
24 #include <mutex>
25 
26 class DtmfEncoderNode : public BaseNode, IImsMediaThread
27 {
28 public:
29     DtmfEncoderNode(BaseSessionCallback* callback = nullptr);
30     virtual ~DtmfEncoderNode();
31     virtual kBaseNodeId GetNodeId();
32     virtual ImsMediaResult Start();
33     virtual void Stop();
34     virtual bool IsRunTime();
35     virtual bool IsSourceNode();
36     virtual void SetConfig(void* config);
37     virtual bool IsSameConfig(void* config);
38     virtual void OnDataFromFrontNode(ImsMediaSubType subtype, uint8_t* pData, uint32_t nDataSize,
39             uint32_t nTimeStamp, bool bMark, uint32_t nSeqNum,
40             ImsMediaSubType nDataType = MEDIASUBTYPE_UNDEFINED, uint32_t arrivalTime = 0);
41     virtual void* run();
42 
43 private:
44     bool SendDTMFEvent(uint8_t digit, uint32_t duration);
45     uint32_t calculateDtmfDuration(uint32_t duration);
46     bool convertSignal(uint8_t digit, uint8_t& signal);
47     uint32_t MakeDTMFPayload(
48             uint8_t* pbPayload, uint8_t nEvent, bool bEnd, uint8_t nVolume, uint32_t nPeriod);
49     ImsMediaCondition mConditionDtmf;
50     ImsMediaCondition mConditionExit;
51     std::mutex mMutex;
52     std::list<uint8_t> mListDtmfDigit;
53     bool mStopDtmf;
54     int8_t mSamplingRate;          // audio sampling rate
55     uint32_t mDuration;            // msec unit, duration of one DTMF tone
56     uint32_t mRetransmitDuration;  // msec unit, duration of retransmitting the last packet
57     uint32_t mVolume;              // Volume of DTMF, 0~63, default value is 10.
58     uint32_t mAudioFrameDuration;
59     int8_t mPtime;
60 };
61 
62 #endif  // DTMFENCODERNODE_H_INCLUDED
63