Skip to content

Commit

Permalink
#1107: make it possible to save the video stream to file for debugging
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@12144 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Mar 14, 2016
1 parent 807b1c7 commit 0b09f7c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
21 changes: 18 additions & 3 deletions src/xpra/codecs/enc_x264/encoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ X264_THREADS = int(os.environ.get("XPRA_X264_THREADS", "0"))
X264_LOGGING = os.environ.get("XPRA_X264_LOGGING", "WARNING")
LOG_NALS = os.environ.get("XPRA_X264_LOG_NALS", "0")=="1"
USE_OPENCL = os.environ.get("XPRA_X264_OPENCL", "0")=="1"
SAVE_TO_FILE = os.environ.get("XPRA_SAVE_TO_FILE")


from xpra.util import nonl
from xpra.util import nonl, AtomicInteger
from xpra.os_util import bytestostr
from xpra.codecs.codec_constants import get_subsampling_divs, video_spec
from collections import deque
Expand Down Expand Up @@ -322,11 +322,13 @@ def get_version():
def get_type():
return "x264"

generation = AtomicInteger()
def get_info():
global COLORSPACES, MAX_WIDTH, MAX_HEIGHT
return {"version" : get_version(),
"buffer_api": get_buffer_api_version(),
"max-size" : (MAX_WIDTH, MAX_HEIGHT),
"generation": generation.get(),
"formats" : COLORSPACES.keys()}

def get_encodings():
Expand Down Expand Up @@ -410,12 +412,13 @@ cdef class Encoder:
cdef unsigned long long bytes_in
cdef unsigned long long bytes_out
cdef object last_frame_times
cdef object file
cdef uint64_t first_frame_timestamp

cdef object __weakref__

def init_context(self, int width, int height, src_format, dst_formats, encoding, int quality, int speed, scaling, options): #@DuplicatedSignature
global COLORSPACE_FORMATS
global COLORSPACE_FORMATS, generation
cs_info = COLORSPACE_FORMATS.get(src_format)
assert cs_info is not None, "invalid source format: %s, must be one of: %s" % (src_format, COLORSPACE_FORMATS.keys())
assert encoding=="h264", "invalid encoding: %s" % encoding
Expand All @@ -441,6 +444,11 @@ cdef class Encoder:
self.profile = cs_info[1]
log("using default profile=%s", self.profile)
self.init_encoder()
gen = generation.increase()
if SAVE_TO_FILE is not None:
filename = SAVE_TO_FILE+str(gen)+".%s" % encoding
self.file = open(filename, 'wb')
log.info("saving %s stream to %s", encoding, filename)

cdef init_encoder(self):
cdef x264_param_t param
Expand Down Expand Up @@ -487,6 +495,10 @@ cdef class Encoder:
self.bytes_out = 0
self.last_frame_times = []
self.first_frame_timestamp = 0
f = self.file
if f:
self.file = None
f.close()


def get_info(self): #@DuplicatedSignature
Expand Down Expand Up @@ -643,6 +655,9 @@ cdef class Encoder:
self.frames += 1
self.last_frame_times.append((start, end))
assert self.context!=NULL
if self.file and frame_size>0:
self.file.write(cdata)
self.file.flush()
return cdata, client_options


Expand Down
18 changes: 18 additions & 0 deletions src/xpra/codecs/vpx/encoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import os
from collections import deque
from xpra.codecs.codec_constants import video_spec
from xpra.os_util import bytestostr
from xpra.util import AtomicInteger

from xpra.log import Logger
log = Logger("encoder", "vpx")

SAVE_TO_FILE = os.environ.get("XPRA_SAVE_TO_FILE")


#sensible default:
cpus = 2
Expand Down Expand Up @@ -269,12 +272,14 @@ def get_output_colorspaces(encoding, input_colorspace):
return [input_colorspace]


generation = AtomicInteger()
def get_info():
global CODECS, MAX_SIZE
info = {"version" : get_version(),
"encodings" : CODECS,
"buffer_api" : get_buffer_api_version(),
"abi_version" : get_abi_version(),
"generation" : generation.get(),
"build_config" : vpx_codec_build_config()}
for e, maxsize in MAX_SIZE.items():
info["%s.max-size" % e] = maxsize
Expand Down Expand Up @@ -368,6 +373,7 @@ cdef class Encoder:
cdef int quality
cdef int lossless
cdef object last_frame_times
cdef object file

cdef object __weakref__

Expand Down Expand Up @@ -461,6 +467,11 @@ cdef class Encoder:
self.codec_control("periodic Q boost", VP9E_SET_FRAME_PERIODIC_BOOST, 0)
self.do_set_encoding_speed(speed)
self.do_set_encoding_quality(quality)
gen = generation.increase()
if SAVE_TO_FILE is not None:
filename = SAVE_TO_FILE+str(gen)+".%s" % encoding
self.file = open(filename, 'wb')
log.info("saving %s stream to %s", encoding, filename)


def codec_control(self, info, int attr, int value):
Expand Down Expand Up @@ -563,6 +574,10 @@ cdef class Encoder:
self.max_threads = 0
self.encoding = ""
self.src_format = ""
f = self.file
if f:
self.file = None
f.close()


def compress_image(self, image, quality=-1, speed=-1, options={}):
Expand Down Expand Up @@ -659,6 +674,9 @@ cdef class Encoder:
log("vpx returning %s image: %s bytes", self.encoding, len(img))
end = time.time()
self.last_frame_times.append((start, end))
if self.file and pkt.data.frame.sz>0:
self.file.write(img)
self.file.flush()
return img

def set_encoding_speed(self, int pct):
Expand Down
25 changes: 20 additions & 5 deletions src/xpra/codecs/xvid/encoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import os
from xpra.log import Logger
log = Logger("encoder", "xvid")

from xpra.util import nonl
from xpra.os_util import bytestostr
from xpra.codecs.codec_constants import get_subsampling_divs, video_spec
from collections import deque
from xpra.util import AtomicInteger
from xpra.codecs.codec_constants import video_spec

from libc.stdint cimport int64_t, uint64_t, uint8_t
SAVE_TO_FILE = os.environ.get("XPRA_SAVE_TO_FILE")


from libc.stdint cimport uint8_t

cdef extern from "string.h":
void * memset ( void * ptr, int value, size_t num )

Expand Down Expand Up @@ -269,11 +269,13 @@ def get_version():
def get_type():
return "xvid"

generation = AtomicInteger()
def get_info():
global COLORSPACES, MAX_WIDTH, MAX_HEIGHT
return {"version" : get_version(),
"buffer_api": get_buffer_api_version(),
"max-size" : (MAX_WIDTH, MAX_HEIGHT),
"generation": generation.get(),
"formats" : COLORSPACES}

def get_encodings():
Expand Down Expand Up @@ -310,6 +312,7 @@ cdef class Encoder:
cdef int speed
cdef unsigned long long bytes_in
cdef unsigned long long bytes_out
cdef object file

cdef object __weakref__

Expand All @@ -326,6 +329,11 @@ cdef class Encoder:
self.frames = 0
self.time = 0
self.init_encoder()
gen = generation.increase()
if SAVE_TO_FILE is not None:
filename = SAVE_TO_FILE+str(gen)+".%s" % encoding
self.file = open(filename, 'wb')
log.info("saving %s stream to %s", encoding, filename)

cdef init_encoder(self):
cdef int r, i
Expand Down Expand Up @@ -367,6 +375,10 @@ cdef class Encoder:
self.time = 0
self.quality = 0
self.speed = 0
f = self.file
if f:
self.file = None
f.close()


def get_info(self): #@DuplicatedSignature
Expand Down Expand Up @@ -489,6 +501,9 @@ cdef class Encoder:
self.time += end-start
self.frames += 1
assert self.context!=NULL
if self.file and r>0:
self.file.write(cdata)
self.file.flush()
return cdata, client_options


Expand Down

0 comments on commit 0b09f7c

Please sign in to comment.