diff options
author | Stefano Sabatini <stefasab@gmail.com> | 2013-11-25 13:27:47 +0100 |
---|---|---|
committer | Stefano Sabatini <stefasab@gmail.com> | 2013-11-26 18:15:18 +0100 |
commit | 0464d272ff9d4d98a1dca56e0a20deb5c56396c4 (patch) | |
tree | 2bda884f6bdbd36fa5bee812403863c5c16a1ded /libavdevice | |
parent | 7467b4f71b4baa586e7a3063ec80b5da91d44dca (diff) | |
download | ffmpeg-0464d272ff9d4d98a1dca56e0a20deb5c56396c4.tar.gz |
lavd/sdl: move compute_overlay_rect() before event_thread()
It will be used in event_thread() in a pending patch.
Diffstat (limited to 'libavdevice')
-rw-r--r-- | libavdevice/sdl.c | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/libavdevice/sdl.c b/libavdevice/sdl.c index 4505cb7224..6328e9f67d 100644 --- a/libavdevice/sdl.c +++ b/libavdevice/sdl.c @@ -84,6 +84,46 @@ static int sdl_write_trailer(AVFormatContext *s) return 0; } +static void compute_overlay_rect(AVFormatContext *s) +{ + AVRational sar, dar; /* sample and display aspect ratios */ + SDLContext *sdl = s->priv_data; + AVStream *st = s->streams[0]; + AVCodecContext *encctx = st->codec; + SDL_Rect *overlay_rect = &sdl->overlay_rect; + + /* compute overlay width and height from the codec context information */ + sar = st->sample_aspect_ratio.num ? st->sample_aspect_ratio : (AVRational){ 1, 1 }; + dar = av_mul_q(sar, (AVRational){ encctx->width, encctx->height }); + + /* we suppose the screen has a 1/1 sample aspect ratio */ + if (sdl->window_width && sdl->window_height) { + /* fit in the window */ + if (av_cmp_q(dar, (AVRational){ sdl->window_width, sdl->window_height }) > 0) { + /* fit in width */ + overlay_rect->w = sdl->window_width; + overlay_rect->h = av_rescale(overlay_rect->w, dar.den, dar.num); + } else { + /* fit in height */ + overlay_rect->h = sdl->window_height; + overlay_rect->w = av_rescale(overlay_rect->h, dar.num, dar.den); + } + } else { + if (sar.num > sar.den) { + overlay_rect->w = encctx->width; + overlay_rect->h = av_rescale(overlay_rect->w, dar.den, dar.num); + } else { + overlay_rect->h = encctx->height; + overlay_rect->w = av_rescale(overlay_rect->h, dar.num, dar.den); + } + sdl->window_width = overlay_rect->w; + sdl->window_height = overlay_rect->h; + } + + overlay_rect->x = (sdl->window_width - overlay_rect->w) / 2; + overlay_rect->y = (sdl->window_height - overlay_rect->h) / 2; +} + static int event_thread(void *arg) { AVFormatContext *s = arg; @@ -163,46 +203,6 @@ init_end: return 0; } -static void compute_overlay_rect(AVFormatContext *s) -{ - AVRational sar, dar; /* sample and display aspect ratios */ - SDLContext *sdl = s->priv_data; - AVStream *st = s->streams[0]; - AVCodecContext *encctx = st->codec; - SDL_Rect *overlay_rect = &sdl->overlay_rect; - - /* compute overlay width and height from the codec context information */ - sar = st->sample_aspect_ratio.num ? st->sample_aspect_ratio : (AVRational){ 1, 1 }; - dar = av_mul_q(sar, (AVRational){ encctx->width, encctx->height }); - - /* we suppose the screen has a 1/1 sample aspect ratio */ - if (sdl->window_width && sdl->window_height) { - /* fit in the window */ - if (av_cmp_q(dar, (AVRational){ sdl->window_width, sdl->window_height }) > 0) { - /* fit in width */ - overlay_rect->w = sdl->window_width; - overlay_rect->h = av_rescale(overlay_rect->w, dar.den, dar.num); - } else { - /* fit in height */ - overlay_rect->h = sdl->window_height; - overlay_rect->w = av_rescale(overlay_rect->h, dar.num, dar.den); - } - } else { - if (sar.num > sar.den) { - overlay_rect->w = encctx->width; - overlay_rect->h = av_rescale(overlay_rect->w, dar.den, dar.num); - } else { - overlay_rect->h = encctx->height; - overlay_rect->w = av_rescale(overlay_rect->h, dar.num, dar.den); - } - sdl->window_width = overlay_rect->w; - sdl->window_height = overlay_rect->h; - } - - overlay_rect->x = (sdl->window_width - overlay_rect->w) / 2; - overlay_rect->y = (sdl->window_height - overlay_rect->h) / 2; -} - static int sdl_write_header(AVFormatContext *s) { SDLContext *sdl = s->priv_data; |