xpra icon
Bug tracker and wiki

Ticket #1341: flush-video-frame.patch

File flush-video-frame.patch, 3.9 KB (added by Antoine Martin, 4 years ago)

ugly PoC hack for flushing frames from the ffmpeg encoder

  • xpra/server/window/window_video_source.py

     
    5151
    5252FAST_ORDER = ["jpeg", "rgb32", "rgb24", "png"] + PREFERED_ENCODING_ORDER
    5353
     54ALWAYS_FLUSH = True
    5455
     56
    5557class WindowVideoSource(WindowSource):
    5658    """
    5759        A WindowSource that handles video codecs.
     
    288290
    289291    def update_encoding_selection(self, encoding=None, exclude=[], init=False):
    290292        #override so we don't use encodings that don't have valid csc modes:
    291         log("wvs.update_encoding_selection(%s, %s, %s)", encoding, exclude, init)
     293        log.error("wvs.update_encoding_selection(%s, %s, %s)", encoding, exclude, init)
     294        log.error("video encodings=%s, core encodings=%s", self.video_encodings, self.core_encodings)
     295        if exclude:
     296            import traceback
     297            #traceback.print_stack()
    292298        for x in self.video_encodings:
    293299            if x not in self.core_encodings:
     300                log.warn("%s not supported by client", x)
    294301                exclude.append(x)
    295302                continue
    296303            csc_modes = self.full_csc_modes.get(x)
     304            csclog.info("full_csc_modes[%s]=%s", x, csc_modes)
    297305            if not csc_modes or x not in self.core_encodings:
    298306                exclude.append(x)
    299307                if not init:
     
    301309                else:
    302310                    l = log
    303311                l("client does not support any csc modes with %s", x)
     312        log.warn("exclude=%s", exclude)
    304313        WindowSource.update_encoding_selection(self, encoding, exclude, init)
    305314
    306315    def do_set_client_properties(self, properties):
     
    15151524        return encode_fn(fallback_encoding, image, options)
    15161525
    15171526    def video_encode(self, encoding, image, options):
    1518         try:
    1519             return self.do_video_encode(encoding, image, options)
    1520         finally:
    1521             self.free_image_wrapper(image)
    1522 
    1523     def do_video_encode(self, encoding, image, options):
    15241527        """
    15251528            This method is used by make_data_packet to encode frames using video encoders.
    15261529            Video encoders only deal with fixed dimensions,
     
    16321635                for k,v in csce.get_info().items():
    16331636                    log.error("   %-20s: %s", k, v)
    16341637            return None
     1638        finally:
     1639            if ALWAYS_FLUSH:
     1640                def frame_flush():
     1641                    log.warn("frame_flush()")
     1642                    data, client_options = ve.compress_image(csc_image, quality, speed, options)
     1643                    self.free_image_wrapper(csc_image)
     1644                    packet = self.make_draw_packet(x, y, w, h, encoding, Compressed(encoding, data), 0, client_options)
     1645                    self.queue_damage_packet(packet)
     1646                self.call_in_encode_thread(True, frame_flush)
     1647            else:
     1648                self.free_image_wrapper(csc_image)
     1649
    16351650        if ret is None:
    16361651            if not self.is_cancelled():
    16371652                videolog.error("video_encode: ouch, %s compression failed", encoding)
     
    16391654        data, client_options = ret
    16401655        end = time.time()
    16411656
    1642         if csc_image!=image:
    1643             self.free_image_wrapper(csc_image)
    1644             del csc_image
    1645 
    16461657        #populate client options:
    16471658        frame = client_options.get("frame", 0)
    16481659        if frame<self.start_video_frame:
     
    17691780        csclog("csc_image(%s, %s, %s) converted to %s in %.1fms (%.1f MPixels/s)",
    17701781                        image, width, height,
    17711782                        csc_image, (1000.0*end-1000.0*start), (width*height/(end-start+0.000001)/1024.0/1024.0))
     1783        self.free_image_wrapper(image)
    17721784        if not csc_image:
    17731785            raise Exception("csc_image: conversion of %s to %s failed" % (image, csce.get_dst_format()))
    17741786        assert csce.get_dst_format()==csc_image.get_pixel_format()