[FFmpeg-devel] [PATCH] lavd/sdl: add event handler thread
Lukasz M
lukasz.m.luki at gmail.com
Sun Nov 24 20:36:28 CET 2013
On 24 November 2013 20:12, Stefano Sabatini <stefasab at gmail.com> wrote:
> Experimental and partially untested, meant to address ticket #1743 and
> #1744.
> ---
> libavdevice/sdl.c | 115
> +++++++++++++++++++++++++++++++++++++++++++++---------
> 1 file changed, 96 insertions(+), 19 deletions(-)
>
> +static int event_thread(void *arg)
> +{
> + AVFormatContext *s = arg;
> + SDLContext *sdl = s->priv_data;
> + int flags = SDL_SWSURFACE | sdl->window_fullscreen ? SDL_FULLSCREEN :
> 0;
> + AVStream *st = s->streams[0];
> + AVCodecContext *encctx = st->codec;
> +
> + /* initialization */
> + SDL_WM_SetCaption(sdl->window_title, sdl->icon_title);
> + sdl->surface = SDL_SetVideoMode(sdl->window_width, sdl->window_height,
> + 24, flags);
> + if (!sdl->surface) {
> + av_log(sdl, AV_LOG_ERROR, "Unable to set video mode: %s\n",
> SDL_GetError());
> + return AVERROR(EINVAL);
>
You will have a deadlock, sdl->inited is never set to 1 and
sdl_write_header will wait forever. The same below.
Returned values are send to nowhere, but no clue if they can be handled.
Setting sdl->quit to 1 and signal sdl->init_event_cond may help.
In sdl_write_header you may check if quit is set and return with error.
> + }
> +
> + sdl->overlay = SDL_CreateYUVOverlay(encctx->width, encctx->height,
> + sdl->overlay_fmt, sdl->surface);
> + if (!sdl->overlay || sdl->overlay->pitches[0] < encctx->width) {
> + av_log(s, AV_LOG_ERROR,
> + "SDL does not support an overlay with size of %dx%d
> pixels\n",
> + encctx->width, encctx->height);
> + return AVERROR(EINVAL);
> + }
> +
> + av_log(s, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s -> w:%d h:%d\n",
> + encctx->width, encctx->height,
> av_get_pix_fmt_name(encctx->pix_fmt),
> + sdl->overlay_width, sdl->overlay_height);
> +
> + SDL_LockMutex(sdl->mutex);
> + sdl->inited = 1;
> + SDL_CondSignal(sdl->init_event_cond);
> + SDL_UnlockMutex(sdl->mutex);
>
You can unlock mutex before signaling.
> + /* event loop */
> + while (!sdl->quit) {
> + SDL_Event event;
> + SDL_PumpEvents();
> + if (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0) {
> + /* fixme: make this customizable? */
> + av_usleep(1000.0);
> + continue;
> + }
> +
> + switch (event.type) {
> + case SDL_KEYDOWN:
> + switch (event.key.keysym.sym) {
> + case SDLK_ESCAPE:
> + case SDLK_q:
> + sdl->quit = 1;
> + break;
> + }
> + break;
> + case SDL_QUIT:
> + sdl->quit = 1;
> + break;
> + default:
> + break;
> + }
> + }
> +
> + return 0;
> +}
> +
>
More information about the ffmpeg-devel
mailing list