1 #ifndef _VA_RESOURCE_POOL
2 #define _VA_RESOURCE_POOL 1
10 #define CHECK_VASTATUS(va_status, func) \
11 if (va_status != VA_STATUS_SUCCESS) { \
12 fprintf(stderr, "%s:%d (%s) failed: %s\n", __func__, __LINE__, func, vaErrorStr(va_status)); \
16 #define CHECK_VASTATUS_RET(va_status, func) \
17 if (va_status != VA_STATUS_SUCCESS) { \
18 fprintf(stderr, "%s:%d (%s) failed with %d\n", __func__, __LINE__, func, va_status); \
22 class VAResourcePool {
25 unsigned width, height;
29 VABufferID data_buffer;
33 VAResourcePool(VADisplay va_dpy, VAImageFormat uyvy_format, VAImageFormat nv12_format, VAConfigID config_id_422, VAConfigID config_id_420, bool with_data_buffer)
35 uyvy_format(uyvy_format),
36 nv12_format(nv12_format),
37 config_id_422(config_id_422),
38 config_id_420(config_id_420),
39 with_data_buffer(with_data_buffer) {}
40 VAResources get_va_resources(unsigned width, unsigned height, uint32_t fourcc);
41 void release_va_resources(VAResources resources);
44 const VADisplay va_dpy;
45 VAImageFormat uyvy_format, nv12_format;
46 const VAConfigID config_id_422, config_id_420;
47 const bool with_data_buffer;
50 std::list<VAResources> freelist; // Under mu.
53 // RAII wrapper to release VAResources on return (even on error).
54 class ReleaseVAResources {
56 ReleaseVAResources() : committed(true) {}
58 ReleaseVAResources(VAResourcePool *pool, const VAResourcePool::VAResources &resources)
59 : pool(pool), resources(resources) {}
61 ReleaseVAResources(ReleaseVAResources &) = delete;
63 ReleaseVAResources(ReleaseVAResources &&other)
64 : pool(other.pool), resources(other.resources), committed(other.committed) {
68 ReleaseVAResources &operator= (ReleaseVAResources &) = delete;
70 ReleaseVAResources &operator= (ReleaseVAResources &&other) {
72 pool->release_va_resources(resources);
75 resources = std::move(other.resources);
76 committed = other.committed;
84 pool->release_va_resources(resources);
88 void commit() { committed = true; }
91 VAResourcePool *pool = nullptr;
92 VAResourcePool::VAResources resources;
93 bool committed = false;
96 #endif // !defined(_VA_RESOURCE_POOL)