From 595235e9c67d58a775ee332aa000b881c6fdf296 Mon Sep 17 00:00:00 2001 From: Gene Hallman Date: Thu, 27 Nov 2014 00:57:25 -0800 Subject: [PATCH] added events for webrtc, restructured media classes --- example/app.py | 19 +++++++++++--- pykurento/media.py | 59 ++++++++++++++++++++++++++++++++---------- pykurento/transport.py | 1 - 3 files changed, 62 insertions(+), 17 deletions(-) diff --git a/example/app.py b/example/app.py index ec0873c..4bb41d9 100755 --- a/example/app.py +++ b/example/app.py @@ -108,6 +108,11 @@ def get(self, room_id=None): class LoopbackHandler(tornado.web.RequestHandler): + def on_event(self, *args, **kwargs): + print "received event!" + print args + print kwargs + def get(self): with open("loopback.html","r") as f: self.finish(f.read()) @@ -116,18 +121,26 @@ def post(self): sdp_offer = self.request.body pipeline = kurento.create_pipeline() wrtc_pub = media.WebRtcEndpoint(pipeline) + + wrtc_pub.on_media_session_started_event(self.on_event) + wrtc_pub.on_media_session_terminated_event(self.on_event) + # wrtc_pub.connect(wrtc_pub) + sdp_answer = wrtc_pub.process_offer(sdp_offer) self.finish(str(sdp_answer)) gst_flip = media.GStreamerFilter(pipeline, command="videoflip method=4") face_overlay = media.FaceOverlayFilter(pipeline) - face_overlay.set_overlayed_image( - "https://raw.githubusercontent.com/minervaproject/pykurento/master/example/static/img/rainbowpox.png", - 0, 0, 1, 1) + face_overlay.set_overlayed_image("https://raw.githubusercontent.com/minervaproject/pykurento/master/example/static/img/rainbowpox.png", 0, 0, 1, 1) + recorder = media.RecorderEndpoint(pipeline, uri="file:///tmp/test.webm") + recorder.record() wrtc_pub.connect(gst_flip) gst_flip.connect(face_overlay) face_overlay.connect(wrtc_pub) + face_overlay.connect(recorder) + + print recorder.get_uri() application = tornado.web.Application([ diff --git a/pykurento/media.py b/pykurento/media.py index d3a3506..54338db 100644 --- a/pykurento/media.py +++ b/pykurento/media.py @@ -7,7 +7,6 @@ # MediaObject # Hub MediaElement MediaPipeline # HubPort Endpoint Filter -# InputEndpoint OutputEndpoint class MediaObject(object): @@ -51,27 +50,53 @@ def connect(self, sink): # ENDPOINTS -class HttpGetEndpoint(MediaElement): - pass +class UriEndpoint(MediaElement): + def get_uri(self): + return self.invoke("getUri") + def pause(self): + return self.invoke("pause") -class HttpPostEndpoint(MediaElement): - pass + def stop(self): + return self.invoke("stop") -class PlayerEndpoint(MediaElement): - pass +class PlayerEndpoint(UriEndpoint): + def play(self): + return self.invoke("play") + def on_end_of_stream_event(self, fn): + return self.subscribe("EndOfStream", fn) -class RecorderEndpoint(MediaElement): - pass + +class RecorderEndpoint(UriEndpoint): + def record(self): + return self.invoke("record") + + +class SessionEndpoint(MediaElement): + def on_media_session_started_event(self, fn): + return self.subscribe("MediaSessionStarted", fn) + + def on_media_session_terminated_event(self, fn): + return self.subscribe("MediaSessionTerminated", fn) + + +class HttpEndpoint(SessionEndpoint): + def get_url(self): + return self.invoke("getUrl") -class RtpEndpoint(MediaElement): +class HttpGetEndpoint(HttpEndpoint): pass - -class WebRtcEndpoint(MediaElement): + +class HttpPostEndpoint(HttpEndpoint): + def on_end_of_stream_event(self, fn): + return self.subscribe("EndOfStream", fn) + + +class SdpEndpoint(SessionEndpoint): def generate_offer(self): return self.invoke("generateOffer") @@ -88,6 +113,14 @@ def get_remote_session_descriptor(self): return self.invoke("getRemoteSessionDescriptor") +class RtpEndpoint(SdpEndpoint): + pass + + +class WebRtcEndpoint(SdpEndpoint): + pass + + # FILTERS class GStreamerFilter(MediaElement): @@ -101,7 +134,7 @@ def set_overlayed_image(self, uri, offset_x, offset_y, width, height): class ZBarFilter(MediaElement): def on_code_found_event(self, fn): - return self.subscribe("CodeFoundEvent", fn) + return self.subscribe("CodeFound", fn) # HUBS diff --git a/pykurento/transport.py b/pykurento/transport.py index 10bf7da..0da14f0 100644 --- a/pykurento/transport.py +++ b/pykurento/transport.py @@ -87,7 +87,6 @@ def _on_message(self, message): logger.debug("received message: %s" % message) if 'method' in resp: - self.current_id = resp["id"] if (resp['method'] == 'onEvent' and 'params' in resp and 'value' in resp['params']