[FFmpeg-devel] Asynchronously delivering data to FFmpeg, and extending the API to do this...
philipp_subx at redfish-solutions.com
Tue Mar 20 04:06:22 EET 2018
I’m looking at the API and trying to figure out how to adapt it to our use, but without much luck. If I get this working, I’ll try to upstream the enhancement in case it’s generically useful.
The problem in a nutshell is we’re using libevent2 and everything is event-driven, including notifications about data arriving from the network.
So rather than using avio_alloc_context() where the read_packet() function does a blocking read on a socket, I need to do the inverse: call a function which collects data until it’s parsed a complete frame, then return an indication of that.
Maybe something like:
bool avio_collect_frame(AVIOContext *avio, uint_t *ptr, size_t *size);
where it’s called with an AVIOContext where data is accumulated internally (and parsed), ptr is a pointer to the new data being presented, and size is a pointer to the number of bytes available (it may get rewritten with the number of bytes actually used… or it could just save the overflow from the current frame and use it for the subsequent frame).
Then in the (read) event handler for data arriving on a socket, we pass each new block to data to this function until it returns true. When it returns true, then we activate an event to decode/render the frame (or handle it however else we might want to).
i.e. something like:
struct event *ev_render;
ev_render = event_new(evbase, -1, 0, render_cb, ctx);
and to fire the renderer:
bytes = bp->size;
if (avio_collect_frame(avio, bp->base, &bytes))
event_active(ev_render, 0, 1);
What’s involved in doing this?
More information about the ffmpeg-devel