[FFmpeg-devel] [PATCH 2/3] lavd: utilize video device callbacks from AVFormatContext

Lukasz M lukasz.m.luki at gmail.com
Mon Jan 13 13:59:13 CET 2014

It is used to detect changes of window size too, but in first place it is
required to know starting window dimension.
You have to call glViewport and prepare projection matrix based on it.
You are right about wrong direction of this communication tho.

> After some thought, I can suggest the following API:
> AVFormatContext.control_message(AVFormatContext *s, int type,
>                                 void *data, size_t data_size);
> -> used to plug application-specific callbacks at various events. For
> example:
>     ctx->control_message(ctx, AV_CTL_MESSAGE_PREPARE_WINDOW_BUFFER, NULL,
> 0);
>     ... OpenGL operations...
>     ctx->control_message(ctx, AV_CTL_MESSAGE_DISPLAY_WINDOW_BUFFER, NULL,
> 0);
> AVOutputFormat.control_message(AVFormatContext *s, int type,
>                                void *data, size_t data_size);
> -> used to signal an output context of various external events. In this
> particular case:
>         AVDeviceWindowChange size = {
>             .width = new_width,
>             .height = new_height
>         };
>         avformat_control_message(ctx, AV_DEVICE_WINDOW_CHANGE,
>                                  &size, sizeof(size));
>     }
> The thing is that preparing the context and swapping the buffers must be
> done by the application, so a custom callback in the context is required,
> while reacting to a window size change depends only on the device, so a
> method in the format is correct.
> But maybe I missed some points I have not thought of.

Your solution is OK and I will try to implement it in this way.
The one thing you missed is that application must send message with window
dimension before write_header.
It still may be "resize" or something like "window created", but these are

> Also, I believe adding the fields and adding the stubs to call them (i.e.
> patches 1 and 2) could be squashed together.

They changed different libs so I splitted it, but your solution probably
will affect only lavf.

More information about the ffmpeg-devel mailing list