diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2013-04-22 15:42:24 +0200 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2013-05-16 17:13:46 +0200 |
commit | be235052bf9ec46086e6cd6748d8e32cc33fbb76 (patch) | |
tree | 11a35c9ad7771dbadde946130b05b24f4bdf47e6 | |
parent | a50c3cea0ba01e87b265edf324eb78e4a8fd120e (diff) |
videotestsrc: call the subsampler
Accumulate the required number of lines and then call the chroma subsampler when
needed to produce the final output image.
-rw-r--r-- | gst/videotestsrc/gstvideotestsrc.c | 36 | ||||
-rw-r--r-- | gst/videotestsrc/gstvideotestsrc.h | 6 | ||||
-rw-r--r-- | gst/videotestsrc/videotestsrc.c | 49 | ||||
-rw-r--r-- | gst/videotestsrc/videotestsrc.h | 6 |
4 files changed, 78 insertions, 19 deletions
diff --git a/gst/videotestsrc/gstvideotestsrc.c b/gst/videotestsrc/gstvideotestsrc.c index 5d104ee72..66ecc5e8e 100644 --- a/gst/videotestsrc/gstvideotestsrc.c +++ b/gst/videotestsrc/gstvideotestsrc.c @@ -656,6 +656,9 @@ gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps) const GstStructure *structure; GstVideoTestSrc *videotestsrc; GstVideoInfo info; + guint i; + guint n_lines; + gint offset; videotestsrc = GST_VIDEO_TEST_SRC (bsrc); @@ -686,10 +689,29 @@ gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps) } /* create chroma subsampler */ - if (videotestsrc->subsample_w) - gst_video_chroma_h_resample_free (videotestsrc->subsample_w); - videotestsrc->subsample_w = gst_video_chroma_h_resample_new (0, - info.chroma_site, 0, info.finfo->unpack_format, -info.finfo->w_sub[2]); + if (videotestsrc->subsample) + gst_video_chroma_resample_free (videotestsrc->subsample); + videotestsrc->subsample = gst_video_chroma_resample_new (0, + info.chroma_site, 0, info.finfo->unpack_format, -info.finfo->w_sub[2], + -info.finfo->h_sub[2]); + + for (i = 0; i < videotestsrc->n_lines; i++) + g_free (videotestsrc->lines[i]); + g_free (videotestsrc->lines); + + if (videotestsrc->subsample != NULL) { + gst_video_chroma_resample_get_info (videotestsrc->subsample, + &n_lines, &offset); + } else { + n_lines = 1; + offset = 0; + } + + videotestsrc->lines = g_malloc (sizeof (gpointer) * n_lines); + for (i = 0; i < n_lines; i++) + videotestsrc->lines[i] = g_malloc ((info.width + 16) * 8); + videotestsrc->n_lines = n_lines; + videotestsrc->offset = offset; /* looks ok here */ videotestsrc->info = info; @@ -920,9 +942,9 @@ gst_video_test_src_stop (GstBaseSrc * basesrc) src->tmpline_u8 = NULL; g_free (src->tmpline_u16); src->tmpline_u16 = NULL; - if (src->subsample_w) - gst_video_chroma_h_resample_free (src->subsample_w); - src->subsample_w = NULL; + if (src->subsample) + gst_video_chroma_resample_free (src->subsample); + src->subsample = NULL; return TRUE; } diff --git a/gst/videotestsrc/gstvideotestsrc.h b/gst/videotestsrc/gstvideotestsrc.h index 5275f58b8..a836104a3 100644 --- a/gst/videotestsrc/gstvideotestsrc.h +++ b/gst/videotestsrc/gstvideotestsrc.h @@ -124,7 +124,7 @@ struct _GstVideoTestSrc { /* video state */ GstVideoInfo info; - GstVideoChromaHResample *subsample_w; + GstVideoChromaResample *subsample; gboolean bayer; gint x_invert; gint y_invert; @@ -169,6 +169,10 @@ struct _GstVideoTestSrc { guint8 *tmpline; guint8 *tmpline2; guint16 *tmpline_u16; + + guint n_lines; + gint offset; + gpointer *lines; }; struct _GstVideoTestSrcClass { diff --git a/gst/videotestsrc/videotestsrc.c b/gst/videotestsrc/videotestsrc.c index 191424ea1..8aabf2ac0 100644 --- a/gst/videotestsrc/videotestsrc.c +++ b/gst/videotestsrc/videotestsrc.c @@ -197,6 +197,9 @@ videotestsrc_setup_paintinfo (GstVideoTestSrc * v, paintinfo * p, int w, int h) p->tmpline2 = v->tmpline2; p->tmpline_u8 = v->tmpline_u8; p->tmpline_u16 = v->tmpline_u16; + p->n_lines = v->n_lines; + p->offset = v->offset; + p->lines = v->lines; p->x_offset = (v->horizontal_speed * v->n_frames) % width; if (p->x_offset < 0) p->x_offset += width; @@ -243,7 +246,7 @@ videotestsrc_setup_paintinfo (GstVideoTestSrc * v, paintinfo * p, int w, int h) } p->background_color.gray = RGB_TO_Y (r, g, b); - p->subsample_w = v->subsample_w; + p->subsample = v->subsample; } static void @@ -1135,14 +1138,23 @@ static void convert_hline_generic (paintinfo * p, GstVideoFrame * frame, int y) { const GstVideoFormatInfo *finfo, *uinfo; - gint i, width = GST_VIDEO_FRAME_WIDTH (frame), bits; - gpointer src; + gint line, offset, i, width, height, bits; + guint n_lines; + gpointer dest; finfo = frame->info.finfo; uinfo = gst_video_format_get_info (finfo->unpack_format); + width = GST_VIDEO_FRAME_WIDTH (frame); + height = GST_VIDEO_FRAME_HEIGHT (frame); + bits = GST_VIDEO_FORMAT_INFO_DEPTH (uinfo, 0); + n_lines = p->n_lines; + offset = p->offset; + line = y % n_lines; + dest = p->lines[line]; + if (bits == 16) { /* 16 bits */ for (i = 0; i < width; i++) { @@ -1151,17 +1163,34 @@ convert_hline_generic (paintinfo * p, GstVideoFrame * frame, int y) p->tmpline_u16[i * 4 + 2] = TO_16 (p->tmpline[i * 4 + 2]); p->tmpline_u16[i * 4 + 3] = TO_16 (p->tmpline[i * 4 + 3]); } - src = p->tmpline_u16; + memcpy (dest, p->tmpline_u16, width * 8); } else { - src = p->tmpline; + memcpy (dest, p->tmpline, width * 4); } - if (p->subsample_w) - gst_video_chroma_h_resample (p->subsample_w, src, src, width); + if (line - offset == n_lines - 1) { + gpointer lines[8]; + guint idx; + + y -= n_lines - 1; - finfo->pack_func (finfo, GST_VIDEO_PACK_FLAG_NONE, - src, 0, frame->data, frame->info.stride, - frame->info.chroma_site, y, width); + for (i = 0; i < n_lines; i++) { + idx = CLAMP (y + i + offset, 0, height); + + GST_DEBUG ("line %d, %d, idx %d", i, y + i + offset, idx); + lines[i] = p->lines[idx % n_lines]; + } + + if (p->subsample) + gst_video_chroma_resample (p->subsample, lines, width); + + for (i = 0; i < n_lines; i++) { + GST_DEBUG ("pack line %d", y + i + offset); + finfo->pack_func (finfo, GST_VIDEO_PACK_FLAG_NONE, + lines[i], 0, frame->data, frame->info.stride, + frame->info.chroma_site, y + i + offset, width); + } + } } static void diff --git a/gst/videotestsrc/videotestsrc.h b/gst/videotestsrc/videotestsrc.h index 5026d4db6..6a69c8c23 100644 --- a/gst/videotestsrc/videotestsrc.h +++ b/gst/videotestsrc/videotestsrc.h @@ -39,7 +39,7 @@ struct paintinfo_struct void (*paint_tmpline) (paintinfo * p, int x, int w); void (*convert_tmpline) (paintinfo * p, GstVideoFrame *frame, int y); void (*convert_hline) (paintinfo * p, GstVideoFrame *frame, int y); - GstVideoChromaHResample *subsample_w; + GstVideoChromaResample *subsample; int x_offset; int x_invert; @@ -50,6 +50,10 @@ struct paintinfo_struct guint8 *tmpline_u8; guint16 *tmpline_u16; + guint n_lines; + gint offset; + gpointer *lines; + struct vts_color_struct foreground_color; struct vts_color_struct background_color; }; |