videotestsrc: add pattern property and snow pattern

This commit is contained in:
David Svensson Fors 2016-11-09 10:13:55 +01:00 committed by Wim Taymans
parent 5c56fbdfc2
commit bc4893057b
2 changed files with 48 additions and 2 deletions

View file

@ -249,11 +249,33 @@ draw_smpte_snow (DrawingData *dd)
} }
} }
static void
draw_snow (DrawingData *dd)
{
int x, y;
for (y = 0; y < dd->height; y++) {
for (x = 0; x < dd->width; x++) {
Pixel p;
unsigned char r = rand ();
p.R = r;
p.G = r;
p.B = r;
update_yuv (&p);
dd->draw_pixel (dd, x, &p);
}
next_line (dd);
}
}
static SpaResult static SpaResult
draw (SpaVideoTestSrc *this, char *data) draw (SpaVideoTestSrc *this, char *data)
{ {
DrawingData dd; DrawingData dd;
SpaResult res; SpaResult res;
uint32_t pattern;
init_colors (); init_colors ();
@ -261,7 +283,13 @@ draw (SpaVideoTestSrc *this, char *data)
if (res != SPA_RESULT_OK) if (res != SPA_RESULT_OK)
return res; return res;
draw_smpte_snow (&dd); pattern = this->props[1].pattern;
if (pattern == pattern_val_smpte_snow)
draw_smpte_snow (&dd);
else if (pattern == pattern_val_snow)
draw_snow (&dd);
else
return SPA_RESULT_NOT_IMPLEMENTED;
return res; return SPA_RESULT_OK;
} }

View file

@ -45,6 +45,7 @@ typedef struct _SpaVideoTestSrc SpaVideoTestSrc;
typedef struct { typedef struct {
SpaProps props; SpaProps props;
bool live; bool live;
uint32_t pattern;
} SpaVideoTestSrcProps; } SpaVideoTestSrcProps;
#define MAX_BUFFERS 16 #define MAX_BUFFERS 16
@ -105,9 +106,19 @@ struct _SpaVideoTestSrc {
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) == 0) #define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) == 0)
#define DEFAULT_LIVE true #define DEFAULT_LIVE true
#define DEFAULT_PATTERN 0
static const uint32_t pattern_val_smpte_snow = 0;
static const uint32_t pattern_val_snow = 1;
static const SpaPropRangeInfo pattern_range[] = {
{ "smpte-snow", { sizeof (uint32_t), &pattern_val_smpte_snow } },
{ "snow", { sizeof (uint32_t), &pattern_val_snow } },
};
enum { enum {
PROP_ID_LIVE, PROP_ID_LIVE,
PROP_ID_PATTERN,
PROP_ID_LAST, PROP_ID_LAST,
}; };
@ -119,12 +130,19 @@ static const SpaPropInfo prop_info[] =
SPA_PROP_TYPE_BOOL, sizeof (bool), SPA_PROP_TYPE_BOOL, sizeof (bool),
SPA_PROP_RANGE_TYPE_NONE, 0, NULL, SPA_PROP_RANGE_TYPE_NONE, 0, NULL,
NULL }, NULL },
{ PROP_ID_PATTERN, offsetof (SpaVideoTestSrcProps, pattern),
"pattern",
SPA_PROP_FLAG_READWRITE,
SPA_PROP_TYPE_UINT32, sizeof (uint32_t),
SPA_PROP_RANGE_TYPE_ENUM, SPA_N_ELEMENTS (pattern_range), pattern_range,
NULL },
}; };
static SpaResult static SpaResult
reset_videotestsrc_props (SpaVideoTestSrcProps *props) reset_videotestsrc_props (SpaVideoTestSrcProps *props)
{ {
props->live = DEFAULT_LIVE; props->live = DEFAULT_LIVE;
props->pattern = DEFAULT_PATTERN;
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }