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 SOCKET_WRITER_NODE_H
18 #define SOCKET_WRITER_NODE_H
19 
20 #include <BaseNode.h>
21 #include <ISocket.h>
22 
23 class SocketWriterNode : public BaseNode
24 {
25 public:
26     SocketWriterNode(BaseSessionCallback* callback = nullptr);
27     virtual ~SocketWriterNode();
28     virtual kBaseNodeId GetNodeId();
29     virtual ImsMediaResult Start();
30     virtual void Stop();
31     virtual bool IsRunTime();
32     virtual bool IsSourceNode();
33     virtual void SetConfig(void* config);
34     virtual bool IsSameConfig(void* config);
35     virtual void OnDataFromFrontNode(ImsMediaSubType subtype, uint8_t* pData, uint32_t nDataSize,
36             uint32_t timestamp, bool mark, uint32_t nSeqNum,
37             ImsMediaSubType nDataType = ImsMediaSubType::MEDIASUBTYPE_UNDEFINED,
38             uint32_t arrivalTime = 0);
39 
40     /**
41      * @brief Set the local socket file descriptor
42      */
43     void SetLocalFd(int fd);
44 
45     /**
46      * @brief Set the local ip address and port number
47      */
48     void SetLocalAddress(const RtpAddress& address);
49 
50     /**
51      * @brief Set the peer ip address and port number
52      */
53     void SetPeerAddress(const RtpAddress& address);
54 
55     /**
56      * @brief Set the protocol type defined as kProtocolType
57      */
SetProtocolType(kProtocolType type)58     void SetProtocolType(kProtocolType type) { mProtocolType = type; }
59 
60 private:
61     int mLocalFd;
62     ISocket* mSocket;
63     kProtocolType mProtocolType;
64     RtpAddress mLocalAddress;
65     RtpAddress mPeerAddress;
66     int8_t mDscp;
67     bool mSocketOpened;
68     bool mDisableSocket;
69 };
70 
71 #endif