Commits

Anonymous committed 4e0f348

Added filepath checks. Also began working on desync issue... corrected
audio clock issue which doesn't reset if the video is seeking. Fixed now
with a beautiful little calculation and check, based on the pts of
audio_packets. Now I realize that the video clock doesn't update wholly
properly.

  • Participants
  • Parent commits 71090b3
  • Branches tylerthemovie

Comments (0)

Files changed (5)

File movie_test.py

 # Without a surface argument, the ffmpeg-wrapper uses the sdl_overlay library. 
 #screen=pygame.display.set_mode((640, 368))
 
+try:
+    #this is to test that the movie module tests filenames to make sure they exist
+    m=movie.Movie("gsdsjgsdj")
+except Exception, e:
+    print e
+    del m
+
+
 m = movie.Movie(filename)
 print m.paused  #always False, unless .pause has been called
 print m.playing #False until play has been called. Will return to false when

File src/_gmovie.c

     vp->dest_rect.w = width;
     vp->dest_rect.h = height;
 
-    if (vp->dest_overlay && vp->overlay>0)
+    if (vp->dest_overlay && vp->overlay>0 && !movie->skip_frame)
     {
      #if 0 
         if (movie->sub_st)
             SDL_UnlockYUVOverlay(vp->dest_overlay);
         }
     }
-    else if(vp->dest_surface && vp->overlay<=0)
+    else if(vp->dest_surface && vp->overlay<=0 && !movie->skip_frame)
     {
         SDL_BlitSurface(vp->dest_surface, &vp->dest_rect, movie->canon_surf, &vp->dest_rect);
     }
 
     movie->pictq_rindex= (movie->pictq_rindex+1)%VIDEO_PICTURE_QUEUE_SIZE;
     movie->pictq_size--;
+    if(movie->skip_frame) movie->skip_frame=0;
     video_refresh_timer(movie);
 }
 
     if (movie->video_st)
     { /*shouldn't ever even get this far if no video_st*/
         movie->diff_co ++;
+       
         /* dequeue the picture */
         vp = &movie->pictq[movie->pictq_rindex];
 
             /* skip or repeat frame. We take into account the
                delay to compute the threshold. I still don't know
                if it is the best guess */
+          
             sync_threshold = FFMAX(AV_SYNC_THRESHOLD, delay);
             if (fabs(diff) < AV_NOSYNC_THRESHOLD)
             {
                 if (diff <= -sync_threshold)
+                {
+                    movie->skip_frame=1;
                     delay = 0;
+                }
                 else if (diff >= sync_threshold)
                     delay = 2 * delay;
             }
             actual_delay = 0.010;
         }
         GRABGIL
-        //PySys_WriteStdout("Actual Delay: %f\ndelay: %f\ndiff: %f\n", actual_delay, delay, diff);
+        PySys_WriteStdout("Actual Delay: %f\tdelay: %f\tdiff: %f\tSync_threshold: %f\n", actual_delay, delay, diff, sync_threshold);
         movie->timing = (actual_delay*1000.0)+1;
         RELEASEGIL
     }
+    if(movie->diff_co==2)
+    {
+    	int fun = movie->diff_co;
+    	fun+=200;	
+    }
 }
 
 int queue_picture(PyMovie *movie, AVFrame *src_frame)
     movie->playing=1;
     ic=movie->ic;
     int co=0;
+    int video_packet=0;
     SDL_Delay(150);
     movie->last_showtime = av_gettime()/1000.0;
     for(;;)
             else if (pkt->stream_index == movie->video_stream)
             {
                 packet_queue_put(&movie->videoq, pkt);
+            	video_packet=1;
             }
             #if 0
             else if (pkt->stream_index == movie->sub_stream)
                 }
             }
          #endif
-        if(movie->video_st)
+        if(movie->video_st && video_packet)
+        {
             video_render(movie);
+        	video_packet=0;
+        }
         /*if(movie->audio_st)
             audio_thread(movie);*/
         #if 0
         	subtitle_render(movie);
         #endif
         if(co<2)
+        {
             video_refresh_timer(movie);
+        }
         if(movie->timing>0)
         {
             double showtime = movie->timing+movie->last_showtime;

File src/_gmovie.h

     SDL_Surface     *canon_surf;     //pointer to the surface given by the programmer. We do NOT free this... it is not ours. We just write to it.
     PyThreadState   *_tstate;        //really do not touch this unless you have to. This is used for threading control and primitives.
 	int finished;
+	int skip_frame;
 	
 	/* command queue stuff */
     CommandQueue *commands;

File src/_gsound.c

     Mix_Chunk *mix;
     int false=0;
     int allocated=0;
-    
     if(!ainfo->ended && (ainfo->queue.size>0||ainfo->playing))
     {
         if(buf)
         else
         {
             //callback call, and convenienty enough, the queue has a buffer ready to go, so we copy it into buf
-            BufferNode *new;
-            queue_get(&ainfo->queue, &new);
-            if(!new)
+            BufferNode *newNode;
+            queue_get(&ainfo->queue, &newNode);
+            if(!newNode)
             {
                 //SDL_mutexV(ainfo->mutex);
                 return -1;
             }
-            ainfo->current_frame_size=new->len;
-            buf = (uint8_t *)PyMem_Malloc((size_t)new->len);
-            memcpy(buf, new->buf, new->len);
-            len=new->len;
-            PyMem_Free(new->buf);
-            new->buf=NULL;
-            PyMem_Free(new);
-            new=NULL;
+            ainfo->current_frame_size=newNode->len;
+            pts=newNode->pts;
+            buf = (uint8_t *)PyMem_Malloc((size_t)newNode->len);
+            memcpy(buf, newNode->buf, newNode->len);
+            len=newNode->len;
+            PyMem_Free(newNode->buf);
+            newNode->buf=NULL;
+            PyMem_Free(newNode);
+            newNode=NULL;
             allocated=1;
         }
     }
 	{
     	int bytes_per_sec = ainfo->channels*ainfo->sample_rate*2;
     	ainfo->audio_clock+= (double) len/(double) bytes_per_sec;
+    	int n_pkts = bytes_per_sec/len;
+    	double change = (double)pts/(double)n_pkts;
+    	if((change-ainfo->audio_clock)> 0.1)
+    	{
+    		ainfo->audio_clock = change;
+    	}
 	}
     ainfo->current_frame_size =len;
     int chan = ainfo->channel;
 }
 int seekBuffer (uint8_t *buf, uint32_t len, int channel)
 {
-    stopBuffer(channel);
-    return playBuffer(buf, len, channel, 0);
+	/*we need to flush our buffer */
+	queue_flush(&ainfo->queue);
+	ainfo->ended=1;
+	return 1;
 }
 
 int setCallback(void (*callback)(int channel))

File src/gmovie.c

         self->overlay = 0;
         self->canon_surf=surf;
     }
+    /* filename checking... */
+    PyObject *path = PyImport_ImportModule("os.path");
+    Py_INCREF(path);
+    PyObject *dict = PyModule_GetDict(path);
+    PyObject *key = Py_BuildValue("s", "exists");
+    Py_INCREF(key);
+	PyObject *existsFunc  = PyDict_GetItem(dict, key);
+	PyObject *boolean = PyObject_CallFunction(existsFunc, "s", filename);
+	Py_INCREF(boolean);
+	if(boolean==Py_False)
+	{
+		Py_DECREF(boolean);
+		Py_DECREF(key);
+		Py_DECREF(path);
+		RAISE(PyExc_ValueError, "This filename does not exist.");
+		return;
+		//Py_RETURN_NONE;
+	}
+	Py_DECREF(boolean);
+	Py_DECREF(key);
+	Py_DECREF(path);    
+    
     self->start_time = AV_NOPTS_VALUE;
     stream_open(self, filename, NULL, 0);
     //PySys_WriteStdout("Time-base-a: %f\n", av_q2d(self->audio_st->codec->time_base));