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 #if defined(PV_PLAY_FROM_FILE_SUPPORT)
19 #include "pv_2way_preview_datapath.h"
20
NewL(PVLogger * aLogger,TPV2WayMediaType aFormat,CPV324m2Way * a2Way)21 CPV2WayPreviewDatapath *CPV2WayPreviewDatapath::NewL(PVLogger *aLogger,
22 TPV2WayMediaType aFormat,
23 CPV324m2Way *a2Way)
24 {
25 CPV2WayPreviewDatapath *self = OSCL_NEW(CPV2WayPreviewDatapath, (aLogger, aFormat, a2Way));
26 OsclError::LeaveIfNull(self);
27
28 if (self)
29 {
30 OSCL_TRAPSTACK_PUSH(self);
31 self->ConstructL();
32 }
33
34 OSCL_TRAPSTACK_POP();
35 return self;
36 }
37
CheckPause()38 void CPV2WayPreviewDatapath::CheckPause()
39 {
40 uint32 i;
41 int32 error;
42
43 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "CPV2WayDatapath::CheckPause state %d\n", iState));
44
45 for (i = 0; i < iNodeList.size(); i++)
46 {
47 if (!iNodeList[i].iCanNodePause) continue;
48
49 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "CPV2WayDatapath::CheckPause node %d state %d\n", i, iNodeList[i].iNode.iNode->GetState()));
50 switch (iNodeList[i].iNode.iNode->GetState())
51 {
52 case EPVMFNodeStarted:
53 OSCL_TRY(error, i2Way->SendNodeCmdL(PV2WAY_NODE_CMD_PAUSE, &(iNodeList[i].iNode), this));
54 OSCL_FIRST_CATCH_ANY(error,
55 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "CPV2WayDatapath::CheckPause unable to pause node\n"));
56 DatapathError();
57 return;);
58 break;
59
60 default:
61 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "CPV2WayDatapath::CheckPause transitional node state!\n"));
62 break;
63 }
64 }
65
66 for (i = 0; i < iNodeList.size(); i++)
67 {
68 //If possible pause node is not paused.
69 if (iNodeList[i].iCanNodePause && (iNodeList[i].iNode.iNode->GetState() != EPVMFNodePaused))
70 {
71 return;
72 }
73 }
74
75 //Disconnect ports
76 for (i = 0; i < iPortPairList.size(); i++)
77 {
78 iPortPairList[i].Disconnect();
79 }
80
81 //If reached this point then the datapath is deemed paused, notify upper layer.
82 SetState(EPaused);
83 PauseComplete();
84 return;
85 }
86
CheckResume()87 void CPV2WayPreviewDatapath::CheckResume()
88 {
89 uint32 i;
90 int32 error;
91
92 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "CPV2WayDatapath::CheckResume state %d\n", iState));
93
94 for (i = 0; i < iNodeList.size(); i++)
95 {
96 if (!iNodeList[i].iCanNodePause) continue;
97
98 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "CPV2WayDatapath::CheckResume node %d state %d\n", i, iNodeList[i].iNode.iNode->GetState()));
99 switch (iNodeList[i].iNode.iNode->GetState())
100 {
101 case EPVMFNodePaused:
102 OSCL_TRY(error, i2Way->SendNodeCmdL(PV2WAY_NODE_CMD_START, &(iNodeList[i].iNode), this));
103 OSCL_FIRST_CATCH_ANY(error,
104 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "CPV2WayDatapath::CheckResume unable to pause node\n"));
105 DatapathError();
106 return;);
107 break;
108
109 default:
110 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "CPV2WayDatapath::CheckResume transitional node state!\n"));
111 break;
112 }
113 }
114
115 for (i = 0; i < iNodeList.size(); i++)
116 {
117 //If possible pause node is not started.
118 if (iNodeList[i].iCanNodePause && (iNodeList[i].iNode.iNode->GetState() != EPVMFNodeStarted))
119 {
120 return;
121 }
122 }
123
124 //Reconnect ports
125 for (i = 0; i < iPortPairList.size(); i++)
126 {
127 iPortPairList[i].Connect();
128 }
129
130 //If reached this point then the datapath is deemed resumed, notify upper layer.
131 SetState(EOpened);
132 ResumeComplete();
133 return;
134 }
135
SetCmd(TPV2WayCmdInfo * aCmdInfo)136 bool CPV2WayPreviewDatapath::SetCmd(TPV2WayCmdInfo *aCmdInfo)
137 {
138 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "CPV2WayPreviewDatapath::SetCmd state %d cmd %x\n", iState, aCmdInfo));
139
140 if (aCmdInfo)
141 {
142 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "CPV2WayPreviewDatapath::SetCmd cmd type %d\n", aCmdInfo->type));
143 switch (aCmdInfo->type)
144 {
145 default:
146 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "CPV2WayPreviewDatapath::SetCmd invalid command\n"));
147 break;
148 }
149
150 }
151 // A null pointer indicates a close for some reason
152 else
153 {
154 if (!CloseDatapath(aCmdInfo)) return false;
155 }
156
157 return true;
158 }
159
OpenComplete()160 void CPV2WayPreviewDatapath::OpenComplete()
161 {
162 CommandComplete(PVMFSuccess);
163 }
164
CloseComplete()165 void CPV2WayPreviewDatapath::CloseComplete()
166 {
167 //If parent was closing, then let it notify the app.
168 if (!IsParentClosing())
169 {
170 //If a command was issued
171 if (iCmdInfo)
172 {
173 //If remove command was issued
174 if (iCmdInfo->type == PVT_COMMAND_REMOVE_PREVIEW_SINK)
175 {
176 CommandComplete(PVMFSuccess);
177 }
178 //Else other command failed
179 else
180 {
181 CommandComplete(PVMFFailure);
182 }
183 }
184 else
185 {
186 int32 error;
187 TPV2WayEventInfo* aEvent = NULL;
188 OSCL_TRY(error, aEvent = i2Way->GetEventInfoL());
189 OSCL_FIRST_CATCH_ANY(error,
190 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "CPV2WayPreviewDatapath::CloseComplete unable to notify app!\n"));
191 return);
192
193 aEvent->type = PVT_INDICATION_PREVIEW_ERROR;
194 aEvent->localBuffer[2] = 0;
195 switch (iFormat)
196 {
197 case PV2WayAudio:
198 aEvent->localBuffer[0] = PV_AUDIO;
199 break;
200 case PV2WayVideo:
201 aEvent->localBuffer[0] = PV_VIDEO;
202 break;
203 case PV2WayMuxData:
204 default:
205 break;
206 }
207
208 aEvent->localBufferSize = 2;
209 i2Way->Dispatch(aEvent);
210 }
211 }
212 }
213
DatapathError()214 void CPV2WayPreviewDatapath::DatapathError()
215 {
216 SetCmd(NULL);
217 }
218
ParentIsClosing()219 bool CPV2WayPreviewDatapath::ParentIsClosing()
220 {
221 PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "CPV2WayPreviewDatapath::ParentIsClosing path state %d\n", iState));
222 return SetCmd(NULL);
223 }
224
225 #endif
226
227
228