Add aspect change support to software decoder path

This commit is contained in:
Johns 2012-01-29 23:57:22 +01:00
parent 1886b745e5
commit e613ff1f7e
3 changed files with 150 additions and 167 deletions

View File

@ -1,6 +1,7 @@
User johns
Date:
Add aspect change support to software decoder path.
Repair software decoder with vaapi vdpau backend.
Add workaround for Intel VA-API MPEG GPU hung.

1
Todo
View File

@ -44,6 +44,7 @@ video:
OSD can only be shown after some stream could be shown
vdpau:
software decoder path not working
libva:
yaepghd (VaapiSetOutputPosition) support

193
video.c
View File

@ -1868,8 +1868,7 @@ static enum PixelFormat Vaapi_get_format(VaapiDecoder * decoder,
// cleanup last context
VaapiCleanup(decoder);
if (!VideoHardwareDecoder
|| (video_ctx->codec_id == CODEC_ID_MPEG2VIDEO
if (!VideoHardwareDecoder || (video_ctx->codec_id == CODEC_ID_MPEG2VIDEO
&& VideoHardwareDecoder == 1)
) { // hardware disabled by config
Debug(3, "codec: hardware acceleration disabled\n");
@ -2114,8 +2113,10 @@ static void VaapiPutSurfaceX11(VaapiDecoder * decoder, VASurfaceID surface,
}
e = GetMsTicks();
if (e - s > 2000) {
Error(_("video/vaapi: gpu hung %d ms %d\n"), e - s, decoder->FrameCounter);
fprintf(stderr, _("video/vaapi: gpu hung %d ms %d\n"), e - s, decoder->FrameCounter);
Error(_("video/vaapi: gpu hung %d ms %d\n"), e - s,
decoder->FrameCounter);
fprintf(stderr, _("video/vaapi: gpu hung %d ms %d\n"), e - s,
decoder->FrameCounter);
}
if (0) {
@ -2335,11 +2336,9 @@ static void VaapiSetup(VaapiDecoder * decoder,
width = video_ctx->width;
height = video_ctx->height;
// FIXME: remove this if
if (decoder->Image->image_id != VA_INVALID_ID) {
if (vaDestroyImage(VaDisplay, decoder->Image->image_id)
!= VA_STATUS_SUCCESS) {
Error("video/vaapi: can't destroy image!\n");
}
abort(); // should be done by VaapiCleanup()
}
VaapiFindImageFormat(decoder, video_ctx->pix_fmt, format);
@ -2810,8 +2809,10 @@ static void VaapiBlackSurface(VaapiDecoder * decoder)
put1 = GetMsTicks();
if (put1 - sync > 2000) {
Error(_("video/vaapi: gpu hung %d ms %d\n"), put1 - sync, decoder->FrameCounter);
fprintf(stderr, _("video/vaapi: gpu hung %d ms %d\n"), put1 - sync, decoder->FrameCounter);
Error(_("video/vaapi: gpu hung %d ms %d\n"), put1 - sync,
decoder->FrameCounter);
fprintf(stderr, _("video/vaapi: gpu hung %d ms %d\n"), put1 - sync,
decoder->FrameCounter);
}
Debug(4, "video/vaapi: sync %2u put1 %2u\n", sync - start, put1 - sync);
@ -3255,20 +3256,8 @@ static void VaapiRenderFrame(VaapiDecoder * decoder,
const AVCodecContext * video_ctx, const AVFrame * frame)
{
VASurfaceID surface;
if (video_ctx->height != decoder->InputHeight
|| video_ctx->width != decoder->InputWidth) {
Debug(3, "video/vaapi: stream <-> surface size mismatch\n");
}
//
// Hardware render
//
if (video_ctx->hwaccel_context) {
int interlaced;
surface = (unsigned)(size_t) frame->data[3];
Debug(4, "video/vaapi: hw render hw surface %#x\n", surface);
// FIXME: some tv-stations toggle interlace on/off
// frame->interlaced_frame isn't always correct set
interlaced = frame->interlaced_frame;
@ -3286,27 +3275,6 @@ static void VaapiRenderFrame(VaapiDecoder * decoder,
interlaced = 1;
}
// update aspect ratio changes
#ifdef still_to_detect_define
if (av_cmp_q(decoder->InputAspect, frame->sample_aspect_ratio)) {
Debug(3, "video/vaapi: aspect ratio changed\n");
//decoder->InputWidth = video_ctx->width;
//decoder->InputHeight = video_ctx->height;
decoder->InputAspect = frame->sample_aspect_ratio;
VaapiUpdateOutput(decoder);
}
#else
if (av_cmp_q(decoder->InputAspect, video_ctx->sample_aspect_ratio)) {
Debug(3, "video/vaapi: aspect ratio changed\n");
//decoder->InputWidth = video_ctx->width;
//decoder->InputHeight = video_ctx->height;
decoder->InputAspect = video_ctx->sample_aspect_ratio;
VaapiUpdateOutput(decoder);
}
#endif
// FIXME: should be done by init video_ctx->field_order
if (decoder->Interlaced != interlaced
|| decoder->TopFieldFirst != frame->top_field_first) {
@ -3316,19 +3284,50 @@ static void VaapiRenderFrame(VaapiDecoder * decoder,
Debug(3, "video/vaapi: interlaced %d top-field-first %d - %d\n",
interlaced, frame->top_field_first, video_ctx->field_order);
#else
Debug(3, "video/vaapi: interlaced %d top-field-first %d\n",
interlaced, frame->top_field_first);
Debug(3, "video/vaapi: interlaced %d top-field-first %d\n", interlaced,
frame->top_field_first);
#endif
decoder->Interlaced = interlaced;
decoder->TopFieldFirst = frame->top_field_first;
decoder->SurfaceField = 1;
}
// update aspect ratio changes
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,60,100)
if (decoder->InputWidth && decoder->InputHeight
&& av_cmp_q(decoder->InputAspect, frame->sample_aspect_ratio)) {
Debug(3, "video/vaapi: aspect ratio changed\n");
decoder->InputAspect = frame->sample_aspect_ratio;
VaapiUpdateOutput(decoder);
}
#else
if (decoder->InputWidth && decoder->InputHeight
&& av_cmp_q(decoder->InputAspect, video_ctx->sample_aspect_ratio)) {
Debug(3, "video/vaapi: aspect ratio changed\n");
decoder->InputAspect = video_ctx->sample_aspect_ratio;
VaapiUpdateOutput(decoder);
}
#endif
//
// Hardware render
//
if (video_ctx->hwaccel_context) {
if (video_ctx->height != decoder->InputHeight
|| video_ctx->width != decoder->InputWidth) {
Error(_("video/vaapi: stream <-> surface size mismatch\n"));
return;
}
surface = (unsigned)(size_t) frame->data[3];
Debug(4, "video/vaapi: hw render hw surface %#x\n", surface);
if (interlaced
&& VideoDeinterlace[decoder->Resolution] ==
VideoDeinterlaceSoftware) {
// FIXME: software deinterlace avpicture_deinterlace
VaapiCpuDeinterlace(decoder, surface);
} else {
VaapiQueueSurface(decoder, surface, 0);
@ -3356,33 +3355,24 @@ static void VaapiRenderFrame(VaapiDecoder * decoder,
|| width != decoder->InputWidth
|| height != decoder->InputHeight) {
Debug(3,
"video/vaapi: stream <-> surface size/interlace mismatch\n");
decoder->CropX = 0;
decoder->CropY = VideoSkipLines;
decoder->CropWidth = video_ctx->width;
decoder->CropHeight = video_ctx->height - VideoSkipLines * 2;
decoder->CropWidth = width;
decoder->CropHeight = height - VideoSkipLines * 2;
decoder->PixFmt = video_ctx->pix_fmt;
// FIXME: aspect done above!
decoder->InputWidth = width;
decoder->InputHeight = height;
VaapiSetup(decoder, video_ctx);
// FIXME: bad interlace like hw-part
// FIXME: aspect ratio
//
// detect interlaced input
//
Debug(3, "video/vaapi: interlaced %d top-field-first %d\n",
frame->interlaced_frame, frame->top_field_first);
decoder->Interlaced = frame->interlaced_frame;
decoder->TopFieldFirst = frame->top_field_first;
decoder->SurfaceField = 1;
// FIXME: I hope this didn't change in the middle of the stream
VaapiUpdateOutput(decoder);
}
// FIXME: Need to insert software deinterlace here
// FIXME: can insert auto-crop here
// FIXME: can/must insert auto-crop here
// get a free surface and upload the image
surface = VaapiGetSurface(decoder);
@ -3426,8 +3416,8 @@ static void VaapiRenderFrame(VaapiDecoder * decoder,
}
}
// vdpau uses this
} else if (decoder->Image->format.fourcc
== VA_FOURCC('I', '4', '2', '0') ) {
} else if (decoder->Image->format.fourcc == VA_FOURCC('I', '4', '2',
'0')) {
picture->data[0] = va_image_data + decoder->Image->offsets[0];
picture->linesize[0] = decoder->Image->pitches[0];
picture->data[1] = va_image_data + decoder->Image->offsets[1];
@ -3449,7 +3439,8 @@ static void VaapiRenderFrame(VaapiDecoder * decoder,
width, height);
}
if (vaUnmapBuffer(VaDisplay, decoder->Image->buf) != VA_STATUS_SUCCESS) {
if (vaUnmapBuffer(VaDisplay, decoder->Image->buf)
!= VA_STATUS_SUCCESS) {
Error(_("video/vaapi: can't unmap the image!\n"));
}
@ -5465,8 +5456,7 @@ static enum PixelFormat Vdpau_get_format(VdpauDecoder * decoder,
Debug(3, "video: new stream format %d\n", GetMsTicks() - VideoSwitch);
VdpauCleanup(decoder);
if (!VideoHardwareDecoder
|| (video_ctx->codec_id == CODEC_ID_MPEG2VIDEO
if (!VideoHardwareDecoder || (video_ctx->codec_id == CODEC_ID_MPEG2VIDEO
&& VideoHardwareDecoder == 1)
) { // hardware disabled by config
Debug(3, "codec: hardware acceleration disabled\n");
@ -6023,21 +6013,8 @@ static void VdpauRenderFrame(VdpauDecoder * decoder,
{
VdpStatus status;
VdpVideoSurface surface;
//
// Hardware render
//
// VDPAU: PIX_FMT_VDPAU_H264 .. PIX_FMT_VDPAU_VC1 PIX_FMT_VDPAU_MPEG4
if ((PIX_FMT_VDPAU_H264 <= video_ctx->pix_fmt
&& video_ctx->pix_fmt <= PIX_FMT_VDPAU_VC1)
|| video_ctx->pix_fmt == PIX_FMT_VDPAU_MPEG4) {
struct vdpau_render_state *vrs;
int interlaced;
vrs = (struct vdpau_render_state *)frame->data[0];
surface = vrs->surface;
Debug(4, "video/vdpau: hw render hw surface %#x\n", surface);
// FIXME: some tv-stations toggle interlace on/off
// frame->interlaced_frame isn't always correct set
interlaced = frame->interlaced_frame;
@ -6055,44 +6032,54 @@ static void VdpauRenderFrame(VdpauDecoder * decoder,
interlaced = 1;
}
// FIXME: should be done by init video_ctx->field_order
if (decoder->Interlaced != interlaced
|| decoder->TopFieldFirst != frame->top_field_first) {
Debug(3, "video/vdpau: interlaced %d top-field-first %d\n", interlaced,
frame->top_field_first);
decoder->Interlaced = interlaced;
decoder->TopFieldFirst = frame->top_field_first;
decoder->SurfaceField = 0;
}
// update aspect ratio changes
#ifdef still_to_detect_define
if (av_cmp_q(decoder->InputAspect, frame->sample_aspect_ratio)) {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,60,100)
if (decoder->InputWidth && decoder->InputHeight
&& av_cmp_q(decoder->InputAspect, frame->sample_aspect_ratio)) {
Debug(3, "video/vdpau: aspect ratio changed\n");
//decoder->InputWidth = video_ctx->width;
//decoder->InputHeight = video_ctx->height;
decoder->InputAspect = frame->sample_aspect_ratio;
VdpauUpdateOutput(decoder);
}
#else
if (av_cmp_q(decoder->InputAspect, video_ctx->sample_aspect_ratio)) {
if (decoder->InputWidth && decoder->InputHeight
&& av_cmp_q(decoder->InputAspect, frame->sample_aspect_ratio)) {
Debug(3, "video/vdpau: aspect ratio changed\n");
//decoder->InputWidth = video_ctx->width;
//decoder->InputHeight = video_ctx->height;
decoder->InputAspect = video_ctx->sample_aspect_ratio;
VdpauUpdateOutput(decoder);
}
#endif
//
// Hardware render
//
// VDPAU: PIX_FMT_VDPAU_H264 .. PIX_FMT_VDPAU_VC1 PIX_FMT_VDPAU_MPEG4
if ((PIX_FMT_VDPAU_H264 <= video_ctx->pix_fmt
&& video_ctx->pix_fmt <= PIX_FMT_VDPAU_VC1)
|| video_ctx->pix_fmt == PIX_FMT_VDPAU_MPEG4) {
struct vdpau_render_state *vrs;
vrs = (struct vdpau_render_state *)frame->data[0];
surface = vrs->surface;
Debug(4, "video/vdpau: hw render hw surface %#x\n", surface);
if (VideoDeinterlace[decoder->Resolution] == VideoDeinterlaceSoftware
&& interlaced) {
// FIXME: software deinterlace avpicture_deinterlace
// FIXME: VdpauCpuDeinterlace(decoder, surface);
} else {
// FIXME: should be done by init
if (decoder->Interlaced != interlaced
|| decoder->TopFieldFirst != frame->top_field_first) {
Debug(3, "video/vdpau: interlaced %d top-field-first %d\n",
interlaced, frame->top_field_first);
decoder->Interlaced = interlaced;
decoder->TopFieldFirst = frame->top_field_first;
decoder->SurfaceField = 0;
}
VdpauQueueSurface(decoder, surface, 0);
}
@ -6103,8 +6090,6 @@ static void VdpauRenderFrame(VdpauDecoder * decoder,
void const *data[3];
uint32_t pitches[3];
// FIXME: aspect change not supported!
//
// Check image, format, size
//
@ -6126,10 +6111,6 @@ static void VdpauRenderFrame(VdpauDecoder * decoder,
//
Debug(3, "video/vdpau: interlaced %d top-field-first %d\n",
frame->interlaced_frame, frame->top_field_first);
decoder->Interlaced = frame->interlaced_frame;
decoder->TopFieldFirst = frame->top_field_first;
decoder->SurfaceField = 0;
// FIXME: I hope this didn't change in the middle of the stream
VdpauCleanup(decoder);