gl_video: change internal API for hwdec mp_image download

Previous API worked under the assumption that download_image is always called
after map_image. In practice this is true, but it's better to have a much
generic API that doesn't depend on the order in which the functions are called.
This commit is contained in:
Stefano Pigozzi 2013-12-02 21:17:26 +01:00
parent 14d92a4685
commit ca956af446
3 changed files with 13 additions and 10 deletions

View File

@ -203,7 +203,8 @@ struct gl_hwdec_driver {
// are not needed anymore. // are not needed anymore.
void (*unmap_image)(struct gl_hwdec *hw); void (*unmap_image)(struct gl_hwdec *hw);
// Return a mp_image downloaded from the GPU (optional) // Return a mp_image downloaded from the GPU (optional)
struct mp_image *(*download_image)(struct gl_hwdec *hw); struct mp_image *(*download_image)(struct gl_hwdec *hw,
struct mp_image *hw_image);
void (*destroy)(struct gl_hwdec *hw); void (*destroy)(struct gl_hwdec *hw);
}; };

View File

@ -102,14 +102,15 @@ static int map_image(struct gl_hwdec *hw, struct mp_image *hw_image,
static void unmap_image(struct gl_hwdec *hw) { } static void unmap_image(struct gl_hwdec *hw) { }
static struct mp_image *download_image(struct gl_hwdec *hw) static struct mp_image *download_image(struct gl_hwdec *hw,
struct mp_image *hw_image)
{ {
struct priv *p = hw->priv; CVPixelBufferRef pbuf = (CVPixelBufferRef)hw_image->planes[3];
CVPixelBufferLockBaseAddress(p->pbuf, 0); CVPixelBufferLockBaseAddress(pbuf, 0);
void *base = CVPixelBufferGetBaseAddress(p->pbuf); void *base = CVPixelBufferGetBaseAddress(pbuf);
size_t width = CVPixelBufferGetWidth(p->pbuf); size_t width = CVPixelBufferGetWidth(pbuf);
size_t height = CVPixelBufferGetHeight(p->pbuf); size_t height = CVPixelBufferGetHeight(pbuf);
size_t stride = CVPixelBufferGetBytesPerRow(p->pbuf); size_t stride = CVPixelBufferGetBytesPerRow(pbuf);
struct mp_image img = {0}; struct mp_image img = {0};
mp_image_setfmt(&img, IMGFMT_UYVY); mp_image_setfmt(&img, IMGFMT_UYVY);
@ -118,7 +119,7 @@ static struct mp_image *download_image(struct gl_hwdec *hw)
img.stride[0] = stride; img.stride[0] = stride;
struct mp_image *image = mp_image_new_copy(&img); struct mp_image *image = mp_image_new_copy(&img);
CVPixelBufferUnlockBaseAddress(p->pbuf, 0); CVPixelBufferUnlockBaseAddress(pbuf, 0);
return image; return image;
} }

View File

@ -1700,7 +1700,8 @@ struct mp_image *gl_video_download_image(struct gl_video *p)
return NULL; return NULL;
if (p->hwdec_active && p->hwdec->driver->download_image) { if (p->hwdec_active && p->hwdec->driver->download_image) {
struct mp_image *dlimage = p->hwdec->driver->download_image(p->hwdec); struct mp_image *dlimage =
p->hwdec->driver->download_image(p->hwdec, vimg->hwimage);
if (dlimage) if (dlimage)
mp_image_set_attributes(dlimage, &p->image_params); mp_image_set_attributes(dlimage, &p->image_params);
return dlimage; return dlimage;