summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/AVStreams/mpeg/source/mpeg_server/Video_Control_i.cpp
blob: 79f5438fe58aa1400e0b38f74d79ab25a568af72 (plain)
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
// $Id$

#include "Video_Control_i.h"
#include "mpeg_server/Video_Server.h"

Video_Control_i::Video_Control_i ()
  : reactor_ (TAO_ORB_Core_instance ()->reactor ())
{
  
}

int
Video_Control_i::create_handlers (void)
{
  ACE_NEW_RETURN (this->data_handler_,
                  Video_Data_Handler,
                  -1);

  ACE_NEW_RETURN (this->sig_handler_, 
                  Video_Sig_Handler,
                  -1);
  return 0;
}
CORBA::Boolean 
Video_Control_i::init_video (const Video_Control::INITvideoPara &para,
                             Video_Control::INITvideoReply_out reply,
                             CORBA::Environment& env)
{
  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) Video_Control_i::init_video () called\n"));
  
  CORBA::Boolean result = this->state_->init_video (para,
                                                    reply);

  ACE_DEBUG ((LM_DEBUG, "(%P|%t) Video_Control_State::init_video returned %d\n", result));
  return result;

}


CORBA::Boolean 
Video_Control_i::stat_stream (CORBA::Char_out ch,
                              CORBA::Long_out size,
                              CORBA::Environment& env)
{
  return 0;
}


CORBA::Boolean 
Video_Control_i::close (CORBA::Environment& env)
{
  ACE_DEBUG ((LM_DEBUG, 
              "(%P|%t) Video_Control_i::close:"
              "shutting down the ORB\n"));

  TAO_ORB_Core_instance ()-> orb ()-> shutdown ();
  return CORBA::B_TRUE;
}


CORBA::Boolean 
Video_Control_i::stat_sent (CORBA::Environment& env)
{
  return 0;
}


CORBA::Boolean 
Video_Control_i::fast_forward (const Video_Control::FFpara &para,
                               CORBA::Environment& env)
{
  return this->state_->fast_forward (para);
}


CORBA::Boolean 
Video_Control_i::fast_backward (const Video_Control::FFpara &para,
                                CORBA::Environment& env)
{
  return this->state_->fast_backward (para);
}


CORBA::Boolean 
Video_Control_i::step (const Video_Control::STEPpara &para,
                       CORBA::Environment& env)
{
  return this->state_->step (para);
}


// this gets called by the client, when it wants
// to start playback
CORBA::Boolean 
Video_Control_i::play (const Video_Control::PLAYpara &para,
                       CORBA::Long_out vts,
                       CORBA::Environment& env)
{
  return this->state_->play (para,
                             vts);
}


CORBA::Boolean 
Video_Control_i::position (const Video_Control::POSITIONpara &para,
                           CORBA::Environment& env)
{
  return this->state_->position (para);
}


CORBA::Boolean 
Video_Control_i::speed (const Video_Control::SPEEDpara &para,
                        CORBA::Environment& env)
{
  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) Video_Control_i::speed () called\n"));
  return this->state_->speed (para);
}


CORBA::Boolean 
Video_Control_i::stop (CORBA::Long cmdsn,
                       CORBA::Environment& env)
{
  return this->state_->stop (cmdsn);
}

CORBA::UShort
Video_Control_i::set_peer (const char *peer,
                           CORBA::Environment &_tao_environment)
{
   ACE_INET_Addr client_data_addr (peer);
  // Data (UDP) Address of the client.

   ACE_DEBUG ((LM_DEBUG,
               "(%P|%t) set_peer called: %s,%s,%d\n",
               peer,
               client_data_addr.get_host_addr (),
               client_data_addr.get_port_number ()));

 
  if (VIDEO_SINGLETON::instance ()->dgram.open (client_data_addr) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, 
                       "(%P|%t) UDP open failed: %p\n"),
                      -1);

  ACE_INET_Addr server_data_addr;
  // Data (UDP) Address of this server.
  
  if (VIDEO_SINGLETON::instance ()-> dgram.get_local_addr 
      (server_data_addr) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, 
                       "(%P|%t) UDP get_local_addr failed: %p\n"),
                      -1);

  ACE_DEBUG ((LM_DEBUG, 
              "(%P|%t) Video_Server: My UDP port number is %d\n",
              server_data_addr.get_port_number ()));

  if (this->register_handlers () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t) Video_Control_i::set_peer: register_handlers failed\n"),
                      -1);

  VIDEO_SINGLETON::instance ()->videoSocket = VIDEO_SINGLETON::instance ()->dgram.get_handle ();

  ACE_DEBUG ((LM_DEBUG,"(%P|%t) set_peer: server port = %d\n",server_data_addr.get_port_number ()));
  return server_data_addr.get_port_number ();

}

int
Video_Control_i::register_handlers (void)
{
  int result;

  // Register the event handlers with the Reactor

  // first the data handler, i.e. UDP
  result = this->reactor_->register_handler (this->data_handler_, 
                                             ACE_Event_Handler::READ_MASK);
  if (result < 0)
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%P|%t) register_handler for data_handler failed\n"),
                        -1);

  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) registered fd for data handler = (%d)\n",
              this->data_handler_->get_handle ()));
  
  // finally, the signal handler, for periodic transmission
  // of packets
  result = this->sig_handler_->register_handler ();
  
  if (result < 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t) register_handler for sig_handler"
                       "failed!\n"),
                      -1);

  return 0;
}

// Changes the state of the video control handler from the current
// state to the state represented by the argument.
void
Video_Control_i::change_state (Video_Control_State *state)
{
  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) Video_Control_i::Changing to state %d\n",
              state->get_state ()));
  this->state_ = state;
}

// Returns the current state object .
Video_Control_State *
Video_Control_i::get_state (void)
{
  return this->state_;
}


Video_Control_i::~Video_Control_i ()
{
  delete this->data_handler_;
  delete this->sig_handler_;
}