1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
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
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18 /**
19 * "pvmf_clientserver_socket_port.cpp"
20 */
21 #ifndef PVMF_CLIENTSERVER_SOCKET_PORT_H_INCLUDED
22 #include "pvmf_clientserver_socket_port.h"
23 #endif
24 #ifndef OSCL_MIME_STRING_UTILS_H
25 #include "pv_mime_string_utils.h"
26 #endif
27
28 ////////////////////////////////////////////////////////////////////////////
PVMFClientServerSocketPort(int32 aTag,PVMFPortActivityHandler * aNode)29 PVMFClientServerSocketPort::PVMFClientServerSocketPort(int32 aTag,
30 PVMFPortActivityHandler* aNode)
31 : PvmfPortBaseImpl(aTag, aNode)
32 {
33 Construct();
34 }
35
36
37 ////////////////////////////////////////////////////////////////////////////
PVMFClientServerSocketPort(int32 aTag,PVMFPortActivityHandler * aNode,uint32 aInCapacity,uint32 aInReserve,uint32 aInThreshold,uint32 aOutCapacity,uint32 aOutReserve,uint32 aOutThreshold)38 PVMFClientServerSocketPort::PVMFClientServerSocketPort(int32 aTag
39 , PVMFPortActivityHandler* aNode
40 , uint32 aInCapacity
41 , uint32 aInReserve
42 , uint32 aInThreshold
43 , uint32 aOutCapacity
44 , uint32 aOutReserve
45 , uint32 aOutThreshold)
46 : PvmfPortBaseImpl(aTag, aNode, aInCapacity, aInReserve,
47 aInThreshold, aOutCapacity, aOutReserve, aOutThreshold)
48 {
49 iPortTag = (PVMFSocketNodePortTag)aTag;
50 Construct();
51 }
52
53
54 ////////////////////////////////////////////////////////////////////////////
Construct()55 void PVMFClientServerSocketPort::Construct()
56 {
57 iConfig = NULL;
58 iLogger = PVLogger::GetLoggerObject("PVMFClientServerSocketPort");
59 oscl_memset(&iStats, 0, sizeof(PvmfPortBaseImplStats));
60 iNumFramesConsumed = 0;
61 PvmiCapabilityAndConfigPortFormatImpl::Construct(PVMF_CLIENTSERVER_SOCKET_PORT_SPECIFIC_ALLOCATOR
62 , PVMF_CLIENTSERVER_SOCKET_PORT_SPECIFIC_ALLOCATOR_VALTYPE);
63 }
64
65
66 ////////////////////////////////////////////////////////////////////////////
~PVMFClientServerSocketPort()67 PVMFClientServerSocketPort::~PVMFClientServerSocketPort()
68 {
69 Disconnect();
70 }
71
72
73 ////////////////////////////////////////////////////////////////////////////
IsFormatSupported(PVMFFormatType aFmt)74 bool PVMFClientServerSocketPort::IsFormatSupported(PVMFFormatType aFmt)
75 {
76 if (aFmt == PVMF_MIME_INET_TCP)
77 return true;
78 else
79 return false;
80 }
81
82
83 ////////////////////////////////////////////////////////////////////////////
FormatUpdated()84 void PVMFClientServerSocketPort::FormatUpdated()
85 {
86 PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO
87 , (0, "PVMFClientServerSocketPort::FormatUpdated %s", iFormat.getMIMEStrPtr()));
88 }
89
90
91 ////////////////////////////////////////////////////////////////////////////
PeekIncomingMsg(PVMFSharedMediaMsgPtr & aMsg)92 PVMFStatus PVMFClientServerSocketPort::PeekIncomingMsg(PVMFSharedMediaMsgPtr& aMsg)
93 {
94 if (iIncomingQueue.iQ.empty())
95 {
96 PVLOGGER_LOGMSG(PVLOGMSG_INST_REL, iLogger, PVLOGMSG_ERR,
97 (0, "0x%x PVMFClientServerSocketPort::PeekIncomingMsg: Error - Incoming queue is empty", this));
98 return PVMFFailure;
99 }
100
101 // Save message to output parameter and erase it from queue
102 aMsg = iIncomingQueue.iQ.front();
103 return PVMFSuccess;
104 }
105
106
107 ////////////////////////////////////////////////////////////////////////////
QueueOutgoingMsg(PVMFSharedMediaMsgPtr aMsg)108 PVMFStatus PVMFClientServerSocketPort::QueueOutgoingMsg(PVMFSharedMediaMsgPtr aMsg)
109 {
110 PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO, (0, "PVMFClientServerSocketPort::QueueOutgoingMsg"));
111
112 //If port is not connected, don't accept data on the
113 //outgoing queue.
114 if (!iConnectedPort)
115 {
116 PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO, (0, "PVMFClientServerSocketPort::QueueOutgoingMsg: Error - Port not connected"));
117 return PVMFFailure;
118 }
119
120 PvmfPortBaseImpl* cpPort = OSCL_STATIC_CAST(PvmfPortBaseImpl*, iConnectedPort);
121
122 // Connected Port incoming Queue is in busy / flushing state. Do not accept more outgoing messages
123 // until the queue is not busy, i.e. queue size drops below specified threshold or FlushComplete
124 // is called.
125 if (cpPort->iIncomingQueue.iBusy)
126 {
127 PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO, (0, "PVMFClientServerSocketPort::QueueOutgoingMsg: Connected Port Incoming queue in busy / flushing state - Attempting to Q in output port's outgoing msg q"));
128 return (PvmfPortBaseImpl::QueueOutgoingMsg(aMsg));
129 }
130
131 // Add message to outgoing queue and notify the node of the activity
132 // There is no need to trap the push_back, since it cannot leave in this usage
133 // Reason being that we do a reserve in the constructor and we do not let the
134 // port queues grow indefinitely (we either a connected port busy or outgoing Q busy
135 // before we reach the reserved limit
136 PVMFStatus status = cpPort->Receive(aMsg);
137
138 if (status != PVMFSuccess)
139 {
140 return PVMFFailure;
141 }
142
143 // Outgoing queue size is at capacity and goes into busy state. The owner node is
144 // notified of this transition into busy state.
145 if (cpPort->isIncomingFull())
146 {
147 PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO, (0, "PVMFClientServerSocketPort::QueueOutgoingMsg: Connected Port incoming queue is full. Goes into busy state"));
148 cpPort->iIncomingQueue.iBusy = true;
149 PvmfPortBaseImpl::PortActivity(PVMF_PORT_ACTIVITY_CONNECTED_PORT_BUSY);
150 }
151
152 return PVMFSuccess;
153 }
154
155
156 ////////////////////////////////////////////////////////////////////////////
IsOutgoingQueueBusy()157 bool PVMFClientServerSocketPort::IsOutgoingQueueBusy()
158 {
159 if (iConnectedPort != NULL)
160 {
161 PvmfPortBaseImpl* cpPort = OSCL_STATIC_CAST(PvmfPortBaseImpl*, iConnectedPort);
162 return (cpPort->iIncomingQueue.iBusy);
163 }
164 return (PvmfPortBaseImpl::IsOutgoingQueueBusy());;
165 }
166
167
168 ////////////////////////////////////////////////////////////////////////////
setParametersSync(PvmiMIOSession aSession,PvmiKvp * aParameters,int num_elements,PvmiKvp * & aRet_kvp)169 void PVMFClientServerSocketPort::setParametersSync(PvmiMIOSession aSession,
170 PvmiKvp* aParameters,
171 int num_elements,
172 PvmiKvp * & aRet_kvp)
173 {
174 PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_INFO, (0, "PVMFClientServerSocketPort::setParametersSync: aSession=0x%x, aParameters=0x%x, num_elements=%d, aRet_kvp=0x%x",
175 aSession, aParameters, num_elements, aRet_kvp));
176 OSCL_UNUSED_ARG(aSession);
177 if (!aParameters || (num_elements != 1) ||
178 (pv_mime_strcmp(aParameters->key, PVMF_CLIENTSERVER_SOCKET_PORT_SPECIFIC_ALLOCATOR_VALTYPE) != 0))
179 {
180 aRet_kvp = aParameters;
181 OSCL_LEAVE(OsclErrArgument);
182 }
183 if (aParameters->value.key_specific_value == NULL)
184 {
185 aRet_kvp = aParameters;
186 OSCL_LEAVE(OsclErrArgument);
187 }
188 else
189 {
190 aRet_kvp = NULL;
191 iAllocSharedPtr =
192 *((OsclSharedPtr<PVMFSharedSocketDataBufferAlloc>*)(aParameters->value.key_specific_value));
193 }
194 }
195
196
197 ////////////////////////////////////////////////////////////////////////////
getParametersSync(PvmiMIOSession aSession,PvmiKeyType aIdentifier,PvmiKvp * & aParameters,int & num_parameter_elements,PvmiCapabilityContext aContext)198 PVMFStatus PVMFClientServerSocketPort::getParametersSync(PvmiMIOSession aSession,
199 PvmiKeyType aIdentifier,
200 PvmiKvp*& aParameters,
201 int& num_parameter_elements,
202 PvmiCapabilityContext aContext)
203 {
204 OSCL_UNUSED_ARG(aContext);
205 OSCL_UNUSED_ARG(aSession);
206 if (pv_mime_strcmp(aIdentifier, PVMI_PORT_CONFIG_INPLACE_DATA_PROCESSING_KEY) != 0)
207 {
208 PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFClientServerSocketPort::getParametersSync: Error - Unsupported PvmiKeyType"));
209 return PVMFErrNotSupported;
210 }
211
212 num_parameter_elements = 0;
213 if (!pvmiGetPortInPlaceDataProcessingInfoSync(PVMI_PORT_CONFIG_INPLACE_DATA_PROCESSING_VALUE, aParameters))
214 {
215 return PVMFFailure;
216 }
217 num_parameter_elements = 1;
218 return PVMFSuccess;
219 }
220
221
222 ////////////////////////////////////////////////////////////////////////////
releaseParameters(PvmiMIOSession aSession,PvmiKvp * aParameters,int num_elements)223 PVMFStatus PVMFClientServerSocketPort::releaseParameters(PvmiMIOSession aSession,
224 PvmiKvp* aParameters,
225 int num_elements)
226 {
227 OSCL_UNUSED_ARG(aSession);
228 if ((num_elements != 1) ||
229 (pv_mime_strcmp(aParameters->key, PVMI_PORT_CONFIG_INPLACE_DATA_PROCESSING_VALUE) != 0))
230 {
231 return PVMFFailure;
232 }
233 OsclMemAllocator alloc;
234 alloc.deallocate((OsclAny*)(aParameters));
235 return PVMFSuccess;
236 }
237
238
239 ////////////////////////////////////////////////////////////////////////////
pvmiGetPortInPlaceDataProcessingInfoSync(const char * aFormatValType,PvmiKvp * & aKvp)240 bool PVMFClientServerSocketPort::pvmiGetPortInPlaceDataProcessingInfoSync(const char*
241 aFormatValType,
242 PvmiKvp*& aKvp)
243 {
244 //Create PvmiKvp for capability settings
245 aKvp = NULL;
246 OsclMemAllocator alloc;
247 uint32 strLen = oscl_strlen(aFormatValType) + 1;
248 uint8* ptr = (uint8*)alloc.allocate(sizeof(PvmiKvp) + strLen);
249
250 if (!ptr)
251 {
252 PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_ERR, (0, "PVMFClientServerSocketPort::pvmiGetPortInPlaceDataProcessingInfoSync: Error - No memory. Cannot allocate PvmiKvp"));
253 return false;
254 }
255
256 aKvp = new(ptr) PvmiKvp;
257 ptr += sizeof(PvmiKvp);
258 aKvp->key = (PvmiKeyType)ptr;
259 oscl_strncpy(aKvp->key, aFormatValType, strLen);
260 aKvp->length = aKvp->capacity = strLen;
261 aKvp->value.bool_value = true;
262 return true;
263 }
264