Skip to content

Commit

Permalink
added events for webrtc, restructured media classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gene Hallman committed Nov 27, 2014
1 parent 6d6377d commit 595235e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 17 deletions.
19 changes: 16 additions & 3 deletions example/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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([
Expand Down
59 changes: 46 additions & 13 deletions pykurento/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# MediaObject
# Hub MediaElement MediaPipeline
# HubPort Endpoint Filter
# InputEndpoint OutputEndpoint


class MediaObject(object):
Expand Down Expand Up @@ -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")

Expand All @@ -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):
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion pykurento/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 595235e

Please sign in to comment.