2012-06-05 10:47:22 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* Library <2002> Ronald Bultje <rbultje@ronald.bitfreak.net>
|
|
|
|
* Copyright (C) 2007 David A. Schleef <ds@schleef.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2012-06-05 10:47:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-12-12 17:13:10 +00:00
|
|
|
#include <gst/video/video.h>
|
2012-06-05 10:47:22 +00:00
|
|
|
#include "video-frame.h"
|
2013-12-25 13:23:04 +00:00
|
|
|
#include "video-tile.h"
|
2012-06-05 10:47:22 +00:00
|
|
|
#include "gstvideometa.h"
|
|
|
|
|
2016-02-20 11:31:43 +00:00
|
|
|
#define CAT_PERFORMANCE video_frame_get_perf_category()
|
|
|
|
|
|
|
|
static inline GstDebugCategory *
|
|
|
|
video_frame_get_perf_category (void)
|
|
|
|
{
|
|
|
|
static GstDebugCategory *cat = NULL;
|
|
|
|
|
|
|
|
if (g_once_init_enter (&cat)) {
|
|
|
|
GstDebugCategory *c;
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_GET (c, "GST_PERFORMANCE");
|
|
|
|
g_once_init_leave (&cat, c);
|
|
|
|
}
|
|
|
|
return cat;
|
|
|
|
}
|
2012-06-05 10:47:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_video_frame_map_id:
|
2021-01-13 10:07:47 +00:00
|
|
|
* @frame: (out caller-allocates): pointer to #GstVideoFrame
|
2012-06-05 10:47:22 +00:00
|
|
|
* @info: a #GstVideoInfo
|
|
|
|
* @buffer: the buffer to map
|
|
|
|
* @id: the frame id to map
|
|
|
|
* @flags: #GstMapFlags
|
|
|
|
*
|
|
|
|
* Use @info and @buffer to fill in the values of @frame with the video frame
|
|
|
|
* information of frame @id.
|
|
|
|
*
|
|
|
|
* When @id is -1, the default frame is mapped. When @id != -1, this function
|
|
|
|
* will return %FALSE when there is no GstVideoMeta with that id.
|
|
|
|
*
|
|
|
|
* All video planes of @buffer will be mapped and the pointers will be set in
|
|
|
|
* @frame->data.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
2021-01-04 22:25:10 +00:00
|
|
|
gst_video_frame_map_id (GstVideoFrame * frame, const GstVideoInfo * info,
|
2012-06-05 10:47:22 +00:00
|
|
|
GstBuffer * buffer, gint id, GstMapFlags flags)
|
|
|
|
{
|
|
|
|
GstVideoMeta *meta;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (frame != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
2018-04-21 04:00:28 +00:00
|
|
|
g_return_val_if_fail (info->finfo != NULL, FALSE);
|
2012-06-05 10:47:22 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
|
|
|
|
|
|
|
if (id == -1)
|
|
|
|
meta = gst_buffer_get_video_meta (buffer);
|
|
|
|
else
|
|
|
|
meta = gst_buffer_get_video_meta_id (buffer, id);
|
|
|
|
|
|
|
|
/* copy the info */
|
|
|
|
frame->info = *info;
|
|
|
|
|
|
|
|
if (meta) {
|
2014-11-28 09:27:28 +00:00
|
|
|
/* All these values must be consistent */
|
|
|
|
g_return_val_if_fail (info->finfo->format == meta->format, FALSE);
|
2015-03-18 20:38:20 +00:00
|
|
|
g_return_val_if_fail (info->width <= meta->width, FALSE);
|
|
|
|
g_return_val_if_fail (info->height <= meta->height, FALSE);
|
2014-11-28 09:27:28 +00:00
|
|
|
g_return_val_if_fail (info->finfo->n_planes == meta->n_planes, FALSE);
|
|
|
|
|
2012-06-05 10:47:22 +00:00
|
|
|
frame->info.finfo = gst_video_format_get_info (meta->format);
|
|
|
|
frame->info.width = meta->width;
|
|
|
|
frame->info.height = meta->height;
|
|
|
|
frame->id = meta->id;
|
|
|
|
frame->flags = meta->flags;
|
|
|
|
|
2014-11-28 09:27:28 +00:00
|
|
|
for (i = 0; i < meta->n_planes; i++) {
|
2013-09-19 15:25:05 +00:00
|
|
|
frame->info.offset[i] = meta->offset[i];
|
2012-06-26 09:10:28 +00:00
|
|
|
if (!gst_video_meta_map (meta, i, &frame->map[i], &frame->data[i],
|
|
|
|
&frame->info.stride[i], flags))
|
|
|
|
goto frame_map_failed;
|
2013-09-19 15:25:05 +00:00
|
|
|
}
|
2012-06-05 10:47:22 +00:00
|
|
|
} else {
|
|
|
|
/* no metadata, we really need to have the metadata when the id is
|
|
|
|
* specified. */
|
|
|
|
if (id != -1)
|
|
|
|
goto no_metadata;
|
|
|
|
|
|
|
|
frame->id = id;
|
|
|
|
frame->flags = 0;
|
|
|
|
|
2012-06-26 09:10:28 +00:00
|
|
|
if (!gst_buffer_map (buffer, &frame->map[0], flags))
|
|
|
|
goto map_failed;
|
2012-06-05 10:47:22 +00:00
|
|
|
|
|
|
|
/* do some sanity checks */
|
|
|
|
if (frame->map[0].size < info->size)
|
|
|
|
goto invalid_size;
|
|
|
|
|
|
|
|
/* set up pointers */
|
|
|
|
for (i = 0; i < info->finfo->n_planes; i++) {
|
|
|
|
frame->data[i] = frame->map[0].data + info->offset[i];
|
|
|
|
}
|
|
|
|
}
|
2014-09-15 22:07:18 +00:00
|
|
|
frame->buffer = buffer;
|
2014-09-12 11:39:16 +00:00
|
|
|
if ((flags & GST_VIDEO_FRAME_MAP_FLAG_NO_REF) == 0)
|
|
|
|
gst_buffer_ref (frame->buffer);
|
|
|
|
|
2012-06-05 10:47:22 +00:00
|
|
|
frame->meta = meta;
|
|
|
|
|
2012-07-23 11:32:59 +00:00
|
|
|
/* buffer flags enhance the frame flags */
|
|
|
|
if (GST_VIDEO_INFO_IS_INTERLACED (info)) {
|
2013-03-25 08:59:45 +00:00
|
|
|
if (GST_VIDEO_INFO_INTERLACE_MODE (info) == GST_VIDEO_INTERLACE_MODE_MIXED) {
|
|
|
|
if (GST_BUFFER_FLAG_IS_SET (buffer, GST_VIDEO_BUFFER_FLAG_INTERLACED)) {
|
|
|
|
frame->flags |= GST_VIDEO_FRAME_FLAG_INTERLACED;
|
|
|
|
}
|
2019-08-16 08:58:28 +00:00
|
|
|
} else {
|
2012-07-23 11:32:59 +00:00
|
|
|
frame->flags |= GST_VIDEO_FRAME_FLAG_INTERLACED;
|
2019-08-16 08:58:28 +00:00
|
|
|
}
|
2013-03-25 08:59:45 +00:00
|
|
|
|
2019-08-16 08:58:28 +00:00
|
|
|
if (GST_VIDEO_INFO_FIELD_ORDER (info) ==
|
|
|
|
GST_VIDEO_FIELD_ORDER_TOP_FIELD_FIRST) {
|
2012-07-23 11:32:59 +00:00
|
|
|
frame->flags |= GST_VIDEO_FRAME_FLAG_TFF;
|
2019-08-16 08:58:28 +00:00
|
|
|
} else {
|
|
|
|
if (GST_BUFFER_FLAG_IS_SET (buffer, GST_VIDEO_BUFFER_FLAG_TFF))
|
|
|
|
frame->flags |= GST_VIDEO_FRAME_FLAG_TFF;
|
|
|
|
if (GST_BUFFER_FLAG_IS_SET (buffer, GST_VIDEO_BUFFER_FLAG_RFF))
|
|
|
|
frame->flags |= GST_VIDEO_FRAME_FLAG_RFF;
|
|
|
|
if (GST_BUFFER_FLAG_IS_SET (buffer, GST_VIDEO_BUFFER_FLAG_ONEFIELD))
|
|
|
|
frame->flags |= GST_VIDEO_FRAME_FLAG_ONEFIELD;
|
|
|
|
}
|
2012-07-23 11:32:59 +00:00
|
|
|
}
|
2012-06-05 10:47:22 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_metadata:
|
|
|
|
{
|
|
|
|
GST_ERROR ("no GstVideoMeta for id %d", id);
|
2014-04-16 17:53:14 +00:00
|
|
|
memset (frame, 0, sizeof (GstVideoFrame));
|
2012-06-05 10:47:22 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-06-26 09:10:28 +00:00
|
|
|
frame_map_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("failed to map video frame plane %d", i);
|
2012-07-25 23:52:25 +00:00
|
|
|
while (--i >= 0)
|
2012-06-26 09:10:28 +00:00
|
|
|
gst_video_meta_unmap (meta, i, &frame->map[i]);
|
2014-04-16 17:53:14 +00:00
|
|
|
memset (frame, 0, sizeof (GstVideoFrame));
|
2012-06-26 09:10:28 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
map_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("failed to map buffer");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-06-05 10:47:22 +00:00
|
|
|
invalid_size:
|
|
|
|
{
|
|
|
|
GST_ERROR ("invalid buffer size %" G_GSIZE_FORMAT " < %" G_GSIZE_FORMAT,
|
|
|
|
frame->map[0].size, info->size);
|
|
|
|
gst_buffer_unmap (buffer, &frame->map[0]);
|
2014-04-16 17:53:14 +00:00
|
|
|
memset (frame, 0, sizeof (GstVideoFrame));
|
2012-06-05 10:47:22 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_video_frame_map:
|
2021-01-13 10:07:47 +00:00
|
|
|
* @frame: (out caller-allocates): pointer to #GstVideoFrame
|
2012-06-05 10:47:22 +00:00
|
|
|
* @info: a #GstVideoInfo
|
|
|
|
* @buffer: the buffer to map
|
|
|
|
* @flags: #GstMapFlags
|
|
|
|
*
|
2016-02-25 17:46:31 +00:00
|
|
|
* Use @info and @buffer to fill in the values of @frame. @frame is usually
|
|
|
|
* allocated on the stack, and you will pass the address to the #GstVideoFrame
|
|
|
|
* structure allocated on the stack; gst_video_frame_map() will then fill in
|
|
|
|
* the structures with the various video-specific information you need to access
|
|
|
|
* the pixels of the video buffer. You can then use accessor macros such as
|
|
|
|
* GST_VIDEO_FRAME_COMP_DATA(), GST_VIDEO_FRAME_PLANE_DATA(),
|
|
|
|
* GST_VIDEO_FRAME_COMP_STRIDE(), GST_VIDEO_FRAME_PLANE_STRIDE() etc.
|
|
|
|
* to get to the pixels.
|
|
|
|
*
|
|
|
|
* |[<!-- language="C" -->
|
|
|
|
* GstVideoFrame vframe;
|
|
|
|
* ...
|
|
|
|
* // set RGB pixels to black one at a time
|
2021-11-11 19:11:25 +00:00
|
|
|
* if (gst_video_frame_map (&vframe, video_info, video_buffer, GST_MAP_WRITE)) {
|
2016-02-25 17:46:31 +00:00
|
|
|
* guint8 *pixels = GST_VIDEO_FRAME_PLANE_DATA (vframe, 0);
|
|
|
|
* guint stride = GST_VIDEO_FRAME_PLANE_STRIDE (vframe, 0);
|
2016-04-02 14:19:44 +00:00
|
|
|
* guint pixel_stride = GST_VIDEO_FRAME_COMP_PSTRIDE (vframe, 0);
|
2016-02-25 17:46:31 +00:00
|
|
|
*
|
|
|
|
* for (h = 0; h < height; ++h) {
|
|
|
|
* for (w = 0; w < width; ++w) {
|
|
|
|
* guint8 *pixel = pixels + h * stride + w * pixel_stride;
|
|
|
|
*
|
|
|
|
* memset (pixel, 0, pixel_stride);
|
|
|
|
* }
|
|
|
|
* }
|
2016-09-19 15:27:10 +00:00
|
|
|
*
|
2021-11-11 19:11:25 +00:00
|
|
|
* gst_video_frame_unmap (&vframe);
|
2016-02-25 17:46:31 +00:00
|
|
|
* }
|
|
|
|
* ...
|
|
|
|
* ]|
|
2012-06-05 10:47:22 +00:00
|
|
|
*
|
|
|
|
* All video planes of @buffer will be mapped and the pointers will be set in
|
|
|
|
* @frame->data.
|
|
|
|
*
|
2016-02-25 17:46:31 +00:00
|
|
|
* The purpose of this function is to make it easy for you to get to the video
|
|
|
|
* pixels in a generic way, without you having to worry too much about details
|
|
|
|
* such as whether the video data is allocated in one contiguous memory chunk
|
|
|
|
* or multiple memory chunks (e.g. one for each plane); or if custom strides
|
|
|
|
* and custom plane offsets are used or not (as signalled by GstVideoMeta on
|
|
|
|
* each buffer). This function will just fill the #GstVideoFrame structure
|
|
|
|
* with the right values and if you use the accessor macros everything will
|
|
|
|
* just work and you can access the data easily. It also maps the underlying
|
|
|
|
* memory chunks for you.
|
|
|
|
*
|
2012-06-05 10:47:22 +00:00
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
2021-01-04 22:25:10 +00:00
|
|
|
gst_video_frame_map (GstVideoFrame * frame, const GstVideoInfo * info,
|
2012-06-05 10:47:22 +00:00
|
|
|
GstBuffer * buffer, GstMapFlags flags)
|
|
|
|
{
|
|
|
|
return gst_video_frame_map_id (frame, info, buffer, -1, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_video_frame_unmap:
|
|
|
|
* @frame: a #GstVideoFrame
|
|
|
|
*
|
|
|
|
* Unmap the memory previously mapped with gst_video_frame_map.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_video_frame_unmap (GstVideoFrame * frame)
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstVideoMeta *meta;
|
|
|
|
gint i;
|
2014-09-12 11:39:16 +00:00
|
|
|
GstMapFlags flags;
|
2012-06-05 10:47:22 +00:00
|
|
|
|
|
|
|
g_return_if_fail (frame != NULL);
|
|
|
|
|
|
|
|
buffer = frame->buffer;
|
|
|
|
meta = frame->meta;
|
2014-09-12 11:39:16 +00:00
|
|
|
flags = frame->map[0].flags;
|
2012-06-05 10:47:22 +00:00
|
|
|
|
|
|
|
if (meta) {
|
|
|
|
for (i = 0; i < frame->info.finfo->n_planes; i++) {
|
|
|
|
gst_video_meta_unmap (meta, i, &frame->map[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gst_buffer_unmap (buffer, &frame->map[0]);
|
|
|
|
}
|
2014-09-12 11:39:16 +00:00
|
|
|
|
|
|
|
if ((flags & GST_VIDEO_FRAME_MAP_FLAG_NO_REF) == 0)
|
|
|
|
gst_buffer_unref (frame->buffer);
|
2012-06-05 10:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-13 10:11:06 +00:00
|
|
|
* gst_video_frame_copy_plane:
|
2012-06-05 10:47:22 +00:00
|
|
|
* @dest: a #GstVideoFrame
|
|
|
|
* @src: a #GstVideoFrame
|
|
|
|
* @plane: a plane
|
|
|
|
*
|
|
|
|
* Copy the plane with index @plane from @src to @dest.
|
|
|
|
*
|
2020-06-15 13:46:17 +00:00
|
|
|
* Note: Since: 1.18, @dest dimensions are allowed to be
|
|
|
|
* smaller than @src dimensions.
|
|
|
|
*
|
2012-06-05 10:47:22 +00:00
|
|
|
* Returns: TRUE if the contents could be copied.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_video_frame_copy_plane (GstVideoFrame * dest, const GstVideoFrame * src,
|
|
|
|
guint plane)
|
|
|
|
{
|
|
|
|
const GstVideoInfo *sinfo;
|
|
|
|
GstVideoInfo *dinfo;
|
2013-12-25 13:23:04 +00:00
|
|
|
const GstVideoFormatInfo *finfo;
|
2021-05-18 19:36:36 +00:00
|
|
|
gint comp[GST_VIDEO_MAX_COMPONENTS];
|
2012-06-05 10:47:22 +00:00
|
|
|
guint8 *sp, *dp;
|
2013-12-25 13:23:04 +00:00
|
|
|
guint w, h;
|
2014-01-09 00:41:56 +00:00
|
|
|
gint ss, ds;
|
2012-06-05 10:47:22 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (dest != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (src != NULL, FALSE);
|
|
|
|
|
|
|
|
sinfo = &src->info;
|
|
|
|
dinfo = &dest->info;
|
|
|
|
|
|
|
|
g_return_val_if_fail (dinfo->finfo->format == sinfo->finfo->format, FALSE);
|
2013-12-25 13:23:04 +00:00
|
|
|
|
|
|
|
finfo = dinfo->finfo;
|
|
|
|
|
2020-06-15 13:46:17 +00:00
|
|
|
g_return_val_if_fail (dinfo->width <= sinfo->width
|
|
|
|
&& dinfo->height <= sinfo->height, FALSE);
|
2013-12-25 13:23:04 +00:00
|
|
|
g_return_val_if_fail (finfo->n_planes > plane, FALSE);
|
2012-06-05 10:47:22 +00:00
|
|
|
|
|
|
|
sp = src->data[plane];
|
|
|
|
dp = dest->data[plane];
|
|
|
|
|
2013-12-25 13:23:04 +00:00
|
|
|
if (GST_VIDEO_FORMAT_INFO_HAS_PALETTE (finfo) && plane == 1) {
|
|
|
|
/* copy the palette and we're done */
|
|
|
|
memcpy (dp, sp, 256 * 4);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-05-18 19:36:36 +00:00
|
|
|
gst_video_format_info_component (finfo, plane, comp);
|
2013-12-25 13:23:04 +00:00
|
|
|
w = GST_VIDEO_FRAME_COMP_WIDTH (dest,
|
2021-05-18 19:36:36 +00:00
|
|
|
comp[0]) * GST_VIDEO_FRAME_COMP_PSTRIDE (dest, comp[0]);
|
2015-09-24 09:33:24 +00:00
|
|
|
/* FIXME: workaround for complex formats like v210, UYVP and IYU1 that have
|
|
|
|
* pstride == 0 */
|
|
|
|
if (w == 0)
|
|
|
|
w = MIN (GST_VIDEO_INFO_PLANE_STRIDE (dinfo, plane),
|
|
|
|
GST_VIDEO_INFO_PLANE_STRIDE (sinfo, plane));
|
|
|
|
|
2021-05-18 19:36:36 +00:00
|
|
|
h = GST_VIDEO_FRAME_COMP_HEIGHT (dest, comp[0]);
|
2013-12-25 13:23:04 +00:00
|
|
|
|
2014-01-09 00:41:56 +00:00
|
|
|
ss = GST_VIDEO_INFO_PLANE_STRIDE (sinfo, plane);
|
|
|
|
ds = GST_VIDEO_INFO_PLANE_STRIDE (dinfo, plane);
|
|
|
|
|
2013-12-25 13:23:04 +00:00
|
|
|
if (GST_VIDEO_FORMAT_INFO_IS_TILED (finfo)) {
|
|
|
|
gint tile_size;
|
|
|
|
gint sx_tiles, sy_tiles, dx_tiles, dy_tiles;
|
|
|
|
guint i, j, ws, hs, ts;
|
|
|
|
GstVideoTileMode mode;
|
|
|
|
|
2014-01-09 00:41:56 +00:00
|
|
|
ws = GST_VIDEO_FORMAT_INFO_TILE_WS (finfo);
|
|
|
|
hs = GST_VIDEO_FORMAT_INFO_TILE_HS (finfo);
|
2013-12-25 13:23:04 +00:00
|
|
|
ts = ws + hs;
|
|
|
|
|
|
|
|
tile_size = 1 << ts;
|
|
|
|
|
2014-01-09 00:41:56 +00:00
|
|
|
mode = GST_VIDEO_FORMAT_INFO_TILE_MODE (finfo);
|
2013-12-25 13:23:04 +00:00
|
|
|
|
2014-01-09 00:41:56 +00:00
|
|
|
sx_tiles = GST_VIDEO_TILE_X_TILES (ss);
|
|
|
|
sy_tiles = GST_VIDEO_TILE_Y_TILES (ss);
|
2013-12-25 13:23:04 +00:00
|
|
|
|
2014-01-09 00:41:56 +00:00
|
|
|
dx_tiles = GST_VIDEO_TILE_X_TILES (ds);
|
|
|
|
dy_tiles = GST_VIDEO_TILE_Y_TILES (ds);
|
2013-12-25 13:23:04 +00:00
|
|
|
|
|
|
|
/* this is the amount of tiles to copy */
|
2013-12-25 15:06:43 +00:00
|
|
|
w = ((w - 1) >> ws) + 1;
|
|
|
|
h = ((h - 1) >> hs) + 1;
|
2013-12-25 13:23:04 +00:00
|
|
|
|
|
|
|
/* FIXME can possibly do better when no retiling is needed, it depends on
|
|
|
|
* the stride and the tile_size */
|
|
|
|
for (j = 0; j < h; j++) {
|
|
|
|
for (i = 0; i < w; i++) {
|
|
|
|
guint si, di;
|
|
|
|
|
|
|
|
si = gst_video_tile_get_index (mode, i, j, sx_tiles, sy_tiles);
|
|
|
|
di = gst_video_tile_get_index (mode, i, j, dx_tiles, dy_tiles);
|
|
|
|
|
|
|
|
memcpy (dp + (di << ts), sp + (si << ts), tile_size);
|
|
|
|
}
|
|
|
|
}
|
2013-12-25 09:45:11 +00:00
|
|
|
} else {
|
2013-12-25 13:23:04 +00:00
|
|
|
guint j;
|
|
|
|
|
2016-02-20 11:31:43 +00:00
|
|
|
GST_CAT_DEBUG (CAT_PERFORMANCE, "copy plane %d, w:%d h:%d ", plane, w, h);
|
2012-06-05 10:47:22 +00:00
|
|
|
|
2013-12-25 13:23:04 +00:00
|
|
|
for (j = 0; j < h; j++) {
|
|
|
|
memcpy (dp, sp, w);
|
|
|
|
dp += ds;
|
|
|
|
sp += ss;
|
|
|
|
}
|
2012-06-05 10:47:22 +00:00
|
|
|
}
|
2013-12-25 13:23:04 +00:00
|
|
|
|
2012-06-05 10:47:22 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_video_frame_copy:
|
|
|
|
* @dest: a #GstVideoFrame
|
|
|
|
* @src: a #GstVideoFrame
|
|
|
|
*
|
|
|
|
* Copy the contents from @src to @dest.
|
|
|
|
*
|
2020-06-16 15:44:08 +00:00
|
|
|
* Note: Since: 1.18, @dest dimensions are allowed to be
|
|
|
|
* smaller than @src dimensions.
|
|
|
|
*
|
2012-06-05 10:47:22 +00:00
|
|
|
* Returns: TRUE if the contents could be copied.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_video_frame_copy (GstVideoFrame * dest, const GstVideoFrame * src)
|
|
|
|
{
|
|
|
|
guint i, n_planes;
|
|
|
|
const GstVideoInfo *sinfo;
|
|
|
|
GstVideoInfo *dinfo;
|
|
|
|
|
|
|
|
g_return_val_if_fail (dest != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (src != NULL, FALSE);
|
|
|
|
|
|
|
|
sinfo = &src->info;
|
|
|
|
dinfo = &dest->info;
|
|
|
|
|
|
|
|
g_return_val_if_fail (dinfo->finfo->format == sinfo->finfo->format, FALSE);
|
2020-06-16 15:44:08 +00:00
|
|
|
g_return_val_if_fail (dinfo->width <= sinfo->width
|
|
|
|
&& dinfo->height <= sinfo->height, FALSE);
|
2012-06-05 10:47:22 +00:00
|
|
|
|
|
|
|
n_planes = dinfo->finfo->n_planes;
|
|
|
|
|
|
|
|
for (i = 0; i < n_planes; i++)
|
|
|
|
gst_video_frame_copy_plane (dest, src, i);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|