changeset 29576:fbed30114410

vo_quartz: change deallocation/uninit to more reliably free allocated data.
author reimar
date Wed, 02 Sep 2009 09:51:38 +0000
parents 0e182921966b
children 0ce49cb1b85b
files libvo/vo_quartz.c
diffstat 1 files changed, 20 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/vo_quartz.c	Tue Sep 01 21:16:58 2009 +0000
+++ b/libvo/vo_quartz.c	Wed Sep 02 09:51:38 2009 +0000
@@ -607,12 +607,28 @@
     aspect_save_screenres(vo_screenwidth, vo_screenheight);
 }
 
+static void free_video_specific(void)
+{
+    if (seqId) CDSequenceEnd(seqId);
+    seqId = 0;
+    free(image_data);
+    image_data = NULL;
+    free(P);
+    P = NULL;
+    CGDataProviderRelease(dataProviderRef);
+    dataProviderRef = NULL;
+    CGImageRelease(image);
+    image = NULL;
+}
+
 static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
 {
     WindowAttributes windowAttrs;
     OSErr qterr;
     CGRect tmpBounds;
 
+    free_video_specific();
+
     vo_dwidth  = d_width  *= winSizeMult;
     vo_dheight = d_height *= winSizeMult;
     config_movie_aspect((float)d_width / d_height);
@@ -634,9 +650,6 @@
     }
     image_size = ((imgRect.right * imgRect.bottom * image_depth) + 7) / 8;
 
-    if (image_data)
-        free(image_data);
-
     image_data = malloc(image_size);
 
     // Create player window//////////////////////////////////////////////////
@@ -789,9 +802,6 @@
         {
             mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [pasp] (%d)\n", qterr);
         }
-        if (P != NULL) {        // second or subsequent movie
-            free(P);
-        }
         P = calloc(sizeof(PlanarPixmapInfoYUV420) + image_size, 1);
         switch (image_format)
         {
@@ -1054,29 +1064,10 @@
 
 static void uninit(void)
 {
-    OSErr qterr;
-
-    switch (image_format)
-    {
-    case IMGFMT_YV12:
-    case IMGFMT_IYUV:
-    case IMGFMT_I420:
-    case IMGFMT_UYVY:
-    case IMGFMT_YUY2:
-    {
-        if (EnterMoviesDone)
-        {
-            qterr = CDSequenceEnd(seqId);
-            if (qterr)
-            {
-                mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: CDSequenceEnd (%d)\n", qterr);
-            }
-        }
-        break;
-    }
-    default:
-        break;
-    }
+    free_video_specific();
+    if (EnterMoviesDone)
+        ExitMovies();
+    EnterMoviesDone = 0;
 
     ShowMenuBar();
 }