1 #ifndef _VA_RESOURCE_POOL
2 #define _VA_RESOURCE_POOL 1
12 #define CHECK_VASTATUS(va_status, func) \
13 if (va_status != VA_STATUS_SUCCESS) { \
14 fprintf(stderr, "%s:%d (%s) failed: %s\n", __func__, __LINE__, func, vaErrorStr(va_status)); \
18 #define CHECK_VASTATUS_RET(va_status, func) \
19 if (va_status != VA_STATUS_SUCCESS) { \
20 fprintf(stderr, "%s:%d (%s) failed with %d\n", __func__, __LINE__, func, va_status); \
24 class VAResourcePool {
27 unsigned width, height;
31 VABufferID data_buffer;
35 VAResourcePool(VADisplay va_dpy, VAImageFormat uyvy_format, VAImageFormat nv12_format, VAConfigID config_id_422, VAConfigID config_id_420, bool with_data_buffer)
37 uyvy_format(uyvy_format),
38 nv12_format(nv12_format),
39 config_id_422(config_id_422),
40 config_id_420(config_id_420),
41 with_data_buffer(with_data_buffer) {}
42 VAResources get_va_resources(unsigned width, unsigned height, uint32_t fourcc);
43 void release_va_resources(VAResources resources);
46 const VADisplay va_dpy;
47 VAImageFormat uyvy_format, nv12_format;
48 const VAConfigID config_id_422, config_id_420;
49 const bool with_data_buffer;
52 std::list<VAResources> freelist; // Under mu.
55 // RAII wrapper to release VAResources on return (even on error).
56 class ReleaseVAResources {
58 ReleaseVAResources() : committed(true) {}
60 ReleaseVAResources(VAResourcePool *pool, const VAResourcePool::VAResources &resources)
61 : pool(pool), resources(resources) {}
63 ReleaseVAResources(ReleaseVAResources &) = delete;
65 ReleaseVAResources(ReleaseVAResources &&other)
66 : pool(other.pool), resources(other.resources), committed(other.committed) {
70 ReleaseVAResources &operator= (ReleaseVAResources &) = delete;
72 ReleaseVAResources &operator= (ReleaseVAResources &&other) {
74 pool->release_va_resources(resources);
77 resources = std::move(other.resources);
78 committed = other.committed;
86 pool->release_va_resources(resources);
90 void commit() { committed = true; }
93 VAResourcePool *pool = nullptr;
94 VAResourcePool::VAResources resources;
95 bool committed = false;
98 #endif // !defined(_VA_RESOURCE_POOL)