mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
visual: add support for GstVideoFrame
Add support for GstVideoMeta and GstVideoFrame. Remove some redundant fields that are also in GstVideoInfo Disable the shader code, it looks broken. Fixes https://bugzilla.gnome.org/show_bug.cgi?id=681719
This commit is contained in:
parent
19695f76d0
commit
c6e19d5df2
3 changed files with 258 additions and 181 deletions
|
@ -39,6 +39,10 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <gst/video/video.h>
|
||||||
|
#include <gst/video/gstvideometa.h>
|
||||||
|
#include <gst/video/gstvideopool.h>
|
||||||
|
|
||||||
#include "gstaudiovisualizer.h"
|
#include "gstaudiovisualizer.h"
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (audio_visualizer_debug);
|
GST_DEBUG_CATEGORY_STATIC (audio_visualizer_debug);
|
||||||
|
@ -129,232 +133,315 @@ gst_audio_visualizer_shader_get_type (void)
|
||||||
/* we're only supporting GST_VIDEO_FORMAT_xRGB right now) */
|
/* we're only supporting GST_VIDEO_FORMAT_xRGB right now) */
|
||||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||||
|
|
||||||
#define SHADE1(_d, _s, _i, _r, _g, _b) \
|
#define SHADE(_d, _s, _i, _r, _g, _b) \
|
||||||
G_STMT_START { \
|
G_STMT_START { \
|
||||||
_d[_i] = (_s[_i] > _b) ? _s[_i] - _b : 0; \
|
_d[_i * 4 + 0] = (_s[_i * 4 + 0] > _b) ? _s[_i * 4 + 0] - _b : 0; \
|
||||||
_i++; \
|
_d[_i * 4 + 1] = (_s[_i * 4 + 1] > _g) ? _s[_i * 4 + 1] - _g : 0; \
|
||||||
_d[_i] = (_s[_i] > _g) ? _s[_i] - _g : 0; \
|
_d[_i * 4 + 2] = (_s[_i * 4 + 2] > _r) ? _s[_i * 4 + 2] - _r : 0; \
|
||||||
_i++; \
|
_d[_i * 4 + 3] = 0; \
|
||||||
_d[_i] = (_s[_i] > _r) ? _s[_i] - _r : 0; \
|
|
||||||
_i++; \
|
|
||||||
_d[_i++] = 0; \
|
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
|
||||||
#define SHADE2(_d, _s, _j, _i, _r, _g, _b) \
|
#else /* G_BYTE_ORDER == G_LITTLE_ENDIAN */
|
||||||
G_STMT_START { \
|
|
||||||
_d[_j++] = (_s[_i] > _b) ? _s[_i] - _b : 0; \
|
|
||||||
_i++; \
|
|
||||||
_d[_j++] = (_s[_i] > _g) ? _s[_i] - _g : 0; \
|
|
||||||
_i++; \
|
|
||||||
_d[_j++] = (_s[_i] > _r) ? _s[_i] - _r : 0; \
|
|
||||||
_i++; \
|
|
||||||
_d[_j++] = 0; \
|
|
||||||
_i++; \
|
|
||||||
} G_STMT_END
|
|
||||||
|
|
||||||
#else
|
#define SHADE(_d, _s, _i, _r, _g, _b) \
|
||||||
|
G_STMT_START { \
|
||||||
#define SHADE1(_d, _s, _i, _r, _g, _b) \
|
_d[_i * 4 + 0] = 0; \
|
||||||
G_STMT_START { \
|
_d[_i * 4 + 1] = (_s[_i * 4 + 1] > _r) ? _s[_i * 4 + 1] - _r : 0; \
|
||||||
_d[_i++] = 0; \
|
_d[_i * 4 + 2] = (_s[_i * 4 + 2] > _g) ? _s[_i * 4 + 2] - _g : 0; \
|
||||||
_d[_i] = (_s[_i] > _r) ? _s[_i] - _r : 0; \
|
_d[_i * 4 + 3] = (_s[_i * 4 + 3] > _b) ? _s[_i * 4 + 3] - _b : 0; \
|
||||||
_i++; \
|
|
||||||
_d[_i] = (_s[_i] > _g) ? _s[_i] - _g : 0; \
|
|
||||||
_i++; \
|
|
||||||
_d[_i] = (_s[_i] > _b) ? _s[_i] - _b : 0; \
|
|
||||||
_i++; \
|
|
||||||
} G_STMT_END
|
|
||||||
|
|
||||||
#define SHADE2(_d, _s, _j, _i, _r, _g, _b) \
|
|
||||||
G_STMT_START { \
|
|
||||||
_d[_j++] = 0; \
|
|
||||||
_i++; \
|
|
||||||
_d[_j++] = (_s[_i] > _r) ? _s[_i] - _r : 0; \
|
|
||||||
_i++; \
|
|
||||||
_d[_j++] = (_s[_i] > _g) ? _s[_i] - _g : 0; \
|
|
||||||
_i++; \
|
|
||||||
_d[_j++] = (_s[_i] > _b) ? _s[_i] - _b : 0; \
|
|
||||||
_i++; \
|
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shader_fade (GstAudioVisualizer * scope, const guint8 * s, guint8 * d)
|
shader_fade (GstAudioVisualizer * scope, const GstVideoFrame * sframe,
|
||||||
|
GstVideoFrame * dframe)
|
||||||
{
|
{
|
||||||
guint i, bpf = scope->bpf;
|
guint i, j;
|
||||||
guint r = (scope->shade_amount >> 16) & 0xff;
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
||||||
guint g = (scope->shade_amount >> 8) & 0xff;
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
||||||
guint b = (scope->shade_amount >> 0) & 0xff;
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
||||||
|
guint8 *s, *d;
|
||||||
|
gint ss, ds, width, height;
|
||||||
|
|
||||||
for (i = 0; i < bpf;) {
|
s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0);
|
||||||
SHADE1 (d, s, i, r, g, b);
|
ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0);
|
||||||
|
d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0);
|
||||||
|
ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0);
|
||||||
|
|
||||||
|
width = GST_VIDEO_FRAME_WIDTH (sframe);
|
||||||
|
height = GST_VIDEO_FRAME_HEIGHT (sframe);
|
||||||
|
|
||||||
|
for (j = 0; j < height; j++) {
|
||||||
|
for (i = 0; i < width; i++) {
|
||||||
|
SHADE (d, s, i, r, g, b);
|
||||||
|
}
|
||||||
|
s += ss;
|
||||||
|
d += ds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shader_fade_and_move_up (GstAudioVisualizer * scope, const guint8 * s,
|
shader_fade_and_move_up (GstAudioVisualizer * scope,
|
||||||
guint8 * d)
|
const GstVideoFrame * sframe, GstVideoFrame * dframe)
|
||||||
{
|
{
|
||||||
guint i, j, bpf = scope->bpf;
|
guint i, j;
|
||||||
guint bpl = 4 * scope->width;
|
|
||||||
guint r = (scope->shade_amount >> 16) & 0xff;
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
||||||
guint g = (scope->shade_amount >> 8) & 0xff;
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
||||||
guint b = (scope->shade_amount >> 0) & 0xff;
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
||||||
|
guint8 *s, *d;
|
||||||
|
gint ss, ds, width, height;
|
||||||
|
|
||||||
for (j = 0, i = bpl; i < bpf;) {
|
s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0);
|
||||||
SHADE2 (d, s, j, i, r, g, b);
|
ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0);
|
||||||
|
d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0);
|
||||||
|
ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0);
|
||||||
|
|
||||||
|
width = GST_VIDEO_FRAME_WIDTH (sframe);
|
||||||
|
height = GST_VIDEO_FRAME_HEIGHT (sframe);
|
||||||
|
|
||||||
|
for (j = 1; j < height; j++) {
|
||||||
|
s += ss;
|
||||||
|
for (i = 0; i < width; i++) {
|
||||||
|
SHADE (d, s, i, r, g, b);
|
||||||
|
}
|
||||||
|
d += ds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shader_fade_and_move_down (GstAudioVisualizer * scope, const guint8 * s,
|
shader_fade_and_move_down (GstAudioVisualizer * scope,
|
||||||
guint8 * d)
|
const GstVideoFrame * sframe, GstVideoFrame * dframe)
|
||||||
{
|
{
|
||||||
guint i, j, bpf = scope->bpf;
|
guint i, j;
|
||||||
guint bpl = 4 * scope->width;
|
|
||||||
guint r = (scope->shade_amount >> 16) & 0xff;
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
||||||
guint g = (scope->shade_amount >> 8) & 0xff;
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
||||||
guint b = (scope->shade_amount >> 0) & 0xff;
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
||||||
|
guint8 *s, *d;
|
||||||
|
gint ss, ds, width, height;
|
||||||
|
|
||||||
for (j = bpl, i = 0; j < bpf;) {
|
s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0);
|
||||||
SHADE2 (d, s, j, i, r, g, b);
|
ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0);
|
||||||
|
d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0);
|
||||||
|
ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0);
|
||||||
|
|
||||||
|
width = GST_VIDEO_FRAME_WIDTH (sframe);
|
||||||
|
height = GST_VIDEO_FRAME_HEIGHT (sframe);
|
||||||
|
|
||||||
|
for (j = 1; j < height; j++) {
|
||||||
|
d += ds;
|
||||||
|
for (i = 0; i < width; i++) {
|
||||||
|
SHADE (d, s, i, r, g, b);
|
||||||
|
}
|
||||||
|
s += ss;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shader_fade_and_move_left (GstAudioVisualizer * scope,
|
shader_fade_and_move_left (GstAudioVisualizer * scope,
|
||||||
const guint8 * s, guint8 * d)
|
const GstVideoFrame * sframe, GstVideoFrame * dframe)
|
||||||
{
|
{
|
||||||
guint i, j, k, bpf = scope->bpf;
|
guint i, j;
|
||||||
guint w = scope->width;
|
|
||||||
guint r = (scope->shade_amount >> 16) & 0xff;
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
||||||
guint g = (scope->shade_amount >> 8) & 0xff;
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
||||||
guint b = (scope->shade_amount >> 0) & 0xff;
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
||||||
|
guint8 *s, *d;
|
||||||
|
gint ss, ds, width, height;
|
||||||
|
|
||||||
|
s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0);
|
||||||
|
ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0);
|
||||||
|
d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0);
|
||||||
|
ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0);
|
||||||
|
|
||||||
|
width = GST_VIDEO_FRAME_WIDTH (sframe);
|
||||||
|
height = GST_VIDEO_FRAME_HEIGHT (sframe);
|
||||||
|
|
||||||
|
width -= 1;
|
||||||
|
s += 4;
|
||||||
|
|
||||||
/* move to the left */
|
/* move to the left */
|
||||||
for (j = 0, i = 4; i < bpf;) {
|
for (j = 0; j < height; j++) {
|
||||||
for (k = 0; k < w - 1; k++) {
|
for (i = 0; i < width; i++) {
|
||||||
SHADE2 (d, s, j, i, r, g, b);
|
SHADE (d, s, i, r, g, b);
|
||||||
}
|
}
|
||||||
i += 4;
|
d += ds;
|
||||||
j += 4;
|
s += ss;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shader_fade_and_move_right (GstAudioVisualizer * scope,
|
shader_fade_and_move_right (GstAudioVisualizer * scope,
|
||||||
const guint8 * s, guint8 * d)
|
const GstVideoFrame * sframe, GstVideoFrame * dframe)
|
||||||
{
|
{
|
||||||
guint i, j, k, bpf = scope->bpf;
|
guint i, j;
|
||||||
guint w = scope->width;
|
|
||||||
guint r = (scope->shade_amount >> 16) & 0xff;
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
||||||
guint g = (scope->shade_amount >> 8) & 0xff;
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
||||||
guint b = (scope->shade_amount >> 0) & 0xff;
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
||||||
|
guint8 *s, *d;
|
||||||
|
gint ss, ds, width, height;
|
||||||
|
|
||||||
/* move to the left */
|
s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0);
|
||||||
for (j = 4, i = 0; i < bpf;) {
|
ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0);
|
||||||
for (k = 0; k < w - 1; k++) {
|
d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0);
|
||||||
SHADE2 (d, s, j, i, r, g, b);
|
ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0);
|
||||||
|
|
||||||
|
width = GST_VIDEO_FRAME_WIDTH (sframe);
|
||||||
|
height = GST_VIDEO_FRAME_HEIGHT (sframe);
|
||||||
|
|
||||||
|
width -= 1;
|
||||||
|
d += 4;
|
||||||
|
|
||||||
|
/* move to the right */
|
||||||
|
for (j = 0; j < height; j++) {
|
||||||
|
for (i = 0; i < width; i++) {
|
||||||
|
SHADE (d, s, i, r, g, b);
|
||||||
}
|
}
|
||||||
i += 4;
|
d += ds;
|
||||||
j += 4;
|
s += ss;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shader_fade_and_move_horiz_out (GstAudioVisualizer * scope,
|
shader_fade_and_move_horiz_out (GstAudioVisualizer * scope,
|
||||||
const guint8 * s, guint8 * d)
|
const GstVideoFrame * sframe, GstVideoFrame * dframe)
|
||||||
{
|
{
|
||||||
guint i, j, bpf = scope->bpf / 2;
|
guint i, j;
|
||||||
guint bpl = 4 * scope->width;
|
|
||||||
guint r = (scope->shade_amount >> 16) & 0xff;
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
||||||
guint g = (scope->shade_amount >> 8) & 0xff;
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
||||||
guint b = (scope->shade_amount >> 0) & 0xff;
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
||||||
|
guint8 *s, *d;
|
||||||
|
gint ss, ds, width, height;
|
||||||
|
|
||||||
|
s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0);
|
||||||
|
ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0);
|
||||||
|
d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0);
|
||||||
|
ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0);
|
||||||
|
|
||||||
|
width = GST_VIDEO_FRAME_WIDTH (sframe);
|
||||||
|
height = GST_VIDEO_FRAME_HEIGHT (sframe);
|
||||||
|
|
||||||
/* move upper half up */
|
/* move upper half up */
|
||||||
for (j = 0, i = bpl; i < bpf;) {
|
for (j = 0; j < height / 2; j++) {
|
||||||
SHADE2 (d, s, j, i, r, g, b);
|
s += ss;
|
||||||
|
for (i = 0; i < width; i++) {
|
||||||
|
SHADE (d, s, i, r, g, b);
|
||||||
|
}
|
||||||
|
d += ds;
|
||||||
}
|
}
|
||||||
/* move lower half down */
|
/* move lower half down */
|
||||||
for (j = bpf + bpl, i = bpf; j < bpf + bpf;) {
|
for (j = 0; j < height / 2; j++) {
|
||||||
SHADE2 (d, s, j, i, r, g, b);
|
d += ds;
|
||||||
|
for (i = 0; i < width; i++) {
|
||||||
|
SHADE (d, s, i, r, g, b);
|
||||||
|
}
|
||||||
|
s += ss;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shader_fade_and_move_horiz_in (GstAudioVisualizer * scope,
|
shader_fade_and_move_horiz_in (GstAudioVisualizer * scope,
|
||||||
const guint8 * s, guint8 * d)
|
const GstVideoFrame * sframe, GstVideoFrame * dframe)
|
||||||
{
|
{
|
||||||
guint i, j, bpf = scope->bpf / 2;
|
guint i, j;
|
||||||
guint bpl = 4 * scope->width;
|
|
||||||
guint r = (scope->shade_amount >> 16) & 0xff;
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
||||||
guint g = (scope->shade_amount >> 8) & 0xff;
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
||||||
guint b = (scope->shade_amount >> 0) & 0xff;
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
||||||
|
guint8 *s, *d;
|
||||||
|
gint ss, ds, width, height;
|
||||||
|
|
||||||
|
s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0);
|
||||||
|
ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0);
|
||||||
|
d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0);
|
||||||
|
ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0);
|
||||||
|
|
||||||
|
width = GST_VIDEO_FRAME_WIDTH (sframe);
|
||||||
|
height = GST_VIDEO_FRAME_HEIGHT (sframe);
|
||||||
|
|
||||||
/* move upper half down */
|
/* move upper half down */
|
||||||
for (i = 0, j = bpl; i < bpf;) {
|
for (j = 0; j < height / 2; j++) {
|
||||||
SHADE2 (d, s, j, i, r, g, b);
|
d += ds;
|
||||||
|
for (i = 0; i < width; i++) {
|
||||||
|
SHADE (d, s, i, r, g, b);
|
||||||
|
}
|
||||||
|
s += ss;
|
||||||
}
|
}
|
||||||
/* move lower half up */
|
/* move lower half up */
|
||||||
for (i = bpf + bpl, j = bpf; i < bpf + bpf;) {
|
for (j = 0; j < height / 2; j++) {
|
||||||
SHADE2 (d, s, j, i, r, g, b);
|
s += ss;
|
||||||
|
for (i = 0; i < width; i++) {
|
||||||
|
SHADE (d, s, i, r, g, b);
|
||||||
|
}
|
||||||
|
d += ds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shader_fade_and_move_vert_out (GstAudioVisualizer * scope,
|
shader_fade_and_move_vert_out (GstAudioVisualizer * scope,
|
||||||
const guint8 * s, guint8 * d)
|
const GstVideoFrame * sframe, GstVideoFrame * dframe)
|
||||||
{
|
{
|
||||||
guint i, j, k, bpf = scope->bpf;
|
guint i, j;
|
||||||
guint m = scope->width / 2;
|
|
||||||
guint r = (scope->shade_amount >> 16) & 0xff;
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
||||||
guint g = (scope->shade_amount >> 8) & 0xff;
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
||||||
guint b = (scope->shade_amount >> 0) & 0xff;
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
||||||
|
guint8 *s, *s1, *d, *d1;
|
||||||
|
gint ss, ds, width, height;
|
||||||
|
|
||||||
/* move left half to the left */
|
s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0);
|
||||||
for (j = 0, i = 4; i < bpf;) {
|
ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0);
|
||||||
for (k = 0; k < m; k++) {
|
d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0);
|
||||||
SHADE2 (d, s, j, i, r, g, b);
|
ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0);
|
||||||
|
|
||||||
|
width = GST_VIDEO_FRAME_WIDTH (sframe);
|
||||||
|
height = GST_VIDEO_FRAME_HEIGHT (sframe);
|
||||||
|
|
||||||
|
for (j = 0; j < height; j++) {
|
||||||
|
/* move left half to the left */
|
||||||
|
s1 = s + 1;
|
||||||
|
for (i = 0; i < width / 2; i++) {
|
||||||
|
SHADE (d, s1, i, r, g, b);
|
||||||
}
|
}
|
||||||
j += 4 * m;
|
/* move right half to the right */
|
||||||
i += 4 * m;
|
d1 = d + 1;
|
||||||
}
|
for (; i < width - 1; i++) {
|
||||||
/* move right half to the right */
|
SHADE (d1, s, i, r, g, b);
|
||||||
for (j = 4 * (m + 1), i = 4 * m; j < bpf;) {
|
|
||||||
for (k = 0; k < m; k++) {
|
|
||||||
SHADE2 (d, s, j, i, r, g, b);
|
|
||||||
}
|
}
|
||||||
j += 4 * m;
|
s += ss;
|
||||||
i += 4 * m;
|
d += ds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shader_fade_and_move_vert_in (GstAudioVisualizer * scope,
|
shader_fade_and_move_vert_in (GstAudioVisualizer * scope,
|
||||||
const guint8 * s, guint8 * d)
|
const GstVideoFrame * sframe, GstVideoFrame * dframe)
|
||||||
{
|
{
|
||||||
guint i, j, k, bpf = scope->bpf;
|
guint i, j;
|
||||||
guint m = scope->width / 2;
|
|
||||||
guint r = (scope->shade_amount >> 16) & 0xff;
|
guint r = (scope->shade_amount >> 16) & 0xff;
|
||||||
guint g = (scope->shade_amount >> 8) & 0xff;
|
guint g = (scope->shade_amount >> 8) & 0xff;
|
||||||
guint b = (scope->shade_amount >> 0) & 0xff;
|
guint b = (scope->shade_amount >> 0) & 0xff;
|
||||||
|
guint8 *s, *s1, *d, *d1;
|
||||||
|
gint ss, ds, width, height;
|
||||||
|
|
||||||
/* move left half to the right */
|
s = GST_VIDEO_FRAME_PLANE_DATA (sframe, 0);
|
||||||
for (j = 4, i = 0; j < bpf;) {
|
ss = GST_VIDEO_FRAME_PLANE_STRIDE (sframe, 0);
|
||||||
for (k = 0; k < m; k++) {
|
d = GST_VIDEO_FRAME_PLANE_DATA (dframe, 0);
|
||||||
SHADE2 (d, s, j, i, r, g, b);
|
ds = GST_VIDEO_FRAME_PLANE_STRIDE (dframe, 0);
|
||||||
|
|
||||||
|
width = GST_VIDEO_FRAME_WIDTH (sframe);
|
||||||
|
height = GST_VIDEO_FRAME_HEIGHT (sframe);
|
||||||
|
|
||||||
|
for (j = 0; j < height; j++) {
|
||||||
|
/* move left half to the right */
|
||||||
|
d1 = d + 1;
|
||||||
|
for (i = 0; i < width / 2; i++) {
|
||||||
|
SHADE (d1, s, i, r, g, b);
|
||||||
}
|
}
|
||||||
j += 4 * m;
|
/* move right half to the left */
|
||||||
i += 4 * m;
|
s1 = s + 1;
|
||||||
}
|
for (; i < width - 1; i++) {
|
||||||
/* move right half to the left */
|
SHADE (d, s1, i, r, g, b);
|
||||||
for (j = 4 * m, i = 4 * (m + 1); i < bpf;) {
|
|
||||||
for (k = 0; k < m; k++) {
|
|
||||||
SHADE2 (d, s, j, i, r, g, b);
|
|
||||||
}
|
}
|
||||||
j += 4 * m;
|
s += ss;
|
||||||
i += 4 * m;
|
d += ds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,10 +584,7 @@ gst_audio_visualizer_init (GstAudioVisualizer * scope,
|
||||||
scope->shade_amount = DEFAULT_SHADE_AMOUNT;
|
scope->shade_amount = DEFAULT_SHADE_AMOUNT;
|
||||||
|
|
||||||
/* reset the initial video state */
|
/* reset the initial video state */
|
||||||
scope->width = 320;
|
gst_video_info_init (&scope->vinfo);
|
||||||
scope->height = 200;
|
|
||||||
scope->fps_n = 25; /* desired frame rate */
|
|
||||||
scope->fps_d = 1;
|
|
||||||
scope->frame_duration = GST_CLOCK_TIME_NONE;
|
scope->frame_duration = GST_CLOCK_TIME_NONE;
|
||||||
|
|
||||||
/* reset the initial state */
|
/* reset the initial state */
|
||||||
|
@ -616,41 +700,31 @@ gst_audio_visualizer_src_setcaps (GstAudioVisualizer * scope, GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstVideoInfo info;
|
GstVideoInfo info;
|
||||||
GstAudioVisualizerClass *klass;
|
GstAudioVisualizerClass *klass;
|
||||||
GstStructure *structure;
|
|
||||||
gboolean res;
|
gboolean res;
|
||||||
|
|
||||||
if (!gst_video_info_from_caps (&info, caps))
|
if (!gst_video_info_from_caps (&info, caps))
|
||||||
goto wrong_caps;
|
goto wrong_caps;
|
||||||
|
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
|
||||||
if (!gst_structure_get_int (structure, "width", &scope->width) ||
|
|
||||||
!gst_structure_get_int (structure, "height", &scope->height) ||
|
|
||||||
!gst_structure_get_fraction (structure, "framerate", &scope->fps_n,
|
|
||||||
&scope->fps_d))
|
|
||||||
goto wrong_caps;
|
|
||||||
|
|
||||||
klass = GST_AUDIO_VISUALIZER_CLASS (G_OBJECT_GET_CLASS (scope));
|
klass = GST_AUDIO_VISUALIZER_CLASS (G_OBJECT_GET_CLASS (scope));
|
||||||
|
|
||||||
scope->vinfo = info;
|
scope->vinfo = info;
|
||||||
scope->video_format = info.finfo->format;
|
|
||||||
|
|
||||||
scope->frame_duration = gst_util_uint64_scale_int (GST_SECOND,
|
scope->frame_duration = gst_util_uint64_scale_int (GST_SECOND,
|
||||||
scope->fps_d, scope->fps_n);
|
GST_VIDEO_INFO_FPS_D (&info), GST_VIDEO_INFO_FPS_N (&info));
|
||||||
scope->spf = gst_util_uint64_scale_int (GST_AUDIO_INFO_RATE (&scope->ainfo),
|
scope->spf = gst_util_uint64_scale_int (GST_AUDIO_INFO_RATE (&scope->ainfo),
|
||||||
scope->fps_d, scope->fps_n);
|
GST_VIDEO_INFO_FPS_D (&info), GST_VIDEO_INFO_FPS_N (&info));
|
||||||
scope->req_spf = scope->spf;
|
scope->req_spf = scope->spf;
|
||||||
|
|
||||||
scope->bpf = scope->width * scope->height * 4;
|
|
||||||
|
|
||||||
if (scope->pixelbuf)
|
if (scope->pixelbuf)
|
||||||
g_free (scope->pixelbuf);
|
g_free (scope->pixelbuf);
|
||||||
scope->pixelbuf = g_malloc0 (scope->bpf);
|
scope->pixelbuf = g_malloc0 (info.size);
|
||||||
|
|
||||||
if (klass->setup)
|
if (klass->setup)
|
||||||
res = klass->setup (scope);
|
res = klass->setup (scope);
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (scope, "video: dimension %dx%d, framerate %d/%d",
|
GST_DEBUG_OBJECT (scope, "video: dimension %dx%d, framerate %d/%d",
|
||||||
scope->width, scope->height, scope->fps_n, scope->fps_d);
|
GST_VIDEO_INFO_WIDTH (&info), GST_VIDEO_INFO_HEIGHT (&info),
|
||||||
|
GST_VIDEO_INFO_FPS_N (&info), GST_VIDEO_INFO_FPS_D (&info));
|
||||||
GST_DEBUG_OBJECT (scope, "blocks: spf %u, req_spf %u",
|
GST_DEBUG_OBJECT (scope, "blocks: spf %u, req_spf %u",
|
||||||
scope->spf, scope->req_spf);
|
scope->spf, scope->req_spf);
|
||||||
|
|
||||||
|
@ -698,10 +772,9 @@ gst_audio_visualizer_src_negotiate (GstAudioVisualizer * scope)
|
||||||
|
|
||||||
target = gst_caps_make_writable (target);
|
target = gst_caps_make_writable (target);
|
||||||
structure = gst_caps_get_structure (target, 0);
|
structure = gst_caps_get_structure (target, 0);
|
||||||
gst_structure_fixate_field_nearest_int (structure, "width", scope->width);
|
gst_structure_fixate_field_nearest_int (structure, "width", 320);
|
||||||
gst_structure_fixate_field_nearest_int (structure, "height", scope->height);
|
gst_structure_fixate_field_nearest_int (structure, "height", 200);
|
||||||
gst_structure_fixate_field_nearest_fraction (structure, "framerate",
|
gst_structure_fixate_field_nearest_fraction (structure, "framerate", 25, 1);
|
||||||
scope->fps_n, scope->fps_d);
|
|
||||||
|
|
||||||
target = gst_caps_fixate (target);
|
target = gst_caps_fixate (target);
|
||||||
|
|
||||||
|
@ -723,16 +796,17 @@ gst_audio_visualizer_src_negotiate (GstAudioVisualizer * scope)
|
||||||
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
|
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
|
||||||
} else {
|
} else {
|
||||||
pool = NULL;
|
pool = NULL;
|
||||||
size = scope->bpf;
|
size = 0;
|
||||||
min = max = 0;
|
min = max = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pool == NULL) {
|
if (pool == NULL) {
|
||||||
/* we did not get a pool, make one ourselves then */
|
/* we did not get a pool, make one ourselves then */
|
||||||
pool = gst_buffer_pool_new ();
|
pool = gst_video_buffer_pool_new ();
|
||||||
}
|
}
|
||||||
|
|
||||||
config = gst_buffer_pool_get_config (pool);
|
config = gst_buffer_pool_get_config (pool);
|
||||||
|
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
||||||
gst_buffer_pool_config_set_params (config, target, size, min, max);
|
gst_buffer_pool_config_set_params (config, target, size, min, max);
|
||||||
gst_buffer_pool_set_config (pool, config);
|
gst_buffer_pool_set_config (pool, config);
|
||||||
|
|
||||||
|
@ -826,7 +900,7 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent,
|
||||||
GST_LOG_OBJECT (scope, "avail: %u, bpf: %u", avail, sbpf);
|
GST_LOG_OBJECT (scope, "avail: %u, bpf: %u", avail, sbpf);
|
||||||
while (avail >= sbpf) {
|
while (avail >= sbpf) {
|
||||||
GstBuffer *outbuf;
|
GstBuffer *outbuf;
|
||||||
GstMapInfo map;
|
GstVideoFrame outframe;
|
||||||
|
|
||||||
/* get timestamp of the current adapter content */
|
/* get timestamp of the current adapter content */
|
||||||
ts = gst_adapter_prev_timestamp (scope->adapter, &dist);
|
ts = gst_adapter_prev_timestamp (scope->adapter, &dist);
|
||||||
|
@ -873,16 +947,20 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent,
|
||||||
GST_BUFFER_TIMESTAMP (outbuf) = ts;
|
GST_BUFFER_TIMESTAMP (outbuf) = ts;
|
||||||
GST_BUFFER_DURATION (outbuf) = scope->frame_duration;
|
GST_BUFFER_DURATION (outbuf) = scope->frame_duration;
|
||||||
|
|
||||||
gst_buffer_map (outbuf, &map, GST_MAP_WRITE);
|
/* this can fail as the data size we need could have changed */
|
||||||
|
if (!(adata = (gpointer) gst_adapter_map (scope->adapter, sbpf)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
gst_video_frame_map (&outframe, &scope->vinfo, outbuf, GST_MAP_READWRITE);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* FIXME? copy uninitialized memory into the destination buffer? */
|
||||||
if (scope->shader) {
|
if (scope->shader) {
|
||||||
memcpy (map.data, scope->pixelbuf, scope->bpf);
|
memcpy (map.data, scope->pixelbuf, scope->bpf);
|
||||||
} else {
|
} else {
|
||||||
memset (map.data, 0, scope->bpf);
|
memset (map.data, 0, scope->bpf);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/* this can fail as the data size we need could have changed */
|
|
||||||
if (!(adata = (gpointer) gst_adapter_map (scope->adapter, sbpf)))
|
|
||||||
break;
|
|
||||||
|
|
||||||
gst_buffer_replace_all_memory (inbuf,
|
gst_buffer_replace_all_memory (inbuf,
|
||||||
gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, adata, sbpf, 0,
|
gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, adata, sbpf, 0,
|
||||||
|
@ -890,18 +968,19 @@ gst_audio_visualizer_chain (GstPad * pad, GstObject * parent,
|
||||||
|
|
||||||
/* call class->render() vmethod */
|
/* call class->render() vmethod */
|
||||||
if (klass->render) {
|
if (klass->render) {
|
||||||
if (!klass->render (scope, inbuf, outbuf)) {
|
if (!klass->render (scope, inbuf, &outframe)) {
|
||||||
ret = GST_FLOW_ERROR;
|
ret = GST_FLOW_ERROR;
|
||||||
} else {
|
} else {
|
||||||
|
#if 0
|
||||||
|
/* FIXME, dest and source reversed? */
|
||||||
/* run various post processing (shading and geometri transformation */
|
/* run various post processing (shading and geometri transformation */
|
||||||
if (scope->shader) {
|
if (scope->shader) {
|
||||||
scope->shader (scope, map.data, scope->pixelbuf);
|
scope->shader (scope, outframe, scope->pixelbuf);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
gst_video_frame_unmap (&outframe);
|
||||||
gst_buffer_unmap (outbuf, &map);
|
|
||||||
gst_buffer_resize (outbuf, 0, scope->bpf);
|
|
||||||
|
|
||||||
g_mutex_unlock (&scope->config_lock);
|
g_mutex_unlock (&scope->config_lock);
|
||||||
ret = gst_pad_push (scope->srcpad, outbuf);
|
ret = gst_pad_push (scope->srcpad, outbuf);
|
||||||
|
|
|
@ -37,7 +37,7 @@ G_BEGIN_DECLS
|
||||||
typedef struct _GstAudioVisualizer GstAudioVisualizer;
|
typedef struct _GstAudioVisualizer GstAudioVisualizer;
|
||||||
typedef struct _GstAudioVisualizerClass GstAudioVisualizerClass;
|
typedef struct _GstAudioVisualizerClass GstAudioVisualizerClass;
|
||||||
|
|
||||||
typedef void (*GstAudioVisualizerShaderFunc)(GstAudioVisualizer *scope, const guint8 *s, guint8 *d);
|
typedef void (*GstAudioVisualizerShaderFunc)(GstAudioVisualizer *scope, const GstVideoFrame *s, GstVideoFrame *d);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GstAudioVisualizerShader:
|
* GstAudioVisualizerShader:
|
||||||
|
@ -88,23 +88,18 @@ struct _GstAudioVisualizer
|
||||||
|
|
||||||
/* video state */
|
/* video state */
|
||||||
GstVideoInfo vinfo;
|
GstVideoInfo vinfo;
|
||||||
GstVideoFormat video_format;
|
|
||||||
gint fps_n, fps_d;
|
|
||||||
gint width;
|
|
||||||
gint height;
|
|
||||||
guint64 frame_duration;
|
guint64 frame_duration;
|
||||||
guint bpf; /* bytes per frame */
|
|
||||||
|
|
||||||
/* audio state */
|
/* audio state */
|
||||||
GstAudioInfo ainfo;
|
GstAudioInfo ainfo;
|
||||||
|
|
||||||
/* configuration mutex */
|
/* configuration mutex */
|
||||||
GMutex config_lock;
|
GMutex config_lock;
|
||||||
|
|
||||||
/* QoS stuff *//* with LOCK */
|
/* QoS stuff *//* with LOCK */
|
||||||
gdouble proportion;
|
gdouble proportion;
|
||||||
GstClockTime earliest_time;
|
GstClockTime earliest_time;
|
||||||
|
|
||||||
GstSegment segment;
|
GstSegment segment;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -116,7 +111,7 @@ struct _GstAudioVisualizerClass
|
||||||
gboolean (*setup) (GstAudioVisualizer * scope);
|
gboolean (*setup) (GstAudioVisualizer * scope);
|
||||||
|
|
||||||
/* virtual function for rendering a frame */
|
/* virtual function for rendering a frame */
|
||||||
gboolean (*render) (GstAudioVisualizer * scope, GstBuffer * audio, GstBuffer * video);
|
gboolean (*render) (GstAudioVisualizer * scope, GstBuffer * audio, GstVideoFrame * video);
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gst_audio_visualizer_get_type (void);
|
GType gst_audio_visualizer_get_type (void);
|
||||||
|
|
|
@ -62,7 +62,7 @@ static void gst_visual_finalize (GObject * object);
|
||||||
|
|
||||||
static gboolean gst_visual_setup (GstAudioVisualizer * bscope);
|
static gboolean gst_visual_setup (GstAudioVisualizer * bscope);
|
||||||
static gboolean gst_visual_render (GstAudioVisualizer * bscope,
|
static gboolean gst_visual_render (GstAudioVisualizer * bscope,
|
||||||
GstBuffer * audio, GstBuffer * video);
|
GstBuffer * audio, GstVideoFrame * video);
|
||||||
|
|
||||||
static GstElementClass *parent_class = NULL;
|
static GstElementClass *parent_class = NULL;
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ static gboolean
|
||||||
gst_visual_setup (GstAudioVisualizer * bscope)
|
gst_visual_setup (GstAudioVisualizer * bscope)
|
||||||
{
|
{
|
||||||
GstVisual *visual = GST_VISUAL (bscope);
|
GstVisual *visual = GST_VISUAL (bscope);
|
||||||
gint pitch, depth;
|
gint depth;
|
||||||
|
|
||||||
gst_visual_clear_actors (visual);
|
gst_visual_clear_actors (visual);
|
||||||
|
|
||||||
|
@ -188,13 +188,14 @@ gst_visual_setup (GstAudioVisualizer * bscope)
|
||||||
|
|
||||||
visual_video_set_depth (visual->video,
|
visual_video_set_depth (visual->video,
|
||||||
visual_video_depth_enum_from_value (depth));
|
visual_video_depth_enum_from_value (depth));
|
||||||
visual_video_set_dimension (visual->video, bscope->width, bscope->height);
|
visual_video_set_dimension (visual->video,
|
||||||
pitch = GST_ROUND_UP_4 (bscope->width * visual->video->bpp);
|
GST_VIDEO_INFO_WIDTH (&bscope->vinfo),
|
||||||
visual_video_set_pitch (visual->video, pitch);
|
GST_VIDEO_INFO_HEIGHT (&bscope->vinfo));
|
||||||
visual_actor_video_negotiate (visual->actor, 0, FALSE, FALSE);
|
visual_actor_video_negotiate (visual->actor, 0, FALSE, FALSE);
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (visual, "WxH: %dx%d, bpp: %d, pitch: %d, depth: %d",
|
GST_DEBUG_OBJECT (visual, "WxH: %dx%d, bpp: %d, depth: %d",
|
||||||
bscope->width, bscope->height, visual->video->bpp, pitch, depth);
|
GST_VIDEO_INFO_WIDTH (&bscope->vinfo),
|
||||||
|
GST_VIDEO_INFO_HEIGHT (&bscope->vinfo), visual->video->bpp, depth);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
|
@ -216,20 +217,22 @@ no_realize:
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_visual_render (GstAudioVisualizer * bscope, GstBuffer * audio,
|
gst_visual_render (GstAudioVisualizer * bscope, GstBuffer * audio,
|
||||||
GstBuffer * video)
|
GstVideoFrame * video)
|
||||||
{
|
{
|
||||||
GstVisual *visual = GST_VISUAL (bscope);
|
GstVisual *visual = GST_VISUAL (bscope);
|
||||||
GstMapInfo amap, vmap;
|
GstMapInfo amap;
|
||||||
const guint16 *adata;
|
const guint16 *adata;
|
||||||
gint i, channels;
|
gint i, channels;
|
||||||
gboolean res = TRUE;
|
gboolean res = TRUE;
|
||||||
|
|
||||||
gst_buffer_map (audio, &amap, GST_MAP_READ);
|
visual_video_set_buffer (visual->video, GST_VIDEO_FRAME_PLANE_DATA (video,
|
||||||
gst_buffer_map (video, &vmap, GST_MAP_WRITE);
|
0));
|
||||||
|
visual_video_set_pitch (visual->video, GST_VIDEO_FRAME_PLANE_STRIDE (video,
|
||||||
visual_video_set_buffer (visual->video, vmap.data);
|
0));
|
||||||
|
|
||||||
channels = GST_AUDIO_INFO_CHANNELS (&bscope->ainfo);
|
channels = GST_AUDIO_INFO_CHANNELS (&bscope->ainfo);
|
||||||
|
|
||||||
|
gst_buffer_map (audio, &amap, GST_MAP_READ);
|
||||||
adata = (const guint16 *) amap.data;
|
adata = (const guint16 *) amap.data;
|
||||||
|
|
||||||
#if defined(VISUAL_API_VERSION) && VISUAL_API_VERSION >= 4000 && VISUAL_API_VERSION < 5000
|
#if defined(VISUAL_API_VERSION) && VISUAL_API_VERSION >= 4000 && VISUAL_API_VERSION < 5000
|
||||||
|
@ -318,7 +321,7 @@ gst_visual_render (GstAudioVisualizer * bscope, GstBuffer * audio,
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (visual, "rendered one frame");
|
GST_DEBUG_OBJECT (visual, "rendered one frame");
|
||||||
done:
|
done:
|
||||||
gst_buffer_unmap (video, &vmap);
|
|
||||||
gst_buffer_unmap (audio, &amap);
|
gst_buffer_unmap (audio, &amap);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue