summaryrefslogtreecommitdiffstats
path: root/video/decode
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-02-17 13:32:27 +0100
committerwm4 <wm4@nowhere>2017-02-17 13:32:27 +0100
commit1e4fd996bb249a773bad5d57ac5b724be52a09af (patch)
treeb8d866473894b8087b941b4fee21bbfd317a8d92 /video/decode
parente8137ee88154b496b2370bbdd93cd3cb3564dc86 (diff)
downloadmpv-1e4fd996bb249a773bad5d57ac5b724be52a09af.tar.bz2
mpv-1e4fd996bb249a773bad5d57ac5b724be52a09af.tar.xz
videotoolbox: factor some duplicated code
The code for copying a videotoolbox surface to mp_image was duplicated (with some minor differences - I picked the hw_videotoolbox.c version, because it was "better"). mp_imgfmt_from_cvpixelformat() is somewhat duplicated with the vt_formats[] table, but this will be fixed in a later commit, and moving the function to shared code is preparation.
Diffstat (limited to 'video/decode')
-rw-r--r--video/decode/hw_videotoolbox.c47
1 files changed, 2 insertions, 45 deletions
diff --git a/video/decode/hw_videotoolbox.c b/video/decode/hw_videotoolbox.c
index c6f1a472bf..8edffb5453 100644
--- a/video/decode/hw_videotoolbox.c
+++ b/video/decode/hw_videotoolbox.c
@@ -25,6 +25,7 @@
#include "video/mp_image.h"
#include "video/decode/lavc.h"
#include "video/mp_image_pool.h"
+#include "video/vt.h"
#include "config.h"
struct priv {
@@ -138,55 +139,11 @@ static void uninit(struct lavc_ctx *ctx)
ctx->hwdec_priv = NULL;
}
-static int mp_imgfmt_from_cvpixelformat(uint32_t cvpixfmt)
-{
- switch (cvpixfmt) {
- case kCVPixelFormatType_420YpCbCr8Planar: return IMGFMT_420P;
- case kCVPixelFormatType_422YpCbCr8: return IMGFMT_UYVY;
- case kCVPixelFormatType_32BGRA: return IMGFMT_RGB0;
- case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange: return IMGFMT_NV12;
- }
- return 0;
-}
-
static struct mp_image *copy_image(struct lavc_ctx *ctx, struct mp_image *hw_image)
{
- if (hw_image->imgfmt != IMGFMT_VIDEOTOOLBOX)
- return hw_image;
-
struct priv *p = ctx->hwdec_priv;
- struct mp_image *image = NULL;
- CVPixelBufferRef pbuf = (CVPixelBufferRef)hw_image->planes[3];
- CVPixelBufferLockBaseAddress(pbuf, kCVPixelBufferLock_ReadOnly);
- size_t width = CVPixelBufferGetWidth(pbuf);
- size_t height = CVPixelBufferGetHeight(pbuf);
- uint32_t cvpixfmt = CVPixelBufferGetPixelFormatType(pbuf);
- int pixfmt = mp_imgfmt_from_cvpixelformat(cvpixfmt);
- if (!pixfmt)
- goto unlock;
-
- struct mp_image img = {0};
- mp_image_setfmt(&img, pixfmt);
- mp_image_set_size(&img, width, height);
-
- if (CVPixelBufferIsPlanar(pbuf)) {
- int planes = CVPixelBufferGetPlaneCount(pbuf);
- for (int i = 0; i < planes; i++) {
- img.planes[i] = CVPixelBufferGetBaseAddressOfPlane(pbuf, i);
- img.stride[i] = CVPixelBufferGetBytesPerRowOfPlane(pbuf, i);
- }
- } else {
- img.planes[0] = CVPixelBufferGetBaseAddress(pbuf);
- img.stride[0] = CVPixelBufferGetBytesPerRow(pbuf);
- }
-
- mp_image_copy_attributes(&img, hw_image);
-
- image = mp_image_pool_new_copy(p->sw_pool, &img);
-
-unlock:
- CVPixelBufferUnlockBaseAddress(pbuf, kCVPixelBufferLock_ReadOnly);
+ struct mp_image *image = mp_vt_download_image(NULL, hw_image, p->sw_pool);
if (image) {
talloc_free(hw_image);
return image;