xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #465: newbuffer-vpx-opengl.patch

File newbuffer-vpx-opengl.patch, 4.6 KB (added by Antoine Martin, 7 years ago)

uses the new buffer API for decoding vpx via dec_vpx and tries to upload to PyOpenGL without copying

  • xpra/client/gl/gl_window_backing.py

     
    55# later version. See the file COPYING for details.
    66
    77#only works with gtk2:
     8import sys
    89import os
    910from gtk import gdk
    1011assert gdk
     
    1617log = Logger("opengl", "paint")
    1718OPENGL_DEBUG = os.environ.get("XPRA_OPENGL_DEBUG", "0")=="1"
    1819
    19 
    2020from xpra.codecs.codec_constants import get_subsampling_divs
    2121from xpra.client.gl.gl_check import get_DISPLAY_MODE
    2222from xpra.client.gl.gl_colorspace_conversions import YUV2RGB_shader, RGBP2RGB_shader
    2323from xpra.client.gtk2.window_backing import GTK2WindowBacking, fire_paint_callbacks
    24 from OpenGL.GL import GL_PROJECTION, GL_MODELVIEW, \
     24from OpenGL.GL import version as OpenGL_version, \
     25    GL_PROJECTION, GL_MODELVIEW, \
    2526    GL_UNPACK_ROW_LENGTH, GL_UNPACK_ALIGNMENT, \
    2627    GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_NEAREST, \
    2728    GL_UNSIGNED_BYTE, GL_LUMINANCE, GL_LINEAR, \
     
    9798from ctypes import c_char_p
    9899
    99100
     101
     102#support for memory views requires Python 2.7 and PyOpenGL 3.1
     103memoryview_type = None
     104if sys.version_info[:2]>=(2,7) and OpenGL_version.__version__.split('.')[:2]>=['3','1']:
     105    memoryview_type = memoryview
     106
     107
    100108# Texture number assignment
    101109#  1 = Y plane
    102110#  2 = U plane
     
    501509        #we get from the avcodec and vpx decoders cannot be used.
    502510        #PyOpenGL version 3.1 has some support for the memory view interface
    503511        #but this requires memoryview support which requires python>=2.7
    504         img.clone_pixel_data()
     512        pixels = img.get_pixels()
     513        assert len(pixels)==3
     514        plane_types = set([type(x) for x in img.get_pixels()])
     515        log.info("memoryview_type=%s, plane_types=%s", memoryview_type, plane_types)
     516        if memoryview_type is not None and len(plane_types)==1 and list(plane_types)[0]==memoryview_type:
     517            log.info("using memoryview directly!")
     518        else:
     519            img.clone_pixel_data()
    505520        gobject.idle_add(self.gl_paint_planar, img, x, y, enc_width, enc_height, width, height, callbacks)
    506521
    507522    def gl_paint_planar(self, img, x, y, enc_width, enc_height, width, height, callbacks):
  • xpra/codecs/vpx/decoder.pyx

     
    3030cdef extern from "Python.h":
    3131    ctypedef int Py_ssize_t
    3232    ctypedef object PyObject
     33
    3334    int PyObject_AsReadBuffer(object obj, void ** buffer, Py_ssize_t * buffer_len) except -1
    34     object PyBuffer_FromMemory(void *ptr, Py_ssize_t size)
    3535
     36    ctypedef struct PyMemoryViewObject:
     37        pass
     38    ctypedef struct Py_buffer:
     39        void *buf
     40        Py_ssize_t len
     41        int readonly
     42        char *format
     43        int ndim
     44        Py_ssize_t *shape
     45        Py_ssize_t *strides
     46        Py_ssize_t *suboffsets
     47        Py_ssize_t itemsize
     48        void *internal
     49    cdef enum:
     50        PyBUF_SIMPLE
     51        PyBUF_WRITABLE
     52        PyBUF_FORMAT
     53        PyBUF_ANY_CONTIGUOUS
     54
     55    object PyMemoryView_FromBuffer(Py_buffer *info)
     56
     57    int PyBuffer_FillInfo(Py_buffer *view, object obj, void *buf,
     58                Py_ssize_t len, int readonly, int infoflags) except -1
     59    int  PyObject_GetBuffer(object, Py_buffer *, int) except -1
     60    void PyBuffer_Release(Py_buffer *)
     61
    3662ctypedef unsigned char uint8_t
    3763ctypedef long vpx_img_fmt_t
    3864ctypedef void vpx_codec_iface_t
     
    276302        cdef object image
    277303        cdef object plane
    278304        cdef void *padded_buf
     305        cdef str astr=""
    279306        cdef Py_ssize_t plane_len = 0
     307        cdef Py_buffer pybuf
     308        cdef Py_ssize_t *shape = [0]
     309       
    280310        assert self.context!=NULL
    281311        assert PyObject_AsReadBuffer(input, <const void**> &buf, &buf_len)==0
    282312
     
    311341            memcpy(padded_buf, <void *>img.planes[i], plane_len)
    312342            memset(<void *>((<char *>padded_buf)+plane_len), 0, stride)
    313343
    314             plane = PyBuffer_FromMemory(padded_buf, plane_len)
    315             pixels.append(plane)
     344            shape[0] = plane_len
     345            PyBuffer_FillInfo(&pybuf, astr, padded_buf, plane_len, False, PyBUF_SIMPLE)
     346            pybuf.format = "B"
     347            pybuf.shape = shape
     348            mv = PyMemoryView_FromBuffer(&pybuf)
     349            log.info("returning memory view: %s", mv)
     350            pixels.append(mv)
    316351
    317352            image.add_buffer(<unsigned long> padded_buf)
    318353        log("vpx returning decoded %s image %s with colorspace=%s", self.encoding, image, image.get_pixel_format())