2010-04-07, 23:52
Here is an attempt to stop the memory leak. Runs smoothly for me:
(edit)
Don't forget to comment out the LOGNOTICE lines when you no longer need them.
Stu-e
Code:
--- DVDFactoryCodec.cpp (revision 29122)
+++ DVDFactoryCodec.cpp (working copy)
@@ -184,7 +184,7 @@
CDVDCodecOptions dvdOptions;
#ifdef HAVE_LIBVDPAU
- if (hint.height >= 720)
+// if (hint.height >= 720)
{
CLog::Log(LOGNOTICE,"Trying VDPAU-MPEG from FFMPEG");
if( (pCodec = OpenCodec(new CDVDVideoCodecFFmpeg(), hint, dvdOptions)) ) return pCodec;
Code:
--- VDPAU.cpp (revision 29122)
+++ VDPAU.cpp (working copy)
@@ -950,6 +950,8 @@
CVDPAU* vdp = (CVDPAU*)ctx->GetHardware();
struct pictureAge* pA = &vdp->picAge;
+ static int VSurfaceRelease = 0;
+
// while we are waiting to recover we can't do anything
if(vdp->recover)
{
@@ -959,16 +961,14 @@
vdpau_render_state * render = NULL;
- // find unused surface
- for(unsigned int i = 0; i < vdp->m_videoSurfaces.size(); i++)
+ if (vdp->m_videoSurfaces.size() >= 50) // Maximum number of surfaces have been created
{
- if(!(vdp->m_videoSurfaces[i]->state & FF_VDPAU_STATE_USED_FOR_REFERENCE))
- {
- render = vdp->m_videoSurfaces[i];
- render->state = 0;
- break;
- }
+ render = vdp->m_videoSurfaces[VSurfaceRelease]; // Re-use oldest surface
+ render->state = 0;
+ if (VSurfaceRelease < (vdp->m_videoSurfaces.size()-1)) VSurfaceRelease++; // Next surface to be released
+ else VSurfaceRelease = 0;
}
+ else VSurfaceRelease = 0; // reset release pointer
VdpStatus vdp_st = VDP_STATUS_ERROR;
if (render == NULL)
@@ -1016,7 +1016,7 @@
}
pic->type= FF_BUFFER_TYPE_USER;
- render->state |= FF_VDPAU_STATE_USED_FOR_REFERENCE;
+// render->state |= FF_VDPAU_STATE_USED_FOR_REFERENCE;
pic->reordered_opaque= avctx->reordered_opaque;
return 0;
}
@@ -1034,7 +1034,7 @@
return;
}
- render->state &= ~FF_VDPAU_STATE_USED_FOR_REFERENCE;
+// render->state &= ~FF_VDPAU_STATE_USED_FOR_REFERENCE;
for(i=0; i<4; i++)
pic->data[i]= NULL;
}
@@ -1126,7 +1126,8 @@
past[0] = past[1];
past[1] = current;
- current = render->surface;
+ current = future;
+ future = render->surface;
if((method == VS_INTERLACEMETHOD_AUTO && pFrame->interlaced_frame)
|| method == VS_INTERLACEMETHOD_VDPAU_BOB
@@ -1173,41 +1174,56 @@
return VC_BUFFER;
}
- VdpVideoSurface past_surfaces[2] = { VDP_INVALID_HANDLE, VDP_INVALID_HANDLE };
- VdpVideoSurface futu_surfaces[1] = { VDP_INVALID_HANDLE };
+ VdpVideoSurface past_surfaces[4] = { VDP_INVALID_HANDLE, VDP_INVALID_HANDLE, VDP_INVALID_HANDLE, VDP_INVALID_HANDLE };
+ VdpVideoSurface futu_surfaces[2] = { VDP_INVALID_HANDLE, VDP_INVALID_HANDLE };
+ uint32_t pastCount = 4;
+ uint32_t futuCount = 2;
if(m_mixerfield == VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME)
{
past_surfaces[1] = past[0];
past_surfaces[0] = past[1];
- futu_surfaces[0] = VDP_INVALID_HANDLE;
+ // current = current
+ futu_surfaces[0] = future;
+ pastCount = 2;
+ futuCount = 1;
+ CLog::Log(LOGNOTICE, "CVDPAU::Decode - Video surfaces %d [%d] %d %d ", futu_surfaces[0],current,past_surfaces[0],past_surfaces[1]);
}
else
{
if(m_mixerstep == 1)
{ // first field
+ past_surfaces[3] = past[0];
+ past_surfaces[2] = past[0];
past_surfaces[1] = past[1];
past_surfaces[0] = past[1];
futu_surfaces[0] = current;
+ // current = current
+ futu_surfaces[1] = future;
}
else
{ // second field
+ past_surfaces[3] = past[0];
+ past_surfaces[2] = past[1];
past_surfaces[1] = past[1];
past_surfaces[0] = current;
- futu_surfaces[0] = VDP_INVALID_HANDLE;
+ // current = current
+ futu_surfaces[0] = future;
+ futu_surfaces[1] = future;
}
+ CLog::Log(LOGNOTICE, "CVDPAU::Decode - Video surfaces %d %d [%d] %d %d %d %d ", futu_surfaces[1],futu_surfaces[0],current,past_surfaces[0],past_surfaces[1],past_surfaces[2],past_surfaces[3]);
}
vdp_st = vdp_presentation_queue_block_until_surface_idle(vdp_flip_queue,outputSurface,&time);
- vdp_st = vdp_video_mixer_render(videoMixer,
+ if (current != VDP_INVALID_HANDLE) vdp_st = vdp_video_mixer_render(videoMixer,
VDP_INVALID_HANDLE,
- 0,
+ 0,
m_mixerfield,
- 2,
+ pastCount,
past_surfaces,
current,
- 1,
+ futuCount,
futu_surfaces,
NULL,
outputSurface,
Don't forget to comment out the LOGNOTICE lines when you no longer need them.
Stu-e