Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

av_rpi_zc_get_buffer2 is declared but it has no implementation #1

Open
imbens opened this issue Mar 29, 2020 · 4 comments
Open

av_rpi_zc_get_buffer2 is declared but it has no implementation #1

imbens opened this issue Mar 29, 2020 · 4 comments

Comments

@imbens
Copy link

imbens commented Mar 29, 2020

I managed to use hevc hardware support via rpi_zc in my application by adding the following to my get_format2:

        if (inFmt[i] == AV_PIX_FMT_RPI4_8) {
            bcm_host_init();
            vcsm_init_ex (1, -1);
            ZcEnv *theEnv = av_rpi_zc_int_env_alloc (inContext);
            av_rpi_zc_init2 (inContext, theEnv->pool_env, theEnv->alloc_buf, theEnv->free_pool);
            inContext->refcounted_frames = 1;
            av_free (theEnv);
            return inFmt[i];
        }

In addition I had to copy the declarations of struct AVZcEnv and struct ZcOldCtxVals from rpi_zc.c. av_rpi_zc_get_buffer2 is declared in rpi_zc.h, but it has no implementation. The implementation is called zc_get_buffer2 in rpi_zc.c, but it is not exported. So my hack seems the only way to use rpi_zc. In a previous version of the hevc patch, av_rpi_zc_init that required no parameters, was available.

@popcornmix
Copy link

@jc-kynesim can you advise?

@jc-kynesim
Copy link

OK - sorry to change stuff on you - I admit I thought I & kodi were the only ones using that interface. However these days life should, in fact, be easier for you - you don't need to call zc_init at all and the rpi hwaccel will allocate stuff correctly anyway. The zc_init functions are now only provided for applications that want to control allocation outside ffmpeg. I should have removed the av_rpi_zc_get_buffer defn from the header but I obviously forgot.

@imbens
Copy link
Author

imbens commented Apr 2, 2020

Thank you, that explains a lot. In my attempts to get anything in AVFrame.buf[0], I first added the zc_init calls and then added codec_context->refcounted_frames = 1; so I assumed that both were necessary.
My next issue with the interface is how to get the vcsm_handle from buf[0]. I think I need that handle to (zero-)copy the frame to a GL texture. The only way I can get the vcsm_handle seems to be with ((ZcBufEnv *)av_buffer_get_opaque (av_rpi_zc_ref (..., frame, ...)))->gmem.vcsm_handle, but then I have to copy the definition of ZcBufEnv from rpi_zc.c. An interface to get the vc_handle from an AVFrame exists, but as far as I know you cannot get a vcsm_handle from a vc_handle?

@jc-kynesim
Copy link

jc-kynesim commented Apr 2, 2020

Ah - yes - you are right - sorry. My apps that need that (vlc) are managing their own buffers and so have the info in their hands which also allows them to bind the DRM handle to the buffer more permanently and the current code has an API that makes that easier (and I can explain that and give examples if you want to go down that route - the built in ZC allocator uses it). In any case I'll build you av_rpi_zc_vcsm_handle() but it will take a few days to work its way through the system.

Going forward we will have a V4L2 HEVC decoder (it exists now but needs linux >= 5.4) which uses dmabufs natively and so the whole ZC thing will go away - it is something of a kludge anyway 'cos I didn't really understand how the ffmpeg hwaccel framework is meant to work (and I'll admit that whilst I understand it a bit better now it still confuses me on a regular basis).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants