2 #include "ace/Get_Opt.h"
4 static FILE *output_file
= 0;
5 // File handle of the file into which received data is written.
7 static const ACE_TCHAR
*output_file_name
= ACE_TEXT ("output");
8 // File name of the file into which received data is written.
11 Receiver_StreamEndPoint::get_callback (const char *,
12 TAO_AV_Callback
*&callback
)
14 // Return the receiver application callback to the AVStreams for
16 callback
= &this->callback_
;
19 // Get the stream controller for this stream.
22 CORBA::Any_ptr streamctrl_any
=
23 this->get_property_value ("Related_StreamCtrl");
25 AVStreams::StreamCtrl_ptr streamctrl
;
26 *streamctrl_any
>>= streamctrl
;
28 // Store the stream control for the stream with the callback.
29 this->callback_
.streamctrl (streamctrl
);
31 catch (const CORBA::Exception
& ex
)
33 ex
._tao_print_exception ("Sender_StreamEndPoint::get_callback failed");
41 Receiver_Callback::Receiver_Callback ()
47 Receiver_Callback::streamctrl (AVStreams::StreamCtrl_ptr streamctrl
)
49 // Set the sender protocol object corresponding to the transport
51 this->streamctrl_
= streamctrl
;
56 Receiver_Callback::receive_frame (ACE_Message_Block
*frame
,
61 // Upcall from the AVStreams when there is data to be received from
65 "Receiver_Callback::receive_frame for frame %d\n",
66 ++this->frame_count_
));
69 if (this->streamctrl_
!= 0)
71 // Modify QoS after receiving 20 frames
72 if (frame_count_
== 20)
74 // Specify the flow for which the qos needs to be changed.
75 TAO_Forward_FlowSpec_Entry
entry ("Data_Receiver",
81 AVStreams::flowSpec
flow_spec (1);
83 flow_spec
[0] = CORBA::string_dup (entry
.entry_to_string ());
85 // Initialize the qos parameter(s) that need to be changed
86 // with the corresponding value.
87 AVStreams::streamQoS qos
;
90 // The QoS Type that needs to be changed.
91 qos
[0].QoSType
= CORBA::string_dup ("video_qos");
93 qos
[0].QoSParams
.length (1);
94 qos
[0].QoSParams
[0].property_name
= CORBA::string_dup ("video_frame_rate");
95 qos
[0].QoSParams
[0].property_value
<<= (CORBA::Short
) 30;
98 // Initiate the modifying of the qos for the flows.
99 this->streamctrl_
->modify_QoS (qos
, flow_spec
);
101 ACE_DEBUG ((LM_DEBUG
,
102 "Stream Ctrl available....Modify QoS called\n"));
105 else ACE_DEBUG ((LM_DEBUG
,
106 "No Stream Ctrl\n"));
110 // Write the received data to the file.
112 ACE_OS::fwrite (frame
->rd_ptr (),
117 if (result
== frame
->length ())
118 ACE_ERROR_RETURN ((LM_ERROR
,
119 "Receiver_Callback::fwrite failed\n"),
122 frame
= frame
->cont ();
129 Receiver_Callback::handle_destroy ()
131 // Called when the distributer requests the stream to be shutdown.
132 ACE_DEBUG ((LM_DEBUG
,
133 "Receiver_Callback::end_stream\n"));
137 TAO_AV_CORE::instance ()->orb ()->shutdown (0);
139 catch (const CORBA::Exception
& ex
)
141 ex
._tao_print_exception ("Receiver_Callback::handle_destroy Failed\n");
148 Receiver::Receiver ()
153 Receiver::~Receiver ()
162 // Initialize the endpoint strategy with the orb and poa.
164 this->reactive_strategy_
.init (TAO_AV_CORE::instance ()->orb (),
165 TAO_AV_CORE::instance ()->poa ());
169 // Register the receiver mmdevice object with the ORB
170 ACE_NEW_RETURN (this->mmdevice_
,
171 TAO_MMDevice (&this->reactive_strategy_
),
174 // Servant Reference Counting to manage lifetime
175 PortableServer::ServantBase_var safe_mmdevice
=
178 CORBA::Object_var mmdevice
=
179 this->mmdevice_
->_this ();
181 // Register the mmdevice with the naming service.
182 CosNaming::Name
name (1);
185 CORBA::string_dup ("Receiver");
187 // Initialize the naming services
188 if (this->naming_client_
.init (TAO_AV_CORE::instance ()->orb ()) != 0)
189 ACE_ERROR_RETURN ((LM_ERROR
,
190 "Unable to initialize "
191 "the TAO_Naming_Client\n"),
194 // Register the receiver object with the naming server.
195 this->naming_client_
->rebind (name
,
202 parse_args (int argc
,
205 // Parse the command line arguments
206 ACE_Get_Opt
opts (argc
,
211 while ((c
= opts ()) != -1)
216 output_file_name
= opts
.opt_arg ();
219 ACE_ERROR_RETURN ((LM_ERROR
,
220 "Usage: receiver -f filename"),
234 // Initialize the ORB first.
236 CORBA::ORB_init (argc
, argv
);
238 CORBA::Object_var obj
239 = orb
->resolve_initial_references ("RootPOA");
241 // Get the POA_var object from Object_var.
242 PortableServer::POA_var root_poa
=
243 PortableServer::POA::_narrow (obj
.in ());
245 PortableServer::POAManager_var mgr
246 = root_poa
->the_POAManager ();
250 // Initialize the AVStreams components.
251 TAO_AV_CORE::instance ()->init (orb
.in (),
261 // Make sure we have a valid <output_file>
262 output_file
= ACE_OS::fopen (output_file_name
,
264 if (output_file
== 0)
265 ACE_ERROR_RETURN ((LM_DEBUG
,
266 "Cannot open output file %s\n",
271 ACE_DEBUG ((LM_DEBUG
,
272 "File Opened Successfully\n"));
289 catch (const CORBA::Exception
& ex
)
291 ex
._tao_print_exception ("receiver::init");
295 ACE_OS::fclose (output_file
);