[vlc-devel] [PATCH 3/7] picture: move the win32 texture buffer to plane setup in the core
Steve Lhomme
robux4 at videolabs.io
Thu May 11 09:36:05 CEST 2017
This will also be used by other chroma conversion filters that deal with GPU
surfaces and CPU access. So it's better to share this generic code everywhere.
---
include/vlc_picture.h | 12 ++++++++
modules/video_output/win32/common.c | 52 +----------------------------------
src/libvlccore.sym | 1 +
src/misc/picture.c | 55 +++++++++++++++++++++++++++++++++++++
4 files changed, 69 insertions(+), 51 deletions(-)
diff --git a/include/vlc_picture.h b/include/vlc_picture.h
index b8d4a5a223..718e3946a4 100644
--- a/include/vlc_picture.h
+++ b/include/vlc_picture.h
@@ -222,6 +222,18 @@ VLC_API int picture_Export( vlc_object_t *p_obj, block_t **pp_image, video_forma
*/
VLC_API int picture_Setup( picture_t *, const video_format_t * );
+/**
+ * This functions sets the internal plane pointers/dimensions for the given
+ * buffer.
+ * This is useful when mapping opaque surfaces into CPU planes.
+ *
+ * p_pic is the picture to update
+ * p_buf is the buffer pointer to use as the start of data for all the planes
+ * i_pitch is the internal line pitch for the buffer
+ * b_swap specifies that the buffer has some planes swapped compared to the known
+ * chroma setup
+ */
+VLC_API int picture_UpdatePlanes(picture_t *p_pic, uint8_t *p_buf, unsigned i_pitch, bool b_swap);
/*****************************************************************************
* Shortcuts to access image components
diff --git a/modules/video_output/win32/common.c b/modules/video_output/win32/common.c
index 328139bee4..251d3cc2b0 100644
--- a/modules/video_output/win32/common.c
+++ b/modules/video_output/win32/common.c
@@ -459,57 +459,7 @@ int CommonUpdatePicture(picture_t *picture, picture_t **fallback,
}
return VLC_SUCCESS;
}
- /* fill in buffer info in first plane */
- picture->p->p_pixels = data;
- picture->p->i_pitch = pitch;
- picture->p->i_lines = picture->format.i_height;
- assert(picture->p->i_visible_pitch <= picture->p->i_pitch);
- assert(picture->p->i_visible_lines <= picture->p->i_lines);
-
- /* Fill chroma planes for biplanar YUV */
- if (picture->format.i_chroma == VLC_CODEC_NV12 ||
- picture->format.i_chroma == VLC_CODEC_NV21 ||
- picture->format.i_chroma == VLC_CODEC_P010) {
-
- for (int n = 1; n < picture->i_planes; n++) {
- const plane_t *o = &picture->p[n-1];
- plane_t *p = &picture->p[n];
-
- p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
- p->i_pitch = pitch;
- p->i_lines = picture->format.i_height;
- assert(p->i_visible_pitch <= p->i_pitch);
- assert(p->i_visible_lines <= p->i_lines);
- }
- /* The dx/d3d buffer is always allocated as NV12 */
- if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_NV12)) {
- /* TODO : Swap NV21 UV planes to match NV12 */
- return VLC_EGENERIC;
- }
- }
-
- /* Fill chroma planes for planar YUV */
- else
- if (picture->format.i_chroma == VLC_CODEC_I420 ||
- picture->format.i_chroma == VLC_CODEC_J420 ||
- picture->format.i_chroma == VLC_CODEC_YV12) {
-
- for (int n = 1; n < picture->i_planes; n++) {
- const plane_t *o = &picture->p[n-1];
- plane_t *p = &picture->p[n];
-
- p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
- p->i_pitch = pitch / 2;
- p->i_lines = picture->format.i_height / 2;
- }
- /* The dx/d3d buffer is always allocated as YV12 */
- if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_YV12)) {
- uint8_t *p_tmp = picture->p[1].p_pixels;
- picture->p[1].p_pixels = picture->p[2].p_pixels;
- picture->p[2].p_pixels = p_tmp;
- }
- }
- return VLC_SUCCESS;
+ return picture_UpdatePlanes(picture, data, pitch, true);
}
void AlignRect(RECT *r, int align_boundary, int align_size)
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 4cb7a22503..da98551cb1 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -327,6 +327,7 @@ picture_pool_Reserve
picture_pool_Wait
picture_Reset
picture_Setup
+picture_UpdatePlanes
plane_CopyPixels
playlist_Add
playlist_AddExt
diff --git a/src/misc/picture.c b/src/misc/picture.c
index 0a2dc8f69a..ceb9fad2d5 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -197,6 +197,61 @@ int picture_Setup( picture_t *p_picture, const video_format_t *restrict fmt )
return VLC_SUCCESS;
}
+int picture_UpdatePlanes(picture_t *picture, uint8_t *data, unsigned pitch, bool check_swap)
+{
+ /* fill in buffer info in first plane */
+ picture->p->p_pixels = data;
+ picture->p->i_pitch = pitch;
+ picture->p->i_lines = picture->format.i_height;
+ assert(picture->p->i_visible_pitch <= picture->p->i_pitch);
+ assert(picture->p->i_visible_lines <= picture->p->i_lines);
+
+ /* Fill chroma planes for biplanar YUV */
+ if (picture->format.i_chroma == VLC_CODEC_NV12 ||
+ picture->format.i_chroma == VLC_CODEC_NV21 ||
+ picture->format.i_chroma == VLC_CODEC_P010) {
+
+ for (int n = 1; n < picture->i_planes; n++) {
+ const plane_t *o = &picture->p[n-1];
+ plane_t *p = &picture->p[n];
+
+ p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
+ p->i_pitch = pitch;
+ p->i_lines = picture->format.i_height / 2;
+ assert(p->i_visible_pitch <= p->i_pitch);
+ assert(p->i_visible_lines <= p->i_lines);
+ }
+ if (check_swap &&
+ vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_NV12)) {
+ /* TODO : Swap NV21 UV planes to match NV12 */
+ return VLC_EGENERIC;
+ }
+ }
+
+ /* Fill chroma planes for planar YUV */
+ else
+ if (picture->format.i_chroma == VLC_CODEC_I420 ||
+ picture->format.i_chroma == VLC_CODEC_J420 ||
+ picture->format.i_chroma == VLC_CODEC_YV12) {
+
+ for (int n = 1; n < picture->i_planes; n++) {
+ const plane_t *o = &picture->p[n-1];
+ plane_t *p = &picture->p[n];
+
+ p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
+ p->i_pitch = pitch / 2;
+ p->i_lines = picture->format.i_height / 2;
+ }
+ if (check_swap &&
+ vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_YV12)) {
+ uint8_t *p_tmp = picture->p[1].p_pixels;
+ picture->p[1].p_pixels = picture->p[2].p_pixels;
+ picture->p[2].p_pixels = p_tmp;
+ }
+ }
+ return VLC_SUCCESS;
+}
+
/*****************************************************************************
*
*****************************************************************************/
--
2.12.1
More information about the vlc-devel
mailing list