• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "audio_only_test.h"
19 
20 
test()21 void audio_only_test::test()
22 {
23     fprintf(fileoutput, "Start audio only test, proxy %d,SrcFormat:", iUseProxy);
24 
25     printFormatString(iAudSrcFormatType);
26 
27     fprintf(fileoutput, " SinkFormat:");
28 
29     printFormatString(iAudSinkFormatType);
30 
31     fprintf(fileoutput, "\n");
32 
33     int error = 0;
34 
35     scheduler = OsclExecScheduler::Current();
36 
37     this->AddToScheduler();
38 
39     init_mime_strings();
40 
41     if (start_async_test())
42     {
43         OSCL_TRY(error, scheduler->StartScheduler());
44         if (error != 0)
45         {
46             test_is_true(false);
47             OSCL_LEAVE(error);
48         }
49     }
50 
51     this->RemoveFromScheduler();
52     test_is_true(iTestStatus);
53 }
54 
55 
Run()56 void audio_only_test::Run()
57 {
58     if (terminal)
59     {
60         if (iUseProxy)
61         {
62             CPV2WayProxyFactory::DeleteTerminal(terminal);
63         }
64         else
65         {
66             CPV2WayEngineFactory::DeleteTerminal(terminal);
67         }
68         terminal = NULL;
69     }
70 
71     if (timer)
72     {
73         delete timer;
74         timer = NULL;
75     }
76 
77     scheduler->StopScheduler();
78 }
79 
DoCancel()80 void audio_only_test::DoCancel()
81 {
82 }
83 
84 
HandleInformationalEvent(const PVAsyncInformationalEvent & aEvent)85 void audio_only_test::HandleInformationalEvent(const PVAsyncInformationalEvent& aEvent)
86 {
87     int error = 0;
88     switch (aEvent.GetEventType())
89     {
90         case PVT_INDICATION_OUTGOING_TRACK:
91         {
92             TPVChannelId *channel_id = (TPVChannelId *)(&aEvent.GetLocalBuffer()[4]);
93             printf("Indication with logical channel #%d ", *channel_id);
94             if (aEvent.GetLocalBuffer()[0] == PV_AUDIO && isFirstSink)
95             {
96                 isFirstSink = false;
97                 iSelAudioSource = get_audio_source(iAudSrcFormatType);
98                 if (iSelAudioSource != NULL)
99                 {
100                     OSCL_TRY(error, iAudioAddSourceId = terminal->AddDataSource(*channel_id, *iSelAudioSource));
101                     printf("Audio");
102                 }
103             }
104             else if (aEvent.GetLocalBuffer()[0] == PV_VIDEO)
105             {
106                 printf("Video");
107             }
108             else
109             {
110                 printf("unknown");
111             }
112             printf(" outgoing Track\n");
113             break;
114         }
115 
116         case PVT_INDICATION_INCOMING_TRACK:
117         {
118             TPVChannelId *channel_id = (TPVChannelId *)(&aEvent.GetLocalBuffer()[4]);
119             printf("Indication with logical channel #%d ", *channel_id);
120             if (aEvent.GetLocalBuffer()[0] == PV_AUDIO && isFirstSrc)
121             {
122                 isFirstSrc = false;
123                 iSelAudioSink = get_audio_sink(iAudSinkFormatType);
124                 if (iSelAudioSink != NULL)
125                 {
126                     OSCL_TRY(error, iAudioAddSinkId = terminal->AddDataSink(*channel_id, *iSelAudioSink));
127                     printf("Audio");
128                 }
129             }
130             else if (aEvent.GetLocalBuffer()[0] == PV_VIDEO)
131             {
132                 printf("Video");
133             }
134             else
135             {
136                 printf("unknown");
137             }
138             printf(" incoming Track\n");
139             break;
140         }
141 
142         case PVT_INDICATION_DISCONNECT:
143             iAudioSourceAdded = false;
144             iVideoSourceAdded = false;
145             iAudioSinkAdded = false;
146             iVideoSinkAdded = false;
147             break;
148 
149         case PVT_INDICATION_CLOSE_TRACK:
150             break;
151 
152         case PVT_INDICATION_INTERNAL_ERROR:
153             break;
154 
155         default:
156             break;
157     }
158 }
159 
ConnectSucceeded()160 void audio_only_test::ConnectSucceeded()
161 {
162 }
163 
ConnectFailed()164 void audio_only_test::ConnectFailed()
165 {
166     reset();
167 }
168 
169 
TimerCallback()170 void audio_only_test::TimerCallback()
171 {
172     int error = 1;
173     timer_elapsed = true;
174     if (iSelAudioSource != NULL)
175     {
176         OSCL_TRY(error, iAudioRemoveSourceId = terminal->RemoveDataSource(*iSelAudioSource));
177     }
178     if (error)
179     {
180         iTestStatus &= false;
181         disconnect();
182     }
183     else
184     {
185         error = 1;
186         if (iSelAudioSink != NULL)
187         {
188             OSCL_TRY(error, iAudioRemoveSinkId = terminal->RemoveDataSink(*iSelAudioSink));
189         }
190         if (error)
191         {
192             iTestStatus &= false;
193             disconnect();
194         }
195     }
196 
197 }
198 
199 
start_async_test()200 bool audio_only_test::start_async_test()
201 {
202     timer = new engine_timer(this);
203     if (timer == NULL)
204     {
205         iTestStatus &= false;
206         return false;
207     }
208 
209     iAudioSourceAdded = false;
210     iAudioSinkAdded = false;
211     isFirstSink = true;
212     isFirstSrc = true;
213 
214     timer->AddToScheduler();
215 
216 
217     return test_base::start_async_test();
218 }
219 
220 
221