File: vasurface_wrapper.h

package info (click to toggle)
libvpl 1%3A2.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,580 kB
  • sloc: cpp: 92,604; ansic: 6,176; python: 4,312; sh: 323; makefile: 7
file content (54 lines) | stat: -rw-r--r-- 2,024 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//==============================================================================
// Copyright Intel Corporation
//
// SPDX-License-Identifier: MIT
//==============================================================================

#include <list>
#include <memory>
#include <vector>
#include "device-vaapi.h"
#include "util.hpp"

struct ImportedVASurfaceWrapper {
    mfxFrameSurface1 *m_imported_mfx_surface;
    VASurfaceID m_vaSurfaceID;

    ImportedVASurfaceWrapper(mfxFrameSurface1 *surf, VASurfaceID vaid, VADisplay vadisplay)
            : m_imported_mfx_surface(surf),
              m_vaSurfaceID(vaid),
              m_vaDisplay(vadisplay) {}

    ImportedVASurfaceWrapper(const ImportedVASurfaceWrapper &)            = delete;
    ImportedVASurfaceWrapper &operator=(const ImportedVASurfaceWrapper &) = delete;

    ImportedVASurfaceWrapper(ImportedVASurfaceWrapper &&)            = delete;
    ImportedVASurfaceWrapper &operator=(ImportedVASurfaceWrapper &&) = delete;

    // vaSurfaces destroyed in the destructor
    ~ImportedVASurfaceWrapper() {
        if (m_imported_mfx_surface && m_imported_mfx_surface->FrameInterface &&
            m_imported_mfx_surface->FrameInterface->Release) {
            std::ignore = m_imported_mfx_surface->FrameInterface->Release(m_imported_mfx_surface);
        }
        if (m_vaSurfaceID != VA_INVALID_SURFACE) {
            std::ignore = vaDestroySurfaces(m_vaDisplay, &m_vaSurfaceID, 1);
        }
    }

    // Pay attention, that VADisplay should stay alive until owned surface destruction
    VADisplay m_vaDisplay;
};

// List of imported VASurfaces to handle deletion
std::list<ImportedVASurfaceWrapper> m_importedVAsurfaces;

void ReleaseFreeSurfaces() {
    for (std::list<ImportedVASurfaceWrapper>::iterator surface = m_importedVAsurfaces.begin();
         surface != m_importedVAsurfaces.end();) {
        if (surface->m_imported_mfx_surface->Data.Locked == 0)
            surface = m_importedVAsurfaces.erase(surface);
        else
            ++surface;
    }
}