Created
January 22, 2015 11:59
-
-
Save lubosz/43ba48cdb74b6dd77d33 to your computer and use it in GitHub Desktop.
Test for testing drm formats and dmabuf pipelines for GStreamer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import subprocess, os, re | |
from gi.repository import Gst | |
from IPython import embed | |
Gst.init() | |
def get_format_list_for(element, direction): | |
factory = Gst.ElementFactory.find(element) | |
for pad_template in factory.get_static_pad_templates(): | |
if pad_template.direction == direction: | |
caps = pad_template.get_caps().to_string() | |
#print(element, caps) | |
formats = caps[caps.find("{")+1:caps.find("}")].split(",") | |
return [f.strip() for f in formats] | |
good_drm_formats_string =""" | |
DRM_FORMAT_RGB565 | |
DRM_FORMAT_XRGB8888 | |
DRM_FORMAT_ARGB8888 | |
DRM_FORMAT_XBGR8888 | |
DRM_FORMAT_ABGR8888 | |
""" | |
good_drm_formats = good_drm_formats_string.split() | |
blacklist =""" | |
ERROR: from element /GstPipeline:pipeline0/GstGLImageSink:glimagesink0: Output window was closed | |
libEGL debug: EGL user error 0x3004 (EGL_BAD_ATTRIBUTE) in eglCreateContext | |
""" | |
good_v_formats = ['RGB16', 'BGR', 'RGB', 'BGRx', 'BGRA', 'xRGB', 'ARGB', 'YUY2', 'UYVY'] | |
good_combos = [ | |
('RGB16','DRM_FORMAT_RGB565', 'v4l2'), | |
#('BGR','DRM_FORMAT_RGB565'), | |
#('RGB','DRM_FORMAT_RGB565'), | |
('BGRx','DRM_FORMAT_XRGB8888', 'v4l2'), | |
('BGRA','DRM_FORMAT_ARGB8888', 'v4l2'), | |
('RGBx','DRM_FORMAT_XBGR8888', 'intel'), | |
('RGBA','DRM_FORMAT_ABGR8888', 'intel'), | |
#('xRGB','DRM_FORMAT_RGB565'), | |
#('ARGB','DRM_FORMAT_RGB565'), | |
#('YUY2','DRM_FORMAT_RGB565'), | |
#('UYVY','DRM_FORMAT_RGB565') | |
] | |
header = open("/usr/include/libdrm/drm_fourcc.h") | |
drm_formats = {} | |
for line in header.readlines(): | |
if "DRM_FORMAT" in line: | |
fourcc = "".join([x.replace("'", "") for x in line.split("(")[1].split(")")[0].split(", ")]) | |
if (len(fourcc) == 4): | |
drm_name = line.strip().split()[1] | |
drm_formats[drm_name] = fourcc | |
def check_drm_formats(): | |
for dformat in drm_formats: | |
run_test(dformat, "BGRA") | |
def inteldmasource(format, buffers): | |
return ["videotestsrc", "num-buffers=%d" % buffers, "!", "video/x-raw,format=%s" % format, "!", "inteldmabufupload"] | |
def v4l2source(format, buffers): | |
return ["v4l2src", "device=/dev/video1", "io-mode=4", "num-buffers=%d" % buffers, "!", "video/x-raw,format=%s" % format] | |
def run_test(drm_format, v4l2src_format, buffers, source=""): | |
env = os.environ.copy() | |
env["EGL_LOG_LEVEL"] = "debug" | |
env["MESA_DEBUG"] = "1" | |
env["GST_GL_PLATFORM"] = "egl" | |
env["GST_GL_API"] = "gles2" | |
env["GST_GL_DRM_FOURCC_OVERRIDE"] = drm_formats[drm_format] | |
if (source == "intel"): | |
source = inteldmasource(v4l2src_format, buffers) | |
else: | |
source = v4l2source(v4l2src_format, buffers) | |
command = ["gst-launch-1.0"] + source + ["!", "glimagesink"] | |
p = subprocess.Popen(command, env=env, stderr=subprocess.PIPE, stdout=subprocess.PIPE) | |
out, err = p.communicate() | |
errors = [] | |
for line in err.decode().strip().split("\n"): | |
if ("error" in line.lower()): | |
if line not in blacklist: | |
errors.append(line) | |
errors = list(set(errors)) | |
print("======================================") | |
print("command : %s" % " ".join(command)) | |
print("drm format : %s" % drm_format) | |
print("fourcc : %s" % drm_formats[drm_format]) | |
print("v4l2src caps: %s" % v4l2src_format) | |
if errors: | |
print("== ERRORS ============================") | |
for error in errors: | |
print(error) | |
print("======================================\n\n") | |
return False | |
else: | |
print("== SUCCESS ===========================") | |
return True | |
def test_drm_formats(): | |
successes, fails = [], [] | |
for dformat in drm_formats: | |
if run_test(dformat, "BGRA", 1): | |
successes.append(dformat) | |
else: | |
fails.append(dformat) | |
print("successes:", successes) | |
print("fails:", fails) | |
def test_good_formats(): | |
successes, fails = [], [] | |
for drm_format in good_drm_formats: | |
for v_format in good_v_formats: | |
if run_test(drm_format, v_format, 1): | |
successes.append((drm_format,v_format)) | |
else: | |
fails.append((dformat,v_format)) | |
print("successes:", successes) | |
print("fails:", fails) | |
def test_v4l2src_formats(v4l2src_formats, buffers): | |
successes, fails = [], [] | |
for vformat in v4l2src_formats: | |
if run_test("DRM_FORMAT_XRGB8888", vformat, buffers): | |
successes.append(vformat) | |
else: | |
fails.append(vformat) | |
print("successes:", successes) | |
print("fails:", fails) | |
def test_combos(): | |
for combo in good_combos: | |
run_test(combo[1], combo[0], 100, combo[2]) | |
def test_with_all_drm(vformat): | |
successes, fails = [], [] | |
for dformat in drm_formats: | |
if run_test(dformat, vformat, 100): | |
successes.append(dformat) | |
else: | |
fails.append(dformat) | |
print("successes:", successes) | |
print("fails:", fails) | |
def test_with_good_drm(vformat): | |
successes, fails = [], [] | |
for dformat in good_drm_formats: | |
if run_test(dformat, vformat, 100): | |
successes.append(dformat) | |
else: | |
fails.append(dformat) | |
print("successes:", successes) | |
print("fails:", fails) | |
format_lists = {} | |
def add_format_list(element, direction): | |
format_lists[element] = get_format_list_for(element, direction) | |
print(element, direction) | |
print(format_lists[element]) | |
def find_format_matches(src, sink): | |
matches = [] | |
for sink_format in sink: | |
for src_format in src: | |
if sink_format == src_format: | |
matches.append(sink_format) | |
return matches | |
add_format_list("inteldmabufupload", Gst.PadDirection.SRC) | |
add_format_list("v4l2src", Gst.PadDirection.SRC) | |
add_format_list("glimagesink", Gst.PadDirection.SINK) | |
intel_matches = find_format_matches(format_lists["inteldmabufupload"], format_lists["glimagesink"]) | |
print("matches for inteldmabufupload:", intel_matches) | |
v4l2_matches = find_format_matches(format_lists["v4l2src"], format_lists["glimagesink"]) | |
print("matches for v4l2src:", v4l2_matches) | |
#for match in intel_matches: | |
# run_test('DRM_FORMAT_ABGR8888', match, 100, "intel") | |
#test_with_good_drm('xRGB') | |
#for match in v4l2_matches: | |
# run_test('DRM_FORMAT_ABGR8888', match, 100, "v4l2") | |
#test_v4l2src_formats() | |
#test_v4l2src_formats() | |
#test_good_formats()test_with_good_drm("BGRA") | |
test_combos() | |
#test_v4l2src_formats(intel_matches, 100) | |
#test_with_all_drm("RGBA") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment