ffplay: add support for negative RGBA linesize

This fixes the crash reported in ticket #5947.

Signed-off-by: Marton Balint <cus@passwd.hu>
pull/241/head
Marton Balint 8 years ago
parent 8c1342e631
commit 58af48f1c3
  1. 12
      ffplay.c

@ -165,6 +165,7 @@ typedef struct Frame {
int format; int format;
AVRational sar; AVRational sar;
int uploaded; int uploaded;
int flip_v;
} Frame; } Frame;
typedef struct FrameQueue { typedef struct FrameQueue {
@ -861,12 +862,20 @@ static int upload_texture(SDL_Texture *tex, AVFrame *frame, struct SwsContext **
int ret = 0; int ret = 0;
switch (frame->format) { switch (frame->format) {
case AV_PIX_FMT_YUV420P: case AV_PIX_FMT_YUV420P:
if (frame->linesize[0] < 0 || frame->linesize[1] < 0 || frame->linesize[2] < 0) {
av_log(NULL, AV_LOG_ERROR, "Negative linesize is not supported for YUV.\n");
return -1;
}
ret = SDL_UpdateYUVTexture(tex, NULL, frame->data[0], frame->linesize[0], ret = SDL_UpdateYUVTexture(tex, NULL, frame->data[0], frame->linesize[0],
frame->data[1], frame->linesize[1], frame->data[1], frame->linesize[1],
frame->data[2], frame->linesize[2]); frame->data[2], frame->linesize[2]);
break; break;
case AV_PIX_FMT_BGRA: case AV_PIX_FMT_BGRA:
if (frame->linesize[0] < 0) {
ret = SDL_UpdateTexture(tex, NULL, frame->data[0] + frame->linesize[0] * (frame->height - 1), -frame->linesize[0]);
} else {
ret = SDL_UpdateTexture(tex, NULL, frame->data[0], frame->linesize[0]); ret = SDL_UpdateTexture(tex, NULL, frame->data[0], frame->linesize[0]);
}
break; break;
default: default:
/* This should only happen if we are not using avfilter... */ /* This should only happen if we are not using avfilter... */
@ -949,9 +958,10 @@ static void video_image_display(VideoState *is)
if (upload_texture(vp->bmp, vp->frame, &is->img_convert_ctx) < 0) if (upload_texture(vp->bmp, vp->frame, &is->img_convert_ctx) < 0)
return; return;
vp->uploaded = 1; vp->uploaded = 1;
vp->flip_v = vp->frame->linesize[0] < 0;
} }
SDL_RenderCopy(renderer, vp->bmp, NULL, &rect); SDL_RenderCopyEx(renderer, vp->bmp, NULL, &rect, 0, NULL, vp->flip_v ? SDL_FLIP_VERTICAL : 0);
if (sp) { if (sp) {
#if USE_ONEPASS_SUBTITLE_RENDER #if USE_ONEPASS_SUBTITLE_RENDER
SDL_RenderCopy(renderer, is->sub_texture, NULL, &rect); SDL_RenderCopy(renderer, is->sub_texture, NULL, &rect);

Loading…
Cancel
Save