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()