GithubHelp home page GithubHelp logo

Comments (9)

xuguangxin avatar xuguangxin commented on June 15, 2024

I do not know why you can create VASurface, but you may need change external.buffers = prime_fd to external.buffers = &prime_fd, because va treat buffers as array:

    if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
        obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
                                                            "gem flinked vaapi surface",
                                                            memory_attibute->buffers[index]);
    else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
        obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
                                                             memory_attibute->buffers[index],
                                                             obj_surface->size);

from libyami-utils.

xuguangxin avatar xuguangxin commented on June 15, 2024

other think maybe the pitch, pitch usually express as byte not pixel

from libyami-utils.

zhijianli88 avatar zhijianli88 commented on June 15, 2024

I do not know why you can create VASurface, but you may need change external.buffers = prime_fd to external.buffers = &prime_fd, because va treat buffers as array:

you are right, it should be &prime_fd. I had fixed it and I have created VASurface successfully.
Today, i dumped the 3)VideoFrame to a jpeg file, i can see a rough guest desktop what i expect.

i'm quite new for libyami, so i'm not clear how to set the pitch.

from libyami-utils.

zhijianli88 avatar zhijianli88 commented on June 15, 2024

more question: Do I need to convert the VideoFrame from RGBX to YUV before I do the encoding encoder->encode(frame);

from libyami-utils.

xuguangxin avatar xuguangxin commented on June 15, 2024

you can check this https://www.x.org/wiki/Development/Documentation/HowVideoCardsWork/ and this http://stackoverflow.com/questions/20541111/how-to-calculate-framebuffer-pitch

from libyami-utils.

xuguangxin avatar xuguangxin commented on June 15, 2024

No need, we will create new surface and convert the RGB to NV12 in libva. However if you have NV12 surface pool you many have better performance. PooledFrameAllocator may make your life easier:

template <class T>
class VideoPool : public EnableSharedFromThis<VideoPool<T> >
{
public:

    SharedPtr<T> alloc()
    {
        SharedPtr<T> ret;
        boost::upgrade_lock<boost::shared_mutex> lock(m_mutex);

        if (!m_freed.empty()) {
            T* p = m_freed.front();
            m_freed.pop_front();
            ret.reset(p, Recycler(this->shared_from_this()));
        }
        return ret;
    }

    VideoPool(std::deque<SharedPtr<T> >& buffers)
    {
            m_holder.swap(buffers);
            for (size_t i = 0; i < m_holder.size(); i++) {
                m_freed.push_back(m_holder[i].get());
            }
    }

private:
    void recycle(T* ptr)
    {
        boost::upgrade_lock<boost::shared_mutex> lock(m_mutex);
        m_freed.push_back(ptr);
    }

    class Recycler
    {
    public:
        Recycler(const SharedPtr<VideoPool<T> >& pool)
            :m_pool(pool)
        {
        }
        void operator()(T* ptr) const
        {
            m_pool->recycle(ptr);
        }
    private:
        SharedPtr<VideoPool<T> > m_pool;
    };

    boost::shared_mutex m_mutex;

    std::deque<T*> m_freed;
    std::deque<SharedPtr<T> > m_holder;
};

struct SurfaceDestoryer
{
private:
    SharedPtr<VADisplay> m_display;
    std::vector<VASurfaceID> m_surfaces;
public:
    SurfaceDestoryer(const SharedPtr<VADisplay>& display, std::vector<VASurfaceID>& surfaces)
        :m_display(display)
    {
        m_surfaces.swap(surfaces);
    }
    void operator()(VideoPool<VideoFrame>* pool)
    {
        if (m_surfaces.size())
            vaDestroySurfaces(*m_display, &m_surfaces[0], m_surfaces.size());
        delete pool;
    }

};

class PooledFrameAllocator
{
public:
    PooledFrameAllocator(const SharedPtr<VADisplay>& display, int poolsize)
        :m_display(display)
        , m_poolsize(poolsize)
    {
    }
    bool setFormat(uint32_t fourcc, int width, int height)
    {
        std::vector<VASurfaceID> surfaces;
        surfaces.resize(m_poolsize);

        VASurfaceAttrib attrib;
        attrib.flags = VA_SURFACE_ATTRIB_SETTABLE;
        attrib.type = VASurfaceAttribPixelFormat;
        attrib.value.type = VAGenericValueTypeInteger;
        attrib.value.value.i = fourcc;


        VAStatus status = vaCreateSurfaces(*m_display, VA_RT_FORMAT_YUV420, width, height,
                                           &surfaces[0], surfaces.size(),
                                           &attrib, 1);
        if (status != VA_STATUS_SUCCESS) {
            ELOG_ERROR("create surface failed, %s", vaErrorStr(status));
            return false;
        }
        std::deque<SharedPtr<VideoFrame> > buffers;
        for (size_t i = 0;  i < surfaces.size(); i++) {
            SharedPtr<VideoFrame> f(new VideoFrame);
            memset(f.get(), 0, sizeof(VideoFrame));
            f->surface = (intptr_t)surfaces[i];
            f->fourcc = fourcc;
            buffers.push_back(f);
        }
        m_pool.reset(new VideoPool<VideoFrame>(buffers), SurfaceDestoryer(m_display, surfaces));
        return true;
    }

    SharedPtr<VideoFrame> alloc()
    {
        return  m_pool->alloc();
    }
private:
    SharedPtr<VADisplay> m_display;
    SharedPtr<VideoPool<VideoFrame> > m_pool;
    int m_poolsize;
};

from libyami-utils.

zhijianli88 avatar zhijianli88 commented on June 15, 2024

you can check this https://www.x.org/wiki/Development/Documentation/HowVideoCardsWork/ and this http://stackoverflow.com/questions/20541111/how-to-calculate-framebuffer-pitch

Thank you very much, I will have look.

from libyami-utils.

zhijianli88 avatar zhijianli88 commented on June 15, 2024

No need, we will create new surface and convert the RGB to NV12 in libva. However if you have NV12 surface pool you many have better performance. PooledFrameAllocator may make your life easier:

My demo have implemented a suface pool primefd-demo:https://github.com/zhijianli88/primefd-demo
But I have not bring it up. It need more investigation.

from libyami-utils.

zhijianli88 avatar zhijianli88 commented on June 15, 2024

Thanks, I will have a look;

On 10/27/2016 11:58 AM, Xu Guangxin wrote:

you can check this https://www.x.org/wiki/Development/Documentation/HowVideoCardsWork/ and this http://stackoverflow.com/questions/20541111/how-to-calculate-framebuffer-pitch

from libyami-utils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.