This is possible because the lifetime of both coincide. Besides reducing the number of allocations this also simplifies access to OpenCLFramesContext as one no longer has to go through AVHWFramesInternal.
Unified · Split
| @@ -143,6 +143,11 @@ typedef struct OpenCLDeviceContext { · 142 unmodified lines | ||
| 143 | 143 | } OpenCLDeviceContext; |
| 144 | 144 | |
| 145 | 145 | typedef struct OpenCLFramesContext { |
| 146 | + /** | |
| 147 | + * The public AVOpenCLFramesContext. See hwcontext_opencl.h for it. | |
| 148 | + */ | |
| 149 | + AVOpenCLFramesContext p; | |
| 150 | + | |
| 146 | 151 | // Command queue used for transfer/mapping operations on this frames |
| 147 | 152 | // context. If the user supplies one, this is a reference to it. |
| 148 | 153 | // Otherwise, it is a reference to the default command queue for the |
| @@ -1700,9 +1705,9 @@ fail: · 1551 unmodified lines | ||
| 1700 | 1705 | |
| 1701 | 1706 | static int opencl_frames_init_command_queue(AVHWFramesContext *hwfc) |
| 1702 | 1707 | { |
| 1703 | − AVOpenCLFramesContext *hwctx = hwfc->hwctx; | |
| 1708 | + OpenCLFramesContext *priv = hwfc->hwctx; | |
| 1709 | + AVOpenCLFramesContext *hwctx = &priv->p; | |
| 1704 | 1710 | OpenCLDeviceContext *devpriv = hwfc->device_ctx->hwctx; |
| 1705 | − OpenCLFramesContext *priv = hwfc->internal->priv; | |
| 1706 | 1711 | cl_int cle; |
| 1707 | 1712 | |
| 1708 | 1713 | priv->command_queue = hwctx->command_queue ? hwctx->command_queue |
| @@ -1732,7 +1737,7 @@ static int opencl_frames_init(AVHWFramesContext *hwfc) · 23 unmodified lines | ||
| 1732 | 1737 | |
| 1733 | 1738 | static void opencl_frames_uninit(AVHWFramesContext *hwfc) |
| 1734 | 1739 | { |
| 1735 | − OpenCLFramesContext *priv = hwfc->internal->priv; | |
| 1740 | + OpenCLFramesContext *priv = hwfc->hwctx; | |
| 1736 | 1741 | cl_int cle; |
| 1737 | 1742 | |
| 1738 | 1743 | #if HAVE_OPENCL_DXVA2 || HAVE_OPENCL_D3D11 |
| @@ -1826,7 +1831,7 @@ static int opencl_wait_events(AVHWFramesContext *hwfc, · 87 unmodified lines | ||
| 1826 | 1831 | static int opencl_transfer_data_from(AVHWFramesContext *hwfc, |
| 1827 | 1832 | AVFrame *dst, const AVFrame *src) |
| 1828 | 1833 | { |
| 1829 | − OpenCLFramesContext *priv = hwfc->internal->priv; | |
| 1834 | + OpenCLFramesContext *priv = hwfc->hwctx; | |
| 1830 | 1835 | cl_image_format image_format; |
| 1831 | 1836 | cl_image_desc image_desc; |
| 1832 | 1837 | cl_int cle; |
| @@ -1881,7 +1886,7 @@ static int opencl_transfer_data_from(AVHWFramesContext *hwfc, · 48 unmodified lines | ||
| 1881 | 1886 | static int opencl_transfer_data_to(AVHWFramesContext *hwfc, |
| 1882 | 1887 | AVFrame *dst, const AVFrame *src) |
| 1883 | 1888 | { |
| 1884 | − OpenCLFramesContext *priv = hwfc->internal->priv; | |
| 1889 | + OpenCLFramesContext *priv = hwfc->hwctx; | |
| 1885 | 1890 | cl_image_format image_format; |
| 1886 | 1891 | cl_image_desc image_desc; |
| 1887 | 1892 | cl_int cle; |
| @@ -1943,7 +1948,7 @@ typedef struct OpenCLMapping { · 55 unmodified lines | ||
| 1943 | 1948 | static void opencl_unmap_frame(AVHWFramesContext *hwfc, |
| 1944 | 1949 | HWMapDescriptor *hwmap) |
| 1945 | 1950 | { |
| 1946 | − OpenCLFramesContext *priv = hwfc->internal->priv; | |
| 1951 | + OpenCLFramesContext *priv = hwfc->hwctx; | |
| 1947 | 1952 | OpenCLMapping *map = hwmap->priv; |
| 1948 | 1953 | cl_event events[AV_NUM_DATA_POINTERS]; |
| 1949 | 1954 | int p, e; |
| @@ -1972,7 +1977,7 @@ static void opencl_unmap_frame(AVHWFramesContext *hwfc, · 22 unmodified lines | ||
| 1972 | 1977 | static int opencl_map_frame(AVHWFramesContext *hwfc, AVFrame *dst, |
| 1973 | 1978 | const AVFrame *src, int flags) |
| 1974 | 1979 | { |
| 1975 | − OpenCLFramesContext *priv = hwfc->internal->priv; | |
| 1980 | + OpenCLFramesContext *priv = hwfc->hwctx; | |
| 1976 | 1981 | cl_map_flags map_flags; |
| 1977 | 1982 | cl_image_format image_format; |
| 1978 | 1983 | cl_image_desc image_desc; |
| @@ -2229,7 +2234,7 @@ static void opencl_unmap_from_qsv(AVHWFramesContext *dst_fc, · 250 unmodified lines | ||
| 2229 | 2234 | { |
| 2230 | 2235 | AVOpenCLFrameDescriptor *desc = hwmap->priv; |
| 2231 | 2236 | OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx; |
| 2232 | − OpenCLFramesContext *frames_priv = dst_fc->internal->priv; | |
| 2237 | + OpenCLFramesContext *frames_priv = dst_fc->hwctx; | |
| 2233 | 2238 | cl_event event; |
| 2234 | 2239 | cl_int cle; |
| 2235 | 2240 | int p; |
| @@ -2265,7 +2270,7 @@ static int opencl_map_from_qsv(AVHWFramesContext *dst_fc, AVFrame *dst, · 29 unmodified lines | ||
| 2265 | 2270 | (AVHWFramesContext*)src->hw_frames_ctx->data; |
| 2266 | 2271 | OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx; |
| 2267 | 2272 | AVOpenCLDeviceContext *dst_dev = &device_priv->p; |
| 2268 | − OpenCLFramesContext *frames_priv = dst_fc->internal->priv; | |
| 2273 | + OpenCLFramesContext *frames_priv = dst_fc->hwctx; | |
| 2269 | 2274 | AVOpenCLFrameDescriptor *desc; |
| 2270 | 2275 | VASurfaceID va_surface; |
| 2271 | 2276 | cl_mem_flags cl_flags; |
| @@ -2363,7 +2368,7 @@ static void opencl_unmap_from_dxva2(AVHWFramesContext *dst_fc, · 91 unmodified lines | ||
| 2363 | 2368 | { |
| 2364 | 2369 | AVOpenCLFrameDescriptor *desc = hwmap->priv; |
| 2365 | 2370 | OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx; |
| 2366 | − OpenCLFramesContext *frames_priv = dst_fc->internal->priv; | |
| 2371 | + OpenCLFramesContext *frames_priv = dst_fc->hwctx; | |
| 2367 | 2372 | cl_event event; |
| 2368 | 2373 | cl_int cle; |
| 2369 | 2374 | |
| @@ -2388,7 +2393,7 @@ static int opencl_map_from_dxva2(AVHWFramesContext *dst_fc, AVFrame *dst, · 18 unmodified lines | ||
| 2388 | 2393 | (AVHWFramesContext*)src->hw_frames_ctx->data; |
| 2389 | 2394 | AVDXVA2FramesContext *src_hwctx = src_fc->hwctx; |
| 2390 | 2395 | OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx; |
| 2391 | − OpenCLFramesContext *frames_priv = dst_fc->internal->priv; | |
| 2396 | + OpenCLFramesContext *frames_priv = dst_fc->hwctx; | |
| 2392 | 2397 | AVOpenCLFrameDescriptor *desc; |
| 2393 | 2398 | cl_event event; |
| 2394 | 2399 | cl_int cle; |
| @@ -2451,7 +2456,7 @@ static int opencl_frames_derive_from_dxva2(AVHWFramesContext *dst_fc, · 56 unmodified lines | ||
| 2451 | 2456 | AVDXVA2FramesContext *src_hwctx = src_fc->hwctx; |
| 2452 | 2457 | OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx; |
| 2453 | 2458 | AVOpenCLDeviceContext *dst_dev = &device_priv->p; |
| 2454 | − OpenCLFramesContext *frames_priv = dst_fc->internal->priv; | |
| 2459 | + OpenCLFramesContext *frames_priv = dst_fc->hwctx; | |
| 2455 | 2460 | cl_mem_flags cl_flags; |
| 2456 | 2461 | cl_int cle; |
| 2457 | 2462 | int err, i, p, nb_planes; |
| @@ -2528,7 +2533,7 @@ static void opencl_unmap_from_d3d11(AVHWFramesContext *dst_fc, · 70 unmodified lines | ||
| 2528 | 2533 | { |
| 2529 | 2534 | AVOpenCLFrameDescriptor *desc = hwmap->priv; |
| 2530 | 2535 | OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx; |
| 2531 | − OpenCLFramesContext *frames_priv = dst_fc->internal->priv; | |
| 2536 | + OpenCLFramesContext *frames_priv = dst_fc->hwctx; | |
| 2532 | 2537 | cl_event event; |
| 2533 | 2538 | cl_int cle; |
| 2534 | 2539 | |
| @@ -2547,7 +2552,7 @@ static int opencl_map_from_d3d11(AVHWFramesContext *dst_fc, AVFrame *dst, · 12 unmodified lines | ||
| 2547 | 2552 | const AVFrame *src, int flags) |
| 2548 | 2553 | { |
| 2549 | 2554 | OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx; |
| 2550 | − OpenCLFramesContext *frames_priv = dst_fc->internal->priv; | |
| 2555 | + OpenCLFramesContext *frames_priv = dst_fc->hwctx; | |
| 2551 | 2556 | AVOpenCLFrameDescriptor *desc; |
| 2552 | 2557 | cl_event event; |
| 2553 | 2558 | cl_int cle; |
| @@ -2607,7 +2612,7 @@ static int opencl_frames_derive_from_d3d11(AVHWFramesContext *dst_fc, · 53 unmodified lines | ||
| 2607 | 2612 | AVD3D11VAFramesContext *src_hwctx = src_fc->hwctx; |
| 2608 | 2613 | OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx; |
| 2609 | 2614 | AVOpenCLDeviceContext *dst_dev = &device_priv->p; |
| 2610 | − OpenCLFramesContext *frames_priv = dst_fc->internal->priv; | |
| 2615 | + OpenCLFramesContext *frames_priv = dst_fc->hwctx; | |
| 2611 | 2616 | cl_mem_flags cl_flags; |
| 2612 | 2617 | cl_int cle; |
| 2613 | 2618 | int err, i, p, nb_planes; |
| @@ -3036,8 +3041,7 @@ const HWContextType ff_hwcontext_type_opencl = { · 422 unmodified lines | ||
| 3036 | 3041 | .name = "OpenCL", |
| 3037 | 3042 | |
| 3038 | 3043 | .device_hwctx_size = sizeof(OpenCLDeviceContext), |
| 3039 | − .frames_hwctx_size = sizeof(AVOpenCLFramesContext), | |
| 3040 | − .frames_priv_size = sizeof(OpenCLFramesContext), | |
| 3044 | + .frames_hwctx_size = sizeof(OpenCLFramesContext), | |
| 3041 | 3045 | |
| 3042 | 3046 | .device_create = &opencl_device_create, |
| 3043 | 3047 | .device_derive = &opencl_device_derive, |