tests: inforce gstreamer code-style

This commit is contained in:
Víctor Manuel Jáquez Leal 2016-04-29 12:48:44 +02:00
parent 018ea8b2fc
commit 74ebee5339
18 changed files with 8345 additions and 8445 deletions

View file

@ -24,170 +24,172 @@
#include <gst/vaapi/gstvaapidisplay.h>
#include "codec.h"
typedef struct {
const gchar *codec_str;
GstVaapiCodec codec;
const gchar *caps_str;
typedef struct
{
const gchar *codec_str;
GstVaapiCodec codec;
const gchar *caps_str;
} CodecMap;
static const CodecMap g_codec_map[] = {
{ "h264", GST_VAAPI_CODEC_H264,
"video/x-h264" },
{ "jpeg", GST_VAAPI_CODEC_JPEG,
"image/jpeg" },
{ "mpeg2", GST_VAAPI_CODEC_MPEG2,
"video/mpeg, mpegversion=2" },
{ "mpeg4", GST_VAAPI_CODEC_MPEG4,
"video/mpeg, mpegversion=4" },
{ "wmv3", GST_VAAPI_CODEC_VC1,
"video/x-wmv, wmvversion=3" },
{ "vc1", GST_VAAPI_CODEC_VC1,
"video/x-wmv, wmvversion=3, format=(string)WVC1" },
{ NULL, }
{"h264", GST_VAAPI_CODEC_H264,
"video/x-h264"},
{"jpeg", GST_VAAPI_CODEC_JPEG,
"image/jpeg"},
{"mpeg2", GST_VAAPI_CODEC_MPEG2,
"video/mpeg, mpegversion=2"},
{"mpeg4", GST_VAAPI_CODEC_MPEG4,
"video/mpeg, mpegversion=4"},
{"wmv3", GST_VAAPI_CODEC_VC1,
"video/x-wmv, wmvversion=3"},
{"vc1", GST_VAAPI_CODEC_VC1,
"video/x-wmv, wmvversion=3, format=(string)WVC1"},
{NULL,}
};
static const CodecMap *
get_codec_map(GstVaapiCodec codec)
get_codec_map (GstVaapiCodec codec)
{
const CodecMap *m;
const CodecMap *m;
if (codec) {
for (m = g_codec_map; m->codec_str != NULL; m++) {
if (m->codec == codec)
return m;
}
if (codec) {
for (m = g_codec_map; m->codec_str != NULL; m++) {
if (m->codec == codec)
return m;
}
return NULL;
}
return NULL;
}
const gchar *
string_from_codec(GstVaapiCodec codec)
string_from_codec (GstVaapiCodec codec)
{
const CodecMap * const m = get_codec_map(codec);
const CodecMap *const m = get_codec_map (codec);
return m ? m->codec_str : NULL;
return m ? m->codec_str : NULL;
}
GstCaps *
caps_from_codec(GstVaapiCodec codec)
caps_from_codec (GstVaapiCodec codec)
{
const CodecMap * const m = get_codec_map(codec);
const CodecMap *const m = get_codec_map (codec);
return m ? gst_caps_from_string(m->caps_str) : NULL;
return m ? gst_caps_from_string (m->caps_str) : NULL;
}
GstVaapiCodec
identify_codec_from_string(const gchar *codec_str)
identify_codec_from_string (const gchar * codec_str)
{
const CodecMap *m;
const CodecMap *m;
if (codec_str) {
for (m = g_codec_map; m->codec_str != NULL; m++) {
if (g_ascii_strcasecmp(m->codec_str, codec_str) == 0)
return m->codec;
}
if (codec_str) {
for (m = g_codec_map; m->codec_str != NULL; m++) {
if (g_ascii_strcasecmp (m->codec_str, codec_str) == 0)
return m->codec;
}
return 0;
}
return 0;
}
typedef struct {
GMappedFile *file;
guint8 *data;
guint size;
guint probability;
GstCaps *caps;
GstTypeFind type_find;
typedef struct
{
GMappedFile *file;
guint8 *data;
guint size;
guint probability;
GstCaps *caps;
GstTypeFind type_find;
} CodecIdentifier;
static const guint8 *
codec_identifier_peek(gpointer data, gint64 offset, guint size)
codec_identifier_peek (gpointer data, gint64 offset, guint size)
{
CodecIdentifier * const cip = data;
CodecIdentifier *const cip = data;
if (offset >= 0 && offset + size <= cip->size)
return cip->data + offset;
if (offset < 0 && ((gint)cip->size + offset) >= 0)
return &cip->data[cip->size + offset];
return NULL;
if (offset >= 0 && offset + size <= cip->size)
return cip->data + offset;
if (offset < 0 && ((gint) cip->size + offset) >= 0)
return &cip->data[cip->size + offset];
return NULL;
}
static void
codec_identifier_suggest(gpointer data, guint probability, GstCaps *caps)
codec_identifier_suggest (gpointer data, guint probability, GstCaps * caps)
{
CodecIdentifier * const cip = data;
CodecIdentifier *const cip = data;
if (cip->probability < probability) {
cip->probability = probability;
gst_caps_replace(&cip->caps, caps);
}
if (cip->probability < probability) {
cip->probability = probability;
gst_caps_replace (&cip->caps, caps);
}
}
static void
codec_identifier_free(CodecIdentifier *cip)
codec_identifier_free (CodecIdentifier * cip)
{
if (!cip)
return;
if (!cip)
return;
if (cip->file) {
g_mapped_file_unref(cip->file);
cip->file = NULL;
}
gst_caps_replace(&cip->caps, NULL);
g_slice_free(CodecIdentifier, cip);
if (cip->file) {
g_mapped_file_unref (cip->file);
cip->file = NULL;
}
gst_caps_replace (&cip->caps, NULL);
g_slice_free (CodecIdentifier, cip);
}
static CodecIdentifier *
codec_identifier_new(const gchar *filename)
codec_identifier_new (const gchar * filename)
{
CodecIdentifier *cip;
GstTypeFind *tfp;
CodecIdentifier *cip;
GstTypeFind *tfp;
cip = g_slice_new0(CodecIdentifier);
if (!cip)
return NULL;
cip = g_slice_new0 (CodecIdentifier);
if (!cip)
return NULL;
cip->file = g_mapped_file_new(filename, FALSE, NULL);
if (!cip->file)
goto error;
cip->file = g_mapped_file_new (filename, FALSE, NULL);
if (!cip->file)
goto error;
cip->size = g_mapped_file_get_length(cip->file);
cip->data = (guint8 *)g_mapped_file_get_contents(cip->file);
if (!cip->data)
goto error;
cip->size = g_mapped_file_get_length (cip->file);
cip->data = (guint8 *) g_mapped_file_get_contents (cip->file);
if (!cip->data)
goto error;
tfp = &cip->type_find;
tfp->peek = codec_identifier_peek;
tfp->suggest = codec_identifier_suggest;
tfp->data = cip;
return cip;
tfp = &cip->type_find;
tfp->peek = codec_identifier_peek;
tfp->suggest = codec_identifier_suggest;
tfp->data = cip;
return cip;
error:
codec_identifier_free(cip);
return NULL;
codec_identifier_free (cip);
return NULL;
}
GstVaapiCodec
identify_codec(const gchar *filename)
identify_codec (const gchar * filename)
{
CodecIdentifier *cip;
GList *type_list, *l;
guint32 codec = 0;
CodecIdentifier *cip;
GList *type_list, *l;
guint32 codec = 0;
cip = codec_identifier_new(filename);
if (!cip)
return 0;
cip = codec_identifier_new (filename);
if (!cip)
return 0;
type_list = gst_type_find_factory_get_list();
for (l = type_list; l != NULL; l = l->next) {
GstTypeFindFactory * const factory = GST_TYPE_FIND_FACTORY(l->data);
gst_type_find_factory_call_function(factory, &cip->type_find);
}
g_list_free(type_list);
type_list = gst_type_find_factory_get_list ();
for (l = type_list; l != NULL; l = l->next) {
GstTypeFindFactory *const factory = GST_TYPE_FIND_FACTORY (l->data);
gst_type_find_factory_call_function (factory, &cip->type_find);
}
g_list_free (type_list);
if (cip->probability >= GST_TYPE_FIND_LIKELY)
codec = gst_vaapi_profile_get_codec(
gst_vaapi_profile_from_caps(cip->caps));
if (cip->probability >= GST_TYPE_FIND_LIKELY)
codec =
gst_vaapi_profile_get_codec (gst_vaapi_profile_from_caps (cip->caps));
codec_identifier_free(cip);
return codec;
codec_identifier_free (cip);
return codec;
}

View file

@ -34,169 +34,169 @@
#include "test-h264.h"
#include "test-vc1.h"
typedef void (*GetVideoInfoFunc)(VideoDecodeInfo *info);
typedef void (*GetVideoInfoFunc) (VideoDecodeInfo * info);
typedef struct _CodecDefs CodecDefs;
struct _CodecDefs {
const gchar *codec_str;
GetVideoInfoFunc get_video_info;
struct _CodecDefs
{
const gchar *codec_str;
GetVideoInfoFunc get_video_info;
};
static const CodecDefs g_codec_defs[] = {
#define INIT_FUNCS(CODEC) { #CODEC, CODEC##_get_video_info }
INIT_FUNCS(jpeg),
INIT_FUNCS(mpeg2),
INIT_FUNCS(mpeg4),
INIT_FUNCS(h264),
INIT_FUNCS(vc1),
INIT_FUNCS (jpeg),
INIT_FUNCS (mpeg2),
INIT_FUNCS (mpeg4),
INIT_FUNCS (h264),
INIT_FUNCS (vc1),
#undef INIT_FUNCS
{ NULL, }
{NULL,}
};
static const CodecDefs *
find_codec_defs(const gchar *codec_str)
find_codec_defs (const gchar * codec_str)
{
const CodecDefs *c;
for (c = g_codec_defs; c->codec_str; c++)
if (strcmp(codec_str, c->codec_str) == 0)
return c;
return NULL;
const CodecDefs *c;
for (c = g_codec_defs; c->codec_str; c++)
if (strcmp (codec_str, c->codec_str) == 0)
return c;
return NULL;
}
static inline const CodecDefs *
get_codec_defs(GstVaapiDecoder *decoder)
get_codec_defs (GstVaapiDecoder * decoder)
{
return gst_vaapi_decoder_get_user_data(decoder);
return gst_vaapi_decoder_get_user_data (decoder);
}
static inline void
set_codec_defs(GstVaapiDecoder *decoder, const CodecDefs *c)
set_codec_defs (GstVaapiDecoder * decoder, const CodecDefs * c)
{
gst_vaapi_decoder_set_user_data(decoder, (gpointer)c);
gst_vaapi_decoder_set_user_data (decoder, (gpointer) c);
}
GstVaapiDecoder *
decoder_new(GstVaapiDisplay *display, const gchar *codec_name)
decoder_new (GstVaapiDisplay * display, const gchar * codec_name)
{
GstVaapiDecoder *decoder;
const CodecDefs *codec;
GstCaps *caps;
VideoDecodeInfo info;
GstVaapiDecoder *decoder;
const CodecDefs *codec;
GstCaps *caps;
VideoDecodeInfo info;
if (!codec_name)
codec_name = "h264";
if (!codec_name)
codec_name = "h264";
codec = find_codec_defs(codec_name);
if (!codec) {
GST_ERROR("failed to find %s codec data", codec_name);
return NULL;
}
codec = find_codec_defs (codec_name);
if (!codec) {
GST_ERROR ("failed to find %s codec data", codec_name);
return NULL;
}
codec->get_video_info(&info);
caps = gst_vaapi_profile_get_caps(info.profile);
if (!caps) {
GST_ERROR("failed to create decoder caps");
return NULL;
}
codec->get_video_info (&info);
caps = gst_vaapi_profile_get_caps (info.profile);
if (!caps) {
GST_ERROR ("failed to create decoder caps");
return NULL;
}
if (info.width > 0 && info.height > 0)
gst_caps_set_simple(caps,
"width", G_TYPE_INT, info.width,
"height", G_TYPE_INT, info.height,
NULL);
if (info.width > 0 && info.height > 0)
gst_caps_set_simple (caps,
"width", G_TYPE_INT, info.width,
"height", G_TYPE_INT, info.height, NULL);
switch (gst_vaapi_profile_get_codec(info.profile)) {
switch (gst_vaapi_profile_get_codec (info.profile)) {
case GST_VAAPI_CODEC_H264:
decoder = gst_vaapi_decoder_h264_new(display, caps);
break;
decoder = gst_vaapi_decoder_h264_new (display, caps);
break;
#if USE_JPEG_DECODER
case GST_VAAPI_CODEC_JPEG:
decoder = gst_vaapi_decoder_jpeg_new(display, caps);
break;
decoder = gst_vaapi_decoder_jpeg_new (display, caps);
break;
#endif
case GST_VAAPI_CODEC_MPEG2:
decoder = gst_vaapi_decoder_mpeg2_new(display, caps);
break;
decoder = gst_vaapi_decoder_mpeg2_new (display, caps);
break;
case GST_VAAPI_CODEC_MPEG4:
decoder = gst_vaapi_decoder_mpeg4_new(display, caps);
break;
decoder = gst_vaapi_decoder_mpeg4_new (display, caps);
break;
case GST_VAAPI_CODEC_VC1:
decoder = gst_vaapi_decoder_vc1_new(display, caps);
break;
decoder = gst_vaapi_decoder_vc1_new (display, caps);
break;
default:
decoder = NULL;
break;
}
gst_caps_unref(caps);
if (!decoder) {
GST_ERROR("failed to create %s decoder", codec->codec_str);
return NULL;
}
decoder = NULL;
break;
}
gst_caps_unref (caps);
if (!decoder) {
GST_ERROR ("failed to create %s decoder", codec->codec_str);
return NULL;
}
set_codec_defs(decoder, codec);
return decoder;
set_codec_defs (decoder, codec);
return decoder;
}
gboolean
decoder_put_buffers(GstVaapiDecoder *decoder)
decoder_put_buffers (GstVaapiDecoder * decoder)
{
const CodecDefs *codec;
VideoDecodeInfo info;
GstBuffer *buffer;
gboolean success;
const CodecDefs *codec;
VideoDecodeInfo info;
GstBuffer *buffer;
gboolean success;
g_return_val_if_fail(decoder != NULL, FALSE);
g_return_val_if_fail (decoder != NULL, FALSE);
codec = get_codec_defs(decoder);
g_return_val_if_fail(codec != NULL, FALSE);
codec = get_codec_defs (decoder);
g_return_val_if_fail (codec != NULL, FALSE);
codec->get_video_info(&info);
buffer = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY,
(guchar *)info.data, info.data_size, 0, info.data_size, NULL, NULL);
if (!buffer) {
GST_ERROR("failed to create encoded data buffer");
return FALSE;
}
codec->get_video_info (&info);
buffer = gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY,
(guchar *) info.data, info.data_size, 0, info.data_size, NULL, NULL);
if (!buffer) {
GST_ERROR ("failed to create encoded data buffer");
return FALSE;
}
success = gst_vaapi_decoder_put_buffer(decoder, buffer);
gst_buffer_unref(buffer);
if (!success) {
GST_ERROR("failed to send video data to the decoder");
return FALSE;
}
success = gst_vaapi_decoder_put_buffer (decoder, buffer);
gst_buffer_unref (buffer);
if (!success) {
GST_ERROR ("failed to send video data to the decoder");
return FALSE;
}
if (!gst_vaapi_decoder_put_buffer(decoder, NULL)) {
GST_ERROR("failed to submit <end-of-stream> to the decoder");
return FALSE;
}
return TRUE;
if (!gst_vaapi_decoder_put_buffer (decoder, NULL)) {
GST_ERROR ("failed to submit <end-of-stream> to the decoder");
return FALSE;
}
return TRUE;
}
GstVaapiSurfaceProxy *
decoder_get_surface(GstVaapiDecoder *decoder)
decoder_get_surface (GstVaapiDecoder * decoder)
{
GstVaapiSurfaceProxy *proxy;
GstVaapiDecoderStatus status;
GstVaapiSurfaceProxy *proxy;
GstVaapiDecoderStatus status;
g_return_val_if_fail(decoder != NULL, NULL);
g_return_val_if_fail (decoder != NULL, NULL);
status = gst_vaapi_decoder_get_surface(decoder, &proxy);
if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) {
GST_ERROR("failed to get decoded surface (decoder status %d)", status);
return NULL;
}
return proxy;
status = gst_vaapi_decoder_get_surface (decoder, &proxy);
if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) {
GST_ERROR ("failed to get decoded surface (decoder status %d)", status);
return NULL;
}
return proxy;
}
const gchar *
decoder_get_codec_name(GstVaapiDecoder *decoder)
decoder_get_codec_name (GstVaapiDecoder * decoder)
{
const CodecDefs *codec;
const CodecDefs *codec;
g_return_val_if_fail(decoder != NULL, NULL);
g_return_val_if_fail (decoder != NULL, NULL);
codec = get_codec_defs(decoder);
g_return_val_if_fail(codec != NULL, FALSE);
codec = get_codec_defs (decoder);
g_return_val_if_fail (codec != NULL, FALSE);
return codec->codec_str;
return codec->codec_str;
}

View file

@ -25,460 +25,376 @@
#include "image.h"
static gboolean
image_draw_rectangle(
GstVaapiImage *image,
gint x,
gint y,
guint width,
guint height,
guint32 color,
guint32 flags
);
image_draw_rectangle (GstVaapiImage * image,
gint x, gint y, guint width, guint height, guint32 color, guint32 flags);
static gboolean
image_draw_color_rectangles(
GstVaapiImage *image,
guint width,
guint height,
const guint32 colors[4],
guint32 flags
)
image_draw_color_rectangles (GstVaapiImage * image,
guint width, guint height, const guint32 colors[4], guint32 flags)
{
const guint w = width / 2;
const guint h = height / 2;
const guint w = width / 2;
const guint h = height / 2;
if (!image_draw_rectangle(image, 0, 0, w, h, colors[0], flags))
return FALSE;
if (!image_draw_rectangle(image, w, 0, w, h, colors[1], flags))
return FALSE;
if (!image_draw_rectangle(image, 0, h, w, h, colors[2], flags))
return FALSE;
if (!image_draw_rectangle(image, w, h, w, h, colors[3], flags))
return FALSE;
return TRUE;
if (!image_draw_rectangle (image, 0, 0, w, h, colors[0], flags))
return FALSE;
if (!image_draw_rectangle (image, w, 0, w, h, colors[1], flags))
return FALSE;
if (!image_draw_rectangle (image, 0, h, w, h, colors[2], flags))
return FALSE;
if (!image_draw_rectangle (image, w, h, w, h, colors[3], flags))
return FALSE;
return TRUE;
}
GstVaapiImage *
image_generate(
GstVaapiDisplay *display,
GstVideoFormat format,
guint width,
guint height
)
image_generate (GstVaapiDisplay * display,
GstVideoFormat format, guint width, guint height)
{
return image_generate_full(display, format, width, height, 0);
return image_generate_full (display, format, width, height, 0);
}
GstVaapiImage *
image_generate_full(
GstVaapiDisplay *display,
GstVideoFormat format,
guint width,
guint height,
guint32 flags
)
image_generate_full (GstVaapiDisplay * display,
GstVideoFormat format, guint width, guint height, guint32 flags)
{
GstVaapiImage *image;
GstVaapiImage *image;
static const guint32 rgb_colors[4] =
{ 0xffff0000, 0xff00ff00, 0xff0000ff, 0xff000000 };
static const guint32 bgr_colors[4] =
{ 0xff000000, 0xff0000ff, 0xff00ff00, 0xffff0000 };
static const guint32 inv_colors[4] =
{ 0xffdeadc0, 0xffdeadc0, 0xffdeadc0, 0xffdeadc0 };
static const guint32 rgb_colors[4] =
{ 0xffff0000, 0xff00ff00, 0xff0000ff, 0xff000000 };
static const guint32 bgr_colors[4] =
{ 0xff000000, 0xff0000ff, 0xff00ff00, 0xffff0000 };
static const guint32 inv_colors[4] =
{ 0xffdeadc0, 0xffdeadc0, 0xffdeadc0, 0xffdeadc0 };
image = gst_vaapi_image_new(display, format, width, height);
if (!image)
return NULL;
image = gst_vaapi_image_new (display, format, width, height);
if (!image)
return NULL;
if (flags) {
if (!image_draw_color_rectangles(image, width, height,
((flags & GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD) ?
rgb_colors : inv_colors),
GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD))
goto error;
if (flags) {
if (!image_draw_color_rectangles (image, width, height,
((flags & GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD) ?
rgb_colors : inv_colors),
GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD))
goto error;
if (!image_draw_color_rectangles(image, width, height,
((flags & GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD) ?
bgr_colors : inv_colors),
GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD))
goto error;
}
else if (!image_draw_color_rectangles(image, width, height, rgb_colors, 0))
goto error;
return image;
if (!image_draw_color_rectangles (image, width, height,
((flags & GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD) ?
bgr_colors : inv_colors),
GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD))
goto error;
} else if (!image_draw_color_rectangles (image, width, height, rgb_colors, 0))
goto error;
return image;
error:
gst_vaapi_object_unref(image);
return NULL;
gst_vaapi_object_unref (image);
return NULL;
}
typedef void (*DrawRectFunc)(
guchar *pixels[3],
guint stride[3],
gint x,
gint y,
guint width,
guint height,
guint32 color
);
typedef void (*DrawRectFunc) (guchar * pixels[3],
guint stride[3], gint x, gint y, guint width, guint height, guint32 color);
static void draw_rect_ARGB(
guchar *pixels[3],
guint stride[3],
gint x,
gint y,
guint width,
guint height,
guint32 color
)
static void
draw_rect_ARGB (guchar * pixels[3],
guint stride[3], gint x, gint y, guint width, guint height, guint32 color)
{
guint i, j;
guint i, j;
color = GUINT32_TO_BE(color);
color = GUINT32_TO_BE (color);
for (j = 0; j < height; j++) {
guint32 *p = (guint32 *)(pixels[0] + (y + j) * stride[0] + x * 4);
for (i = 0; i < width; i++)
p[i] = color;
for (j = 0; j < height; j++) {
guint32 *p = (guint32 *) (pixels[0] + (y + j) * stride[0] + x * 4);
for (i = 0; i < width; i++)
p[i] = color;
}
}
static void
draw_rect_BGRA (guchar * pixels[3],
guint stride[3], gint x, gint y, guint width, guint height, guint32 color)
{
// Converts ARGB color to BGRA
color = GUINT32_SWAP_LE_BE (color);
draw_rect_ARGB (pixels, stride, x, y, width, height, color);
}
static void
draw_rect_RGBA (guchar * pixels[3],
guint stride[3], gint x, gint y, guint width, guint height, guint32 color)
{
// Converts ARGB color to RGBA
color = ((color >> 24) & 0xff) | ((color & 0xffffff) << 8);
draw_rect_ARGB (pixels, stride, x, y, width, height, color);
}
static void
draw_rect_ABGR (guchar * pixels[3],
guint stride[3], gint x, gint y, guint width, guint height, guint32 color)
{
// Converts ARGB color to ABGR
color = ((color & 0xff00ff00) |
((color >> 16) & 0xff) | ((color & 0xff) << 16));
draw_rect_ARGB (pixels, stride, x, y, width, height, color);
}
static void
draw_rect_NV12 ( // Y, UV planes
guchar * pixels[3],
guint stride[3], gint x, gint y, guint width, guint height, guint32 color)
{
const guchar Y = color >> 16;
const guchar Cb = color >> 8;
const guchar Cr = color;
guchar *dst;
guint i, j;
dst = pixels[0] + y * stride[0] + x;
for (j = 0; j < height; j++, dst += stride[0])
for (i = 0; i < width; i++)
dst[i] = Y;
x /= 2;
y /= 2;
width /= 2;
height /= 2;
dst = pixels[1] + y * stride[1] + x * 2;
for (j = 0; j < height; j++, dst += stride[1])
for (i = 0; i < width; i++) {
dst[2 * i + 0] = Cb;
dst[2 * i + 1] = Cr;
}
}
static void draw_rect_BGRA(
guchar *pixels[3],
guint stride[3],
gint x,
gint y,
guint width,
guint height,
guint32 color
)
static void
draw_rect_YV12 ( // Y, V, U planes
guchar * pixels[3],
guint stride[3], gint x, gint y, guint width, guint height, guint32 color)
{
// Converts ARGB color to BGRA
color = GUINT32_SWAP_LE_BE(color);
const guchar Y = color >> 16;
const guchar Cb = color >> 8;
const guchar Cr = color;
guchar *pY, *pU, *pV;
guint i, j;
draw_rect_ARGB(pixels, stride, x, y, width, height, color);
}
pY = pixels[0] + y * stride[0] + x;
for (j = 0; j < height; j++, pY += stride[0])
for (i = 0; i < width; i++)
pY[i] = Y;
static void draw_rect_RGBA(
guchar *pixels[3],
guint stride[3],
gint x,
gint y,
guint width,
guint height,
guint32 color
)
{
// Converts ARGB color to RGBA
color = ((color >> 24) & 0xff) | ((color & 0xffffff) << 8);
x /= 2;
y /= 2;
width /= 2;
height /= 2;
draw_rect_ARGB(pixels, stride, x, y, width, height, color);
}
static void draw_rect_ABGR(
guchar *pixels[3],
guint stride[3],
gint x,
gint y,
guint width,
guint height,
guint32 color
)
{
// Converts ARGB color to ABGR
color = ((color & 0xff00ff00) |
((color >> 16) & 0xff) |
((color & 0xff) << 16));
draw_rect_ARGB(pixels, stride, x, y, width, height, color);
}
static void draw_rect_NV12( // Y, UV planes
guchar *pixels[3],
guint stride[3],
gint x,
gint y,
guint width,
guint height,
guint32 color
)
{
const guchar Y = color >> 16;
const guchar Cb = color >> 8;
const guchar Cr = color;
guchar *dst;
guint i, j;
dst = pixels[0] + y * stride[0] + x;
for (j = 0; j < height; j++, dst += stride[0])
for (i = 0; i < width; i++)
dst[i] = Y;
x /= 2;
y /= 2;
width /= 2;
height /= 2;
dst = pixels[1] + y * stride[1] + x * 2;
for (j = 0; j < height; j++, dst += stride[1])
for (i = 0; i < width; i++) {
dst[2*i + 0] = Cb;
dst[2*i + 1] = Cr;
}
}
static void draw_rect_YV12( // Y, V, U planes
guchar *pixels[3],
guint stride[3],
gint x,
gint y,
guint width,
guint height,
guint32 color
)
{
const guchar Y = color >> 16;
const guchar Cb = color >> 8;
const guchar Cr = color;
guchar *pY, *pU, *pV;
guint i, j;
pY = pixels[0] + y * stride[0] + x;
for (j = 0; j < height; j++, pY += stride[0])
for (i = 0; i < width; i++)
pY[i] = Y;
x /= 2;
y /= 2;
width /= 2;
height /= 2;
pV = pixels[1] + y * stride[1] + x;
pU = pixels[2] + y * stride[2] + x;
for (j = 0; j < height; j++, pU += stride[1], pV += stride[2])
for (i = 0; i < width; i++) {
pU[i] = Cb;
pV[i] = Cr;
}
}
static void draw_rect_I420( // Y, U, V planes
guchar *pixels[3],
guint stride[3],
gint x,
gint y,
guint width,
guint height,
guint32 color
)
{
guchar *new_pixels[3] = { pixels[0], pixels[2], pixels[1] };
guint new_stride[3] = { stride[0], stride[2], stride[1] };
draw_rect_YV12(new_pixels, new_stride, x, y, width, height, color);
}
static void draw_rect_YUV422(guchar *pixels[3], guint stride[3],
gint x, gint y, guint width, guint height, guint32 color)
{
guint i, j;
width /= 2;
for (j = 0; j < height; j++) {
guint32 * const p = (guint32 *)
(pixels[0] + (y + j) * stride[0] + x * 2);
for (i = 0; i < width; i++)
p[i] = color;
pV = pixels[1] + y * stride[1] + x;
pU = pixels[2] + y * stride[2] + x;
for (j = 0; j < height; j++, pU += stride[1], pV += stride[2])
for (i = 0; i < width; i++) {
pU[i] = Cb;
pV[i] = Cr;
}
}
static void draw_rect_YUY2(guchar *pixels[3], guint stride[3],
static void
draw_rect_I420 ( // Y, U, V planes
guchar * pixels[3],
guint stride[3], gint x, gint y, guint width, guint height, guint32 color)
{
guchar *new_pixels[3] = { pixels[0], pixels[2], pixels[1] };
guint new_stride[3] = { stride[0], stride[2], stride[1] };
draw_rect_YV12 (new_pixels, new_stride, x, y, width, height, color);
}
static void
draw_rect_YUV422 (guchar * pixels[3], guint stride[3],
gint x, gint y, guint width, guint height, guint32 color)
{
const guchar Y = color >> 16;
const guchar Cb = color >> 8;
const guchar Cr = color;
guint i, j;
color = (Y << 24) | (Cb << 16) | (Y << 8) | Cr;
draw_rect_YUV422(pixels, stride, x, y, width, height, GUINT32_TO_BE(color));
width /= 2;
for (j = 0; j < height; j++) {
guint32 *const p = (guint32 *)
(pixels[0] + (y + j) * stride[0] + x * 2);
for (i = 0; i < width; i++)
p[i] = color;
}
}
static void draw_rect_UYVY(guchar *pixels[3], guint stride[3],
static void
draw_rect_YUY2 (guchar * pixels[3], guint stride[3],
gint x, gint y, guint width, guint height, guint32 color)
{
const guchar Y = color >> 16;
const guchar Cb = color >> 8;
const guchar Cr = color;
const guchar Y = color >> 16;
const guchar Cb = color >> 8;
const guchar Cr = color;
color = (Cb << 24) | (Y << 16) | (Cr << 8) | Y;
draw_rect_YUV422(pixels, stride, x, y, width, height, GUINT32_TO_BE(color));
color = (Y << 24) | (Cb << 16) | (Y << 8) | Cr;
draw_rect_YUV422 (pixels, stride, x, y, width, height, GUINT32_TO_BE (color));
}
static void draw_rect_AYUV(
guchar *pixels[3],
guint stride[3],
gint x,
gint y,
guint width,
guint height,
guint32 color
)
static void
draw_rect_UYVY (guchar * pixels[3], guint stride[3],
gint x, gint y, guint width, guint height, guint32 color)
{
guint i, j;
const guchar Y = color >> 16;
const guchar Cb = color >> 8;
const guchar Cr = color;
color = color | 0xff000000;
for (j = 0; j < height; j++) {
guint32 *p = (guint32 *)(pixels[0] + (y + j) * stride[0] + x * 4);
for (i = 0; i < width; i++)
p[i] = color;
}
color = (Cb << 24) | (Y << 16) | (Cr << 8) | Y;
draw_rect_YUV422 (pixels, stride, x, y, width, height, GUINT32_TO_BE (color));
}
static inline guint32 argb2yuv(guint32 color)
static void
draw_rect_AYUV (guchar * pixels[3],
guint stride[3], gint x, gint y, guint width, guint height, guint32 color)
{
const gint32 r = (color >> 16) & 0xff;
const gint32 g = (color >> 8) & 0xff;
const gint32 b = (color ) & 0xff;
guint i, j;
const guint32 y = (( 306 * r + 601 * g + 116 * b) >> 10);
const guint32 u = ((-172 * r - 339 * g + 512 * b) >> 10) + 128;
const guint32 v = (( 512 * r - 428 * g - 83 * b) >> 10) + 128;
color = color | 0xff000000;
return (y << 16) | (u << 8) | v;
for (j = 0; j < height; j++) {
guint32 *p = (guint32 *) (pixels[0] + (y + j) * stride[0] + x * 4);
for (i = 0; i < width; i++)
p[i] = color;
}
}
static inline guint32
argb2yuv (guint32 color)
{
const gint32 r = (color >> 16) & 0xff;
const gint32 g = (color >> 8) & 0xff;
const gint32 b = (color) & 0xff;
const guint32 y = ((306 * r + 601 * g + 116 * b) >> 10);
const guint32 u = ((-172 * r - 339 * g + 512 * b) >> 10) + 128;
const guint32 v = ((512 * r - 428 * g - 83 * b) >> 10) + 128;
return (y << 16) | (u << 8) | v;
}
gboolean
image_draw_rectangle(
GstVaapiImage *image,
gint x,
gint y,
guint width,
guint height,
guint32 color,
guint32 flags
)
image_draw_rectangle (GstVaapiImage * image,
gint x, gint y, guint width, guint height, guint32 color, guint32 flags)
{
const GstVideoFormat image_format = gst_vaapi_image_get_format(image);
const guint image_width = gst_vaapi_image_get_width(image);
const guint image_height = gst_vaapi_image_get_height(image);
GstVaapiDisplay *display;
guchar *pixels[3];
guint stride[3];
DrawRectFunc draw_rect = NULL;
guint i;
const GstVideoFormat image_format = gst_vaapi_image_get_format (image);
const guint image_width = gst_vaapi_image_get_width (image);
const guint image_height = gst_vaapi_image_get_height (image);
GstVaapiDisplay *display;
guchar *pixels[3];
guint stride[3];
DrawRectFunc draw_rect = NULL;
guint i;
static const struct {
GstVideoFormat format;
DrawRectFunc draw_rect;
}
map[] = {
static const struct
{
GstVideoFormat format;
DrawRectFunc draw_rect;
}
map[] = {
#define _(FORMAT) { GST_VIDEO_FORMAT_##FORMAT, draw_rect_##FORMAT }
_(ARGB),
_(ARGB),
_(BGRA),
_(RGBA),
_(ABGR),
_(NV12),
_(YV12),
_(I420),
_(YUY2),
_(UYVY),
_(AYUV),
_(RGBA), _(ABGR), _(NV12), _(YV12), _(I420), _(YUY2), _(UYVY), _(AYUV),
#undef _
{ 0, }
};
{
0,}
};
for (i = 0; !draw_rect && map[i].format; i++)
if (map[i].format == image_format)
draw_rect = map[i].draw_rect;
if (!draw_rect)
return FALSE;
for (i = 0; !draw_rect && map[i].format; i++)
if (map[i].format == image_format)
draw_rect = map[i].draw_rect;
if (!draw_rect)
return FALSE;
if (x < 0)
x = 0;
if (y < 0)
y = 0;
if (width > image_width - x)
width = image_width - x;
if (height > image_height - y)
height = image_height - y;
if (x < 0)
x = 0;
if (y < 0)
y = 0;
if (width > image_width - x)
width = image_width - x;
if (height > image_height - y)
height = image_height - y;
display = gst_vaapi_object_get_display(GST_VAAPI_OBJECT(image));
if (!display)
return FALSE;
display = gst_vaapi_object_get_display (GST_VAAPI_OBJECT (image));
if (!display)
return FALSE;
if (!gst_vaapi_image_map(image))
return FALSE;
if (!gst_vaapi_image_map (image))
return FALSE;
for (i = 0; i < gst_vaapi_image_get_plane_count(image); i++) {
pixels[i] = gst_vaapi_image_get_plane(image, i);
stride[i] = gst_vaapi_image_get_pitch(image, i);
switch (flags) {
case GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD:
pixels[i] += stride[i];
// fall-through
case GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD:
stride[i] *= 2;
break;
}
for (i = 0; i < gst_vaapi_image_get_plane_count (image); i++) {
pixels[i] = gst_vaapi_image_get_plane (image, i);
stride[i] = gst_vaapi_image_get_pitch (image, i);
switch (flags) {
case GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD:
pixels[i] += stride[i];
// fall-through
case GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD:
stride[i] *= 2;
break;
}
}
if (flags)
y /= 2, height /= 2;
if (flags)
y /= 2, height /= 2;
if (gst_vaapi_video_format_is_yuv(image_format))
color = argb2yuv(color);
if (gst_vaapi_video_format_is_yuv (image_format))
color = argb2yuv (color);
draw_rect(pixels, stride, x, y, width, height, color);
return gst_vaapi_image_unmap(image);
draw_rect (pixels, stride, x, y, width, height, color);
return gst_vaapi_image_unmap (image);
}
gboolean
image_upload(GstVaapiImage *image, GstVaapiSurface *surface)
image_upload (GstVaapiImage * image, GstVaapiSurface * surface)
{
GstVaapiDisplay *display;
GstVideoFormat format;
GstVaapiImage *surface_image;
GstVaapiSubpicture *subpicture;
gboolean success;
GstVaapiDisplay *display;
GstVideoFormat format;
GstVaapiImage *surface_image;
GstVaapiSubpicture *subpicture;
gboolean success;
display = gst_vaapi_object_get_display(GST_VAAPI_OBJECT(surface));
if (!display)
return FALSE;
display = gst_vaapi_object_get_display (GST_VAAPI_OBJECT (surface));
if (!display)
return FALSE;
format = gst_vaapi_image_get_format(image);
if (!format)
return FALSE;
format = gst_vaapi_image_get_format (image);
if (!format)
return FALSE;
if (gst_vaapi_surface_put_image(surface, image))
return TRUE;
surface_image = gst_vaapi_surface_derive_image(surface);
if (surface_image) {
success = gst_vaapi_image_copy(surface_image, image);
gst_vaapi_object_unref(surface_image);
if (success)
return TRUE;
}
g_print("could not upload %s image to surface\n",
gst_vaapi_video_format_to_string(format));
if (!gst_vaapi_display_has_subpicture_format(display, format, NULL))
return FALSE;
g_print("trying as a subpicture\n");
subpicture = gst_vaapi_subpicture_new(image, 0);
if (!subpicture)
g_error("could not create VA subpicture");
if (!gst_vaapi_surface_associate_subpicture(surface, subpicture,
NULL, NULL))
g_error("could not associate subpicture to surface");
/* The surface holds a reference to the subpicture. This is safe */
gst_vaapi_object_unref(subpicture);
if (gst_vaapi_surface_put_image (surface, image))
return TRUE;
surface_image = gst_vaapi_surface_derive_image (surface);
if (surface_image) {
success = gst_vaapi_image_copy (surface_image, image);
gst_vaapi_object_unref (surface_image);
if (success)
return TRUE;
}
g_print ("could not upload %s image to surface\n",
gst_vaapi_video_format_to_string (format));
if (!gst_vaapi_display_has_subpicture_format (display, format, NULL))
return FALSE;
g_print ("trying as a subpicture\n");
subpicture = gst_vaapi_subpicture_new (image, 0);
if (!subpicture)
g_error ("could not create VA subpicture");
if (!gst_vaapi_surface_associate_subpicture (surface, subpicture, NULL, NULL))
g_error ("could not associate subpicture to surface");
/* The surface holds a reference to the subpicture. This is safe */
gst_vaapi_object_unref (subpicture);
return TRUE;
}

View file

@ -48,34 +48,30 @@
static const VideoOutputInfo *g_video_output;
static const VideoOutputInfo g_video_outputs[] = {
/* Video outputs are sorted in test order for automatic characterisation */
/* Video outputs are sorted in test order for automatic characterisation */
#if USE_WAYLAND
{ "wayland",
gst_vaapi_display_wayland_new,
gst_vaapi_window_wayland_new
},
{"wayland",
gst_vaapi_display_wayland_new,
gst_vaapi_window_wayland_new},
#endif
#if USE_X11
{ "x11",
gst_vaapi_display_x11_new,
gst_vaapi_window_x11_new,
gst_vaapi_pixmap_x11_new
},
{"x11",
gst_vaapi_display_x11_new,
gst_vaapi_window_x11_new,
gst_vaapi_pixmap_x11_new},
#endif
#if USE_GLX
{ "glx",
gst_vaapi_display_glx_new,
gst_vaapi_window_glx_new,
gst_vaapi_pixmap_x11_new
},
{"glx",
gst_vaapi_display_glx_new,
gst_vaapi_window_glx_new,
gst_vaapi_pixmap_x11_new},
#endif
#if USE_DRM
{ "drm",
gst_vaapi_display_drm_new,
gst_vaapi_window_drm_new
},
{"drm",
gst_vaapi_display_drm_new,
gst_vaapi_window_drm_new},
#endif
{ NULL, }
{NULL,}
};
static gchar *g_output_name;
@ -86,163 +82,164 @@ static gboolean g_egl_mode = FALSE;
static guint g_gles_version;
static GOptionEntry g_options[] = {
{ "list-outputs", 0,
0,
G_OPTION_ARG_NONE, &g_list_outputs,
"list video outputs", NULL },
{ "output", 'o',
0,
G_OPTION_ARG_STRING, &g_output_name,
"video output name", NULL },
{ "fullscreen", 'f',
0,
G_OPTION_ARG_NONE, &g_fullscreen,
"fullscreen mode", NULL },
{ "egl", 0,
0,
G_OPTION_ARG_NONE, &g_egl_mode,
"enable EGL rendering", NULL },
{ "gles-version", 0,
0,
G_OPTION_ARG_INT, &g_gles_version,
"OpenGL|ES version (in --egl mode)", NULL },
{ NULL, }
{"list-outputs", 0,
0,
G_OPTION_ARG_NONE, &g_list_outputs,
"list video outputs", NULL},
{"output", 'o',
0,
G_OPTION_ARG_STRING, &g_output_name,
"video output name", NULL},
{"fullscreen", 'f',
0,
G_OPTION_ARG_NONE, &g_fullscreen,
"fullscreen mode", NULL},
{"egl", 0,
0,
G_OPTION_ARG_NONE, &g_egl_mode,
"enable EGL rendering", NULL},
{"gles-version", 0,
0,
G_OPTION_ARG_INT, &g_gles_version,
"OpenGL|ES version (in --egl mode)", NULL},
{NULL,}
};
static void
list_outputs(void)
list_outputs (void)
{
const VideoOutputInfo *o;
const VideoOutputInfo *o;
g_print("Video outputs:");
for (o = g_video_outputs; o->name != NULL; o++)
g_print(" %s", o->name);
g_print("\n");
g_print ("Video outputs:");
for (o = g_video_outputs; o->name != NULL; o++)
g_print (" %s", o->name);
g_print ("\n");
}
gboolean
video_output_init(int *argc, char *argv[], GOptionEntry *options)
video_output_init (int *argc, char *argv[], GOptionEntry * options)
{
GOptionContext *ctx;
gboolean success;
GOptionContext *ctx;
gboolean success;
#if !GLIB_CHECK_VERSION(2,31,0)
if (!g_thread_supported())
g_thread_init(NULL);
if (!g_thread_supported ())
g_thread_init (NULL);
#endif
ctx = g_option_context_new("- test options");
if (!ctx)
return FALSE;
ctx = g_option_context_new ("- test options");
if (!ctx)
return FALSE;
g_option_context_add_group(ctx, gst_init_get_option_group());
g_option_context_add_main_entries(ctx, g_options, NULL);
if (options)
g_option_context_add_main_entries(ctx, options, NULL);
success = g_option_context_parse(ctx, argc, &argv, NULL);
g_option_context_free(ctx);
g_option_context_add_group (ctx, gst_init_get_option_group ());
g_option_context_add_main_entries (ctx, g_options, NULL);
if (options)
g_option_context_add_main_entries (ctx, options, NULL);
success = g_option_context_parse (ctx, argc, &argv, NULL);
g_option_context_free (ctx);
if (g_list_outputs) {
list_outputs();
exit(0);
}
return success;
if (g_list_outputs) {
list_outputs ();
exit (0);
}
return success;
}
void
video_output_exit(void)
video_output_exit (void)
{
g_free(g_output_name);
gst_deinit();
g_free (g_output_name);
gst_deinit ();
}
const VideoOutputInfo *
video_output_lookup(const gchar *output_name)
video_output_lookup (const gchar * output_name)
{
const VideoOutputInfo *o;
const VideoOutputInfo *o;
if (!output_name)
return NULL;
for (o = g_video_outputs; o->name != NULL; o++) {
if (g_ascii_strcasecmp(o->name, output_name) == 0)
return o;
}
if (!output_name)
return NULL;
for (o = g_video_outputs; o->name != NULL; o++) {
if (g_ascii_strcasecmp (o->name, output_name) == 0)
return o;
}
return NULL;
}
GstVaapiDisplay *
video_output_create_display(const gchar *display_name)
video_output_create_display (const gchar * display_name)
{
const VideoOutputInfo *o = g_video_output;
GstVaapiDisplay *egl_display, *display = NULL;
const VideoOutputInfo *o = g_video_output;
GstVaapiDisplay *egl_display, *display = NULL;
if (!o) {
if (g_output_name)
o = video_output_lookup(g_output_name);
else {
for (o = g_video_outputs; o->name != NULL; o++) {
display = o->create_display(display_name);
if (display) {
if (gst_vaapi_display_get_display(display))
break;
gst_vaapi_display_unref(display);
display = NULL;
}
}
if (!o) {
if (g_output_name)
o = video_output_lookup (g_output_name);
else {
for (o = g_video_outputs; o->name != NULL; o++) {
display = o->create_display (display_name);
if (display) {
if (gst_vaapi_display_get_display (display))
break;
gst_vaapi_display_unref (display);
display = NULL;
}
if (!o || !o->name)
return NULL;
g_print("Using %s video output\n", o->name);
g_video_output = o;
}
}
if (!o || !o->name)
return NULL;
g_print ("Using %s video output\n", o->name);
g_video_output = o;
}
if (!display)
display = o->create_display(display_name);
if (!display)
display = o->create_display (display_name);
if (g_egl_mode) {
if (g_egl_mode) {
#if USE_EGL
egl_display = gst_vaapi_display_egl_new (display, g_gles_version);
egl_display = gst_vaapi_display_egl_new (display, g_gles_version);
#else
egl_display = NULL;
g_print("error: unsupported EGL renderering mode\n");
egl_display = NULL;
g_print ("error: unsupported EGL renderering mode\n");
#endif
gst_vaapi_display_unref (display);
if (!egl_display)
return NULL;
display = egl_display;
}
return display;
gst_vaapi_display_unref (display);
if (!egl_display)
return NULL;
display = egl_display;
}
return display;
}
GstVaapiWindow *
video_output_create_window(GstVaapiDisplay *display, guint width, guint height)
video_output_create_window (GstVaapiDisplay * display, guint width,
guint height)
{
GstVaapiWindow *window;
GstVaapiWindow *window;
if (!g_video_output)
return NULL;
if (!g_video_output)
return NULL;
#if USE_EGL
if (g_egl_mode)
window = gst_vaapi_window_egl_new(display, width, height);
else
if (g_egl_mode)
window = gst_vaapi_window_egl_new (display, width, height);
else
#endif
window = g_video_output->create_window(display, width, height);
if (!window)
return NULL;
window = g_video_output->create_window (display, width, height);
if (!window)
return NULL;
/* Force fullscreen mode, should this be requested by the user */
if (g_fullscreen)
gst_vaapi_window_set_fullscreen(window, TRUE);
return window;
/* Force fullscreen mode, should this be requested by the user */
if (g_fullscreen)
gst_vaapi_window_set_fullscreen (window, TRUE);
return window;
}
GstVaapiPixmap *
video_output_create_pixmap(GstVaapiDisplay *display, GstVideoFormat format,
video_output_create_pixmap (GstVaapiDisplay * display, GstVideoFormat format,
guint width, guint height)
{
if (!g_video_output || !g_video_output->create_pixmap)
return NULL;
return g_video_output->create_pixmap(display, format, width, height);
if (!g_video_output || !g_video_output->create_pixmap)
return NULL;
return g_video_output->create_pixmap (display, format, width, height);
}

File diff suppressed because it is too large Load diff

View file

@ -31,115 +31,114 @@
/* Set to 1 to check display cache works (shared VA display) */
#define CHECK_DISPLAY_CACHE 1
static inline void pause(void)
static inline void
pause (void)
{
g_print("Press any key to continue...\n");
getchar();
g_print ("Press any key to continue...\n");
getchar ();
}
static gchar *g_codec_str;
static gboolean g_use_pixmap;
static GOptionEntry g_options[] = {
{ "codec", 'c',
0,
G_OPTION_ARG_STRING, &g_codec_str,
"codec to test", NULL },
{ "pixmap", 0,
0,
G_OPTION_ARG_NONE, &g_use_pixmap,
"use render-to-pixmap", NULL },
{ NULL, }
{"codec", 'c',
0,
G_OPTION_ARG_STRING, &g_codec_str,
"codec to test", NULL},
{"pixmap", 0,
0,
G_OPTION_ARG_NONE, &g_use_pixmap,
"use render-to-pixmap", NULL},
{NULL,}
};
int
main(int argc, char *argv[])
main (int argc, char *argv[])
{
GstVaapiDisplay *display, *display2;
GstVaapiWindow *window;
GstVaapiPixmap *pixmap = NULL;
GstVaapiDecoder *decoder;
GstVaapiSurfaceProxy *proxy;
GstVaapiSurface *surface;
const GstVaapiRectangle *crop_rect;
GstVaapiDisplay *display, *display2;
GstVaapiWindow *window;
GstVaapiPixmap *pixmap = NULL;
GstVaapiDecoder *decoder;
GstVaapiSurfaceProxy *proxy;
GstVaapiSurface *surface;
const GstVaapiRectangle *crop_rect;
static const guint win_width = 640;
static const guint win_height = 480;
static const guint win_width = 640;
static const guint win_height = 480;
if (!video_output_init(&argc, argv, g_options))
g_error("failed to initialize video output subsystem");
if (!video_output_init (&argc, argv, g_options))
g_error ("failed to initialize video output subsystem");
g_print("Test decode\n");
g_print ("Test decode\n");
display = video_output_create_display(NULL);
if (!display)
g_error("could not create VA display");
display = video_output_create_display (NULL);
if (!display)
g_error ("could not create VA display");
if (CHECK_DISPLAY_CACHE)
display2 = video_output_create_display(NULL);
else
display2 = gst_vaapi_display_ref(display);
if (!display2)
g_error("could not create second VA display");
if (CHECK_DISPLAY_CACHE)
display2 = video_output_create_display (NULL);
else
display2 = gst_vaapi_display_ref (display);
if (!display2)
g_error ("could not create second VA display");
window = video_output_create_window(display, win_width, win_height);
if (!window)
g_error("could not create window");
window = video_output_create_window (display, win_width, win_height);
if (!window)
g_error ("could not create window");
decoder = decoder_new(display, g_codec_str);
if (!decoder)
g_error("could not create decoder");
decoder = decoder_new (display, g_codec_str);
if (!decoder)
g_error ("could not create decoder");
g_print("Decode %s sample frame\n", decoder_get_codec_name(decoder));
g_print ("Decode %s sample frame\n", decoder_get_codec_name (decoder));
if (!decoder_put_buffers(decoder))
g_error("could not fill decoder with sample data");
if (!decoder_put_buffers (decoder))
g_error ("could not fill decoder with sample data");
proxy = decoder_get_surface(decoder);
if (!proxy)
g_error("could not get decoded surface");
proxy = decoder_get_surface (decoder);
if (!proxy)
g_error ("could not get decoded surface");
surface = gst_vaapi_surface_proxy_get_surface(proxy);
crop_rect = gst_vaapi_surface_proxy_get_crop_rect(proxy);
surface = gst_vaapi_surface_proxy_get_surface (proxy);
crop_rect = gst_vaapi_surface_proxy_get_crop_rect (proxy);
gst_vaapi_window_show(window);
gst_vaapi_window_show (window);
if (g_use_pixmap) {
guint width, height;
if (g_use_pixmap) {
guint width, height;
if (crop_rect) {
width = crop_rect->width;
height = crop_rect->height;
}
else
gst_vaapi_surface_get_size(surface, &width, &height);
if (crop_rect) {
width = crop_rect->width;
height = crop_rect->height;
} else
gst_vaapi_surface_get_size (surface, &width, &height);
pixmap = video_output_create_pixmap(display, GST_VIDEO_FORMAT_xRGB,
width, height);
if (!pixmap)
g_error("could not create pixmap");
pixmap = video_output_create_pixmap (display, GST_VIDEO_FORMAT_xRGB,
width, height);
if (!pixmap)
g_error ("could not create pixmap");
if (!gst_vaapi_pixmap_put_surface(pixmap, surface, crop_rect,
GST_VAAPI_PICTURE_STRUCTURE_FRAME))
g_error("could not render to pixmap");
if (!gst_vaapi_window_put_pixmap(window, pixmap, NULL, NULL))
g_error("could not render pixmap");
}
else if (!gst_vaapi_window_put_surface(window, surface, crop_rect, NULL,
if (!gst_vaapi_pixmap_put_surface (pixmap, surface, crop_rect,
GST_VAAPI_PICTURE_STRUCTURE_FRAME))
g_error("could not render surface");
g_error ("could not render to pixmap");
pause();
if (!gst_vaapi_window_put_pixmap (window, pixmap, NULL, NULL))
g_error ("could not render pixmap");
} else if (!gst_vaapi_window_put_surface (window, surface, crop_rect, NULL,
GST_VAAPI_PICTURE_STRUCTURE_FRAME))
g_error ("could not render surface");
if (pixmap)
gst_vaapi_pixmap_unref(pixmap);
gst_vaapi_surface_proxy_unref(proxy);
gst_vaapi_decoder_unref(decoder);
gst_vaapi_window_unref(window);
gst_vaapi_display_unref(display);
gst_vaapi_display_unref(display2);
g_free(g_codec_str);
video_output_exit();
return 0;
pause ();
if (pixmap)
gst_vaapi_pixmap_unref (pixmap);
gst_vaapi_surface_proxy_unref (proxy);
gst_vaapi_decoder_unref (decoder);
gst_vaapi_window_unref (window);
gst_vaapi_display_unref (display);
gst_vaapi_display_unref (display2);
g_free (g_codec_str);
video_output_exit ();
return 0;
}

View file

@ -54,514 +54,512 @@
#define CHECK_DISPLAY_CACHE 1
static void
print_value(const GValue *value, const gchar *name)
print_value (const GValue * value, const gchar * name)
{
gchar *value_string;
gchar *value_string;
value_string = g_strdup_value_contents(value);
if (!value_string)
return;
g_print(" %s: %s\n", name, value_string);
g_free(value_string);
value_string = g_strdup_value_contents (value);
if (!value_string)
return;
g_print (" %s: %s\n", name, value_string);
g_free (value_string);
}
static void
print_profiles(GArray *profiles, const gchar *name)
print_profiles (GArray * profiles, const gchar * name)
{
GstVaapiCodec codec;
const gchar *codec_name, *profile_name;
guint i;
GstVaapiCodec codec;
const gchar *codec_name, *profile_name;
guint i;
g_print("%u %s caps\n", profiles->len, name);
g_print ("%u %s caps\n", profiles->len, name);
for (i = 0; i < profiles->len; i++) {
const GstVaapiProfile profile =
g_array_index(profiles, GstVaapiProfile, i);
for (i = 0; i < profiles->len; i++) {
const GstVaapiProfile profile =
g_array_index (profiles, GstVaapiProfile, i);
codec = gst_vaapi_profile_get_codec(profile);
if (!codec)
continue;
codec = gst_vaapi_profile_get_codec (profile);
if (!codec)
continue;
codec_name = gst_vaapi_codec_get_name(codec);
if (!codec_name)
continue;
codec_name = gst_vaapi_codec_get_name (codec);
if (!codec_name)
continue;
profile_name = gst_vaapi_profile_get_name(profile);
if (!profile_name)
continue;
profile_name = gst_vaapi_profile_get_name (profile);
if (!profile_name)
continue;
g_print(" %s: %s profile\n", codec_name, profile_name);
}
g_print (" %s: %s profile\n", codec_name, profile_name);
}
}
static void
print_format_yuv(const VAImageFormat *va_format)
print_format_yuv (const VAImageFormat * va_format)
{
const guint32 fourcc = va_format->fourcc;
const guint32 fourcc = va_format->fourcc;
g_print(" fourcc '%c%c%c%c'",
fourcc & 0xff,
(fourcc >> 8) & 0xff,
(fourcc >> 16) & 0xff,
(fourcc >> 24) & 0xff);
g_print (" fourcc '%c%c%c%c'",
fourcc & 0xff,
(fourcc >> 8) & 0xff, (fourcc >> 16) & 0xff, (fourcc >> 24) & 0xff);
}
static void
print_format_rgb(const VAImageFormat *va_format)
print_format_rgb (const VAImageFormat * va_format)
{
g_print(" %d bits per pixel, %s endian,",
va_format->bits_per_pixel,
va_format->byte_order == VA_MSB_FIRST ? "big" : "little");
g_print(" %s masks", va_format->alpha_mask ? "rgba" : "rgb");
g_print(" 0x%08x 0x%08x 0x%08x",
va_format->red_mask, va_format->green_mask, va_format->blue_mask);
if (va_format->alpha_mask)
g_print(" 0x%08x", va_format->alpha_mask);
g_print (" %d bits per pixel, %s endian,",
va_format->bits_per_pixel,
va_format->byte_order == VA_MSB_FIRST ? "big" : "little");
g_print (" %s masks", va_format->alpha_mask ? "rgba" : "rgb");
g_print (" 0x%08x 0x%08x 0x%08x",
va_format->red_mask, va_format->green_mask, va_format->blue_mask);
if (va_format->alpha_mask)
g_print (" 0x%08x", va_format->alpha_mask);
}
static void
print_formats(GArray *formats, const gchar *name)
print_formats (GArray * formats, const gchar * name)
{
guint i;
guint i;
g_print("%u %s caps\n", formats->len, name);
g_print ("%u %s caps\n", formats->len, name);
for (i = 0; i < formats->len; i++) {
const GstVideoFormat format = g_array_index(formats, GstVideoFormat, i);
const VAImageFormat *va_format;
for (i = 0; i < formats->len; i++) {
const GstVideoFormat format = g_array_index (formats, GstVideoFormat, i);
const VAImageFormat *va_format;
g_print(" %s:", gst_vaapi_video_format_to_string(format));
g_print (" %s:", gst_vaapi_video_format_to_string (format));
va_format = gst_vaapi_video_format_to_va_format(format);
if (!va_format)
g_error("could not determine VA format");
va_format = gst_vaapi_video_format_to_va_format (format);
if (!va_format)
g_error ("could not determine VA format");
if (gst_vaapi_video_format_is_yuv(format))
print_format_yuv(va_format);
else
print_format_rgb(va_format);
g_print("\n");
}
if (gst_vaapi_video_format_is_yuv (format))
print_format_yuv (va_format);
else
print_format_rgb (va_format);
g_print ("\n");
}
}
typedef struct _GstVaapiDisplayProperty GstVaapiDisplayProperty;
struct _GstVaapiDisplayProperty {
const gchar *name;
GValue value;
struct _GstVaapiDisplayProperty
{
const gchar *name;
GValue value;
};
static void
gst_vaapi_display_property_free(GstVaapiDisplayProperty *prop)
gst_vaapi_display_property_free (GstVaapiDisplayProperty * prop)
{
if (!prop)
return;
g_value_unset(&prop->value);
g_slice_free(GstVaapiDisplayProperty, prop);
if (!prop)
return;
g_value_unset (&prop->value);
g_slice_free (GstVaapiDisplayProperty, prop);
}
static GstVaapiDisplayProperty *
gst_vaapi_display_property_new(const gchar *name)
gst_vaapi_display_property_new (const gchar * name)
{
GstVaapiDisplayProperty *prop;
GstVaapiDisplayProperty *prop;
prop = g_slice_new0(GstVaapiDisplayProperty);
if (!prop)
return NULL;
prop->name = name;
return prop;
prop = g_slice_new0 (GstVaapiDisplayProperty);
if (!prop)
return NULL;
prop->name = name;
return prop;
}
static void
free_property_cb(gpointer data, gpointer user_data)
free_property_cb (gpointer data, gpointer user_data)
{
gst_vaapi_display_property_free(data);
gst_vaapi_display_property_free (data);
}
static void
dump_properties(GstVaapiDisplay *display)
dump_properties (GstVaapiDisplay * display)
{
GstVaapiDisplayProperty *prop;
GPtrArray *properties;
guint i;
GstVaapiDisplayProperty *prop;
GPtrArray *properties;
guint i;
static const gchar *g_properties[] = {
GST_VAAPI_DISPLAY_PROP_RENDER_MODE,
GST_VAAPI_DISPLAY_PROP_ROTATION,
GST_VAAPI_DISPLAY_PROP_HUE,
GST_VAAPI_DISPLAY_PROP_SATURATION,
GST_VAAPI_DISPLAY_PROP_BRIGHTNESS,
GST_VAAPI_DISPLAY_PROP_CONTRAST,
NULL
};
static const gchar *g_properties[] = {
GST_VAAPI_DISPLAY_PROP_RENDER_MODE,
GST_VAAPI_DISPLAY_PROP_ROTATION,
GST_VAAPI_DISPLAY_PROP_HUE,
GST_VAAPI_DISPLAY_PROP_SATURATION,
GST_VAAPI_DISPLAY_PROP_BRIGHTNESS,
GST_VAAPI_DISPLAY_PROP_CONTRAST,
NULL
};
properties = g_ptr_array_new();
if (!properties)
return;
properties = g_ptr_array_new ();
if (!properties)
return;
for (i = 0; g_properties[i] != NULL; i++) {
const gchar * const name = g_properties[i];
for (i = 0; g_properties[i] != NULL; i++) {
const gchar *const name = g_properties[i];
if (!gst_vaapi_display_has_property(display, name))
continue;
prop = gst_vaapi_display_property_new(name);
if (!prop) {
GST_ERROR("failed to allocate GstVaapiDisplayProperty");
goto end;
}
if (!gst_vaapi_display_has_property (display, name))
continue;
if (!gst_vaapi_display_get_property(display, name, &prop->value)) {
GST_ERROR("failed to get property '%s'", name);
goto end;
}
g_ptr_array_add(properties, prop);
prop = gst_vaapi_display_property_new (name);
if (!prop) {
GST_ERROR ("failed to allocate GstVaapiDisplayProperty");
goto end;
}
g_print("%u properties\n", properties->len);
for (i = 0; i < properties->len; i++) {
prop = g_ptr_array_index(properties, i);
print_value(&prop->value, prop->name);
if (!gst_vaapi_display_get_property (display, name, &prop->value)) {
GST_ERROR ("failed to get property '%s'", name);
goto end;
}
g_ptr_array_add (properties, prop);
}
g_print ("%u properties\n", properties->len);
for (i = 0; i < properties->len; i++) {
prop = g_ptr_array_index (properties, i);
print_value (&prop->value, prop->name);
}
end:
if (properties) {
g_ptr_array_foreach(properties, free_property_cb, NULL);
g_ptr_array_free(properties, TRUE);
}
if (properties) {
g_ptr_array_foreach (properties, free_property_cb, NULL);
g_ptr_array_free (properties, TRUE);
}
}
static void
dump_info(GstVaapiDisplay *display)
dump_info (GstVaapiDisplay * display)
{
GArray *profiles, *formats;
GArray *profiles, *formats;
profiles = gst_vaapi_display_get_decode_profiles(display);
if (!profiles)
g_error("could not get VA decode profiles");
profiles = gst_vaapi_display_get_decode_profiles (display);
if (!profiles)
g_error ("could not get VA decode profiles");
print_profiles(profiles, "decoders");
g_array_unref(profiles);
print_profiles (profiles, "decoders");
g_array_unref (profiles);
profiles = gst_vaapi_display_get_encode_profiles(display);
if (!profiles)
g_error("could not get VA encode profiles");
profiles = gst_vaapi_display_get_encode_profiles (display);
if (!profiles)
g_error ("could not get VA encode profiles");
print_profiles(profiles, "encoders");
g_array_unref(profiles);
print_profiles (profiles, "encoders");
g_array_unref (profiles);
formats = gst_vaapi_display_get_image_formats(display);
if (!formats)
g_error("could not get VA image formats");
formats = gst_vaapi_display_get_image_formats (display);
if (!formats)
g_error ("could not get VA image formats");
print_formats(formats, "image");
g_array_unref(formats);
print_formats (formats, "image");
g_array_unref (formats);
formats = gst_vaapi_display_get_subpicture_formats(display);
if (!formats)
g_error("could not get VA subpicture formats");
formats = gst_vaapi_display_get_subpicture_formats (display);
if (!formats)
g_error ("could not get VA subpicture formats");
print_formats(formats, "subpicture");
g_array_unref(formats);
print_formats (formats, "subpicture");
g_array_unref (formats);
dump_properties(display);
dump_properties (display);
}
int
main(int argc, char *argv[])
main (int argc, char *argv[])
{
GstVaapiDisplay *display, *display2;
guint width, height, par_n, par_d;
GstVaapiDisplay *display, *display2;
guint width, height, par_n, par_d;
gst_init(&argc, &argv);
gst_init (&argc, &argv);
#if USE_DRM
g_print("#\n");
g_print("# Create display with gst_vaapi_display_drm_new()\n");
g_print("#\n");
{
display = gst_vaapi_display_drm_new(NULL);
if (!display)
g_error("could not create Gst/VA display");
g_print ("#\n");
g_print ("# Create display with gst_vaapi_display_drm_new()\n");
g_print ("#\n");
{
display = gst_vaapi_display_drm_new (NULL);
if (!display)
g_error ("could not create Gst/VA display");
dump_info(display);
gst_vaapi_display_unref(display);
}
g_print("\n");
dump_info (display);
gst_vaapi_display_unref (display);
}
g_print ("\n");
g_print("#\n");
g_print("# Create display with gst_vaapi_display_drm_new_with_device()\n");
g_print("#\n");
{
int drm_device;
g_print ("#\n");
g_print ("# Create display with gst_vaapi_display_drm_new_with_device()\n");
g_print ("#\n");
{
int drm_device;
drm_device = open(DRM_DEVICE_PATH, O_RDWR|O_CLOEXEC);
if (drm_device < 0)
g_error("could not open DRM device");
drm_device = open (DRM_DEVICE_PATH, O_RDWR | O_CLOEXEC);
if (drm_device < 0)
g_error ("could not open DRM device");
display = gst_vaapi_display_drm_new_with_device(drm_device);
if (!display)
g_error("could not create Gst/VA display");
display = gst_vaapi_display_drm_new_with_device (drm_device);
if (!display)
g_error ("could not create Gst/VA display");
dump_info(display);
gst_vaapi_display_unref(display);
close(drm_device);
}
g_print("\n");
dump_info (display);
gst_vaapi_display_unref (display);
close (drm_device);
}
g_print ("\n");
g_print("#\n");
g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplayDRM()]\n");
g_print("#\n");
{
int drm_device;
VADisplay va_display;
g_print ("#\n");
g_print
("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplayDRM()]\n");
g_print ("#\n");
{
int drm_device;
VADisplay va_display;
drm_device = open(DRM_DEVICE_PATH, O_RDWR|O_CLOEXEC);
if (drm_device < 0)
g_error("could not open DRM device");
drm_device = open (DRM_DEVICE_PATH, O_RDWR | O_CLOEXEC);
if (drm_device < 0)
g_error ("could not open DRM device");
va_display = vaGetDisplayDRM(drm_device);
if (!va_display)
g_error("could not create VA display");
va_display = vaGetDisplayDRM (drm_device);
if (!va_display)
g_error ("could not create VA display");
display = gst_vaapi_display_new_with_display(va_display);
if (!display)
g_error("could not create Gst/VA display");
display = gst_vaapi_display_new_with_display (va_display);
if (!display)
g_error ("could not create Gst/VA display");
dump_info(display);
gst_vaapi_display_unref(display);
close(drm_device);
}
g_print("\n");
dump_info (display);
gst_vaapi_display_unref (display);
close (drm_device);
}
g_print ("\n");
#endif
#if USE_X11
g_print("#\n");
g_print("# Create display with gst_vaapi_display_x11_new()\n");
g_print("#\n");
{
display = gst_vaapi_display_x11_new(NULL);
if (!display)
g_error("could not create Gst/VA display");
g_print ("#\n");
g_print ("# Create display with gst_vaapi_display_x11_new()\n");
g_print ("#\n");
{
display = gst_vaapi_display_x11_new (NULL);
if (!display)
g_error ("could not create Gst/VA display");
if (CHECK_DISPLAY_CACHE) {
display2 = gst_vaapi_display_x11_new(NULL);
if (CHECK_DISPLAY_CACHE) {
display2 = gst_vaapi_display_x11_new (NULL);
/* Check for the same X11 display */
g_assert(gst_vaapi_display_x11_get_display(
GST_VAAPI_DISPLAY_X11(display)) ==
gst_vaapi_display_x11_get_display(
GST_VAAPI_DISPLAY_X11(display2)));
/* Check for the same X11 display */
g_assert (gst_vaapi_display_x11_get_display (GST_VAAPI_DISPLAY_X11
(display)) ==
gst_vaapi_display_x11_get_display (GST_VAAPI_DISPLAY_X11 (display2)));
/* Check for the same VA display */
g_assert(gst_vaapi_display_get_display(display) ==
gst_vaapi_display_get_display(display2));
/* Check for the same VA display */
g_assert (gst_vaapi_display_get_display (display) ==
gst_vaapi_display_get_display (display2));
gst_vaapi_display_unref(display2);
gst_vaapi_display_unref (display2);
#if USE_GLX
display2 = gst_vaapi_display_glx_new(NULL);
display2 = gst_vaapi_display_glx_new (NULL);
/* Check for the different X11 display */
/* XXX: it is also desired to cache underlying X11 displays */
g_assert(gst_vaapi_display_x11_get_display(
GST_VAAPI_DISPLAY_X11(display)) !=
gst_vaapi_display_x11_get_display(
GST_VAAPI_DISPLAY_X11(display2)));
/* Check for the different X11 display */
/* XXX: it is also desired to cache underlying X11 displays */
g_assert (gst_vaapi_display_x11_get_display (GST_VAAPI_DISPLAY_X11
(display)) !=
gst_vaapi_display_x11_get_display (GST_VAAPI_DISPLAY_X11 (display2)));
/* Check for different VA display */
g_assert(gst_vaapi_display_get_display(display) !=
gst_vaapi_display_get_display(display2));
/* Check for different VA display */
g_assert (gst_vaapi_display_get_display (display) !=
gst_vaapi_display_get_display (display2));
gst_vaapi_display_unref(display2);
gst_vaapi_display_unref (display2);
#endif
}
gst_vaapi_display_get_size(display, &width, &height);
g_print("Display size: %ux%u\n", width, height);
gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);
dump_info(display);
gst_vaapi_display_unref(display);
}
g_print("\n");
g_print("#\n");
g_print("# Create display with gst_vaapi_display_x11_new_with_display()\n");
g_print("#\n");
{
Display *x11_display;
gst_vaapi_display_get_size (display, &width, &height);
g_print ("Display size: %ux%u\n", width, height);
x11_display = XOpenDisplay(NULL);
if (!x11_display)
g_error("could not create X11 display");
gst_vaapi_display_get_pixel_aspect_ratio (display, &par_n, &par_d);
g_print ("Pixel aspect ratio: %u/%u\n", par_n, par_d);
display = gst_vaapi_display_x11_new_with_display(x11_display);
if (!display)
g_error("could not create Gst/VA display");
dump_info (display);
gst_vaapi_display_unref (display);
}
g_print ("\n");
if (CHECK_DISPLAY_CACHE) {
display2 = gst_vaapi_display_x11_new_with_display(x11_display);
g_print ("#\n");
g_print ("# Create display with gst_vaapi_display_x11_new_with_display()\n");
g_print ("#\n");
{
Display *x11_display;
/* Check for the same VA display */
g_assert(gst_vaapi_display_get_display(display) ==
gst_vaapi_display_get_display(display2));
x11_display = XOpenDisplay (NULL);
if (!x11_display)
g_error ("could not create X11 display");
gst_vaapi_display_unref(display2);
}
display = gst_vaapi_display_x11_new_with_display (x11_display);
if (!display)
g_error ("could not create Gst/VA display");
dump_info(display);
gst_vaapi_display_unref(display);
XCloseDisplay(x11_display);
if (CHECK_DISPLAY_CACHE) {
display2 = gst_vaapi_display_x11_new_with_display (x11_display);
/* Check for the same VA display */
g_assert (gst_vaapi_display_get_display (display) ==
gst_vaapi_display_get_display (display2));
gst_vaapi_display_unref (display2);
}
g_print("\n");
g_print("#\n");
g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplay()]\n");
g_print("#\n");
{
Display *x11_display;
VADisplay va_display;
dump_info (display);
gst_vaapi_display_unref (display);
XCloseDisplay (x11_display);
}
g_print ("\n");
x11_display = XOpenDisplay(NULL);
if (!x11_display)
g_error("could not create X11 display");
g_print ("#\n");
g_print
("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplay()]\n");
g_print ("#\n");
{
Display *x11_display;
VADisplay va_display;
va_display = vaGetDisplay(x11_display);
if (!va_display)
g_error("could not create VA display");
x11_display = XOpenDisplay (NULL);
if (!x11_display)
g_error ("could not create X11 display");
display = gst_vaapi_display_new_with_display(va_display);
if (!display)
g_error("could not create Gst/VA display");
va_display = vaGetDisplay (x11_display);
if (!va_display)
g_error ("could not create VA display");
dump_info(display);
gst_vaapi_display_unref(display);
XCloseDisplay(x11_display);
}
g_print("\n");
display = gst_vaapi_display_new_with_display (va_display);
if (!display)
g_error ("could not create Gst/VA display");
dump_info (display);
gst_vaapi_display_unref (display);
XCloseDisplay (x11_display);
}
g_print ("\n");
#endif
#if USE_GLX
g_print("#\n");
g_print("# Create display with gst_vaapi_display_glx_new()\n");
g_print("#\n");
{
display = gst_vaapi_display_glx_new(NULL);
if (!display)
g_error("could not create Gst/VA display");
g_print ("#\n");
g_print ("# Create display with gst_vaapi_display_glx_new()\n");
g_print ("#\n");
{
display = gst_vaapi_display_glx_new (NULL);
if (!display)
g_error ("could not create Gst/VA display");
if (CHECK_DISPLAY_CACHE) {
display2 = gst_vaapi_display_glx_new(NULL);
if (CHECK_DISPLAY_CACHE) {
display2 = gst_vaapi_display_glx_new (NULL);
/* Check for the same X11 display */
g_assert(gst_vaapi_display_x11_get_display(
GST_VAAPI_DISPLAY_X11(display)) ==
gst_vaapi_display_x11_get_display(
GST_VAAPI_DISPLAY_X11(display2)));
/* Check for the same X11 display */
g_assert (gst_vaapi_display_x11_get_display (GST_VAAPI_DISPLAY_X11
(display)) ==
gst_vaapi_display_x11_get_display (GST_VAAPI_DISPLAY_X11 (display2)));
/* Check for the same VA display */
g_assert(gst_vaapi_display_get_display(display) ==
gst_vaapi_display_get_display(display2));
/* Check for the same VA display */
g_assert (gst_vaapi_display_get_display (display) ==
gst_vaapi_display_get_display (display2));
gst_vaapi_display_unref(display2);
gst_vaapi_display_unref (display2);
display2 = gst_vaapi_display_x11_new(NULL);
display2 = gst_vaapi_display_x11_new (NULL);
/* Check for the same X11 display */
g_assert(gst_vaapi_display_x11_get_display(
GST_VAAPI_DISPLAY_X11(display)) ==
gst_vaapi_display_x11_get_display(
GST_VAAPI_DISPLAY_X11(display2)));
/* Check for the same X11 display */
g_assert (gst_vaapi_display_x11_get_display (GST_VAAPI_DISPLAY_X11
(display)) ==
gst_vaapi_display_x11_get_display (GST_VAAPI_DISPLAY_X11 (display2)));
/* Check for the same VA display */
g_assert(gst_vaapi_display_get_display(display) ==
gst_vaapi_display_get_display(display2));
/* Check for the same VA display */
g_assert (gst_vaapi_display_get_display (display) ==
gst_vaapi_display_get_display (display2));
gst_vaapi_display_unref(display2);
}
gst_vaapi_display_get_size(display, &width, &height);
g_print("Display size: %ux%u\n", width, height);
gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);
dump_info(display);
gst_vaapi_display_unref(display);
gst_vaapi_display_unref (display2);
}
g_print("\n");
g_print("#\n");
g_print("# Create display with gst_vaapi_display_glx_new_with_display()\n");
g_print("#\n");
{
Display *x11_display;
gst_vaapi_display_get_size (display, &width, &height);
g_print ("Display size: %ux%u\n", width, height);
x11_display = XOpenDisplay(NULL);
if (!x11_display)
g_error("could not create X11 display");
gst_vaapi_display_get_pixel_aspect_ratio (display, &par_n, &par_d);
g_print ("Pixel aspect ratio: %u/%u\n", par_n, par_d);
display = gst_vaapi_display_glx_new_with_display(x11_display);
if (!display)
g_error("could not create Gst/VA display");
dump_info (display);
gst_vaapi_display_unref (display);
}
g_print ("\n");
dump_info(display);
gst_vaapi_display_unref(display);
XCloseDisplay(x11_display);
}
g_print("\n");
g_print ("#\n");
g_print ("# Create display with gst_vaapi_display_glx_new_with_display()\n");
g_print ("#\n");
{
Display *x11_display;
x11_display = XOpenDisplay (NULL);
if (!x11_display)
g_error ("could not create X11 display");
display = gst_vaapi_display_glx_new_with_display (x11_display);
if (!display)
g_error ("could not create Gst/VA display");
dump_info (display);
gst_vaapi_display_unref (display);
XCloseDisplay (x11_display);
}
g_print ("\n");
#ifdef HAVE_VA_VA_GLX_H
g_print("#\n");
g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplayGLX()]\n");
g_print("#\n");
{
Display *x11_display;
VADisplay va_display;
g_print ("#\n");
g_print
("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplayGLX()]\n");
g_print ("#\n");
{
Display *x11_display;
VADisplay va_display;
x11_display = XOpenDisplay(NULL);
if (!x11_display)
g_error("could not create X11 display");
x11_display = XOpenDisplay (NULL);
if (!x11_display)
g_error ("could not create X11 display");
va_display = vaGetDisplayGLX(x11_display);
if (!va_display)
g_error("could not create VA display");
va_display = vaGetDisplayGLX (x11_display);
if (!va_display)
g_error ("could not create VA display");
display = gst_vaapi_display_new_with_display(va_display);
if (!display)
g_error("could not create Gst/VA display");
display = gst_vaapi_display_new_with_display (va_display);
if (!display)
g_error ("could not create Gst/VA display");
dump_info(display);
gst_vaapi_display_unref(display);
XCloseDisplay(x11_display);
}
g_print("\n");
dump_info (display);
gst_vaapi_display_unref (display);
XCloseDisplay (x11_display);
}
g_print ("\n");
#endif
#endif
#if USE_WAYLAND
g_print("#\n");
g_print("# Create display with gst_vaapi_display_wayland_new()\n");
g_print("#\n");
{
display = gst_vaapi_display_wayland_new(NULL);
if (!display)
g_error("could not create Gst/VA display");
g_print ("#\n");
g_print ("# Create display with gst_vaapi_display_wayland_new()\n");
g_print ("#\n");
{
display = gst_vaapi_display_wayland_new (NULL);
if (!display)
g_error ("could not create Gst/VA display");
gst_vaapi_display_get_size(display, &width, &height);
g_print("Display size: %ux%u\n", width, height);
gst_vaapi_display_get_size (display, &width, &height);
g_print ("Display size: %ux%u\n", width, height);
gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);
gst_vaapi_display_get_pixel_aspect_ratio (display, &par_n, &par_d);
g_print ("Pixel aspect ratio: %u/%u\n", par_n, par_d);
dump_info(display);
gst_vaapi_display_unref(display);
}
g_print("\n");
dump_info (display);
gst_vaapi_display_unref (display);
}
g_print ("\n");
#endif
gst_deinit();
return 0;
gst_deinit ();
return 0;
}

View file

@ -38,419 +38,418 @@ static gchar *g_deinterlace_str;
static gchar *g_deinterlace_flags_str;
static GOptionEntry g_options[] = {
{ "src-format", 's',
0,
G_OPTION_ARG_STRING, &g_src_format_str,
"source surface format", NULL },
{ "crop-rect", 'c',
0,
G_OPTION_ARG_STRING, &g_crop_rect_str,
"cropping rectangle", NULL },
{ "denoise", 0,
0,
G_OPTION_ARG_STRING, &g_denoise_str,
"set noise reduction level", NULL },
{ "sharpen", 0,
0,
G_OPTION_ARG_STRING, &g_sharpen_str,
"set sharpening level", NULL },
{ "deinterlace", 0,
0,
G_OPTION_ARG_STRING, &g_deinterlace_str,
"enable deinterlacing", NULL },
{ "deinterlace-flags", 0,
0,
G_OPTION_ARG_STRING, &g_deinterlace_flags_str,
"deinterlacing flags", NULL },
{ NULL, }
{"src-format", 's',
0,
G_OPTION_ARG_STRING, &g_src_format_str,
"source surface format", NULL},
{"crop-rect", 'c',
0,
G_OPTION_ARG_STRING, &g_crop_rect_str,
"cropping rectangle", NULL},
{"denoise", 0,
0,
G_OPTION_ARG_STRING, &g_denoise_str,
"set noise reduction level", NULL},
{"sharpen", 0,
0,
G_OPTION_ARG_STRING, &g_sharpen_str,
"set sharpening level", NULL},
{"deinterlace", 0,
0,
G_OPTION_ARG_STRING, &g_deinterlace_str,
"enable deinterlacing", NULL},
{"deinterlace-flags", 0,
0,
G_OPTION_ARG_STRING, &g_deinterlace_flags_str,
"deinterlacing flags", NULL},
{NULL,}
};
#define APP_ERROR app_error_quark()
static GQuark
app_error_quark(void)
app_error_quark (void)
{
static gsize g_quark;
static gsize g_quark;
if (g_once_init_enter(&g_quark)) {
gsize quark = (gsize)g_quark_from_static_string("AppError");
g_once_init_leave(&g_quark, quark);
}
return g_quark;
if (g_once_init_enter (&g_quark)) {
gsize quark = (gsize) g_quark_from_static_string ("AppError");
g_once_init_leave (&g_quark, quark);
}
return g_quark;
}
typedef enum {
APP_ERROR_NONE,
APP_ERROR_CREATE_TEST_SURFACE,
typedef enum
{
APP_ERROR_NONE,
APP_ERROR_CREATE_TEST_SURFACE,
} AppError;
static inline void
pause(void)
pause (void)
{
g_print("Press any key to continue...\n");
getchar();
g_print ("Press any key to continue...\n");
getchar ();
}
static GstVaapiSurface *
create_test_surface(GstVaapiDisplay *display, guint width, guint height,
guint flags, GError **error_ptr)
create_test_surface (GstVaapiDisplay * display, guint width, guint height,
guint flags, GError ** error_ptr)
{
GstVideoFormat format = GST_VIDEO_FORMAT_I420;
GstVaapiSurface *surface = NULL;
GstVaapiImage *image = NULL;
GError *error = NULL;
GstVideoFormat format = GST_VIDEO_FORMAT_I420;
GstVaapiSurface *surface = NULL;
GstVaapiImage *image = NULL;
GError *error = NULL;
if (g_src_format_str) {
format = gst_video_format_from_string(g_src_format_str);
if (format == GST_VIDEO_FORMAT_UNKNOWN)
goto error_invalid_format;
}
if (g_src_format_str) {
format = gst_video_format_from_string (g_src_format_str);
if (format == GST_VIDEO_FORMAT_UNKNOWN)
goto error_invalid_format;
}
surface = gst_vaapi_surface_new_with_format(display, format, width, height);
if (!surface)
goto error_create_surface;
surface = gst_vaapi_surface_new_with_format (display, format, width, height);
if (!surface)
goto error_create_surface;
image = image_generate_full(display, format, width, height, flags);
if (!image)
goto error_create_image;
image = image_generate_full (display, format, width, height, flags);
if (!image)
goto error_create_image;
if (!image_upload(image, surface))
goto error_upload_image;
if (!image_upload (image, surface))
goto error_upload_image;
gst_vaapi_object_unref(image);
return surface;
gst_vaapi_object_unref (image);
return surface;
/* ERRORS */
/* ERRORS */
error_invalid_format:
error = g_error_new(APP_ERROR, APP_ERROR_CREATE_TEST_SURFACE,
"unknown format %s", g_src_format_str);
goto error_cleanup;
error = g_error_new (APP_ERROR, APP_ERROR_CREATE_TEST_SURFACE,
"unknown format %s", g_src_format_str);
goto error_cleanup;
error_create_surface:
error = g_error_new(APP_ERROR, APP_ERROR_CREATE_TEST_SURFACE,
"unsupported format %s", gst_vaapi_video_format_to_string(format));
goto error_cleanup;
error = g_error_new (APP_ERROR, APP_ERROR_CREATE_TEST_SURFACE,
"unsupported format %s", gst_vaapi_video_format_to_string (format));
goto error_cleanup;
error_create_image:
error = g_error_new(APP_ERROR, APP_ERROR_CREATE_TEST_SURFACE,
"unsupported %s image", gst_vaapi_video_format_to_string(format));
goto error_cleanup;
error = g_error_new (APP_ERROR, APP_ERROR_CREATE_TEST_SURFACE,
"unsupported %s image", gst_vaapi_video_format_to_string (format));
goto error_cleanup;
error_upload_image:
error = g_error_new(APP_ERROR, APP_ERROR_CREATE_TEST_SURFACE,
"failed to upload %s image", gst_vaapi_video_format_to_string(format));
goto error_cleanup;
error = g_error_new (APP_ERROR, APP_ERROR_CREATE_TEST_SURFACE,
"failed to upload %s image", gst_vaapi_video_format_to_string (format));
goto error_cleanup;
error_cleanup:
if (image)
gst_vaapi_object_unref(image);
if (surface)
gst_vaapi_object_unref(surface);
if (error_ptr)
*error_ptr = error;
else
g_error_free(error);
return NULL;
if (image)
gst_vaapi_object_unref (image);
if (surface)
gst_vaapi_object_unref (surface);
if (error_ptr)
*error_ptr = error;
else
g_error_free (error);
return NULL;
}
static void
dump_operation(GstVaapiFilterOpInfo *op_info)
dump_operation (GstVaapiFilterOpInfo * op_info)
{
GParamSpec * const pspec = op_info->pspec;
GValue value = G_VALUE_INIT;
gchar *value_str;
GParamSpec *const pspec = op_info->pspec;
GValue value = G_VALUE_INIT;
gchar *value_str;
if (!op_info)
return;
if (!op_info)
return;
g_print(" %s: ", g_param_spec_get_name(pspec));
g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE(pspec));
g_param_value_set_default(pspec, &value);
value_str = g_strdup_value_contents(&value);
g_print("%s (default: %s)\n", G_VALUE_TYPE_NAME(&value),
value_str ? value_str : "<unknown>");
g_free(value_str);
g_print (" %s: ", g_param_spec_get_name (pspec));
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
g_param_value_set_default (pspec, &value);
value_str = g_strdup_value_contents (&value);
g_print ("%s (default: %s)\n", G_VALUE_TYPE_NAME (&value),
value_str ? value_str : "<unknown>");
g_free (value_str);
}
static void
dump_operations(GstVaapiFilter *filter)
dump_operations (GstVaapiFilter * filter)
{
GPtrArray * const ops = gst_vaapi_filter_get_operations(filter);
guint i;
GPtrArray *const ops = gst_vaapi_filter_get_operations (filter);
guint i;
if (!ops)
return;
if (!ops)
return;
g_print("%u operations\n", ops->len);
for (i = 0; i < ops->len; i++)
dump_operation(g_ptr_array_index(ops, i));
g_ptr_array_unref(ops);
g_print ("%u operations\n", ops->len);
for (i = 0; i < ops->len; i++)
dump_operation (g_ptr_array_index (ops, i));
g_ptr_array_unref (ops);
}
static void
dump_formats(GstVaapiFilter *filter)
dump_formats (GstVaapiFilter * filter)
{
GArray * const formats = gst_vaapi_filter_get_formats(filter);
guint i;
GArray *const formats = gst_vaapi_filter_get_formats (filter);
guint i;
if (!formats)
return;
if (!formats)
return;
g_print("%u formats\n", formats->len);
for (i = 0; i < formats->len; i++) {
GstVideoFormat format = g_array_index(formats, GstVideoFormat, i);
g_print(" %s\n", gst_vaapi_video_format_to_string(format));
}
g_array_unref(formats);
g_print ("%u formats\n", formats->len);
for (i = 0; i < formats->len; i++) {
GstVideoFormat format = g_array_index (formats, GstVideoFormat, i);
g_print (" %s\n", gst_vaapi_video_format_to_string (format));
}
g_array_unref (formats);
}
static gboolean
parse_double(const gchar *str, gdouble *out_value_ptr)
parse_double (const gchar * str, gdouble * out_value_ptr)
{
gchar *endptr = NULL;
gdouble out_value;
gchar *endptr = NULL;
gdouble out_value;
g_return_val_if_fail(out_value_ptr != NULL, FALSE);
g_return_val_if_fail (out_value_ptr != NULL, FALSE);
errno = 0;
out_value = g_ascii_strtod(str, &endptr);
if (!endptr || *endptr != '\0' || errno == ERANGE)
return FALSE;
*out_value_ptr = out_value;
return TRUE;
}
static gboolean
parse_crop_rect(const gchar *str, GstVaapiRectangle *crop_rect)
{
if (str) {
// Format: <WIDTH> 'x' <HEIGHT>
if (sscanf(str, "%ux%u", &crop_rect->width, &crop_rect->height) == 2) {
crop_rect->x = 0;
crop_rect->y = 0;
return TRUE;
}
// Format: '('? <X> ',' <Y> ')'? <WIDTH> 'x' <HEIGHT>
if (sscanf(str, "(%d,%d):%ux%u", &crop_rect->x, &crop_rect->y,
&crop_rect->width, &crop_rect->height) == 4 ||
sscanf(str, "%d,%d:%ux%u", &crop_rect->x, &crop_rect->y,
&crop_rect->width, &crop_rect->height) == 4)
return TRUE;
}
errno = 0;
out_value = g_ascii_strtod (str, &endptr);
if (!endptr || *endptr != '\0' || errno == ERANGE)
return FALSE;
*out_value_ptr = out_value;
return TRUE;
}
static gboolean
parse_enum(const gchar *str, GType type, gint default_value,
gint *out_value_ptr)
parse_crop_rect (const gchar * str, GstVaapiRectangle * crop_rect)
{
gint out_value = default_value;
g_return_val_if_fail(out_value_ptr != NULL, FALSE);
if (str) {
const GEnumValue *enum_value;
GEnumClass * const enum_class = g_type_class_ref(type);
if (!enum_class)
return FALSE;
enum_value = g_enum_get_value_by_nick(enum_class, str);
if (enum_value)
out_value = enum_value->value;
g_type_class_unref(enum_class);
if (!enum_value)
return FALSE;
if (str) {
// Format: <WIDTH> 'x' <HEIGHT>
if (sscanf (str, "%ux%u", &crop_rect->width, &crop_rect->height) == 2) {
crop_rect->x = 0;
crop_rect->y = 0;
return TRUE;
}
*out_value_ptr = out_value;
return TRUE;
// Format: '('? <X> ',' <Y> ')'? <WIDTH> 'x' <HEIGHT>
if (sscanf (str, "(%d,%d):%ux%u", &crop_rect->x, &crop_rect->y,
&crop_rect->width, &crop_rect->height) == 4 ||
sscanf (str, "%d,%d:%ux%u", &crop_rect->x, &crop_rect->y,
&crop_rect->width, &crop_rect->height) == 4)
return TRUE;
}
return FALSE;
}
static gboolean
parse_flags(const gchar *str, GType type, guint *out_value_ptr)
parse_enum (const gchar * str, GType type, gint default_value,
gint * out_value_ptr)
{
gchar **tokens = NULL;
gint i, value, out_value = 0;
gboolean success = FALSE;
gint out_value = default_value;
g_return_val_if_fail(out_value_ptr != NULL, FALSE);
g_return_val_if_fail (out_value_ptr != NULL, FALSE);
if (str) {
tokens = g_strsplit(str, ",", 32);
if (!tokens)
return FALSE;
if (str) {
const GEnumValue *enum_value;
GEnumClass *const enum_class = g_type_class_ref (type);
for (i = 0; tokens[i] != NULL; i++) {
if (!parse_enum(tokens[i], type, 0, &value))
goto end;
out_value |= value;
}
if (!enum_class)
return FALSE;
enum_value = g_enum_get_value_by_nick (enum_class, str);
if (enum_value)
out_value = enum_value->value;
g_type_class_unref (enum_class);
if (!enum_value)
return FALSE;
}
*out_value_ptr = out_value;
return TRUE;
}
static gboolean
parse_flags (const gchar * str, GType type, guint * out_value_ptr)
{
gchar **tokens = NULL;
gint i, value, out_value = 0;
gboolean success = FALSE;
g_return_val_if_fail (out_value_ptr != NULL, FALSE);
if (str) {
tokens = g_strsplit (str, ",", 32);
if (!tokens)
return FALSE;
for (i = 0; tokens[i] != NULL; i++) {
if (!parse_enum (tokens[i], type, 0, &value))
goto end;
out_value |= value;
}
*out_value_ptr = out_value;
success = TRUE;
}
*out_value_ptr = out_value;
success = TRUE;
end:
g_strfreev(tokens);
return success;
g_strfreev (tokens);
return success;
}
static inline gboolean
parse_deinterlace(const gchar *str, GstVaapiDeinterlaceMethod *deinterlace_ptr)
parse_deinterlace (const gchar * str,
GstVaapiDeinterlaceMethod * deinterlace_ptr)
{
g_return_val_if_fail(deinterlace_ptr != NULL, FALSE);
g_return_val_if_fail (deinterlace_ptr != NULL, FALSE);
if (!str) {
*deinterlace_ptr = GST_VAAPI_DEINTERLACE_METHOD_NONE;
return TRUE;
}
return parse_enum(str, GST_VAAPI_TYPE_DEINTERLACE_METHOD,
GST_VAAPI_DEINTERLACE_METHOD_NONE, (gint *)deinterlace_ptr);
if (!str) {
*deinterlace_ptr = GST_VAAPI_DEINTERLACE_METHOD_NONE;
return TRUE;
}
return parse_enum (str, GST_VAAPI_TYPE_DEINTERLACE_METHOD,
GST_VAAPI_DEINTERLACE_METHOD_NONE, (gint *) deinterlace_ptr);
}
static inline gboolean
parse_deinterlace_flags(const gchar *str, guint *deinterlace_flags_ptr)
parse_deinterlace_flags (const gchar * str, guint * deinterlace_flags_ptr)
{
return parse_flags(str, GST_VAAPI_TYPE_DEINTERLACE_FLAGS,
deinterlace_flags_ptr);
return parse_flags (str, GST_VAAPI_TYPE_DEINTERLACE_FLAGS,
deinterlace_flags_ptr);
}
int
main(int argc, char *argv[])
main (int argc, char *argv[])
{
GstVaapiDisplay *display;
GstVaapiWindow *window;
GstVaapiSurface *src_surface, *dst_surface;
GstVaapiFilter *filter = NULL;
GstVaapiFilterStatus status;
GstVaapiDeinterlaceMethod deinterlace_method;
guint deinterlace_flags = 0;
guint filter_flags = 0;
guint surface_flags = 0;
gdouble denoise_level, sharpen_level;
GError *error = NULL;
GstVaapiDisplay *display;
GstVaapiWindow *window;
GstVaapiSurface *src_surface, *dst_surface;
GstVaapiFilter *filter = NULL;
GstVaapiFilterStatus status;
GstVaapiDeinterlaceMethod deinterlace_method;
guint deinterlace_flags = 0;
guint filter_flags = 0;
guint surface_flags = 0;
gdouble denoise_level, sharpen_level;
GError *error = NULL;
static const guint src_width = 320;
static const guint src_height = 240;
static const guint dst_width = 480;
static const guint dst_height = 360;
static const guint win_width = 640;
static const guint win_height = 480;
static const guint src_width = 320;
static const guint src_height = 240;
static const guint dst_width = 480;
static const guint dst_height = 360;
static const guint win_width = 640;
static const guint win_height = 480;
if (!video_output_init(&argc, argv, g_options))
g_error("failed to initialize video output subsystem");
if (!video_output_init (&argc, argv, g_options))
g_error ("failed to initialize video output subsystem");
if (g_denoise_str && !parse_double(g_denoise_str, &denoise_level))
g_error("failed to parse noise reduction level");
if (g_denoise_str && !parse_double (g_denoise_str, &denoise_level))
g_error ("failed to parse noise reduction level");
if (g_sharpen_str && !parse_double(g_sharpen_str, &sharpen_level))
g_error("failed to parse sharpening level");
if (g_sharpen_str && !parse_double (g_sharpen_str, &sharpen_level))
g_error ("failed to parse sharpening level");
if (!parse_deinterlace(g_deinterlace_str, &deinterlace_method))
g_error("failed to parse deinterlace method `%s'", g_deinterlace_str);
if (!parse_deinterlace (g_deinterlace_str, &deinterlace_method))
g_error ("failed to parse deinterlace method `%s'", g_deinterlace_str);
if (!parse_deinterlace_flags(g_deinterlace_flags_str, &deinterlace_flags))
g_error("failed to parse deinterlace flags `%s'",
g_deinterlace_flags_str);
if (!parse_deinterlace_flags (g_deinterlace_flags_str, &deinterlace_flags))
g_error ("failed to parse deinterlace flags `%s'", g_deinterlace_flags_str);
display = video_output_create_display(NULL);
if (!display)
g_error("failed to create VA display");
display = video_output_create_display (NULL);
if (!display)
g_error ("failed to create VA display");
window = video_output_create_window(display, win_width, win_height);
if (!window)
g_error("failed to create window");
window = video_output_create_window (display, win_width, win_height);
if (!window)
g_error ("failed to create window");
filter = gst_vaapi_filter_new(display);
if (!filter)
g_error("failed to create video processing pipeline");
filter = gst_vaapi_filter_new (display);
if (!filter)
g_error ("failed to create video processing pipeline");
dump_operations(filter);
dump_formats(filter);
dump_operations (filter);
dump_formats (filter);
if (g_crop_rect_str) {
GstVaapiRectangle crop_rect;
if (g_crop_rect_str) {
GstVaapiRectangle crop_rect;
if (!parse_crop_rect(g_crop_rect_str, &crop_rect))
g_error("failed to parse cropping rectangle");
if (!parse_crop_rect (g_crop_rect_str, &crop_rect))
g_error ("failed to parse cropping rectangle");
printf("Frame cropping: (%d,%d), size %ux%u\n",
crop_rect.x, crop_rect.y, crop_rect.width, crop_rect.height);
printf ("Frame cropping: (%d,%d), size %ux%u\n",
crop_rect.x, crop_rect.y, crop_rect.width, crop_rect.height);
if (!gst_vaapi_filter_set_cropping_rectangle(filter, &crop_rect))
g_error("failed to set cropping rectangle");
}
if (!gst_vaapi_filter_set_cropping_rectangle (filter, &crop_rect))
g_error ("failed to set cropping rectangle");
}
if (g_denoise_str) {
printf("Noise reduction level: %f\n", denoise_level);
if (g_denoise_str) {
printf ("Noise reduction level: %f\n", denoise_level);
if (!gst_vaapi_filter_set_denoising_level(filter, denoise_level))
g_error("failed to set denoising level");
}
if (!gst_vaapi_filter_set_denoising_level (filter, denoise_level))
g_error ("failed to set denoising level");
}
if (g_sharpen_str) {
printf("Sharpening level: %f\n", sharpen_level);
if (g_sharpen_str) {
printf ("Sharpening level: %f\n", sharpen_level);
if (!gst_vaapi_filter_set_sharpening_level(filter, sharpen_level))
g_error("failed to set sharpening level");
}
if (!gst_vaapi_filter_set_sharpening_level (filter, sharpen_level))
g_error ("failed to set sharpening level");
}
if (deinterlace_method != GST_VAAPI_DEINTERLACE_METHOD_NONE) {
printf("Enable deinterlacing: %s\n", g_deinterlace_str);
if (deinterlace_method != GST_VAAPI_DEINTERLACE_METHOD_NONE) {
printf ("Enable deinterlacing: %s\n", g_deinterlace_str);
if (!gst_vaapi_filter_set_deinterlacing(filter, deinterlace_method,
deinterlace_flags))
g_error("failed to set deinterlacing method");
}
else if (deinterlace_flags) {
if (deinterlace_flags & GST_VAAPI_DEINTERLACE_FLAG_TOPFIELD)
filter_flags = GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD;
else
filter_flags = GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD;
}
if (!gst_vaapi_filter_set_deinterlacing (filter, deinterlace_method,
deinterlace_flags))
g_error ("failed to set deinterlacing method");
} else if (deinterlace_flags) {
if (deinterlace_flags & GST_VAAPI_DEINTERLACE_FLAG_TOPFIELD)
filter_flags = GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD;
else
filter_flags = GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD;
}
if (deinterlace_method != GST_VAAPI_DEINTERLACE_METHOD_NONE ||
deinterlace_flags) {
if (!(deinterlace_flags & GST_VAAPI_DEINTERLACE_FLAG_ONEFIELD))
surface_flags = GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD |
GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD;
else if (deinterlace_flags & GST_VAAPI_DEINTERLACE_FLAG_TOPFIELD)
surface_flags = GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD;
else
surface_flags = GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD;
}
if (deinterlace_method != GST_VAAPI_DEINTERLACE_METHOD_NONE ||
deinterlace_flags) {
if (!(deinterlace_flags & GST_VAAPI_DEINTERLACE_FLAG_ONEFIELD))
surface_flags = GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD |
GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD;
else if (deinterlace_flags & GST_VAAPI_DEINTERLACE_FLAG_TOPFIELD)
surface_flags = GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD;
else
surface_flags = GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD;
}
src_surface = create_test_surface(display, src_width, src_height,
surface_flags, &error);
if (!src_surface)
g_error("failed to create source VA surface: %s", error->message);
src_surface = create_test_surface (display, src_width, src_height,
surface_flags, &error);
if (!src_surface)
g_error ("failed to create source VA surface: %s", error->message);
dst_surface = gst_vaapi_surface_new(display, GST_VAAPI_CHROMA_TYPE_YUV420,
dst_width, dst_height);
if (!dst_surface)
g_error("failed to create target VA surface");
dst_surface = gst_vaapi_surface_new (display, GST_VAAPI_CHROMA_TYPE_YUV420,
dst_width, dst_height);
if (!dst_surface)
g_error ("failed to create target VA surface");
status = gst_vaapi_filter_process(filter, src_surface, dst_surface,
filter_flags);
if (status != GST_VAAPI_FILTER_STATUS_SUCCESS)
g_error("failed to process video filters");
status = gst_vaapi_filter_process (filter, src_surface, dst_surface,
filter_flags);
if (status != GST_VAAPI_FILTER_STATUS_SUCCESS)
g_error ("failed to process video filters");
gst_vaapi_window_show(window);
gst_vaapi_window_show (window);
if (!gst_vaapi_window_put_surface(window, dst_surface, NULL, NULL,
GST_VAAPI_PICTURE_STRUCTURE_FRAME))
g_error("failed to render target surface");
if (!gst_vaapi_window_put_surface (window, dst_surface, NULL, NULL,
GST_VAAPI_PICTURE_STRUCTURE_FRAME))
g_error ("failed to render target surface");
pause();
pause ();
gst_vaapi_filter_unref(filter);
gst_vaapi_object_unref(dst_surface);
gst_vaapi_object_unref(src_surface);
gst_vaapi_window_unref(window);
gst_vaapi_display_unref(display);
video_output_exit();
g_free(g_src_format_str);
g_free(g_crop_rect_str);
g_free(g_denoise_str);
g_free(g_sharpen_str);
g_free(g_deinterlace_str);
g_free(g_deinterlace_flags_str);
return 0;
gst_vaapi_filter_unref (filter);
gst_vaapi_object_unref (dst_surface);
gst_vaapi_object_unref (src_surface);
gst_vaapi_window_unref (window);
gst_vaapi_display_unref (display);
video_output_exit ();
g_free (g_src_format_str);
g_free (g_crop_rect_str);
g_free (g_denoise_str);
g_free (g_sharpen_str);
g_free (g_deinterlace_str);
g_free (g_deinterlace_flags_str);
return 0;
}

File diff suppressed because it is too large Load diff

View file

@ -2071,11 +2071,12 @@ static const guchar jpeg_clip[JPEG_CLIP_DATA_SIZE] = {
0xd9
};
void jpeg_get_video_info(VideoDecodeInfo *info)
void
jpeg_get_video_info (VideoDecodeInfo * info)
{
info->profile = GST_VAAPI_PROFILE_JPEG_BASELINE;
info->width = JPEG_CLIP_WIDTH;
info->height = JPEG_CLIP_HEIGHT;
info->data = jpeg_clip;
info->data_size = JPEG_CLIP_DATA_SIZE;
info->profile = GST_VAAPI_PROFILE_JPEG_BASELINE;
info->width = JPEG_CLIP_WIDTH;
info->height = JPEG_CLIP_HEIGHT;
info->data = jpeg_clip;
info->data_size = JPEG_CLIP_DATA_SIZE;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1421,7 +1421,8 @@ static const guint32 text[] = {
0x00000000, 0x00000000, 0x00000000, 0x00000000
};
void subpicture_get_info(VideoSubpictureInfo *info)
void
subpicture_get_info (VideoSubpictureInfo * info)
{
info->width = SUBPICTURE_WIDTH;
info->height = SUBPICTURE_HEIGHT;

View file

@ -27,146 +27,147 @@
#include "output.h"
#include "test-subpicture-data.h"
static inline void pause(void)
static inline void
pause (void)
{
g_print("Press any key to continue...\n");
getchar();
g_print ("Press any key to continue...\n");
getchar ();
}
static gchar *g_codec_str;
static gdouble g_global_alpha = 1.0;
static GOptionEntry g_options[] = {
{ "codec", 'c',
0,
G_OPTION_ARG_STRING, &g_codec_str,
"codec to test", NULL },
{ "global-alpha", 'g',
0,
G_OPTION_ARG_DOUBLE, &g_global_alpha,
"global-alpha value", NULL },
{ NULL, }
{"codec", 'c',
0,
G_OPTION_ARG_STRING, &g_codec_str,
"codec to test", NULL},
{"global-alpha", 'g',
0,
G_OPTION_ARG_DOUBLE, &g_global_alpha,
"global-alpha value", NULL},
{NULL,}
};
static void
upload_subpicture(GstBuffer *buffer, const VideoSubpictureInfo *subinfo)
upload_subpicture (GstBuffer * buffer, const VideoSubpictureInfo * subinfo)
{
const guint32 * const src = subinfo->data;
guint i, len = subinfo->data_size / 4;
GstMapInfo map_info;
guint32 *dst;
const guint32 *const src = subinfo->data;
guint i, len = subinfo->data_size / 4;
GstMapInfo map_info;
guint32 *dst;
if (!gst_buffer_map(buffer, &map_info, GST_MAP_WRITE))
return;
dst = (guint32 *)map_info.data;
if (!gst_buffer_map (buffer, &map_info, GST_MAP_WRITE))
return;
dst = (guint32 *) map_info.data;
/* Convert from RGBA source to ARGB */
for (i = 0; i < len; i++) {
const guint32 rgba = src[i];
dst[i] = (rgba >> 8) | (rgba << 24);
}
/* Convert from RGBA source to ARGB */
for (i = 0; i < len; i++) {
const guint32 rgba = src[i];
dst[i] = (rgba >> 8) | (rgba << 24);
}
gst_buffer_unmap(buffer, &map_info);
gst_buffer_unmap (buffer, &map_info);
}
int
main(int argc, char *argv[])
main (int argc, char *argv[])
{
GstVaapiDisplay *display;
GstVaapiWindow *window;
GstVaapiDecoder *decoder;
GstVaapiSurfaceProxy *proxy;
GstVaapiSurface *surface;
GstBuffer *buffer;
VideoSubpictureInfo subinfo;
GstVaapiRectangle subrect;
GstVideoOverlayRectangle *overlay;
GstVideoOverlayComposition *compo;
guint flags = 0;
GstVaapiDisplay *display;
GstVaapiWindow *window;
GstVaapiDecoder *decoder;
GstVaapiSurfaceProxy *proxy;
GstVaapiSurface *surface;
GstBuffer *buffer;
VideoSubpictureInfo subinfo;
GstVaapiRectangle subrect;
GstVideoOverlayRectangle *overlay;
GstVideoOverlayComposition *compo;
guint flags = 0;
static const guint win_width = 640;
static const guint win_height = 480;
static const guint win_width = 640;
static const guint win_height = 480;
if (!video_output_init(&argc, argv, g_options))
g_error("failed to initialize video output subsystem");
if (!video_output_init (&argc, argv, g_options))
g_error ("failed to initialize video output subsystem");
if (g_global_alpha != 1.0)
flags |= GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA;
if (g_global_alpha != 1.0)
flags |= GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA;
g_print("Test subpicture\n");
g_print ("Test subpicture\n");
display = video_output_create_display(NULL);
if (!display)
g_error("could not create VA display");
display = video_output_create_display (NULL);
if (!display)
g_error ("could not create VA display");
window = video_output_create_window(display, win_width, win_height);
if (!window)
g_error("could not create window");
window = video_output_create_window (display, win_width, win_height);
if (!window)
g_error ("could not create window");
decoder = decoder_new(display, g_codec_str);
if (!decoder)
g_error("could not create decoder");
decoder = decoder_new (display, g_codec_str);
if (!decoder)
g_error ("could not create decoder");
if (!decoder_put_buffers(decoder))
g_error("could not fill decoder with sample data");
if (!decoder_put_buffers (decoder))
g_error ("could not fill decoder with sample data");
proxy = decoder_get_surface(decoder);
if (!proxy)
g_error("could not get decoded surface");
proxy = decoder_get_surface (decoder);
if (!proxy)
g_error ("could not get decoded surface");
surface = gst_vaapi_surface_proxy_get_surface(proxy);
surface = gst_vaapi_surface_proxy_get_surface (proxy);
subpicture_get_info(&subinfo);
buffer = gst_buffer_new_and_alloc(subinfo.data_size);
upload_subpicture(buffer, &subinfo);
subpicture_get_info (&subinfo);
buffer = gst_buffer_new_and_alloc (subinfo.data_size);
upload_subpicture (buffer, &subinfo);
/* We position the subpicture at the bottom center */
subrect.x = (gst_vaapi_surface_get_width(surface) - subinfo.width) / 2;
subrect.y = gst_vaapi_surface_get_height(surface) - subinfo.height - 10;
subrect.height = subinfo.height;
subrect.width = subinfo.width;
/* We position the subpicture at the bottom center */
subrect.x = (gst_vaapi_surface_get_width (surface) - subinfo.width) / 2;
subrect.y = gst_vaapi_surface_get_height (surface) - subinfo.height - 10;
subrect.height = subinfo.height;
subrect.width = subinfo.width;
{
GstVideoMeta * const vmeta =
gst_buffer_add_video_meta(buffer, GST_VIDEO_FRAME_FLAG_NONE,
GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB,
subinfo.width, subinfo.height);
if (!vmeta)
g_error("could not create video meta");
{
GstVideoMeta *const vmeta =
gst_buffer_add_video_meta (buffer, GST_VIDEO_FRAME_FLAG_NONE,
GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB,
subinfo.width, subinfo.height);
if (!vmeta)
g_error ("could not create video meta");
overlay = gst_video_overlay_rectangle_new_raw(buffer,
subrect.x, subrect.y, subrect.width, subrect.height, flags);
}
if (!overlay)
g_error("could not create video overlay");
gst_buffer_unref(buffer);
overlay = gst_video_overlay_rectangle_new_raw (buffer,
subrect.x, subrect.y, subrect.width, subrect.height, flags);
}
if (!overlay)
g_error ("could not create video overlay");
gst_buffer_unref (buffer);
if (flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA)
gst_video_overlay_rectangle_set_global_alpha(overlay, g_global_alpha);
if (flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA)
gst_video_overlay_rectangle_set_global_alpha (overlay, g_global_alpha);
compo = gst_video_overlay_composition_new(overlay);
if (!compo)
g_error("could not create video overlay composition");
gst_video_overlay_rectangle_unref(overlay);
compo = gst_video_overlay_composition_new (overlay);
if (!compo)
g_error ("could not create video overlay composition");
gst_video_overlay_rectangle_unref (overlay);
if (!gst_vaapi_surface_set_subpictures_from_composition(surface, compo,
FALSE))
g_error("could not create subpictures from video overlay compoition");
if (!gst_vaapi_surface_set_subpictures_from_composition (surface, compo,
FALSE))
g_error ("could not create subpictures from video overlay compoition");
gst_vaapi_window_show(window);
gst_vaapi_window_show (window);
if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL,
GST_VAAPI_PICTURE_STRUCTURE_FRAME))
g_error("could not render surface");
if (!gst_vaapi_window_put_surface (window, surface, NULL, NULL,
GST_VAAPI_PICTURE_STRUCTURE_FRAME))
g_error ("could not render surface");
pause();
pause ();
gst_video_overlay_composition_unref(compo);
gst_vaapi_surface_proxy_unref(proxy);
gst_vaapi_decoder_unref(decoder);
gst_vaapi_window_unref(window);
gst_vaapi_display_unref(display);
g_free(g_codec_str);
video_output_exit();
return 0;
gst_video_overlay_composition_unref (compo);
gst_vaapi_surface_proxy_unref (proxy);
gst_vaapi_decoder_unref (decoder);
gst_vaapi_window_unref (window);
gst_vaapi_display_unref (display);
g_free (g_codec_str);
video_output_exit ();
return 0;
}

View file

@ -29,78 +29,78 @@
#define MAX_SURFACES 4
int
main(int argc, char *argv[])
main (int argc, char *argv[])
{
GstVaapiDisplay *display;
GstVaapiSurface *surface;
GstVaapiID surface_id;
GstVaapiSurface *surfaces[MAX_SURFACES];
GstVaapiVideoPool *pool;
gint i;
GstVaapiDisplay *display;
GstVaapiSurface *surface;
GstVaapiID surface_id;
GstVaapiSurface *surfaces[MAX_SURFACES];
GstVaapiVideoPool *pool;
gint i;
static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
static const guint width = 320;
static const guint height = 240;
static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
static const guint width = 320;
static const guint height = 240;
if (!video_output_init(&argc, argv, NULL))
g_error("failed to initialize video output subsystem");
if (!video_output_init (&argc, argv, NULL))
g_error ("failed to initialize video output subsystem");
display = video_output_create_display(NULL);
if (!display)
g_error("could not create Gst/VA display");
display = video_output_create_display (NULL);
if (!display)
g_error ("could not create Gst/VA display");
surface = gst_vaapi_surface_new(display, chroma_type, width, height);
surface = gst_vaapi_surface_new (display, chroma_type, width, height);
if (!surface)
g_error ("could not create Gst/VA surface");
surface_id = gst_vaapi_surface_get_id (surface);
g_print ("created surface %" GST_VAAPI_ID_FORMAT "\n",
GST_VAAPI_ID_ARGS (surface_id));
gst_vaapi_object_unref (surface);
pool = gst_vaapi_surface_pool_new (display, GST_VIDEO_FORMAT_ENCODED,
width, height);
if (!pool)
g_error ("could not create Gst/VA surface pool");
for (i = 0; i < MAX_SURFACES; i++) {
surface = gst_vaapi_video_pool_get_object (pool);
if (!surface)
g_error("could not create Gst/VA surface");
g_error ("could not allocate Gst/VA surface from pool");
g_print ("created surface %" GST_VAAPI_ID_FORMAT " from pool\n",
GST_VAAPI_ID_ARGS (gst_vaapi_surface_get_id (surface)));
surfaces[i] = surface;
}
surface_id = gst_vaapi_surface_get_id(surface);
g_print("created surface %" GST_VAAPI_ID_FORMAT "\n",
GST_VAAPI_ID_ARGS(surface_id));
/* Check the pool doesn't return the last free'd surface */
surface = gst_vaapi_object_ref (surfaces[1]);
gst_vaapi_object_unref(surface);
for (i = 0; i < 2; i++)
gst_vaapi_video_pool_put_object (pool, surfaces[i]);
pool = gst_vaapi_surface_pool_new(display, GST_VIDEO_FORMAT_ENCODED,
width, height);
if (!pool)
g_error("could not create Gst/VA surface pool");
for (i = 0; i < 2; i++) {
surfaces[i] = gst_vaapi_video_pool_get_object (pool);
if (!surfaces[i])
g_error ("could not re-allocate Gst/VA surface%d from pool", i);
g_print ("created surface %" GST_VAAPI_ID_FORMAT " from pool (realloc)\n",
GST_VAAPI_ID_ARGS (gst_vaapi_surface_get_id (surfaces[i])));
}
for (i = 0; i < MAX_SURFACES; i++) {
surface = gst_vaapi_video_pool_get_object(pool);
if (!surface)
g_error("could not allocate Gst/VA surface from pool");
g_print("created surface %" GST_VAAPI_ID_FORMAT " from pool\n",
GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surface)));
surfaces[i] = surface;
}
if (surface == surfaces[0])
g_error ("Gst/VA pool doesn't queue free surfaces");
/* Check the pool doesn't return the last free'd surface */
surface = gst_vaapi_object_ref(surfaces[1]);
for (i = MAX_SURFACES - 1; i >= 0; i--) {
if (!surfaces[i])
continue;
gst_vaapi_video_pool_put_object (pool, surfaces[i]);
surfaces[i] = NULL;
}
for (i = 0; i < 2; i++)
gst_vaapi_video_pool_put_object(pool, surfaces[i]);
for (i = 0; i < 2; i++) {
surfaces[i] = gst_vaapi_video_pool_get_object(pool);
if (!surfaces[i])
g_error("could not re-allocate Gst/VA surface%d from pool", i);
g_print("created surface %" GST_VAAPI_ID_FORMAT " from pool (realloc)\n",
GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surfaces[i])));
}
if (surface == surfaces[0])
g_error("Gst/VA pool doesn't queue free surfaces");
for (i = MAX_SURFACES - 1; i >= 0; i--) {
if (!surfaces[i])
continue;
gst_vaapi_video_pool_put_object(pool, surfaces[i]);
surfaces[i] = NULL;
}
/* Unref in random order to check objects are correctly refcounted */
gst_vaapi_display_unref(display);
gst_vaapi_video_pool_unref(pool);
gst_vaapi_object_unref(surface);
video_output_exit();
return 0;
/* Unref in random order to check objects are correctly refcounted */
gst_vaapi_display_unref (display);
gst_vaapi_video_pool_unref (pool);
gst_vaapi_object_unref (surface);
video_output_exit ();
return 0;
}

View file

@ -28,167 +28,152 @@
#include <gst/vaapi/gstvaapiimage.h>
#include "image.h"
static inline void pause(void)
static inline void
pause (void)
{
g_print("Press any key to continue...\n");
getchar();
g_print ("Press any key to continue...\n");
getchar ();
}
static inline guint gl_get_current_texture_2d(void)
static inline guint
gl_get_current_texture_2d (void)
{
GLint texture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &texture);
return (guint)texture;
GLint texture;
glGetIntegerv (GL_TEXTURE_BINDING_2D, &texture);
return (guint) texture;
}
int
main(int argc, char *argv[])
main (int argc, char *argv[])
{
GstVaapiDisplay *display;
GstVaapiWindow *window;
GstVaapiWindowGLX *glx_window;
GstVaapiSurface *surface;
GstVaapiImage *image;
GstVaapiTexture *textures[2];
GstVaapiTexture *texture;
GLuint texture_id;
GstVaapiRectangle src_rect;
GstVaapiRectangle dst_rect;
guint flags = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
GstVaapiDisplay *display;
GstVaapiWindow *window;
GstVaapiWindowGLX *glx_window;
GstVaapiSurface *surface;
GstVaapiImage *image;
GstVaapiTexture *textures[2];
GstVaapiTexture *texture;
GLuint texture_id;
GstVaapiRectangle src_rect;
GstVaapiRectangle dst_rect;
guint flags = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
static const guint width = 320;
static const guint height = 240;
static const guint win_width = 640;
static const guint win_height = 480;
static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
static const guint width = 320;
static const guint height = 240;
static const guint win_width = 640;
static const guint win_height = 480;
gst_init(&argc, &argv);
gst_init (&argc, &argv);
display = gst_vaapi_display_glx_new(NULL);
if (!display)
g_error("could not create VA display");
display = gst_vaapi_display_glx_new (NULL);
if (!display)
g_error ("could not create VA display");
surface = gst_vaapi_surface_new(display, chroma_type, width, height);
if (!surface)
g_error("could not create VA surface");
surface = gst_vaapi_surface_new (display, chroma_type, width, height);
if (!surface)
g_error ("could not create VA surface");
image = image_generate(display, GST_VIDEO_FORMAT_NV12, width, height);
if (!image)
g_error("could not create VA image");
if (!image_upload(image, surface))
g_error("could not upload VA image to surface");
image = image_generate (display, GST_VIDEO_FORMAT_NV12, width, height);
if (!image)
g_error ("could not create VA image");
if (!image_upload (image, surface))
g_error ("could not upload VA image to surface");
window = gst_vaapi_window_glx_new(display, win_width, win_height);
if (!window)
g_error("could not create window");
glx_window = GST_VAAPI_WINDOW_GLX(window);
window = gst_vaapi_window_glx_new (display, win_width, win_height);
if (!window)
g_error ("could not create window");
glx_window = GST_VAAPI_WINDOW_GLX (window);
gst_vaapi_window_show(window);
gst_vaapi_window_show (window);
if (!gst_vaapi_window_glx_make_current(glx_window))
g_error("coult not bind GL context");
if (!gst_vaapi_window_glx_make_current (glx_window))
g_error ("coult not bind GL context");
g_print("#\n");
g_print("# Create texture with gst_vaapi_texture_glx_new()\n");
g_print("#\n");
{
texture = gst_vaapi_texture_glx_new(
display,
GL_TEXTURE_2D,
GL_RGBA,
width,
height
);
if (!texture)
g_error("could not create VA texture");
g_print ("#\n");
g_print ("# Create texture with gst_vaapi_texture_glx_new()\n");
g_print ("#\n");
{
texture = gst_vaapi_texture_glx_new (display,
GL_TEXTURE_2D, GL_RGBA, width, height);
if (!texture)
g_error ("could not create VA texture");
textures[0] = texture;
texture_id = gst_vaapi_texture_get_id(texture);
textures[0] = texture;
texture_id = gst_vaapi_texture_get_id (texture);
if (!gst_vaapi_texture_put_surface(texture, surface, NULL, flags))
g_error("could not transfer VA surface to texture");
if (!gst_vaapi_texture_put_surface (texture, surface, NULL, flags))
g_error ("could not transfer VA surface to texture");
if (!gst_vaapi_window_glx_put_texture(glx_window, texture, NULL, NULL))
g_error("could not render texture into the window");
}
if (!gst_vaapi_window_glx_put_texture (glx_window, texture, NULL, NULL))
g_error ("could not render texture into the window");
}
g_print("#\n");
g_print("# Create texture with gst_vaapi_texture_glx_new_wrapped()\n");
g_print("#\n");
{
const GLenum target = GL_TEXTURE_2D;
const GLenum format = GL_BGRA;
g_print ("#\n");
g_print ("# Create texture with gst_vaapi_texture_glx_new_wrapped()\n");
g_print ("#\n");
{
const GLenum target = GL_TEXTURE_2D;
const GLenum format = GL_BGRA;
glEnable(target);
glGenTextures(1, &texture_id);
glBindTexture(target, texture_id);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glTexImage2D(
target,
0,
GL_RGBA8,
width, height,
0,
format,
GL_UNSIGNED_BYTE,
NULL
);
glDisable(target);
glEnable (target);
glGenTextures (1, &texture_id);
glBindTexture (target, texture_id);
glTexParameteri (target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
glTexImage2D (target,
0, GL_RGBA8, width, height, 0, format, GL_UNSIGNED_BYTE, NULL);
glDisable (target);
texture = gst_vaapi_texture_glx_new_wrapped(
display,
texture_id,
target,
format
);
if (!texture)
g_error("could not create VA texture");
texture = gst_vaapi_texture_glx_new_wrapped (display,
texture_id, target, format);
if (!texture)
g_error ("could not create VA texture");
if (texture_id != gst_vaapi_texture_get_id(texture))
g_error("invalid texture id");
if (texture_id != gst_vaapi_texture_get_id (texture))
g_error ("invalid texture id");
if (gl_get_current_texture_2d() != texture_id)
g_error("gst_vaapi_texture_glx_new_wrapped() altered texture bindings");
if (gl_get_current_texture_2d () != texture_id)
g_error ("gst_vaapi_texture_glx_new_wrapped() altered texture bindings");
textures[1] = texture;
textures[1] = texture;
if (!gst_vaapi_texture_put_surface(texture, surface, NULL, flags))
g_error("could not transfer VA surface to texture");
if (!gst_vaapi_texture_put_surface (texture, surface, NULL, flags))
g_error ("could not transfer VA surface to texture");
if (gl_get_current_texture_2d() != texture_id)
g_error("gst_vaapi_texture_put_surface() altered texture bindings");
if (gl_get_current_texture_2d () != texture_id)
g_error ("gst_vaapi_texture_put_surface() altered texture bindings");
src_rect.x = 0;
src_rect.y = 0;
src_rect.width = width;
src_rect.height = height;
src_rect.x = 0;
src_rect.y = 0;
src_rect.width = width;
src_rect.height = height;
dst_rect.x = win_width/2;
dst_rect.y = win_height/2;
dst_rect.width = win_width/2;
dst_rect.height = win_height/2;
dst_rect.x = win_width / 2;
dst_rect.y = win_height / 2;
dst_rect.width = win_width / 2;
dst_rect.height = win_height / 2;
if (!gst_vaapi_window_glx_put_texture(glx_window, texture,
&src_rect, &dst_rect))
g_error("could not render texture into the window");
if (!gst_vaapi_window_glx_put_texture (glx_window, texture,
&src_rect, &dst_rect))
g_error ("could not render texture into the window");
if (gl_get_current_texture_2d() != texture_id)
g_error("gst_vaapi_window_glx_put_texture() altered texture bindings");
}
if (gl_get_current_texture_2d () != texture_id)
g_error ("gst_vaapi_window_glx_put_texture() altered texture bindings");
}
gst_vaapi_window_glx_swap_buffers(glx_window);
pause();
gst_vaapi_window_glx_swap_buffers (glx_window);
pause ();
gst_vaapi_texture_unref(textures[0]);
gst_vaapi_texture_unref(textures[1]);
glDeleteTextures(1, &texture_id);
gst_vaapi_texture_unref (textures[0]);
gst_vaapi_texture_unref (textures[1]);
glDeleteTextures (1, &texture_id);
gst_vaapi_window_unref(window);
gst_vaapi_display_unref(display);
gst_deinit();
return 0;
gst_vaapi_window_unref (window);
gst_vaapi_display_unref (display);
gst_deinit ();
return 0;
}

File diff suppressed because it is too large Load diff

View file

@ -44,199 +44,195 @@
#include "image.h"
static inline void
pause(void)
pause (void)
{
g_print("Press any key to continue...\n");
getchar();
g_print ("Press any key to continue...\n");
getchar ();
}
static GstVaapiSurface *
create_test_surface(GstVaapiDisplay *display, guint width, guint height)
create_test_surface (GstVaapiDisplay * display, guint width, guint height)
{
GstVaapiImage *image = NULL;
GstVaapiSurface *surface;
guint i;
GstVaapiImage *image = NULL;
GstVaapiSurface *surface;
guint i;
static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
static const GstVideoFormat image_formats[] = {
GST_VIDEO_FORMAT_NV12,
GST_VIDEO_FORMAT_YV12,
GST_VIDEO_FORMAT_I420,
GST_VIDEO_FORMAT_AYUV,
GST_VIDEO_FORMAT_ARGB,
GST_VIDEO_FORMAT_BGRA,
GST_VIDEO_FORMAT_RGBA,
GST_VIDEO_FORMAT_ABGR,
GST_VIDEO_FORMAT_UNKNOWN
};
static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
static const GstVideoFormat image_formats[] = {
GST_VIDEO_FORMAT_NV12,
GST_VIDEO_FORMAT_YV12,
GST_VIDEO_FORMAT_I420,
GST_VIDEO_FORMAT_AYUV,
GST_VIDEO_FORMAT_ARGB,
GST_VIDEO_FORMAT_BGRA,
GST_VIDEO_FORMAT_RGBA,
GST_VIDEO_FORMAT_ABGR,
GST_VIDEO_FORMAT_UNKNOWN
};
surface = gst_vaapi_surface_new(display, chroma_type, width, height);
if (!surface)
g_error("could not create Gst/VA surface");
surface = gst_vaapi_surface_new (display, chroma_type, width, height);
if (!surface)
g_error ("could not create Gst/VA surface");
for (i = 0; image_formats[i] != GST_VIDEO_FORMAT_UNKNOWN; i++) {
const GstVideoFormat format = image_formats[i];
for (i = 0; image_formats[i] != GST_VIDEO_FORMAT_UNKNOWN; i++) {
const GstVideoFormat format = image_formats[i];
image = image_generate(display, format, width, height);
if (!image)
break;
if (image_upload(image, surface))
break;
}
image = image_generate (display, format, width, height);
if (!image)
g_error("could not create Gst/VA image");
break;
if (image_upload (image, surface))
break;
}
if (!image)
g_error ("could not create Gst/VA image");
if (!gst_vaapi_surface_sync(surface))
g_error("could not complete image upload");
if (!gst_vaapi_surface_sync (surface))
g_error ("could not complete image upload");
gst_vaapi_object_unref(image);
return surface;
gst_vaapi_object_unref (image);
return surface;
}
int
main(int argc, char *argv[])
main (int argc, char *argv[])
{
GstVaapiDisplay *display;
GstVaapiWindow *window;
GstVaapiSurface *surface;
guint flags = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
GstVaapiDisplay *display;
GstVaapiWindow *window;
GstVaapiSurface *surface;
guint flags = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
static const guint width = 320;
static const guint height = 240;
static const guint win_width = 640;
static const guint win_height = 480;
static const guint width = 320;
static const guint height = 240;
static const guint win_width = 640;
static const guint win_height = 480;
gst_init(&argc, &argv);
gst_init (&argc, &argv);
#if USE_DRM
display = gst_vaapi_display_drm_new(NULL);
if (!display)
g_error("could not create Gst/VA (DRM) display");
display = gst_vaapi_display_drm_new (NULL);
if (!display)
g_error ("could not create Gst/VA (DRM) display");
surface = create_test_surface(display, width, height);
if (!surface)
g_error("could not create Gst/VA surface");
surface = create_test_surface (display, width, height);
if (!surface)
g_error ("could not create Gst/VA surface");
g_print("#\n");
g_print("# Create window with gst_vaapi_window_drm_new()\n");
g_print("#\n");
{
window = gst_vaapi_window_drm_new(display, win_width, win_height);
if (!window)
g_error("could not create dummy window");
g_print ("#\n");
g_print ("# Create window with gst_vaapi_window_drm_new()\n");
g_print ("#\n");
{
window = gst_vaapi_window_drm_new (display, win_width, win_height);
if (!window)
g_error ("could not create dummy window");
gst_vaapi_window_show(window);
gst_vaapi_window_show (window);
if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
g_error("could not render surface");
if (!gst_vaapi_window_put_surface (window, surface, NULL, NULL, flags))
g_error ("could not render surface");
pause();
gst_vaapi_window_unref(window);
}
pause ();
gst_vaapi_window_unref (window);
}
gst_vaapi_object_unref(surface);
gst_vaapi_display_unref(display);
gst_vaapi_object_unref (surface);
gst_vaapi_display_unref (display);
#endif
#if USE_X11
display = gst_vaapi_display_x11_new(NULL);
if (!display)
g_error("could not create Gst/VA display");
display = gst_vaapi_display_x11_new (NULL);
if (!display)
g_error ("could not create Gst/VA display");
surface = create_test_surface(display, width, height);
if (!surface)
g_error("could not create Gst/VA surface");
surface = create_test_surface (display, width, height);
if (!surface)
g_error ("could not create Gst/VA surface");
g_print("#\n");
g_print("# Create window with gst_vaapi_window_x11_new()\n");
g_print("#\n");
{
window = gst_vaapi_window_x11_new(display, win_width, win_height);
if (!window)
g_error("could not create window");
g_print ("#\n");
g_print ("# Create window with gst_vaapi_window_x11_new()\n");
g_print ("#\n");
{
window = gst_vaapi_window_x11_new (display, win_width, win_height);
if (!window)
g_error ("could not create window");
gst_vaapi_window_show(window);
gst_vaapi_window_show (window);
if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
g_error("could not render surface");
if (!gst_vaapi_window_put_surface (window, surface, NULL, NULL, flags))
g_error ("could not render surface");
pause();
gst_vaapi_window_unref(window);
}
pause ();
gst_vaapi_window_unref (window);
}
g_print("#\n");
g_print("# Create window with gst_vaapi_window_x11_new_with_xid()\n");
g_print("#\n");
{
Display * const dpy = gst_vaapi_display_x11_get_display(GST_VAAPI_DISPLAY_X11(display));
Window rootwin, win;
int screen;
unsigned long white_pixel, black_pixel;
g_print ("#\n");
g_print ("# Create window with gst_vaapi_window_x11_new_with_xid()\n");
g_print ("#\n");
{
Display *const dpy =
gst_vaapi_display_x11_get_display (GST_VAAPI_DISPLAY_X11 (display));
Window rootwin, win;
int screen;
unsigned long white_pixel, black_pixel;
screen = DefaultScreen(dpy);
rootwin = RootWindow(dpy, screen);
white_pixel = WhitePixel(dpy, screen);
black_pixel = BlackPixel(dpy, screen);
screen = DefaultScreen (dpy);
rootwin = RootWindow (dpy, screen);
white_pixel = WhitePixel (dpy, screen);
black_pixel = BlackPixel (dpy, screen);
win = XCreateSimpleWindow(
dpy,
rootwin,
0, 0, win_width, win_height,
0, black_pixel,
white_pixel
);
if (!win)
g_error("could not create X window");
win = XCreateSimpleWindow (dpy,
rootwin, 0, 0, win_width, win_height, 0, black_pixel, white_pixel);
if (!win)
g_error ("could not create X window");
window = gst_vaapi_window_x11_new_with_xid(display, win);
if (!window)
g_error("could not create window");
window = gst_vaapi_window_x11_new_with_xid (display, win);
if (!window)
g_error ("could not create window");
gst_vaapi_window_show(window);
gst_vaapi_window_show (window);
if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
g_error("could not render surface");
if (!gst_vaapi_window_put_surface (window, surface, NULL, NULL, flags))
g_error ("could not render surface");
pause();
gst_vaapi_window_unref(window);
XUnmapWindow(dpy, win);
XDestroyWindow(dpy, win);
}
pause ();
gst_vaapi_window_unref (window);
XUnmapWindow (dpy, win);
XDestroyWindow (dpy, win);
}
gst_vaapi_object_unref(surface);
gst_vaapi_display_unref(display);
gst_vaapi_object_unref (surface);
gst_vaapi_display_unref (display);
#endif
#if USE_WAYLAND
display = gst_vaapi_display_wayland_new(NULL);
if (!display)
g_error("could not create Gst/VA (Wayland) display");
display = gst_vaapi_display_wayland_new (NULL);
if (!display)
g_error ("could not create Gst/VA (Wayland) display");
surface = create_test_surface(display, width, height);
if (!surface)
g_error("could not create Gst/VA surface");
surface = create_test_surface (display, width, height);
if (!surface)
g_error ("could not create Gst/VA surface");
g_print("#\n");
g_print("# Create window with gst_vaapi_window_wayland_new()\n");
g_print("#\n");
{
window = gst_vaapi_window_wayland_new(display, win_width, win_height);
if (!window)
g_error("could not create window");
g_print ("#\n");
g_print ("# Create window with gst_vaapi_window_wayland_new()\n");
g_print ("#\n");
{
window = gst_vaapi_window_wayland_new (display, win_width, win_height);
if (!window)
g_error ("could not create window");
gst_vaapi_window_show(window);
gst_vaapi_window_show (window);
if (!gst_vaapi_window_put_surface(window, surface, NULL, NULL, flags))
g_error("could not render surface");
if (!gst_vaapi_window_put_surface (window, surface, NULL, NULL, flags))
g_error ("could not render surface");
pause();
gst_vaapi_window_unref(window);
}
pause ();
gst_vaapi_window_unref (window);
}
gst_vaapi_object_unref(surface);
gst_vaapi_display_unref(display);
gst_vaapi_object_unref (surface);
gst_vaapi_display_unref (display);
#endif
gst_deinit();
return 0;
gst_deinit ();
return 0;
}