def __init__(self, handle): Activity.__init__(self, handle) # Self-Enforced max_participants self.max_participants = SUGAR_MAX_PARTICIPANTS # Prepare Storage Components self.network_stack = None self.gstreamer_stack = None # Set Owner self.owner = presenceservice.get_instance().get_owner() # Setup GUI logger.debug("Preparing GUI") self.set_canvas(Gui(self)) # Setup GStreamer Stack logger.debug("Setting up GSTStack") self.gststack = GSTStack() self.get_canvas().set_gstreamer_stack(self.gststack); # Setup Network Stack logger.debug("Connect Event to Setup Network Stack on Demand") self.establish_activity_sharing(handle)
def __init__(self, handle): Activity.__init__(self, handle) # Self-Enforced max_participants self.max_participants = 2 # Revise logical checks to shared_activity flags and remove these: if self.shared_activity: self.sent_ip = 1 else: self.sent_ip = 2 ########### # Setup Gui ########### self.set_canvas(Gui(self)) ##################### # Setup Network Stack ##################### # self.netstack = NetworkStack(self) # self._sh_hnd = self.connect('shared', self.netstack.shared_cb) # self._jo_hnd = self.connect('joined', self.netstack.joined_cb) ################# # Setup Pipeline ################# print "Setting up GStreamer" self.gststack = GSTStack(self.get_canvas().render_preview, self.get_canvas().render_incoming) self.gststack.build_preview() self.gststack.build_incoming_pipeline() GObject.idle_add(self.gststack.start_stop_incoming_pipeline, True)
def __init__(self, handle): Activity.__init__(self, handle) # gobject is used for timeing (will be removed when rtp is implemented) gobject.threads_init() # Set if they started the activity self.isServer = not self._shared_activity # Let sugar know we only want a 1 to 1 share (limit to 2 people) # Note this is not enforced by sugar yet :( self.max_participants = 2 #FIXME: This is a hack to only allow our ip to be sent once. #AKA disables others from double streaming if self.isServer: # server will send out ip twice, first when joinning empty channel # second when the user joins self.sent_ip = 2 else: self.sent_ip = 1 # INITIALIZE GUI ################ self.set_title('OpenVideoChat') # Setup Gui ########### self.gui = Gui(self) self.gui.show() self.set_canvas(self.gui) # Setup Network Stack ##################### self.netstack = SugarNetworkStack(self) self._sh_hnd = self.connect('shared', self.netstack.shared_cb) self._jo_hnd = self.connect('joined', self.netstack.joined_cb) # Setup Pipeline ################# self.gststack = GSTStack( self.gui.send_video_to_screen ) self.gststack.build_incoming_pipeline() gobject.idle_add( self.gststack.start_stop_incoming_pipeline, True ) print "Activity Started"
def setup_gstreamer(self, sender): # Create GStreamer for Testing self.gst = GSTStack() # Get Video Bus self.bus = self.gst.build_preview() # Attach to Preview self.bus.connect("sync-message::element", self.draw_preview) # Try Changing Caps (SUCCESS!) self.gst.change_resolution(self.draw.get_allocation().width, self.draw.get_allocation().height)
def __init__(self, handle): Activity.__init__(self, handle) # gobject is used for timeing (will be removed when rtp is implemented) gobject.threads_init() # Set if they started the activity self.isServer = not self._shared_activity # Let sugar know we only want a 1 to 1 share (limit to 2 people) # Note this is not enforced by sugar yet :( self.max_participants = 2 #FIXME: This is a hack to only allow our ip to be sent once. #AKA disables others from double streaming if self.isServer: # server will send out ip twice, first when joinning empty channel # second when the user joins self.sent_ip = 2 else: self.sent_ip = 1 # INITIALIZE GUI ################ self.set_title('OpenVideoChat') # Setup Gui ########### self.gui = Gui(self) self.gui.show() self.set_canvas(self.gui) # Setup Network Stack ##################### self.netstack = SugarNetworkStack(self) self._sh_hnd = self.connect('shared', self.netstack.shared_cb) self._jo_hnd = self.connect('joined', self.netstack.joined_cb) # Setup Pipeline ################# self.gststack = GSTStack(self.gui.send_video_to_screen) self.gststack.build_incoming_pipeline() gobject.idle_add(self.gststack.start_stop_incoming_pipeline, True) print "Activity Started"
class OpenVideoChatActivity(Activity): def __init__(self, handle): Activity.__init__(self, handle) # gobject is used for timeing (will be removed when rtp is implemented) gobject.threads_init() # Set if they started the activity self.isServer = not self._shared_activity # Let sugar know we only want a 1 to 1 share (limit to 2 people) # Note this is not enforced by sugar yet :( self.max_participants = 2 #FIXME: This is a hack to only allow our ip to be sent once. #AKA disables others from double streaming if self.isServer: # server will send out ip twice, first when joinning empty channel # second when the user joins self.sent_ip = 2 else: self.sent_ip = 1 # INITIALIZE GUI ################ self.set_title('OpenVideoChat') # Setup Gui ########### self.gui = Gui(self) self.gui.show() self.set_canvas(self.gui) # Setup Network Stack ##################### self.netstack = SugarNetworkStack(self) self._sh_hnd = self.connect('shared', self.netstack.shared_cb) self._jo_hnd = self.connect('joined', self.netstack.joined_cb) # Setup Pipeline ################# self.gststack = GSTStack( self.gui.send_video_to_screen ) self.gststack.build_incoming_pipeline() gobject.idle_add( self.gststack.start_stop_incoming_pipeline, True ) print "Activity Started" def can_close( self ): print "Closing, stopping pipelines" self.gststack.start_stop_incoming_pipeline(False) self.gststack.start_stop_outgoing_pipeline(False) return True def _alert(self, title, text=None, timeout=5): alert = NotifyAlert(timeout=timeout) alert.props.title = title alert.props.msg = text self.add_alert(alert) alert.connect('response', self._alert_cancel_cb) alert.show() def _alert_cancel_cb(self, alert, response_id): self.remove_alert(alert) def net_cb(self, src, args): """ Callback for network commands """ if src == "chat": message, sender = args self.gui.add_chat_text( message ) elif src == "join": handle = self.netstack.get_tube_handle() if handle and self.sent_ip > 0: import socket import fcntl import struct import array # http://code.activestate.com/recipes/439094-get-the-ip-address-associated-with-a-network-inter/ def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]) )[20:24]) #http://code.activestate.com/recipes/439093-get-names-of-all-up-network-interfaces-linux-only/ def all_interfaces(): max_possible = 128 # arbitrary. raise if needed. bytes = max_possible * 32 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) names = array.array('B', '\0' * bytes) outbytes = struct.unpack('iL', fcntl.ioctl( s.fileno(), 0x8912, # SIOCGIFCONF struct.pack('iL', bytes, names.buffer_info()[0]) ))[0] namestr = names.tostring() return [namestr[i:i+32].split('\0', 1)[0] for i in range(0, outbytes, 32)] for interface in all_interfaces(): if interface != 'lo': try: ip = get_ip_address(interface) self.sent_ip = self.sent_ip - 1 handle.announce_ip(ip) break except: print "Interface %s did not give ip" % interface else: print "Could not find ip address" elif src == "ip": #FIXME: Store ip with user so we can make user lists to switch between later on if not hasattr( self, 'out' ): #~ s1,s2,s3 = self.out.get_state() #~ if s2 == gst.STATE_PLAYING: #~ print args,"has sent its ip, ignoring as we are allready streaming" #~ else: self.gststack.build_outgoing_pipeline( args ) # FIXME gobject.timeout_add(5000, self.gststack.start_stop_outgoing_pipeline) else: print args,"has sent its ip, ignoring as we are allready streaming" elif src == "buddy_add": self.gui.add_chat_text(_("%s has joined the chat") % args) elif src == "buddy_rem": self.gui.add_chat_text(_("%s has left the chat") % args) def send_chat_text(self, text): handle = self.netstack.get_tube_handle() prof = profile.get_nick_name() if handle: handle.send_chat_text( "<%s> %s" % (prof, text) ) # # Save Chat Log # def write_file(self, file_path): file = open(file_path, 'w') file.write( self.gui.get_history() ) file.close() # # Load Chat Log # def read_file(self, file_path): file = open(file_path, 'r') self.gui.add_chat_text(file.read()) file.close()
class OpenVideoChatActivity(Activity): def __init__(self, handle): Activity.__init__(self, handle) # gobject is used for timeing (will be removed when rtp is implemented) gobject.threads_init() # Set if they started the activity self.isServer = not self._shared_activity # Let sugar know we only want a 1 to 1 share (limit to 2 people) # Note this is not enforced by sugar yet :( self.max_participants = 2 #FIXME: This is a hack to only allow our ip to be sent once. #AKA disables others from double streaming if self.isServer: # server will send out ip twice, first when joinning empty channel # second when the user joins self.sent_ip = 2 else: self.sent_ip = 1 # INITIALIZE GUI ################ self.set_title('OpenVideoChat') # Setup Gui ########### self.gui = Gui(self) self.gui.show() self.set_canvas(self.gui) # Setup Network Stack ##################### self.netstack = SugarNetworkStack(self) self._sh_hnd = self.connect('shared', self.netstack.shared_cb) self._jo_hnd = self.connect('joined', self.netstack.joined_cb) # Setup Pipeline ################# self.gststack = GSTStack(self.gui.send_video_to_screen) self.gststack.build_incoming_pipeline() gobject.idle_add(self.gststack.start_stop_incoming_pipeline, True) print "Activity Started" def can_close(self): print "Closing, stopping pipelines" self.gststack.start_stop_incoming_pipeline(False) self.gststack.start_stop_outgoing_pipeline(False) return True def _alert(self, title, text=None, timeout=5): alert = NotifyAlert(timeout=timeout) alert.props.title = title alert.props.msg = text self.add_alert(alert) alert.connect('response', self._alert_cancel_cb) alert.show() def _alert_cancel_cb(self, alert, response_id): self.remove_alert(alert) def net_cb(self, src, args): """ Callback for network commands """ if src == "chat": message, sender = args self.gui.add_chat_text(message) elif src == "join": handle = self.netstack.get_tube_handle() if handle and self.sent_ip > 0: import socket import fcntl import struct import array # http://code.activestate.com/recipes/439094-get-the-ip-address # -associated-with-a-network-inter/ def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]))[20:24]) # http://code.activestate.com/recipes/439093-get-names-of-all- # up-network-interfaces-linux-only/ def all_interfaces(): max_possible = 128 # arbitrary. raise if needed. bytes = max_possible * 32 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) names = array.array('B', '\0' * bytes) outbytes = struct.unpack('iL', fcntl.ioctl( s.fileno(), 0x8912, # SIOCGIFCONF struct.pack('iL', bytes, names.buffer_info()[0])))[0] namestr = names.tostring() return [namestr[i:i + 32].split('\0', 1)[0] for i in range (0, outbytes, 32)] for interface in all_interfaces(): if interface != 'lo': try: ip = get_ip_address(interface) self.sent_ip = self.sent_ip - 1 handle.announce_ip(ip) break except: print "Interface %s did not give ip" % interface else: print "Could not find ip address" elif src == "ip": # fixme: Store ip with user so we can make user lists to switch # between later on if not hasattr(self, 'out'): #~ s1,s2,s3 = self.out.get_state() #~ if s2 == gst.STATE_PLAYING: #~ print args,"has sent its ip, ignoring as we are already # streaming" #~ else: self.gststack.build_outgoing_pipeline(args) # FIXME gobject.timeout_add(5000, self.gststack. start_stop_outgoing_pipeline) else: print args, "has sent its ip, ignoring as we are already \ streaming" elif src == "buddy_add": self.gui.add_chat_text(_("%s has joined the chat") % args) elif src == "buddy_rem": self.gui.add_chat_text(_("%s has left the chat") % args) def send_chat_text(self, text): handle = self.netstack.get_tube_handle() prof = profile.get_nick_name() if handle: handle.send_chat_text("<%s> %s" % (prof, text)) # # Save Chat Log # def write_file(self, file_path): file = open(file_path, 'w') file.write(self.gui.get_history()) file.close() # # Load Chat Log # def read_file(self, file_path): file = open(file_path, 'r') self.gui.add_chat_text(file.read()) file.close()
class TestWindow(Activity): def __init__(self, handler): Activity.__init__(self, handler) # Setup Activity self.max_participants = 1 self.setup_toolbar() # Create Drawing Area self.draw = Gtk.DrawingArea() self.draw.show() # Apply Canvas self.set_canvas(self.draw) # Add signal for realized self.get_canvas().connect('realize', self.setup_gstreamer) def setup_gstreamer(self, sender): # Create GStreamer for Testing self.gst = GSTStack() # Get Video Bus self.bus = self.gst.build_preview() # Attach to Preview self.bus.connect("sync-message::element", self.draw_preview) # Try Changing Caps (SUCCESS!) self.gst.change_resolution(self.draw.get_allocation().width, self.draw.get_allocation().height) def draw_preview(self, bus, message): if message.get_structure() is None: return # Capture the new GStreamer handle request if message.get_structure().get_name() == "prepare-window-handle": message.src.set_window_handle(self.draw.get_window().get_xid()) def setup_toolbar(self): toolbar_box = ToolbarBox() activity_button = ActivityButton(self) toolbar_box.toolbar.insert(activity_button, 0) activity_button.show() # Test Button video_toggle_button = ToolButton() video_toggle_button.connect("clicked", self.test_toggle) video_toggle_button.set_icon_name('activity-start') video_toggle_button.set_tooltip_text('Toggle Video Size') toolbar_box.toolbar.insert(video_toggle_button, 1) video_toggle_button.show() separator = Gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar_box.toolbar.insert(separator, -1) separator.show() stop_button = StopButton(self) toolbar_box.toolbar.insert(stop_button, -1) stop_button.show() self.set_toolbar_box(toolbar_box) toolbar_box.show() def test_toggle(self, sender): # Try Turning Video on/off (SUCCESS!) self.gst.toggle_playback()
class OpenVideoChatActivity(Activity): def __init__(self, handle): Activity.__init__(self, handle) # Self-Enforced max_participants self.max_participants = 2 # Revise logical checks to shared_activity flags and remove these: if self.shared_activity: self.sent_ip = 1 else: self.sent_ip = 2 ########### # Setup Gui ########### self.set_canvas(Gui(self)) ##################### # Setup Network Stack ##################### # self.netstack = NetworkStack(self) # self._sh_hnd = self.connect('shared', self.netstack.shared_cb) # self._jo_hnd = self.connect('joined', self.netstack.joined_cb) ################# # Setup Pipeline ################# print "Setting up GStreamer" self.gststack = GSTStack(self.get_canvas().render_preview, self.get_canvas().render_incoming) self.gststack.build_preview() self.gststack.build_incoming_pipeline() GObject.idle_add(self.gststack.start_stop_incoming_pipeline, True) def can_close(self): print "Closing, stopping pipelines" self.gststack.start_stop_incoming_pipeline(False) self.gststack.start_stop_outgoing_pipeline(False) return True def _alert(self, title, text=None, timeout=5): alert = NotifyAlert(timeout=timeout) alert.props.title = title alert.props.msg = text self.add_alert(alert) alert.connect('response', self._alert_cancel_cb) alert.show() def _alert_cancel_cb(self, alert, response_id): self.remove_alert(alert) # def net_cb(self, src, args): # """ # Callback for network commands # """ # # new chat message # if src == "chat": # message, sender = args # self.get_canvas().receive_message(message) # # join request # elif src == "join": # handle = self.netstack.get_tube_handle() # if handle and self.sent_ip > 0: # # http://code.activestate.com/recipes/439094-get-the-ip-address # # -associated-with-a-network-inter/ # def get_ip_address(ifname): # s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # return socket.inet_ntoa(fcntl.ioctl( # s.fileno(), # 0x8915, # SIOCGIFADDR # struct.pack('256s', ifname[:15]))[20:24]) # # http://code.activestate.com/recipes/439093-get-names-of-all- # # up-network-interfaces-linux-only/ # def all_interfaces(): # max_possible = 128 # arbitrary. raise if needed. # bytes = max_possible * 32 # s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # names = array.array('B', '\0' * bytes) # outbytes = struct.unpack('iL', fcntl.ioctl( # s.fileno(), # 0x8912, # SIOCGIFCONF # struct.pack('iL', bytes, names.buffer_info()[0])))[0] # namestr = names.tostring() # return [namestr[i:i + 32].split('\0', 1)[0] for i in range # (0, outbytes, 32)] # for interface in all_interfaces(): # if interface != 'lo': # try: # ip = get_ip_address(interface) # self.sent_ip = self.sent_ip - 1 # handle.announce_ip(ip) # break # except: # print "Interface %s did not give ip" % interface # else: # print "Could not find ip address" # elif src == "ip": # # fixme: Store ip with user so we can make user lists to switch # # between later on # if not hasattr(self, 'out'): # #~ s1,s2,s3 = self.out.get_state() # #~ if s2 == gst.STATE_PLAYING: # #~ print args,"has sent its ip, ignoring as we are already # # streaming" # #~ else: # self.gststack.build_outgoing_pipeline(args) # # FIXME # GObject.timeout_add(5000, self.gststack.start_stop_outgoing_pipeline) # else: # print args, "has sent its ip, ignoring as we are already \ # streaming" # elif src == "buddy_add": # self.get_canvas().receive_message(_("%s has joined the chat") % args) # elif src == "buddy_rem": # self.get_canvas().receive_message(_("%s has left the chat") % args) # # Send new chat message # def send_message(self, text): # handle = self.netstack.get_tube_handle() # prof = profile.get_nick_name() # if handle: # handle.receive_message("<%s> %s" % (prof, text)) def get_stream(self): return RECEIVING_STREAM def send_stream(self): self.get_canvas().run_toggles() # Save Chat Log to History def write_file(self, file_path): file = open(file_path, 'w') file.write(self.get_canvas().get_history()) file.close() # Load Chat Log from History def read_file(self, file_path): file = open(file_path, 'r') self.get_canvas().receive_message(file.read()) file.close()