10 from subprocess
import PIPE
18 def internal(signal, frame):
38 has_data_config = rospy.has_param(rospy.get_name() +
"/data")
39 if not has_data_config:
40 rospy.logdebug(
"no data config. ignore data events")
42 has_media_config = rospy.has_param(rospy.get_name() +
"/media")
43 if not has_media_config:
44 rospy.logdebug(
"no media config. ignore media events")
50 if "result" not in event:
52 if "event" not in event[
"result"]:
55 request_type = event[
"result"][
"request_type"]
56 if request_type ==
"PEER":
58 event, has_data_config, has_media_config
60 elif request_type ==
"DATA":
63 elif request_type ==
"MEDIA":
68 if event[
"result"][
"event"] ==
"CLOSE":
73 '{"request_type": "SYSTEM", "command": "SHUTDOWN"}' 76 (result, pid) =
gst_launch(
"SYSTEM_EXIT",
"", 0)
77 rospy.signal_shutdown(
"finish")
78 elif event[
"result"][
"event"] ==
"CALL":
79 if not has_media_config:
82 media_connection_id = event[
"result"][
"call_params"][
93 if not event[
"is_success"]:
96 if event[
"result"][
"event"] ==
"STREAM":
99 event[
"result"][
"media_connection_id"]
102 rospy.loginfo(
"MediaConnection Status")
103 rospy.loginfo(media_status_response)
110 script = rospy.get_param(rospy.get_name() +
"/media/gst_script")
114 event[
"result"][
"send_params"][
"video"][
"media"]
117 script = script.replace(
118 "DEST_VIDEO_RTP_PORT", str(video_send_params[1])
121 script = script.replace(
122 "DEST_VIDEO_RTCP_PORT", str(video_send_params[3])
128 event[
"result"][
"send_params"][
"audio"][
"media"]
131 script = script.replace(
132 "DEST_AUDIO_RTP_PORT", str(audio_send_params[1])
135 script = script.replace(
136 "DEST_AUDIO_RTCP_PORT", str(audio_send_params[3])
143 event[
"result"][
"redirect_params"][
"video"]
146 script = script.replace(
147 "SRC_VIDEO_RTP_PORT", str(video_recv_params[1])
150 script = script.replace(
151 "SRC_VIDEO_RTCP_PORT", str(video_recv_params[3])
157 event[
"result"][
"redirect_params"][
"audio"]
160 script = script.replace(
161 "SRC_AUDIO_RTP_PORT", str(audio_recv_params[1])
164 script = script.replace(
165 "SRC_AUDIO_RTCP_PORT", str(audio_recv_params[3])
170 script = script.replace(
"DEST", str(video_send_params[0]))
173 (result, pid) =
gst_launch(
"LAUNCH", script, 0)
175 self._pid_map[event[
"result"][
"media_connection_id"]] = pid
176 elif event[
"result"][
"event"] ==
"CLOSE":
177 media_connection_id = event[
"result"][
"media_connection_id"]
178 if media_connection_id
in self._pid_map:
179 pid = self._pid_map[media_connection_id]
181 self._pid_map.pop(media_connection_id)
185 if not rospy.has_param(rospy.get_name() +
"/peer_id"):
186 rospy.logerr(
"no peer_id")
188 peer_id = rospy.get_param(rospy.get_name() +
"/peer_id")
189 target_id = rospy.get_param(rospy.get_name() +
"/media/target_id")
191 if "API_KEY" not in os.environ:
192 rospy.logerr(
"no API_KEY")
193 rospy.logerr(
"exiting")
196 key = os.environ[
"API_KEY"]
200 if not peer_create_response[
"is_success"]:
204 peer_id = peer_create_response[
"result"][
"peer_id"]
205 token = peer_create_response[
"result"][
"token"]
211 rospy.loginfo(
"Peer Object has been created")
212 rospy.loginfo(status_response)
229 if __name__ ==
"__main__":
230 rospy.init_node(
"my_node", log_level=rospy.INFO)
def gst_launch(message_type, command, pid)
def create_peer_status_request(peer_id, token)
def skyway_event(peer_id, token)
def skyway_control(json_str)
def delete_peer_request(peer_id, token)
def create_peer_request(peer_id, api_key)