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 #include "video_only_test.h" 19 20 #ifndef PV_MP4_H263_ENC_EXTENSION_H_INCLUDED 21 #include "pvmp4h263encextension.h" 22 #endif 23 24 #define TRADEOFF_VALUE 5 25 #define TRADEOFF_VALUE_2 10 26 27 28 void video_only_test::test() 29 { 30 fprintf(fileoutput, "Start video only test, proxy %d SrcFormat:", iUseProxy); 31 32 printFormatString(iVidSrcFormatType); 33 34 fprintf(fileoutput, " SinkFormat:"); 35 36 printFormatString(iVidSinkFormatType); 37 38 fprintf(fileoutput, "\n"); 39 40 int error = 0; 41 42 scheduler = OsclExecScheduler::Current(); 43 44 this->AddToScheduler(); 45 46 init_mime_strings(); 47 48 if (start_async_test()) 49 { 50 OSCL_TRY(error, scheduler->StartScheduler()); 51 if (error != 0) 52 { 53 OSCL_LEAVE(error); 54 } 55 } 56 57 this->RemoveFromScheduler(); 58 } 59 60 61 void video_only_test::Run() 62 { 63 if (terminal) 64 { 65 if (iUseProxy) 66 { 67 CPV2WayProxyFactory::DeleteTerminal(terminal); 68 } 69 else 70 { 71 CPV2WayEngineFactory::DeleteTerminal(terminal); 72 } 73 terminal = NULL; 74 } 75 76 if (timer) 77 { 78 delete timer; 79 timer = NULL; 80 } 81 82 scheduler->StopScheduler(); 83 } 84 85 void video_only_test::DoCancel() 86 { 87 } 88 89 void video_only_test::HandleInformationalEvent(const PVAsyncInformationalEvent& aEvent) 90 { 91 int error = 0; 92 switch (aEvent.GetEventType()) 93 { 94 case PVT_INDICATION_OUTGOING_TRACK: 95 { 96 TPVChannelId *channel_id = (TPVChannelId *)(&aEvent.GetLocalBuffer()[4]); 97 printf("Indication with logical channel #%d ", *channel_id); 98 if (aEvent.GetLocalBuffer()[0] == PV_AUDIO) 99 { 100 printf("Audio"); 101 } 102 else if (aEvent.GetLocalBuffer()[0] == PV_VIDEO) 103 { 104 iOutgoingVideo = *channel_id; 105 iSelVideoSource = get_video_source(iVidSrcFormatType); 106 if (iSelVideoSource != NULL) 107 { 108 OSCL_TRY(error, iVideoAddSourceId = terminal->AddDataSource(*channel_id, *iSelVideoSource)); 109 printf("Video"); 110 } 111 } 112 else 113 { 114 printf("unknown"); 115 } 116 printf(" outgoing Track\n"); 117 break; 118 } 119 120 case PVT_INDICATION_INCOMING_TRACK: 121 { 122 TPVChannelId *channel_id = (TPVChannelId *)(&aEvent.GetLocalBuffer()[4]); 123 printf("Indication with logical channel #%d ", *channel_id); 124 if (aEvent.GetLocalBuffer()[0] == PV_AUDIO) 125 { 126 printf("Audio"); 127 } 128 else if (aEvent.GetLocalBuffer()[0] == PV_VIDEO) 129 { 130 iIncomingVideo = *channel_id; 131 iSelVideoSink = get_video_sink(iVidSinkFormatType); 132 if (iSelVideoSink != NULL) 133 { 134 OSCL_TRY(error, iVideoAddSinkId = terminal->AddDataSink(*channel_id, *iSelVideoSink)); 135 printf("Video"); 136 } 137 } 138 else 139 { 140 printf("unknown"); 141 } 142 printf(" incoming Track\n"); 143 break; 144 } 145 146 case PVT_INDICATION_DISCONNECT: 147 iAudioSourceAdded = false; 148 iVideoSourceAdded = false; 149 iAudioSinkAdded = false; 150 iVideoSinkAdded = false; 151 break; 152 153 case PVT_INDICATION_CLOSE_TRACK: 154 break; 155 156 case PVT_INDICATION_INTERNAL_ERROR: 157 break; 158 159 default: 160 break; 161 } 162 } 163 164 void video_only_test::H324MConfigCommandCompletedL(PVMFCmdResp& aResponse) 165 { 166 OSCL_UNUSED_ARG(aResponse); 167 } 168 169 void video_only_test::H324MConfigHandleInformationalEventL(PVMFAsyncEvent& aEvent) 170 { 171 switch (aEvent.GetEventType()) 172 { 173 case PV_INDICATION_VIDEO_SPATIAL_TEMPORAL_TRADEOFF_COMMAND: 174 if (aEvent.GetLocalBuffer()[2] == TRADEOFF_VALUE) 175 { 176 H324MConfigInterface * i324Interface = (H324MConfigInterface *)i324mConfigInterface; 177 iTradeOffInd = i324Interface->SendVideoTemporalSpatialTradeoffIndication(iOutgoingVideo, TRADEOFF_VALUE_2); 178 } 179 break; 180 case PV_INDICATION_VIDEO_SPATIAL_TEMPORAL_TRADEOFF_INDICATION: 181 if (aEvent.GetLocalBuffer()[2] == TRADEOFF_VALUE_2) 182 { 183 test_is_true(true); 184 timer->RunIfNotReady(TEST_DURATION); 185 } 186 break; 187 } 188 } 189 190 void video_only_test::DoStuffWithH324MConfig() 191 { 192 H324MConfigInterface * i324Interface = (H324MConfigInterface *)i324mConfigInterface; 193 i324Interface->SetObserver(this); 194 iTradeOffCmd = i324Interface->SendVideoTemporalSpatialTradeoffCommand(iIncomingVideo, TRADEOFF_VALUE); 195 iEncIFCommandId = terminal->QueryInterface(PVMp4H263EncExtensionUUID, iVidEncIFace); 196 } 197 198 void video_only_test::VideoAddSinkSucceeded() 199 { 200 iVideoSinkAdded = true; 201 if (iVideoSourceAdded) 202 { 203 i324mConfigInterface = iH324MConfig; 204 // OSCL_TRY(error, i324mIFCommandId = terminal->QueryInterface(PVH324MConfigUuid, i324mConfigInterface,NULL)); 205 if (i324mConfigInterface == NULL) 206 { 207 test_is_true(false); 208 disconnect(); 209 } 210 DoStuffWithH324MConfig(); 211 } 212 } 213 void video_only_test::VideoAddSourceSucceeded() 214 { 215 iVideoSourceAdded = true; 216 if (iVideoSinkAdded) 217 { 218 i324mConfigInterface = iH324MConfig; 219 // OSCL_TRY(error, i324mIFCommandId = terminal->QueryInterface(PVH324MConfigUuid, i324mConfigInterface,NULL)); 220 if (i324mConfigInterface == NULL) 221 { 222 test_is_true(false); 223 disconnect(); 224 } 225 DoStuffWithH324MConfig(); 226 } 227 } 228 void video_only_test::VideoAddSourceFailed() 229 { 230 if (iVidSrcFormatType == PVMF_MIME_M4V) 231 { 232 test_is_true(true); 233 } 234 else 235 { 236 test_is_true(false); 237 } 238 disconnect(); 239 } 240 241 void video_only_test::EncoderIFSucceeded() 242 { 243 PVMp4H263EncExtensionInterface *iface = (PVMp4H263EncExtensionInterface *)iVidEncIFace; 244 iface->RequestIFrame(); 245 } 246 void video_only_test::EncoderIFFailed() 247 { 248 EncoderIFSucceeded(); 249 } 250 void video_only_test::DisCmdFailed() 251 { 252 DisCmdSucceeded(); 253 } 254 void video_only_test::DisCmdSucceeded() 255 { 256 printf("Finished disconnecting \n"); 257 // destroy_sink_source(); 258 if (i324mConfigInterface) 259 i324mConfigInterface->removeRef(); 260 reset(); 261 } 262 263 void video_only_test::InitFailed() 264 { 265 test_is_true(false); 266 test_base::InitFailed(); 267 } 268 269 void video_only_test::ConnectSucceeded() 270 { 271 } 272 273 void video_only_test::ConnectFailed() 274 { 275 } 276 277 void video_only_test::TimerCallback() 278 { 279 int error = 1; 280 281 if (iSelVideoSource != NULL) 282 { 283 OSCL_TRY(error, iVideoRemoveSourceId = terminal->RemoveDataSource(*iSelVideoSource)); 284 if (error) 285 { 286 test_is_true(false); 287 disconnect(); 288 } 289 } 290 } 291 292 bool video_only_test::start_async_test() 293 { 294 timer = new engine_timer(this); 295 if (timer == NULL) 296 { 297 test_is_true(false); 298 return false; 299 } 300 timer->AddToScheduler(); 301 302 303 return test_base::start_async_test(); 304 } 305 306 307 308 309 310