[vlc-commits] picture: add picture_Clone()
Rémi Denis-Courmont
git at videolan.org
Sat Nov 4 17:33:05 CET 2017
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov 4 17:55:22 2017 +0200| [00425a2585b1a9821b1521e907f01d98d03ae897] | committer: Rémi Denis-Courmont
picture: add picture_Clone()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=00425a2585b1a9821b1521e907f01d98d03ae897
---
include/vlc_picture.h | 11 +++++++++++
src/libvlccore.sym | 1 +
src/misc/picture.c | 32 ++++++++++++++++++++++++++++++++
src/misc/picture_pool.c | 6 ++++++
4 files changed, 50 insertions(+)
diff --git a/include/vlc_picture.h b/include/vlc_picture.h
index 3d71633fe4..74f156fbbd 100644
--- a/include/vlc_picture.h
+++ b/include/vlc_picture.h
@@ -189,6 +189,17 @@ VLC_API void plane_CopyPixels( plane_t *p_dst, const plane_t *p_src );
VLC_API void picture_Copy( picture_t *p_dst, const picture_t *p_src );
/**
+ * Perform a shallow picture copy
+ *
+ * This function makes a shallow copy of an existing picture. The same planes
+ * and resources will be used, and the cloned picture reference count will be
+ * incremented.
+ *
+ * \return A clone picture on success, NULL on error.
+ */
+VLC_API picture_t *picture_Clone(picture_t *pic);
+
+/**
* This function will export a picture to an encoded bitstream.
*
* pp_image will contain the encoded bitstream in psz_format format.
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 21316ce2b8..539ddff8a8 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -295,6 +295,7 @@ net_vaPrintf
net_Write
NTPtime64
picture_BlendSubpicture
+picture_Clone
picture_CopyPixels
picture_Hold
picture_Release
diff --git a/src/misc/picture.c b/src/misc/picture.c
index 2762358049..c14e600d3f 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -374,6 +374,38 @@ void picture_Copy( picture_t *p_dst, const picture_t *p_src )
picture_CopyProperties( p_dst, p_src );
}
+static void picture_DestroyClone(picture_t *clone)
+{
+ picture_t *picture = ((picture_priv_t *)clone)->gc.opaque;
+
+ free(clone);
+ picture_Release(picture);
+}
+
+picture_t *picture_Clone(picture_t *picture)
+{
+ /* TODO: merge common code with picture_pool_ClonePicture(). */
+ picture_resource_t res = {
+ .p_sys = picture->p_sys,
+ .pf_destroy = picture_DestroyClone,
+ };
+
+ for (int i = 0; i < picture->i_planes; i++) {
+ res.p[i].p_pixels = picture->p[i].p_pixels;
+ res.p[i].i_lines = picture->p[i].i_lines;
+ res.p[i].i_pitch = picture->p[i].i_pitch;
+ }
+
+ picture_t *clone = picture_NewFromResource(&picture->format, &res);
+ if (likely(clone != NULL)) {
+ ((picture_priv_t *)clone)->gc.opaque = picture;
+ picture_Hold(picture);
+
+ if (picture->context != NULL)
+ clone->context = picture->context->copy(picture->context);
+ }
+ return clone;
+}
/*****************************************************************************
*
diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index bb957c4af5..7b5a82bfba 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -299,6 +299,12 @@ void picture_pool_Cancel(picture_pool_t *pool, bool canceled)
bool picture_pool_OwnsPic(picture_pool_t *pool, picture_t *pic)
{
picture_priv_t *priv = (picture_priv_t *)pic;
+
+ while (priv->gc.destroy != picture_pool_ReleasePicture) {
+ pic = priv->gc.opaque;
+ priv = (picture_priv_t *)pic;
+ }
+
uintptr_t sys = (uintptr_t)priv->gc.opaque;
picture_pool_t *picpool = (void *)(sys & ~(POOL_MAX - 1));
return pool == picpool;
More information about the vlc-commits
mailing list