Commits

zeroth  committed 9ac8fde

Did some basic if conditionals on library version numbers to work around
older libraries of ffmpeg.

Started construction of a command queue, to properly have the movie
module respond to a command fully in time, before processing another.

  • Participants
  • Parent commits ec60de7
  • Branches tylerthemovie

Comments (0)

Files changed (7)

 _numericsurfarray src/_numericsurfarray.c $(SDL) $(DEBUG)
 _numericsndarray src/_numericsndarray.c $(SDL) $(MIXER) $(DEBUG)
 movie src/movie.c $(SDL) $(SMPEG) $(DEBUG)
-_movie src/_gsound.c src/_gmovie.c src/gmovie.c $(SDL) $(FFMPEG) $(DEBUG)
+_movie src/_gsound.c src/_gmovie.c src/gmovie.c src/_gcommand.c $(SDL) $(FFMPEG) $(DEBUG)
 scrap src/scrap.c $(SDL) $(SCRAP) $(DEBUG)
 _camera src/_camera.c src/camera_v4l2.c src/camera_v4l.c $(SDL) $(DEBUG)
 pypm src/pypm.c $(SDL) $(PORTMIDI) $(PORTTIME) $(DEBUG)

File src/_gcommand.c

+#include "_gcommand.h"
+
+
+void addCommand(CommandQueue *q, Command *comm)
+{
+	SDL_LockMutex(q->q_mutex);
+	if(!q->first)
+	{
+		q->first=comm;
+		q->size++;
+		SDL_UnlockMutex(q->q_mutex);
+		return;
+	}
+	if(!q->last)
+	{
+		q->last=comm;
+		q->first->next=comm;
+		q->size++;
+		SDL_UnlockMutex(q->q_mutex);
+		return;
+	}
+	q->last->next=comm;
+	q->last=comm;
+	q->size++;
+	SDL_UnlockMutex(q->q_mutex);
+	return;
+}
+
+Command *getCommand(CommandQueue *q)
+{
+	SDL_LockMutex(q->q_mutex);
+	Command *comm;
+	if(!q->last && q->first)
+	{
+		comm=q->first;
+		q->size--;
+		SDL_UnlockMutex(q->q_mutex);
+		return comm;
+	}
+	else if (!q->last && !q->first)
+	{
+		SDL_UnlockMutex(q->q_mutex);
+		return NULL;
+	}
+	comm=q->first;
+	q->first=q->first->next;
+	q->size--;
+	SDL_UnlockMutex(q->q_mutex);
+	return comm;
+}
+
+int hasCommand(CommandQueue *q)
+{
+	if(q->size>0)
+		return 1;
+	return 0;
+}
+
+void flushCommands(CommandQueue *q)
+{
+	SDL_LockMutex(q->q_mutex);
+	Command *prev;
+	Command *cur = q->first;
+	while(cur!=NULL)
+	{
+		prev=cur;
+		cur=cur->next;
+		PyMem_Free(prev);
+		q->size--;
+	}
+	SDL_UnlockMutex(q->q_mutex);
+}

File src/_gcommand.h

+#ifndef _GCOMMAND_H_
+#define _GCOMMAND_H_
+#include <SDL.h>
+#include <SDL_thread.h>
+#include <Python.h>
+
+typedef struct Command
+{
+	int type;
+	struct Command *next;
+	size_t size;
+} Command;
+
+typedef struct CommandQueue
+{
+	int size;
+	SDL_mutex *q_mutex;
+	Command *first;
+	Command *last;
+} CommandQueue;
+
+
+void addCommand(CommandQueue *q, Command *comm);
+Command *getCommand(CommandQueue *q);
+int hasCommand(CommandQueue *q);
+void flushCommands(CommandQueue *q);
+
+#endif /*_GCOMMAND_H_*/

File src/_gmovie.c

     vp = &movie->pictq[movie->pictq_rindex];
     vp->ready =0;
 	//set up the aspect ratio values..
-    if (movie->video_st->sample_aspect_ratio.num)
-        aspect_ratio = av_q2d(movie->video_st->sample_aspect_ratio);
-    else if (movie->video_st->codec->sample_aspect_ratio.num)
-        aspect_ratio = av_q2d(movie->video_st->codec->sample_aspect_ratio);
-    else
-        aspect_ratio = 0;
-    if (aspect_ratio <= 0.0)
-        aspect_ratio = 1.0;
-        
+	if(LIBAVFORMAT_VERSION_INT>= 3415808)
+	{
+	    if (movie->video_st->sample_aspect_ratio.num)
+	        aspect_ratio = av_q2d(movie->video_st->sample_aspect_ratio);
+	    else if (movie->video_st->codec->sample_aspect_ratio.num)
+	        aspect_ratio = av_q2d(movie->video_st->codec->sample_aspect_ratio);
+	    else
+	        aspect_ratio = 0;
+	    if (aspect_ratio <= 0.0)
+	        aspect_ratio = 1.0;
+	}
+	else
+	{
+		aspect_ratio = 1.0;
+	}
     //then we load in width and height values based on the aspect ration and w/h.    
     int w=0;
     int h=0;
     enc->skip_frame= AVDISCARD_DEFAULT;
     enc->skip_idct= AVDISCARD_DEFAULT;
     enc->skip_loop_filter= AVDISCARD_DEFAULT;
-    enc->error_recognition= FF_ER_CAREFUL;
+    if(LIBAVCODEC_VERSION_INT>=3412992) //(52<<16)+(20<<8)+0 ie 52.20.0 
+	{
+	    enc->error_recognition= FF_ER_CAREFUL;
+	}
     enc->error_concealment= 3;
 
 
     movie->finished =0;
     ic=movie->ic;
     int co=0;
-    SDL_Delay(100);
+    SDL_Delay(150);
     movie->last_showtime = av_gettime()/1000.0;
     for(;;)
     {
 
         /* NOTE: ipts is the PTS of the _first_ picture beginning in
            this packet, if any */
-
+		int64_t opaque;
+		if(LIBAVCODEC_VERSION_INT<3412992) //(52<<16)+(20<<8)+0 ie 52.20.0 
+		{
+			opaque=pkt->pts;
+		}
         movie->video_st->codec->reordered_opaque= pkt->pts;
         len1 = avcodec_decode_video(movie->video_st->codec,
                                     frame, &got_picture,
                                     pkt->data, pkt->size);
-
-        if(( pkt->dts == AV_NOPTS_VALUE) && (frame->reordered_opaque != AV_NOPTS_VALUE))
+		if((LIBAVCODEC_VERSION_INT<3412992) && (pkt->dts == AV_NOPTS_VALUE)) //(52<<16)+(20<<8)+0 ie 52.20.0 
+		{  
+			//due to short circuiting this checks first, then if that fails it does the invalid old checks. :)
+			pts=opaque;
+		}
+        else if(( pkt->dts == AV_NOPTS_VALUE) && (frame->reordered_opaque != AV_NOPTS_VALUE))
         {
             pts= frame->reordered_opaque;
         }

File src/_gmovie.h

 #include "surface.h"
 #include "_gsound.h"
 #include "structmember.h"
+#include "_gcommand.h"
 
 /* Library includes */
 /* This is as small as I could make it... */

File test/_dummymovietest.py

+#################################### IMPORTS ###################################
+
+from __future__ import generators
+
+if __name__ == '__main__':
+    import sys
+    import os
+    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
+    parent_dir, pkg_name = os.path.split(pkg_dir)
+    is_pygame_pkg = (pkg_name == 'tests' and
+                     os.path.split(parent_dir)[1] == 'pygame')
+    if not is_pygame_pkg:
+        sys.path.insert(0, parent_dir)
+else:
+    is_pygame_pkg = __name__.startswith('pygame.tests.')
+
+if is_pygame_pkg:
+    from pygame.tests.test_utils import test_not_implemented, unittest, trunk_relative_path
+else:
+    from test.test_utils import test_not_implemented, unittest
+
+
+import pygame
+import pygame._dummybackend as gmovie
+from pygame.locals import *
+
+import os
+import sys
+import time
+
+################################### CONSTANTS ##################################
+filename = "War3.avi"
+
+
+class MovieTypeTest( unittest.TestCase ): 
+    def test_init(self):     
+        pygame.display.init()    
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        self.assertEqual(movie, True)
+
+        #screen = pygame.display.get_surface()
+        #movie = pygame.gmovie.Movie(filename, screen)
+        #self.assertEqual(movie, True)
+        
+        del movie
+        
+    def test_play_pause(self):
+        pygame.display.init()
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        
+        self.assertEqual(movie.playing, False)
+
+        movie.play(-1)
+
+        self.assertEqual(movie.playing, True)
+        self.assertEqual(movie.paused, False)
+
+        movie.pause()
+
+        self.assertEqual(movie.playing, False)
+        self.assertEqual(movie.paused, True)
+        
+        movie.pause()
+    
+        self.assertEqual(movie.playing, True)
+        self.assertEqual(movie.paused, False)
+        
+        del movie
+        
+    def test_stop(self):
+        pygame.display.init()
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        
+        self.assertEqual(movie.playing, False)
+        movie.play(-1)
+        self.assertEqual(movie.playing, True)
+        self.assertEqual(movie.paused, False)
+        movie.stop()
+        self.assertEqual(movie.playing, False)
+        self.assertEqual(movie.paused, False)
+        
+        del movie
+        
+    def test_rewind(self):
+        pygame.display.init()
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        
+        movie.play(-1)
+        time.sleep(2)
+        #equivalent to stop without a time-argument
+        movie.rewind()
+        self.assertEqual(movie.playing, False)
+        self.assertEqual(movie.paused, False)
+        
+        del movie
+
+    def test_width(self):
+        pygame.display.init()
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        print movie.width
+        self.assertEqual(movie.width, 200)
+        
+        del movie
+        
+    def test_height(self):
+        pygame.display.init()
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        print movie.height
+        self.assertEqual(movie.height, 200)
+        
+        del movie
+
+        
+    def test_resize(self):
+        
+        pygame.display.init()
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        
+        movie.play(-1)
+        movie.resize(movie.width/2, movie.height/2)
+        #equivalent to stop without a time-argument
+        
+        self.assertEqual(movie.height, 100)
+        self.assertEqual(movie.width, 100)
+        
+        del movie
+        
+        

File test/_vlcmovietest.py

+#################################### IMPORTS ###################################
+
+from __future__ import generators
+
+if __name__ == '__main__':
+    import sys
+    import os
+    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
+    parent_dir, pkg_name = os.path.split(pkg_dir)
+    is_pygame_pkg = (pkg_name == 'tests' and
+                     os.path.split(parent_dir)[1] == 'pygame')
+    if not is_pygame_pkg:
+        sys.path.insert(0, parent_dir)
+else:
+    is_pygame_pkg = __name__.startswith('pygame.tests.')
+
+if is_pygame_pkg:
+    from pygame.tests.test_utils import test_not_implemented, unittest, trunk_relative_path
+else:
+    from test.test_utils import test_not_implemented, unittest
+
+
+import pygame
+import pygame._vlcbackend as gmovie
+from pygame.locals import *
+
+import os
+import sys
+import time
+
+################################### CONSTANTS ##################################
+filename = "War3.avi"
+
+
+class MovieTypeTest( unittest.TestCase ): 
+    def test_init(self):     
+        pygame.display.init()    
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        self.assertEqual(movie, True)
+
+        #screen = pygame.display.get_surface()
+        #movie = pygame.gmovie.Movie(filename, screen)
+        #self.assertEqual(movie, True)
+        
+        del movie
+        
+    def test_play_pause(self):
+        pygame.display.init()
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        
+        self.assertEqual(movie.playing, False)
+
+        movie.play(-1)
+
+        self.assertEqual(movie.playing, True)
+        self.assertEqual(movie.paused, False)
+
+        movie.pause()
+
+        self.assertEqual(movie.playing, False)
+        self.assertEqual(movie.paused, True)
+        
+        movie.pause()
+    
+        self.assertEqual(movie.playing, True)
+        self.assertEqual(movie.paused, False)
+        
+        del movie
+        
+    def test_stop(self):
+        pygame.display.init()
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        
+        self.assertEqual(movie.playing, False)
+        movie.play(-1)
+        self.assertEqual(movie.playing, True)
+        self.assertEqual(movie.paused, False)
+        movie.stop()
+        self.assertEqual(movie.playing, False)
+        self.assertEqual(movie.paused, False)
+        
+        del movie
+        
+    def test_rewind(self):
+        pygame.display.init()
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        
+        movie.play(-1)
+        time.sleep(2)
+        #equivalent to stop without a time-argument
+        movie.rewind()
+        self.assertEqual(movie.playing, False)
+        self.assertEqual(movie.paused, False)
+        
+        del movie
+
+    def test_width(self):
+        pygame.display.init()
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        print movie.width
+        self.assertEqual(movie.width, 200)
+        
+        del movie
+        
+    def test_height(self):
+        pygame.display.init()
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        print movie.height
+        self.assertEqual(movie.height, 200)
+        
+        del movie
+
+        
+    def test_resize(self):
+        
+        pygame.display.init()
+        pygame.mixer.quit()
+        movie_file = trunk_relative_path('examples/data/blue.mpg')
+        movie = gmovie.Movie(movie_file)
+        
+        movie.play(-1)
+        movie.resize(movie.width/2, movie.height/2)
+        #equivalent to stop without a time-argument
+        
+        self.assertEqual(movie.height, 100)
+        self.assertEqual(movie.width, 100)
+        
+        del movie
+        
+