Commits

zeroth  committed 1548c2a

Fixed memory leak issues. Now only gains 0.1 MB per play.

  • Participants
  • Parent commits a2c558c
  • Branches tylerthemovie

Comments (0)

Files changed (3)

File src/_gmovie.c

         screen = SDL_GetVideoSurface ();
         if (!screen)
 		{
-			GRABGIL
-            RAISE (PyExc_SDLError, "Display mode not set");
-        	Py_DECREF(is);
-        	RELEASEGIL
-        	return -1;
+			screen = SDL_SetVideoMode(w, h, 0, SDL_SWSURFACE);
+			if(!screen)
+			{
+				GRABGIL
+	        	RAISE(PyExc_SDLError, "Could not initialize a new video surface.");
+	        	Py_DECREF(is);
+	        	RELEASEGIL
+	        	return -1;	
+			}
 		}
         vp->dest_overlay = SDL_CreateYUVOverlay (w, h, SDL_YV12_OVERLAY, screen);
         if (!vp->dest_overlay)
     int dst_pix_fmt;
     AVPicture pict;
     VidPicture *vp;
-    struct SwsContext *img_convert_ctx=NULL;
+    struct SwsContext *img_convert_ctx=movie->img_convert_ctx;
 
 	vp = &movie->pictq[movie->pictq_windex];
 	
             fprintf(stderr, "Cannot initialize the conversion context\n");
             exit(1);
         }
+        movie->img_convert_ctx = img_convert_ctx;
         sws_scale(img_convert_ctx, src_frame->data, src_frame->linesize,
                   0, movie->video_st->codec->height, pict.data, pict.linesize);
 
         RELEASEGIL
         return -1;
     }
+    
     enc = ic->streams[stream_index]->codec;
-
     /* prepare audio output */
     if (enc->codec_type == CODEC_TYPE_AUDIO) {
         if (enc->channels > 0) {
     is->dest_mutex = SDL_CreateMutex();
 	
     is->subpq_mutex = SDL_CreateMutex();
-    is->subpq_cond = SDL_CreateCond();
+    //is->subpq_cond = SDL_CreateCond();
     
     is->paused = 1;
     is->av_sync_type = AV_SYNC_VIDEO_MASTER;
         ret = -1;
         goto fail;
     }
-    is->ic = ic;
     err = av_find_stream_info(ic);
     if (err < 0) {
     	GRABGIL
     if(ic->pb)
         ic->pb->eof_reached= 0; //FIXME hack, ffplay maybe should not use url_feof() to test for the end
 	
+
+	is->ic = ic;
     /* if seeking requested, we execute it */
     if (is->start_time != AV_NOPTS_VALUE) {
         int64_t timestamp;
  fail:
     /* disable interrupting */
 
+	//if(ap)
+	//	av_freep(params);
 	if(ret!=0)
 	{
 		GRABGIL
 		RELEASEGIL
 		return is;
 	}
+	
 	GRABGIL
 	Py_DECREF(is);
     RELEASEGIL
     		}
 		SDL_DestroyMutex(is->dest_mutex);
      	SDL_DestroyMutex(is->subpq_mutex);
-        SDL_DestroyCond(is->subpq_cond);
+        //SDL_DestroyCond(is->subpq_cond);
+    	if(is->img_convert_ctx)
+    	{
+    		sws_freeContext(is->img_convert_ctx);
+    		is->img_convert_ctx=NULL;
+    	}
     }
     /* close each stream */
     if (is->audio_stream >= 0)
 		movie->loops--;
 		movie=stream_open(movie, movie->filename, NULL);
 		movie->paused=0;
-		state =decoder(movie);	
-	}	
+		state =decoder(movie);
+		stream_component_close(movie, movie->video_st->index);
+	}
+	if(gstate==PyGILState_LOCKED) RELEASEGIL	
 	return state;
 }
 
 	ic=is->ic;
 	int co=0;
 	is->last_showtime = av_gettime()/1000.0;
-    video_open(is, is->pictq_windex);
+    //video_open(is, is->pictq_windex);
     for(;;) {
 		//PySys_WriteStdout("decoder: loop %i.\n", co);
 		co++;
 	        if (ret < 0) {
 	            if (ret != AVERROR_EOF && url_ferror(ic->pb) == 0) {
 	                goto fail;
-	                continue;
 	            } else
 	            {
 	                break;

File src/_gmovie.h

 	PacketQueue videoq;
 	SDL_mutex *videoq_mutex;
 	SDL_cond *videoq_cond;
+	struct SwsContext *img_convert_ctx;
 
 	/* subtitle members */	
     SDL_Thread *subtitle_tid;                    //thread id for subtitle decode thread

File src/gmovie.c

 	PyEval_InitThreads();
 	DECLAREGIL
 	Py_INCREF(movie);
+    PySys_WriteStdout("Inside .play\n");
     int loops;
     if(!PyArg_ParseTuple(args, "i", &loops))
     {