2 #include "ace/Get_Opt.h"
3 #include "ace/High_Res_Timer.h"
5 static FILE *output_file
= 0;
6 // File handle of the file into which received data is written.
8 static const ACE_TCHAR
*output_file_name
= ACE_TEXT ("output");
9 // File name of the file into which received data is written.
14 Receiver_StreamEndPoint::get_callback (const char *,
15 TAO_AV_Callback
*&callback
)
17 // Return the receiver application callback to the AVStreams for
19 callback
= &this->callback_
;
23 Receiver_Callback::Receiver_Callback ()
29 Receiver_Callback::receive_frame (ACE_Message_Block
*frame
,
34 // Upcall from the AVStreams when there is data to be received from
38 "Receiver_Callback::receive_frame for frame %d\n",
39 this->frame_count_
++));
41 int frame_size
= BUFSIZ
;
43 // Write the received data to the file.
45 ACE_OS::fwrite (frame
->rd_ptr (),
50 if (result
== frame
->length ())
51 ACE_ERROR_RETURN ((LM_ERROR
,
52 "Receiver_Callback::fwrite failed\n"),
54 frame
->rd_ptr (frame_size
);
57 ACE_OS::memcpy (&stamp
, frame
->rd_ptr (), sizeof (stamp
));
59 ACE_UINT64 usec
= stamp
;
60 ACE_UINT32 val_1
= ACE_CU64_TO_CU32 (usec
);
71 Receiver_Callback::handle_destroy ()
73 // Called when the distributer requests the stream to be shutdown.
75 "Receiver_Callback::end_stream\n"));
86 Receiver::~Receiver ()
94 // Initialize the endpoint strategy with the orb and poa.
96 this->reactive_strategy_
.init (TAO_AV_CORE::instance ()->orb (),
97 TAO_AV_CORE::instance ()->poa ());
101 // Register the receiver mmdevice object with the ORB
102 ACE_NEW_RETURN (this->mmdevice_
,
103 TAO_MMDevice (&this->reactive_strategy_
),
106 // Servant Reference Counting to manage lifetime
107 PortableServer::ServantBase_var safe_mmdevice
=
110 CORBA::Object_var mmdevice
=
111 this->mmdevice_
->_this ();
113 // Register the mmdevice with the naming service.
114 CosNaming::Name
name (1);
117 CORBA::string_dup ("Receiver");
119 // Initialize the naming services
120 if (this->naming_client_
.init (TAO_AV_CORE::instance ()->orb ()) != 0)
121 ACE_ERROR_RETURN ((LM_ERROR
,
122 "Unable to initialize "
123 "the TAO_Naming_Client\n"),
126 // Register the receiver object with the naming server.
127 this->naming_client_
->rebind (name
,
134 parse_args (int argc
,
137 // Parse the command line arguments
138 ACE_Get_Opt
opts (argc
,
143 while ((c
= opts ()) != -1)
148 output_file_name
= opts
.opt_arg ();
151 ACE_ERROR_RETURN ((LM_ERROR
,
152 "Usage: receiver -f filename"),
166 ACE_High_Res_Timer::global_scale_factor ();
168 // Initialize the ORB first.
170 CORBA::ORB_init (argc
, argv
);
172 CORBA::Object_var obj
173 = orb
->resolve_initial_references ("RootPOA");
175 // Get the POA_var object from Object_var.
176 PortableServer::POA_var root_poa
=
177 PortableServer::POA::_narrow (obj
.in ());
179 PortableServer::POAManager_var mgr
180 = root_poa
->the_POAManager ();
184 // Initialize the AVStreams components.
185 TAO_AV_CORE::instance ()->init (orb
.in (),
195 // Make sure we have a valid <output_file>
196 output_file
= ACE_OS::fopen (output_file_name
,
198 if (output_file
== 0)
199 ACE_ERROR_RETURN ((LM_DEBUG
,
200 "Cannot open output file %s\n",
205 ACE_DEBUG ((LM_DEBUG
,
206 "File Opened Successfully\n"));
218 orb
->perform_work ();
226 catch (const CORBA::Exception
& ex
)
228 ex
._tao_print_exception ("receiver::init");
232 ACE_OS::fclose (output_file
);