3 #include "ace/Get_Opt.h"
4 #include "ace/High_Res_Timer.h"
6 ACE_High_Res_Timer last_frame_sent_time
;
7 // The time taken for sending a frmae and preparing for the next frame
9 ACE_Time_Value inter_frame_time
;
10 // The time that should lapse between two consecutive frames sent.
12 FTP_Client_Callback::FTP_Client_Callback ()
16 FTP_Client_StreamEndPoint::FTP_Client_StreamEndPoint ()
21 FTP_Client_StreamEndPoint::get_callback (const char *,
22 TAO_AV_Callback
*&callback
)
24 // Create and return the clienmt application callback and return to the AVStreams
25 // for further upcalls.
26 callback
= &this->callback_
;
31 FTP_Client_StreamEndPoint::set_protocol_object (const char *,
32 TAO_AV_Protocol_Object
*object
)
34 // Set the client protocol object corresponding to the transport protocol selected.
35 CLIENT::instance ()->set_protocol_object (object
);
40 :client_mmdevice_ (&endpoint_strategy_
),
45 protocol_ (ACE_OS::strdup ("UDP")),
48 this->mb
.size (BUFSIZ
);
52 Client::set_protocol_object (TAO_AV_Protocol_Object
*object
)
54 // Set the client protocol object corresponding to the transport protocol selected.
55 this->protocol_object_
= object
;
59 Client::parse_args (int argc
,
62 // Parse command line arguments
63 ACE_Get_Opt
opts (argc
, argv
, ACE_TEXT("f:l:a:p:r:sd"));
68 while ((c
= opts ()) != -1)
73 this->filename_
= ACE_OS::strdup (ACE_TEXT_ALWAYS_CHAR (opts
.opt_arg ()));
76 this->address_
= ACE_OS::strdup (ACE_TEXT_ALWAYS_CHAR (opts
.opt_arg ()));
79 this->peer_addr_str_
= ACE_OS::strdup (ACE_TEXT_ALWAYS_CHAR (opts
.opt_arg ()));
82 this->protocol_
= ACE_OS::strdup (ACE_TEXT_ALWAYS_CHAR (opts
.opt_arg ()));
85 this->frame_rate_
= ACE_OS::atoi (opts
.opt_arg ());
94 ACE_DEBUG ((LM_DEBUG
,"Unknown Option\n"));
110 return this->flowname_
;
114 Client::streamctrl ()
116 return &this->streamctrl_
;
121 Client::frame_rate ()
123 return this->frame_rate_
;
127 // Method to get the object reference of the server
129 Client::bind_to_server ()
131 // Initialize the naming services
132 if (my_naming_client_
.init (TAO_AV_CORE::instance ()->orb ()) != 0)
133 ACE_ERROR_RETURN ((LM_ERROR
,
134 " (%P|%t) Unable to initialize "
135 "the TAO_Naming_Client.\n"),
138 CosNaming::Name
server_mmdevice_name (1);
139 server_mmdevice_name
.length (1);
140 server_mmdevice_name
[0].id
= CORBA::string_dup ("Server_MMDevice");
142 // Resolve the server object reference from the Naming Service
143 CORBA::Object_var server_mmdevice_obj
=
144 my_naming_client_
->resolve (server_mmdevice_name
);
146 this->server_mmdevice_
=
147 AVStreams::MMDevice::_narrow (server_mmdevice_obj
.in ());
149 if (CORBA::is_nil (this->server_mmdevice_
.in ()))
150 ACE_ERROR_RETURN ((LM_ERROR
,
151 "Could not resolve Server_MMdevice in Naming service <%s>\n"),
158 Client::init (int argc
,
164 CORBA::String_var ior
;
166 // Initialize the endpoint strategy with the orb and poa.
167 this->endpoint_strategy_
.init(TAO_AV_CORE::instance ()->orb (),
168 TAO_AV_CORE::instance ()->poa ());
170 // Parse the command line arguments
171 int result
= this->parse_args (argc
,
177 // Open file to read.
178 this->fp_
= ACE_OS::fopen (this->filename_
,
181 ACE_ERROR_RETURN ((LM_DEBUG
,
182 "Cannot open input file %s\n",
187 = this->bind_to_server ();
189 // Resolve the object reference of the server from the Naming Service.
191 ACE_ERROR_RETURN ((LM_ERROR
,
192 "(%P|%t) Error binding to the naming service\n"),
195 // Create the Flow protocol name
196 char flow_protocol_str
[BUFSIZ
];
198 ACE_OS::strcpy (flow_protocol_str
,
201 ACE_OS::strcpy (flow_protocol_str
,
204 // Initialize the QoS
205 AVStreams::streamQoS_var
the_qos (new AVStreams::streamQoS
);
207 // Set the address of the ftp client.
209 if (this->address_
!= 0)
210 ACE_NEW_RETURN (addr
,
211 ACE_INET_Addr (this->address_
),
216 ACE_OS::hostname (buf
,
218 ACE_NEW_RETURN (addr
,
219 ACE_INET_Addr ("5000",
224 // Initialize the flowname
225 ACE_NEW_RETURN (this->flowname_
,
229 ACE_OS::sprintf (this->flowname_
,
233 // Create the forward flow specification to describe the flow.
234 TAO_Forward_FlowSpec_Entry
entry (this->flowname_
,
241 ACE_INET_Addr
* peer_addr
;
242 if (this->peer_addr_str_
!= 0)
243 ACE_NEW_RETURN (peer_addr
,
244 ACE_INET_Addr (this->peer_addr_str_
),
249 ACE_OS::hostname (buf
,
251 ACE_NEW_RETURN (peer_addr
,
252 ACE_INET_Addr ("5050",
257 entry
.set_peer_addr (peer_addr
);
259 AVStreams::flowSpec
flow_spec (1);
260 flow_spec
.length (1);
261 flow_spec
[0] = CORBA::string_dup (entry
.entry_to_string ());
263 AVStreams::MMDevice_var client_mmdevice
=
264 this->client_mmdevice_
._this ();
266 // Bind/Connect the client and server MMDevices.
267 CORBA::Boolean bind_result
=
268 this->streamctrl_
.bind_devs (client_mmdevice
.in (),
269 this->server_mmdevice_
.in (),
273 if (bind_result
== 0)
274 ACE_ERROR_RETURN ((LM_ERROR
,"streamctrl::bind_devs failed\n"),-1);
279 // Method to send data at the specified rate
283 // Rate at which frames of data need to be sent.
284 this->frame_rate_
= CLIENT::instance ()->frame_rate ();
286 // Time within which a frame should be sent.
287 double frame_time
= 1/ (double) this->frame_rate_
;
289 if (TAO_debug_level
> 0)
290 ACE_DEBUG ((LM_DEBUG
,
291 "Frame Time ONE = %f\n Frame Rate = %d\n",
295 // The time between two consecutive frames.
296 inter_frame_time
.set (frame_time
);
298 if (TAO_debug_level
> 0)
299 ACE_DEBUG ((LM_DEBUG
,
300 "Inter Frame Time = %d\n",
301 inter_frame_time
.msec ()));
305 // Continue to send data till the file is read to the end.
308 // Count the frames sent.
311 // Read from the file into a message block.
312 size_t n
= ACE_OS::fread(this->mb
.rd_ptr (),
315 CLIENT::instance ()->file ());
319 if (feof (CLIENT::instance ()->file ()))
321 // At end of file break the loop and end the client.
322 if (TAO_debug_level
> 0)
323 ACE_DEBUG ((LM_DEBUG
,"Handle_Start:End of file\n"));
331 if ( this->count_
> 1)
333 // Greater than the first frame.
335 // Stop the timer that was started just before the previous frame was sent.
336 last_frame_sent_time
.stop ();
338 // Get the time elapsed after sending the previous frame.
340 last_frame_sent_time
.elapsed_time (tv
);
342 if (TAO_debug_level
> 0)
343 ACE_DEBUG ((LM_DEBUG
,
344 "Elapsed Time = %d\n",
347 // Check to see if the inter frame time has elapsed.
348 if (tv
< inter_frame_time
)
350 // Inter frame time has not elapsed.
352 // Claculate the time to wait before the next frame needs to be sent.
353 ACE_Time_Value
wait_time (inter_frame_time
- tv
);
355 if (TAO_debug_level
> 0)
356 ACE_DEBUG ((LM_DEBUG
,
360 // run the orb for the wait time so the client can continue other orb requests.
361 TAO_AV_CORE::instance ()->orb ()->run (wait_time
);
365 // Start timer before sending the frame.
366 last_frame_sent_time
.start ();
369 int result
= this->protocol_object_
->send_frame (&this->mb
);
371 ACE_ERROR_RETURN ((LM_ERROR
,
372 "send failed:%p","FTP_Client_Flow_Handler::send\n"),
374 ACE_DEBUG ((LM_DEBUG
,"Client::pace_data buffer sent successfully\n"));
380 // Since the file is read stop the stream.
381 AVStreams::flowSpec
stop_spec (1);
382 CLIENT::instance ()->streamctrl ()->destroy (stop_spec
);
384 // Shut the orb down.
385 TAO_AV_CORE::instance ()->orb ()->shutdown (0);
387 catch (const CORBA::Exception
& ex
)
389 ex
._tao_print_exception ("Client::pace_data Failed");
396 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
400 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
402 CORBA::Object_var obj
403 = orb
->resolve_initial_references ("RootPOA");
406 //Get the POA_var object from Object_var
407 PortableServer::POA_var root_poa
408 = PortableServer::POA::_narrow (obj
.in ());
410 PortableServer::POAManager_var mgr
411 = root_poa
->the_POAManager ();
415 // Initialize the AV STream components.
416 TAO_AV_CORE::instance ()->init (orb
.in (),
419 // INitialize the Client.
421 result
= CLIENT::instance ()->init (argc
,
425 ACE_ERROR_RETURN ((LM_ERROR
,
426 "client::init failed\n"),1);
428 // Start sending data.
429 result
= CLIENT::instance ()->pace_data ();
433 catch (const CORBA::Exception
& ex
)
436 ex
._tao_print_exception ("Client Failed\n");
445 #if defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION)
446 template ACE_Unmanaged_Singleton
<Client
, ACE_Null_Mutex
> *ACE_Unmanaged_Singleton
<Client
, ACE_Null_Mutex
>::singleton_
;
447 #endif /* ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION */