Comments (9)
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.
other think maybe the pitch, pitch usually express as byte not pixel
from libyami-utils.
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.
more question: Do I need to convert the VideoFrame from RGBX to YUV before I do the encoding encoder->encode(frame);
from libyami-utils.
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.
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.
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.
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.
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)
- remove common/v4l2_wrapper.h
- Could you please be consistent on Release Names?????? HOT 1
- Compile error: av_register_all is deprecated
- vp8 temporal svc encoding quits with assert error. HOT 1
- VP8 SVCT yamitranscode pink artefakts with fast moving picture in CBR/VBR mode
- [regression] Arbitrary initialization of VideoDecodeBuffer::flag causes incorrect AVC/HEVC decoding
- keyFrame management with vpx encoders
- v4l2 apps main functions to return 0 explicitly HOT 1
- Add transcoder latency log for performance test HOT 3
- yamitranscode: disable scaling at run time HOT 1
- Compile failure on Ubuntu Trusty (14.04) with AVFORMAT HOT 10
- Setup travis-ci HOT 3
- Setup coverity scans
- Some artifacts of gtest were retained in libyami-utils
- Replace AVStream embedded codec context with AVCodecParameters instance HOT 6
- Fails to build from source with --disable-x11 HOT 4
- [HEVC 10bit encode] yamiencode raised core dump issue when did the hevc 10bit encode test HOT 2
- [regression] yamidecode Segmentation Fault since 52fe395427b3 HOT 7
- yamitranscode gives 10-15% performance difference from run to run HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libyami-utils.