Anonymous avatar Anonymous committed b69c7ba

Managed to start compilation process for ff_movie.c. Still lots of
errors to fix before compilation will be fixed.

Comments (0)

Files changed (11)

 SCRAP = -lX11
 PORTMIDI = -lportmidi
 PORTTIME = -lporttime
+FFMPEG   = --lavcodec -lavdevice -lavformat -lavutil -lswscale
 #--EndConfig
 
 #DEBUG = -C-W -C-Wall
 _numericsurfarray src/_numericsurfarray.c $(SDL) $(DEBUG)
 _numericsndarray src/_numericsndarray.c $(SDL) $(MIXER) $(DEBUG)
 movie src/movie.c $(SDL) $(SMPEG) $(DEBUG)
+gmovie src/ff_movie.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)
 
 #these get prefixes with '/usr' and '/usr/local' or the $LOCALBASE
 origincdirs = ['/include', '/include/SDL', '/include/SDL',
-               '/include/smpeg' ]
+               '/include/smpeg', 'include/ffmpeg']
 origlibdirs = ['/lib','/lib64','/X11R6/lib']
 
 def confirm(message):
         Dependency('SCRAP', '', 'libX11', ['X11']),
         Dependency('PORTMIDI', 'portmidi.h', 'libportmidi.so', ['portmidi']),
         Dependency('PORTTIME', 'porttime.h', 'libporttime.so', ['porttime']),
+        Dependency('FFMPEG', 'ffmpeg/avformat.h', 'libavformat.so', ['avformat', 'avdevice', 'avcodec',  'avutil', 'swscale']),        
+        #Dependency('FFMPEG', 'ffmpeg/avformat.h',  'libavformat.so', ['avformat']) ,
+        #Dependency('FFMPEG', 'ffmpeg/avstring.h',  'libavstring.so', ['avstring']) ,
+        #Dependency('FFMPEG', 'ffmpeg/swscale.h',  'libswscale.so', ['swscale']) ,
+        #Dependency('FFMPEG', 'ffmpeg/avcodec.h',  'libavcodec.so', ['avcodec']) ,
+        #Dependency('FFMPEG', 'libavdevice/avdevice.h',  'libavdevice.so', ['avdevice']) ,
         #Dependency('GFX', 'SDL_gfxPrimitives.h', 'libSDL_gfx.so', ['SDL_gfx']),
     ]
     if not DEPS[0].found:
 
 import sys
 
-__all__ = ['geterror']
+__all__ = ['geterror', 'long_', 'xrange_', 'ord_', 'unichr_',
+           'unicode_', 'raw_input_']
 
 def geterror ():
     return sys.exc_info()[1]
 
 import os, sys
 
+#Python 3 compatibility
+try:
+    bytes
+except NameError:
+    def toascii(raw):
+        return raw.decode('ascii', 'ignore').encode('ascii')
+else:
+    def toascii(raw):
+        return raw.decode('ascii', 'ignore')
 
 #create simple version of the font name
 def _simplename(name):
-    for char in '_ -':
-        name = name.replace(char, '')
-    name = name.lower()
-    name = name.replace('-', '')
-    name = name.replace("'", '')
-    return name
+    return ''.join([c.lower() for c in name if c.isalnum()])
 
 
 #insert a font and style into the font dictionary
 
 #read of the fonts on osx (fill me in!)
 def initsysfonts_darwin():
+    # if the X11 binary exists... try and use that.
+    #  TODO: Not likely to be there on pre 10.4.x ...
+    #    so still need to do other OSX specific method.
+    if os.path.exists("/usr/X11/bin/fc-list"):
+        return initsysfonts_unix()
+
     paths = ['/Library/Fonts',
              '~/Library/Fonts',
              '/Local/Library/Fonts',
 
 #read the fonts on unix
 def initsysfonts_unix():
+    import subprocess
+
     fonts = {}
 
     # we use the fc-list from fontconfig to get a list of fonts.
 
     try:
-        # note, we use popen3 for if fc-list isn't there to stop stderr printing.
-        flin, flout, flerr = os.popen3('fc-list : file family style')
-    except:
+        # note, we capture stderr so if fc-list isn't there to stop stderr printing.
+        flout, flerr = subprocess.Popen('fc-list : file family style', shell=True,
+                                        stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+                                        close_fds=True).communicate()
+    except Exception:
         return fonts
 
+    entries = toascii(flout)
     try:
-        for line in flout:
+        for line in entries.split('\n'):
             try:
                 filename, family, style = line.split(':', 2)
                 if filename[-4:].lower() in ['.ttf', '.ttc']:
                     bold = style.find('Bold') >= 0
                     italic = style.find('Italic') >= 0
                     oblique = style.find('Oblique') >= 0
-                    _addfont(_simplename(family), bold, italic or oblique, filename, fonts)
-            except:
+                    for name in family.split(','):
+                        if name:
+                            break
+                    else:
+                        name = os.path.splitext(os.path.basename(filename))[0]
+                    _addfont(_simplename(name),
+                             bold, italic or oblique, filename, fonts)
+            except Exception:
                 # try the next one.
                 pass
-    except:
+    except Exception:
         pass
 
     return fonts
     """
     if not Sysfonts:
         initsysfonts()
-    return Sysfonts.keys()
+    return list(Sysfonts.keys())
 
 
 def match_font(name, bold=0, italic=0):
                 elif bold:
                     bold = 0
                 elif not fontname:
-                    fontname = styles.values()[0]
+                    fontname = list(styles.values())[0]
         if fontname: break
     return fontname
 

src/audioconvert.h

  */
 
 
-#include "avcodec.h"
+#include <ffmpeg/avcodec.h>
 
 
 /**
  * Imported by movie.py(hopefully)
  */
 
-#include <ctype.h>
-#include <Python.h>
-#include <math.h>
-#include <limits.h>
+
+#include <ffmpeg/avcodec.h>
+#include <ffmpeg/avformat.h>
 #include <ffmpeg/avstring.h>
-#include <ffmpeg/rtsp.h>
+//#include <ffmpeg/rtsp.h>
 #include <ffmpeg/swscale.h>
-#include <ffmpeg/opt.h>
+//#include <ffmpeg/opt.h>
 #include <libavdevice/avdevice.h>
 
 #include "pygamedocs.h"
 #define FF_REFRESH_EVENT (SDL_USEREVENT + 1)
 #define FF_QUIT_EVENT    (SDL_USEREVENT + 2)
 
+//static int sws_flags = SWS_BICUBIC;
+
 
 /*internal functions for video playing. Not accessible to Python */
 
-int __Y[256];
-int __CrtoR[256];
-int __CrtoG[256];
-int __CbtoG[256];
-int __CbtoB[256];
-
-void initializeLookupTables() {
-
-    float f;
-    int i;
-
-    for(i=0; i<256; i++) {
-
-        f = ( float)i;
-
-        __Y[i] = (int)( 1.164 * ( f-16.0) );
-
-        __CrtoR[i] = (int)( 1.596 * ( f-128.0) );
-
-        __CrtoG[i] = (int)( 0.813 * ( f-128.0) );
-        __CbtoG[i] = (int)( 0.392 * ( f-128.0) );
-
-        __CbtoB[i] = (int)( 2.017 * ( f-128.0) );
-    }
-}
-
 
 /* packet queue handling */
 static void packet_queue_init(PacketQueue *q)
     return ret;
 }
 
+#define BPP 1
+
 static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect, int imgw, int imgh)
 {
     int wrap, wrap3, width2, skip2;
         }
     }
 }
-
 static void free_subpicture(SubPicture *sp)
 {
     int i;
 
     //vp = &is->pictq[is->pictq_rindex];
     PyVideoStream *pvs = (PyVideoStream *)PySequence_GetItem(is->streams, (Py_ssize_t) is->video_stream);
-    PyINCREF((PyObject *)pvs);
+    Py_INCREF((PyObject *)pvs);
     
     vp = &pvs->pictq[pvs->pictq_rindex];
     if (pvs->out_surf || pvs->bmp) {
         {
             PySubtitleStream *pss;
             pss = (PySubtitleStream *)PySequence_GetItem(is->streams, (Py_ssize_t) is->subtitle_stream);
-            PyINCREF((PyObject *)pss);
+            Py_INCREF((PyObject *)pss);
             
             if (pss->subpq_size > 0)
             {
                 sp = &pss->subpq[pss->subpq_rindex];
 
-                if (pvs->pts >= pss->pts + ((float) pss->sub.start_display_time / 1000))
+                if (pvs->pts >= pss->pts + ((float) sp->sub.start_display_time / 1000))
                 {
 
                     if(is->overlay>0)
                         pict.linesize[1] = pvs->bmp->pitches[2];
                         pict.linesize[2] = pvs->bmp->pitches[1];
 
-                        for (i = 0; i < pss->sub.num_rects; i++)
-                            blend_subrect(&pict, pss->sub.rects[i],
+                        for (i = 0; i < sp->sub.num_rects; i++)
+                            blend_subrect(&pict, sp->sub.rects[i],
                                           pvs->bmp->w, pvs->bmp->h);
 
                         SDL_UnlockYUVOverlay (pvs->bmp);
                     }
                     else
                     {
-                        if (pvs->out_surf->flags & SDL_OPENGL && !(pvs->out_surf->flags & (SDL_OPENGLBLIT & ~SDL_OPENGL)))
+                        /*if (pvs->out_surf->flags & SDL_OPENGL && !(pvs->out_surf->flags & (SDL_OPENGLBLIT & ~SDL_OPENGL)))
                                 return RAISE (PyExc_SDLError,
-                                              "Cannot blit to OPENGL Surfaces (OPENGLBLIT is ok)");
+                                              "Cannot blit to OPENGL Surfaces (OPENGLBLIT is ok)");*/
                         SDL_LockSurface(pvs->out_surf);
                         pict.data[0] = pvs->out_surf->pixels[0];
                         pict.data[1] = pvs->out_surf->pixels[1];
                         pict.linesize[1] = pvs->out_surf->pitch;
                         pict.linesize[2] = pvs->out_surf->pitch;
 
-                        for (i = 0; i < pss->sub.num_rects; i++)
+                        for (i = 0; i < sp->sub.num_rects; i++)
                             //TODO:check if blend_subrect works with RGB
-                            blend_subrect(&pict, pss->sub.rects[i],
+                            blend_subrect(&pict, sp->sub.rects[i],
                                           pvs->out_surf->w, pvs->out_surf->h);
                                               
-                        
+                        SDL_UnlockSurface(pvs->out_surf);
                     }
                 }
             }
 
     PyVideoStream *pvs;
     pvs = (PyVideoStream *)PySequence_GetItem(is->streams, (Py_ssize_t) is->video_stream);
-    PyINCREF((PyObject *) pvs);
+    Py_INCREF((PyObject *) pvs);
     
     w = pvs->video_st->codec->width;
     h = pvs->video_st->codec->height;
         if (!pvs->bmp)
             return RAISE (PyExc_SDLError, "Cannot create overlay");
 
-        
+    } 
     else if (!pvs->out_surf && is->overlay<=0)
     {
+        int flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
         //we create a pygame surface
         SDL_Surface *screen;
         #ifndef __APPLE__
 
     pvs->width = w;
     pvs->height = h;
-    PyDECREF((PyObject *) pvs);
+    Py_DECREF((PyObject *) pvs);
     return 0;
 }
 
     SDL_AddTimer(delay, sdl_refresh_timer_cb, is);
 }
 
+static int audio_write_get_buf_size(PyMovie *is)
+{
+    PyAudioStream *pas = (PyAudioStream *)PySequence_GetItem(is->streams, (Py_ssize_t) is->audio_stream);
+    Py_INCREF((PyObject *) pas);
+    int temp = pas->audio_buf_size - pas->audio_buf_index;
+    Py_DECREF((PyObject *) pas);
+    return temp;
+}
+
 /* get the current audio clock value */
 static double get_audio_clock(PyMovie *is)
 {
 {
     is->paused = !is->paused;
     if (!is->paused) {
-        PyObject *pvs;
+        PyVideoStream *pvs;
+        PyAudioStream *pas;
         pvs = (PyVideoStream *)PySequence_GetItem(is->streams, (Py_ssize_t) is->video_stream);
         Py_INCREF((PyObject *)pvs);
         
                     }
                     pss->subtitle_stream_changed = 0;
 
-                    SDL_CondSignal(is->subpq_cond);
-                    SDL_UnlockMutex(is->subpq_mutex);
+                    SDL_CondSignal(pss->subpq_cond);
+                    SDL_UnlockMutex(pss->subpq_mutex);
                 } else {
                     if (pss->subpq_size > 0) {
                         sp = &pss->subpq[pss->subpq_rindex];
 #endif
     if(is->overlay>0)
     {
+        SDL_Surface *screen = SDL_GetVideoSurface ();
         pvs->bmp = SDL_CreateYUVOverlay(pvs->video_st->codec->width,
                                    pvs->video_st->codec->height,
                                    SDL_YV12_OVERLAY,
     }
     else
     {
-        
+        pvs->out_surf= SDL_GetVideoSurface ();
     }
     vp->width = pvs->video_st->codec->width;
     vp->height = pvs->video_st->codec->height;
             pict.linesize[0] = pvs->bmp->pitches[0];
             pict.linesize[1] = pvs->bmp->pitches[2];
             pict.linesize[2] = pvs->bmp->pitches[1];
-            sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
+            //sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
             img_convert_ctx = sws_getCachedContext(img_convert_ctx,
                 pvs->video_st->codec->width, pvs->video_st->codec->height,
                 pvs->video_st->codec->pix_fmt,
         }
         else
         {
-            dst_pix_fmt = PIX_FMT_RGB48;
+            dst_pix_fmt = PIX_FMT_RGB24;
               
             SDL_LockSurface (pvs->out_surf);
 
             pict.linesize[0] = pvs->out_surf->pitch;
             pict.linesize[1] = pvs->out_surf->pitch;
             pict.linesize[2] = pvs->out_surf->pitch;
-            sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
+            //sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
             img_convert_ctx = sws_getCachedContext(img_convert_ctx,
                 pvs->video_st->codec->width, pvs->video_st->codec->height,
                 pvs->video_st->codec->pix_fmt,
 
 static int subtitle_thread(void *arg)
 {
-    VideoState *is = arg;
+    PyMovie *is = arg;
     SubPicture *sp;
     AVPacket pkt1, *pkt = &pkt1;
     int len1, got_subtitle;
     Py_DECREF((PyObject *) pas);
 }
 
-/* get the current audio output buffer size, in samples. With SDL, we
-   cannot have a precise information */
-static int audio_write_get_buf_size(PyMovie *is)
-{
 
-    PyAudioStream   *pas;
-
-    pas = (PyAudioStream *)PySequence_GetItem(is->streams, (Py_ssize_t) is->audio_stream);
-    Py_INCREF((PyObject *)pas);
-    
-    int temp = pas->audio_buf_size - pas->audio_buf_index;
-    Py_DECREF((PyObject *) pas);
-    return temp;
-}
 
 /* prepare a new audio buffer */
 static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
     enc->error_recognition= error_recognition;
     enc->error_concealment= error_concealment;
 
-    set_context_opts(enc, avctx_opts[enc->codec_type], 0);
+    //set_context_opts(enc, avctx_opts[enc->codec_type], 0);
 
     if (!codec ||
         avcodec_open(enc, codec) < 0)
     switch(enc->codec_type) {
     case CODEC_TYPE_AUDIO:
         pas->audio_st = NULL;
-        PySequence_SetItem(is->streams, (Py_ssize_t)is->audio_stream, PyNone);
+        PySequence_SetItem(is->streams, (Py_ssize_t)is->audio_stream, Py_None);
         is->audio_stream = -1;
         Py_DECREF((PyObject *) pas);
         _dealloc_aud_stream(pas);
         break;
     case CODEC_TYPE_VIDEO:
         pvs->video_st = NULL;
-        PySequence_SetItem(is->streams, (Py_ssize_t)is->video_stream, PyNone);
+        PySequence_SetItem(is->streams, (Py_ssize_t)is->video_stream, Py_None);
         is->video_stream = -1;
         Py_DECREF((PyObject *) pvs);
         _dealloc_vid_stream(pvs);
         break;
     case CODEC_TYPE_SUBTITLE:
         pss->subtitle_st = NULL;
-        PySequence_SetItem(is->streams, (Py_ssize_t)is->subtitle_stream, PyNone);
+        PySequence_SetItem(is->streams, (Py_ssize_t)is->subtitle_stream, Py_None);
         Py_DECREF(pss);
         is->subtitle_stream = -1;
         _dealloc_sub_stream(pss);
 
     PyAudioStream* pas;
     PyVideoStream* pvs;
-    PySubStream*   pss;
+    PySubtitleStream*   pss;
 
     url_set_interrupt_cb(decode_interrupt_cb);
 
             packet_queue_put(&pas->audioq, pkt);
         } else if (pkt->stream_index == is->vid_stream_ix) {
             packet_queue_put(&pvs->videoq, pkt);
-        } else if (pkt->stream_index == is->subt_stream_ix) {
+        } else if (pkt->stream_index == is->sub_stream_ix) {
             packet_queue_put(&pss->subtitleq, pkt);
         } else {
             av_free_packet(pkt);
         stream_component_close(is, is->aud_stream_ix);
     if (is->vid_stream_ix >= 0)
         stream_component_close(is, is->vid_stream_ix);
-    if (is->subt_stream_ix >= 0)
+    if (is->sub_stream_ix >= 0)
         stream_component_close(is, is->sub_stream_ix);
     if (is->ic) {
         av_close_input_file(is->ic);
     
     if(is->audio_stream)
     {
-        PyList_SetItem(is->streams, (Py_ssize_t)is->audio_stream, PyNone) 
+        PyList_SetItem(is->streams, (Py_ssize_t)is->audio_stream, Py_None);
     }
     if(is->video_stream)
     {
-        PyList_SetItem(is->streams, (Py_ssize_t)is->video_stream, PyNone)
+        PyList_SetItem(is->streams, (Py_ssize_t)is->video_stream, Py_None);
     }
     if(is->subtitle_stream)
     {
-        PyList_SetItem(is->streams, (Py_ssize_t)is->subtitle_stream, PyNone)
+        PyList_SetItem(is->streams, (Py_ssize_t)is->subtitle_stream, Py_None);
     }
     
     _dealloc_vid_stream(pvs);
     0,                          /* tp_weaklistoffset */
     0,                          /* tp_iter */
     0,                          /* tp_iternext */
-    &Movie_methods,             /* tp_methods */
+    *Movie_methods,             /* tp_methods */
     0,                          /* tp_members */
     _movie_getsets,             /* tp_getset */
     0,                          /* tp_base */
     0                           /* tp_del */
 };
 
-/*class methods and internals 
-static PyMovie * _movie_new_internal(PyTypeObject *type, PyObject* fle, PyObject* surface); //expects file to have been opened in _movie_new
-static PyObject* _movie_new (PyTypeObject *type, PyObject *args,
-    PyObject *kwds);
-static void _movie_dealloc (PyMovie *movie);
-static PyObject* _movie_repr (PyMovie *movie);
-static PyObject* _movie_str (PyMovie *movie);
-static PyObject* _movie_play(PyMovie *movie, PyObject* args);
-static PyObject* _movie_stop(PyMovie *movie);
-static PyObject* _movie_pause(PyMovie *movie);
-static PyObject* _movie_rewind(PyMovie *movie, PyObject* args);
 
-/* Getters/setters 
-static PyObject* _movie_get_paused (PyMovie *movie, void *closure);
-static PyObject* _movie_get_playing (PyMovie *movie, void *closure);
 
-/* C API interfaces 
-static PyObject* PyMovie_New (char *fname);
-*/
-
-static PyMovie* _movie_new_internal(PyTypeObject *type, char *filename, PyObject* surface)
+static PyObject* _movie_new_internal(PyTypeObject *type, char *filename, PyObject* surface)
 {
     /*Expects filename. If surface is null, then it sets overlay to >0. */
     PyMovie *movie  = (PyMovie *)type->tp_alloc (type, 0);
         surf = PySurface_AsSurface(surface);
         movie->out_surf=surf;
         movie->overlay=1;
+    
     else
     {
         movie->overlay=0;
         Py_RETURN_NONE;
     }
     Py_DECREF((PyObject *) movie);
-    return movie;
+    return (PyObject *)movie;
 }
     
 static PyObject* _movie_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
     PyObject *obj;
     int loops;
-    PyArg_ParseTuple(args, "i", &obj)
+    PyArg_ParseTuple(args, "i", &obj);
     if(!obj)
     {
         loops =1;
 }
 static PyObject* _movie_get_playing (PyMovie *movie, void *closure)
 {
-    return PyInt_FromInt(movie->playing);
+    PyObject *pyo;
+    pyo= PyInt_FromInt(movie->playing);
+    return pyo;
 }
 
 static PyObject* PyMovie_New (char *fname, SDL_Surface *surf)
 {
-    return _movie_new_internal(PyMovie_Type, fname, surf);
+    return _movie_new_internal(&PyMovie_Type, fname, PySurface_FromSurface(surf));
 }
+
+void
+initmovie(void)
+{
+    PyObject* module;
+
+    #if PY3
+    static struct PyModuleDef _module = {
+        PyModuleDef_HEAD_INIT,
+        "movie",
+        NULL,
+        -1,
+        Movie_methods,
+        NULL, NULL, NULL, NULL
+    };
+#endif
+
+    /* imported needed apis; Do this first so if there is an error
+       the module is not loaded.
+    */
+    import_pygame_base ();
+    if (PyErr_Occurred ()) {
+        MODINIT_ERROR;
+    }
+
+   // Create the module
+   #if PY3
+    module = PyModule_Create (&_module);
+#else
+    module = Py_InitModule3 ( MODPREFIX "movie", NULL, NULL); //movie doc needed
+#endif
+   if (module == NULL) {
+      return;
+   }
+
+   // Fill in some slots in the type, and make it ready
+   //PyVector_Type.tp_new = PyType_GenericNew;
+   if (PyType_Ready(&PyMovie_Type) < 0) {
+      MODINIT_ERROR;
+   }
+   //Register all the fun stuff for movies.
+   avcodec_register_all();
+   avdevice_register_all();
+   av_register_all();
+
+   av_init_packet(&flush_pkt);
+   flush_pkt.data= "FLUSH";
+
+   // Add the type to the module.
+   Py_INCREF(&PyMovie_Type);
+   PyModule_AddObject(module, "Movie", (PyObject*)&PyMovie_Type);
+}
     //    QETimer *video_timer;
     int width, height, xleft, ytop;
 
-    
+    int pts;
 
 } PyVideoStream;
 
     AVPacket audio_pkt;
     uint8_t *audio_pkt_data;
     int audio_pkt_size;
-    enum SampleFormat audio_src_fmt;
+    enum SampleFormat *audio_src_fmt;
     AVAudioConvert *reformat_ctx;
 
     /*time-keeping values
     double frame_last_pts;
     double frame_last_delay;
     double frame_offset;
-    
+    int pts;
 
 } PyAudioStream;
 
     double frame_last_pts;
     double frame_last_delay;
     double frame_offset;
+    
+    int pts;
 
 } PySubtitleStream;
 
     int abort_request;      /* lets other threads know to stop. */
     AVFormatContext *ic;    /* context information about the format of the video file */
 
+    SDL_Surface *out_surf;
+
     /* General seek/pause state variables */
     int paused;
     int last_paused;
 } PyMovie;
 
 /*class methods and internals */
-static PyMovie * _movie_new_internal(PyTypeObject *type, PyObject* fle, PyObject* surface); //expects file to have been opened in _movie_new
+static PyObject* _movie_new_internal(PyTypeObject *type, char *filename, PyObject* surface); //expects file to have been opened in _movie_new
 static PyObject* _movie_new (PyTypeObject *type, PyObject *args,
     PyObject *kwds);
 static void _movie_dealloc (PyMovie *movie);
 static PyObject* _movie_get_playing (PyMovie *movie, void *closure);
 
 /* C API interfaces */
-static PyObject* PyMovie_New (char *fname);
+static PyObject* PyMovie_New (char *fname, SDL_Surface *surf);
 
 /*internals */
-static PyAudioStream* _get_audio_stream(PyObject* stream);
-static PyVideoStream* _get_video_stream(PyObject* stream);
-static PySubStream* _get_sub_stream(PyObject* stream);
+static PyAudioStream* _new_audio_stream();
+static PyVideoStream* _new_video_stream();
+static PySubtitleStream* _new_sub_stream();
 
-static int _if_audio_stream(PyObject* stream);
-static int _if_video_stream(PyObject* stream);
-static int _if_sub_stream(PyObject* stream);
+static void _dealloc_aud_stream(PyAudioStream *pas);
+static void _dealloc_vid_stream(PyVideoStream *pvs);
+static void _dealloc_sub_stream(PySubtitleStream *pss);
 
+

test/font_tags.py

+__tags__ = []
+
+import sys
+# Font support not fully implemented for Python 3.x.
+if sys.version_info >= (3, 0, 0) and sys.platform.startswith['Win']:
+    __tags__.extend(['ignore', 'subprocess_ignore'])

test/font_test.py

+import sys
+import os
 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
     is_pygame_pkg = __name__.startswith('pygame.tests.')
 
 if is_pygame_pkg:
-    from pygame.tests.test_utils import test_not_implemented, unittest
+    from pygame.tests.test_utils import test_not_implemented, unittest, \
+                                        geterror
 else:
-    from test.test_utils import test_not_implemented, unittest
+    from test.test_utils import test_not_implemented, unittest, geterror
 import pygame
 
 
 class FontModuleTest( unittest.TestCase ):
-    def testFontRendering( self ):
-        """ 
-        """
-        #print __file__
-        pygame.font.init ()
-        f = pygame.font.Font(None, 20)
-        s = f.render("foo", True, [0, 0, 0], [255, 255, 255])
-        s = f.render("xxx", True, [0, 0, 0], [255, 255, 255])
-        s = f.render("", True, [0, 0, 0], [255, 255, 255])
-        s = f.render("foo", False, [0, 0, 0], [255, 255, 255])
-        s = f.render("xxx", False, [0, 0, 0], [255, 255, 255])
-        s = f.render("xxx", False, [0, 0, 0])
-        s = f.render("   ", False, [0, 0, 0])
-        s = f.render("   ", False, [0, 0, 0], [255, 255, 255])
-        # null text should be 1 pixel wide.
-        s = f.render("", False, [0, 0, 0], [255, 255, 255])
-        self.assertEqual(s.get_size()[0], 1)
-        #print "fonttest done"
-        pygame.font.quit ()
+    def setUp(self):
+        pygame.font.init()
 
-    def todo_test_SysFont(self):
+    def tearDown(self):
+        pygame.font.quit()
 
-        # __doc__ (as of 2008-08-02) for pygame.font.SysFont:
+    def test_SysFont(self):
+        # Can only check that a font object is returned.
+        fonts = pygame.font.get_fonts()
+        o = pygame.font.SysFont(fonts[0], 20)
+        self.failUnless(isinstance(o, pygame.font.FontType))
+        o = pygame.font.SysFont(fonts[0], 20, italic=True)
+        self.failUnless(isinstance(o, pygame.font.FontType))
+        o = pygame.font.SysFont(fonts[0], 20, bold=True)
+        self.failUnless(isinstance(o, pygame.font.FontType))
+        o = pygame.font.SysFont('thisisnotafont', 20)
+        self.failUnless(isinstance(o, pygame.font.FontType))
 
-          # pygame.font.SysFont(name, size, bold=False, italic=False) -> Font
-          # create a pygame Font from system font resources
-          # 
-          # This will search the system fonts for the given font
-          # name. You can also enable bold or italic styles, and
-          # the appropriate system font will be selected if available.
-          # 
-          # This will always return a valid Font object, and will
-          # fallback on the builtin pygame font if the given font
-          # is not found.
-          # 
-          # Name can also be a comma separated list of names, in
-          # which case set of names will be searched in order. Pygame
-          # uses a small set of common font aliases, if the specific
-          # font you ask for is not available, a reasonable alternative
-          # may be used.
-          # 
-          # Return a new Font object that is loaded from the system fonts. The
-          # font will match the requested bold and italic flags. If a suitable
-          # system font is not found this will fallback on loading the default
-          # pygame font. The font name can be a comma separated list of font
-          # names to look for.
-          # 
+    def test_get_default_font(self):
+        self.failUnlessEqual(pygame.font.get_default_font(), 'freesansbold.ttf')
 
-        self.fail() 
+    def test_get_fonts(self):
+        fnts = pygame.font.get_fonts()
+        self.failUnless(fnts)
+        for name in fnts:
+            self.failUnless(isinstance(name, str))
+            self.failUnless(name.islower(), name)
+            self.failUnless(name.isalnum(), name)
 
-    def todo_test_get_default_font(self):
+    def test_get_init(self):
+        self.failUnless(pygame.font.get_init())
+        pygame.font.quit()
+        self.failIf(pygame.font.get_init())
 
-        # __doc__ (as of 2008-08-02) for pygame.font.get_default_font:
+    def test_init(self):
+        pygame.font.init()
 
-          # pygame.font.get_default_font(): return string
-          # get the filename of the default font
-          # 
-          # Return the filename of the system font. This is not the full path to
-          # the file. This file can usually be found in the same directory as
-          # the font module, but it can also be bundled in separate archives.
-          # 
+    def test_match_font(self):
+        fonts = pygame.font.get_fonts()
 
-        self.fail() 
+        # Ensure all listed fonts are in fact available, and the returned file
+        # name is a full path.
+        for font in fonts:
+            path = pygame.font.match_font(font)
+            self.failIf(path is None)
+            self.failUnless(os.path.isabs(path))
 
-    def todo_test_get_fonts(self):
+        # Look for a bold font.
+        for font in fonts:
+            if pygame.font.match_font(font, bold=True) is not None:
+                break
+        else:
+            self.fail()
 
-        # __doc__ (as of 2008-08-02) for pygame.font.get_fonts:
+        # Look for an italic font.
+        for font in fonts:
+            if pygame.font.match_font(font, italic=True) is not None:
+                break
+        else:
+            self.fail()
 
-          # pygame.font.get_fonts() -> list
-          # get a list of system font names
-          # 
-          # Returns the list of all found system fonts. Note that
-          # the names of the fonts will be all lowercase with spaces
-          # removed. This is how pygame internally stores the font
-          # names for matching.
-          # 
-          # Returns a list of all the fonts available on the system. The names
-          # of the fonts will be set to lowercase with all spaces and
-          # punctuation removed. This works on most systems, but some will
-          # return an empty list if they cannot find fonts.
-          # 
+        # Check for not found.
+        self.failUnless(pygame.font.match_font('thisisnotafont') is None)
 
-        self.fail() 
+        # Check comma separated list.
+        names = ','.join(['thisisnotafont', fonts[-1], 'anothernonfont'])
+        self.failIf(pygame.font.match_font(names) is None)
+        names = ','.join(['thisisnotafont1', 'thisisnotafont2', 'thisisnotafont3'])
+        self.failUnless(pygame.font.match_font(names) is None)
 
-    def todo_test_get_init(self):
+    def test_quit(self):
+        pygame.font.quit()
 
-        # __doc__ (as of 2008-08-02) for pygame.font.get_init:
-
-          # pygame.font.get_init(): return bool
-          # true if the font module is initialized
-          # 
-          # Test if the font module is initialized or not. 
-
-        self.fail() 
-
-    def todo_test_init(self):
-
-        # __doc__ (as of 2008-08-02) for pygame.font.init:
-
-          # pygame.font.init(): return None
-          # initialize the font module
-          # 
-          # This method is called automatically by pygame.init(). It initializes
-          # the font module. The module must be initialized before any other
-          # functions will work.
-          # 
-          # It is safe to call this function more than once. 
-
-        self.fail() 
-
-    def todo_test_match_font(self):
-
-        # __doc__ (as of 2008-08-02) for pygame.font.match_font:
-
-          # pygame.font.match_font(name, bold=0, italic=0) -> name
-          # find the filename for the named system font
-          # 
-          # This performs the same font search as the SysFont()
-          # function, only it returns the path to the TTF file
-          # that would be loaded. The font name can be a comma
-          # separated list of font names to try.
-          # 
-          # If no match is found, None is returned.
-          # 
-          # Returns the full path to a font file on the system. If bold or
-          # italic are set to true, this will attempt to find the correct family
-          # of font.
-          # 
-          # The font name can actually be a comma separated list of font names
-          # to try. If none of the given names are found, None is returned.
-          # 
-          # Example: 
-          #     print pygame.font.match_font('bitstreamverasans')
-          #     # output is: /usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf
-          #     # (but only if you have Vera on your system)
-
-        self.fail() 
-
-    def todo_test_quit(self):
-
-        # __doc__ (as of 2008-08-02) for pygame.font.quit:
-
-          # pygame.font.quit(): return None
-          # uninitialize the font module
-          # 
-          # Manually uninitialize SDL_ttf's font system. This is called
-          # automatically by pygame.quit().
-          # 
-          # It is safe to call this function even if font is currently not initialized. 
-
-        self.fail() 
 
 class FontTypeTest( unittest.TestCase ):
     def todo_test_get_ascent(self):
 
         self.fail() 
 
-    def todo_test_get_bold(self):
-
-        # __doc__ (as of 2008-08-02) for pygame.font.Font.get_bold:
-
-          # Font.get_bold(): return bool
-          # check if text will be rendered bold
-          # 
-          # Return True when the font bold rendering mode is enabled. 
-
-        self.fail() 
-
     def todo_test_get_descent(self):
 
         # __doc__ (as of 2008-08-02) for pygame.font.Font.get_descent:
 
         self.fail() 
 
-    def todo_test_get_italic(self):
-
-        # __doc__ (as of 2008-08-02) for pygame.font.Font.get_italic:
-
-          # Font.get_italic(): return bool
-          # check if the text will be rendered italic
-          # 
-          # Return True when the font italic rendering mode is enabled. 
-
-        self.fail() 
-
     def todo_test_get_linesize(self):
 
         # __doc__ (as of 2008-08-02) for pygame.font.Font.get_linesize:
 
         self.fail() 
 
-    def todo_test_get_underline(self):
-
-        # __doc__ (as of 2008-08-02) for pygame.font.Font.get_underline:
-
-          # Font.get_underline(): return bool
-          # check if text will be rendered with an underline
-          # 
-          # Return True when the font underline is enabled. 
-
-        self.fail() 
-
     def todo_test_metrics(self):
 
         # __doc__ (as of 2008-08-02) for pygame.font.Font.metrics:
         self.fail() 
 
     def todo_test_render(self):
+        """ 
+        """
+
+        f = pygame.font.Font(None, 20)
+        s = f.render("foo", True, [0, 0, 0], [255, 255, 255])
+        s = f.render("xxx", True, [0, 0, 0], [255, 255, 255])
+        s = f.render("", True, [0, 0, 0], [255, 255, 255])
+        s = f.render("foo", False, [0, 0, 0], [255, 255, 255])
+        s = f.render("xxx", False, [0, 0, 0], [255, 255, 255])
+        s = f.render("xxx", False, [0, 0, 0])
+        s = f.render("   ", False, [0, 0, 0])
+        s = f.render("   ", False, [0, 0, 0], [255, 255, 255])
+        # null text should be 1 pixel wide.
+        s = f.render("", False, [0, 0, 0], [255, 255, 255])
+        self.assertEqual(s.get_size()[0], 1)
 
         # __doc__ (as of 2008-08-02) for pygame.font.Font.render:
 
           # Font rendering is not thread safe: only a single thread can render
           # text any time.
 
-        self.fail() 
 
-    def todo_test_set_bold(self):
+    def test_set_bold(self):
+        f = pygame.font.Font(None, 20)
+        self.failIf(f.get_bold())
+        f.set_bold(True)
+        self.failUnless(f.get_bold())
+        f.set_bold(False)
+        self.failIf(f.get_bold())
 
-        # __doc__ (as of 2008-08-02) for pygame.font.Font.set_bold:
+    def test_set_italic(self):
+        f = pygame.font.Font(None, 20)
+        self.failIf(f.get_italic())
+        f.set_italic(True)
+        self.failUnless(f.get_italic())
+        f.set_italic(False)
+        self.failIf(f.get_bold())
 
-          # Font.set_bold(bool): return None
-          # enable fake rendering of bold text
-          # 
-          # Enables the bold rendering of text. This is a fake stretching of the
-          # font that doesn't look good on many font types. If possible load the
-          # font from a real bold font file. While bold, the font will have a
-          # different width than when normal. This can be mixed with the italic
-          # and underline modes.
-
-        self.fail() 
-
-    def todo_test_set_italic(self):
-
-        # __doc__ (as of 2008-08-02) for pygame.font.Font.set_italic:
-
-          # Font.set_bold(bool): return None
-          # enable fake rendering of italic text
-          # 
-          # Enables fake rendering of italic text. This is a fake skewing of the
-          # font that doesn't look good on many font types. If possible load the
-          # font from a real italic font file. While italic the font will have a
-          # different width than when normal. This can be mixed with the bold
-          # and underline modes.
-
-        self.fail() 
-
-    def todo_test_set_underline(self):
-
-        # __doc__ (as of 2008-08-02) for pygame.font.Font.set_underline:
-
-          # Font.set_underline(bool): return None
-          # control if text is rendered with an underline
-          # 
-          # When enabled, all rendered fonts will include an underline. The
-          # underline is always one pixel thick, regardless of font size. This
-          # can be mixed with the bold and italic modes.
-
-        self.fail() 
+    def test_set_underline(self):
+        f = pygame.font.Font(None, 20)
+        self.failIf(f.get_underline())
+        f.set_underline(True)
+        self.failUnless(f.get_underline())
+        f.set_underline(False)
+        self.failIf(f.get_underline())
 
     def todo_test_size(self):
 

test/mixer_music_test.py

 
         # The mp3 test file can crash smpeg on some systems.
         ## formats = ['mp3', 'ogg', 'wav']
-        format = ['ogg', 'wav']
+        formats = ['ogg', 'wav']
 
         for f in formats:
             musfn = os.path.join(data_fname, 'house_lo.%s' % f)

test/test_utils/__init__.py

     from test.test_utils import unittest
 
 import tempfile, sys, pygame, time, os
+
+################################################################################
+# Python 3.x compatibility
 try:
     xrange_ = xrange
 except NameError:
 except NameError:
     raw_input_ = input
 
+def geterror():
+    return sys.exc_info()[1]
+
 ################################################################################
 
 this_dir = os.path.dirname(os.path.abspath(__file__))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.