1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
// $Id$
#include "ping.h"
#include "orbsvcs/AV/Protocol_Factory.h"
#include "tao/corba.h"
#include "tao/Strategies/advanced_resource.h"
#include "ace/Get_Opt.h"
#include "ace/High_Res_Timer.h"
#include "ace/Stats.h"
ACE_RCSID(Latency, ping, "$Id$")
const char *ior_output_file = "ping.ior";
const char *protocol = "RTP/UDP";
int milliseconds = 100;
int respond = 1;
AVStreams::protocolSpec ping_protocols;
AVStreams::protocolSpec pong_protocols;
Pong_Send_Callback pong_callback;
ACE_hrtime_t recv_base = 0;
ACE_Throughput_Stats recv_latency;
int
parse_args (int argc, char *argv[])
{
ACE_Get_Opt get_opts (argc, argv, "xo:s:r:t:");
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case 'o':
ior_output_file = get_opts.opt_arg ();
break;
case 'r':
{
CORBA::ULong l = ping_protocols.length ();
ping_protocols.length (l + 1);
ping_protocols[l] = CORBA::string_dup (get_opts.opt_arg ());
}
break;
case 's':
{
CORBA::ULong l = pong_protocols.length ();
pong_protocols.length (l + 1);
pong_protocols[l] = CORBA::string_dup (get_opts.opt_arg ());
}
break;
case 't':
milliseconds = ACE_OS::atoi (get_opts.opt_arg ());
break;
case 'x':
respond = 0;
break;
case '?':
default:
ACE_ERROR_RETURN ((LM_ERROR,
"usage: %s "
"-o <iorfile> "
"-r <protocol=addr> "
"-s <protocol=addr> "
"-t <milliseconds> "
"\n",
argv [0]),
-1);
}
// If no protocols are specified use the default...
if (ping_protocols.length () == 0)
{
ping_protocols.length (1);
ping_protocols[0] = CORBA::string_dup ("UDP=224.9.9.2:12345");
}
if (pong_protocols.length () == 0)
{
pong_protocols.length (1);
pong_protocols[0] = CORBA::string_dup ("UDP=224.9.9.2:23456");
}
// Indicates sucessful parsing of the command line
return 0;
}
int main (int argc, char *argv[])
{
ACE_TRY_NEW_ENV
{
parse_args (argc, argv);
CORBA::ORB_var orb = CORBA::ORB_init (argc,
argv);
CORBA::Object_var obj
= orb->resolve_initial_references ("RootPOA" TAO_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
PortableServer::POA_var poa
= PortableServer::POA::_narrow (obj.in ());
PortableServer::POAManager_var mgr
= poa->the_POAManager ();
mgr->activate ();
TAO_AV_CORE::instance ()->init (orb.in (),
poa.in ()
TAO_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// Register the video mmdevice object with the ORB
Reactive_Strategy *reactive_strategy;
ACE_NEW_RETURN (reactive_strategy,
Reactive_Strategy,
1);
reactive_strategy->init (orb.in (), poa.in ());
TAO_MMDevice *mmdevice_impl;
ACE_NEW_RETURN (mmdevice_impl,
TAO_MMDevice (reactive_strategy),
1);
AVStreams::MMDevice_var mmdevice =
mmdevice_impl->_this (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
CORBA::String_var ior =
orb->object_to_string (mmdevice.in () TAO_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "Activated as <%s>\n", ior.in ()));
// If the ior_output_file exists, output the ior to it
if (ior_output_file != 0)
{
FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
if (output_file == 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Cannot open output file for writing IOR: %s",
ior_output_file),
1);
ACE_OS::fprintf (output_file, "%s", ior.in ());
ACE_OS::fclose (output_file);
}
Ping_Recv_FDev* ping_fdev_impl;
ACE_NEW_RETURN (ping_fdev_impl,
Ping_Recv_FDev ("Ping"),
1);
Pong_Send_FDev* pong_fdev_impl;
ACE_NEW_RETURN (pong_fdev_impl,
Pong_Send_FDev ("Pong"),
1);
AVStreams::FDev_var ping_fdev =
ping_fdev_impl->_this (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
AVStreams::FDev_var pong_fdev =
pong_fdev_impl->_this (TAO_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
mmdevice->add_fdev (ping_fdev.in () TAO_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (respond == 1)
{
mmdevice->add_fdev (pong_fdev.in () TAO_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
orb->run ();
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "Calibrating scale factory . . . "));
ACE_UINT32 gsf = ACE_High_Res_Timer::global_scale_factor ();
ACE_DEBUG ((LM_DEBUG, "done %d \n", gsf));
recv_latency.dump_results ("Receive", gsf);
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"Caught exception:");
return 1;
}
ACE_ENDTRY;
return 0;
}
// ****************************************************************
Ping_Recv::Ping_Recv (void)
: TAO_FlowConsumer ("Ping",
ping_protocols,
"UNS:ping")
{
}
int
Ping_Recv::get_callback (const char *,
TAO_AV_Callback *&callback)
{
ACE_DEBUG ((LM_DEBUG,"Ping_Recv::get_callback\n"));
callback = &this->callback_;
return 0;
}
Ping_Recv_Callback::Ping_Recv_Callback (void)
: count_ (0)
{
}
int
Ping_Recv_Callback::handle_stop (void)
{
ACE_DEBUG ((LM_DEBUG,"Ping_Recv_Callback::stop"));
TAO_AV_CORE::instance ()->orb ()->shutdown ();
return 0;
}
int
Ping_Recv_Callback::receive_frame (ACE_Message_Block *frame,
TAO_AV_frame_info *,
const ACE_Addr &)
{
this->count_++;
ACE_DEBUG ((LM_DEBUG,"Ping_Recv_Callback::receive_frame %d\n", this->count_));
if (this->count_ < 10)
{
for (const ACE_Message_Block *i = frame;
i != 0;
i = i->cont ())
{
ACE_hrtime_t stamp;
if (i->length () < sizeof(stamp))
return 0;
ACE_OS::memcpy (&stamp, i->rd_ptr (), sizeof(stamp));
ACE_hrtime_t now = ACE_OS::gethrtime ();
if (recv_base == 0)
{
recv_base = now;
}
else
{
recv_latency.sample (now - recv_base,
now - stamp);
}
if (respond == 1)
pong_callback.send_response (stamp);
}
}
else
TAO_AV_CORE::instance ()->orb ()->shutdown ();
return 0;
}
int
Ping_Recv_Callback::handle_destroy (void)
{
ACE_DEBUG ((LM_DEBUG,"Ping_Recv_Callback::destroy\n"));
return 0;
}
// ****************************************************************
Pong_Send::Pong_Send (void)
: TAO_FlowProducer ("Pong",
pong_protocols,
"UNS:pong")
{
}
int
Pong_Send::get_callback (const char *,
TAO_AV_Callback *&callback)
{
ACE_DEBUG ((LM_DEBUG,"Pong_Send::get_callback\n"));
callback = &pong_callback;
return 0;
}
void
Pong_Send_Callback::get_timeout (ACE_Time_Value *&tv,
void *&)
{
// @@ ACE_NEW (tv, ACE_Time_Value (0, milliseconds * 1000));
tv = 0;
}
int
Pong_Send_Callback::handle_timeout (void *)
{
// ACE_DEBUG ((LM_DEBUG, "pong timeout (ignored)\n"));
return 0;
}
int
Pong_Send_Callback::handle_end_stream (void)
{
return 0;
}
int
Pong_Send_Callback::send_response (ACE_hrtime_t stamp)
{
ACE_DEBUG ((LM_DEBUG, "pong send response)\n"));
ACE_hrtime_t buf[2];
ACE_Message_Block mb (ACE_reinterpret_cast (char*,buf),
sizeof(buf));
buf[0] = stamp;
buf[1] = ACE_OS::gethrtime ();
mb.wr_ptr (sizeof(buf));
int result = this->protocol_object_->send_frame (&mb);
if (result < 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Pong_Send_Callback::send - %p\n",
""),
-1);
return 0;
}
// ****************************************************************
// @@ TODO
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class TAO_AV_Endpoint_Reactive_Strategy_B<TAO_StreamEndPoint_B, TAO_VDev, AV_Null_MediaCtrl>;
template class TAO_AV_Endpoint_Reactive_Strategy<TAO_StreamEndPoint_B, TAO_VDev, AV_Null_MediaCtrl>;
template class TAO_FDev<TAO_FlowProducer, Ping_Recv>;
template class TAO_FDev<Pong_Send, TAO_FlowConsumer>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate TAO_AV_Endpoint_Reactive_Strategy_B<TAO_StreamEndPoint_B, TAO_VDev, AV_Null_MediaCtrl>
#pragma instantiate TAO_AV_Endpoint_Reactive_Strategy<TAO_StreamEndPoint_B, TAO_VDev, AV_Null_MediaCtrl>
#pragma instantiate TAO_FDev<TAO_FlowProducer, Ping_Recv>
#pragma instantiate TAO_FDev<Pong_Send, TAO_FlowConsumer>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
|