1. pygame
  2. pygame
  3. pygame

Commits

zeroth  committed e83650e

Updates no merges yet

  • Participants
  • Parent commits 40997ea
  • Branches tylerthemovie

Comments (0)

Files changed (2)

File src/ff_movie.c

View file
  • Ignore whitespace
 
 static void video_image_display(PyMovie *is)
 {
+    Py_INCREF((PyObject *) is);
     VideoPicture *vp;
     SubPicture *sp;
     AVPicture pict;
 #endif
     }
     Py_DECREF((PyObject *)pvs);
+    Py_DECREF((PyObject *) is);
 }
 
 
 
 static int video_open(PyMovie *is){
     int w,h;
-
+    Py_INCREF((PyObject *) is);
     PyVideoStream *pvs;
     pvs = (PyVideoStream *)PySequence_GetItem(is->streams, (Py_ssize_t) is->video_stream);
     Py_INCREF((PyObject *) pvs);
     pvs->width = w;
     pvs->height = h;
     Py_DECREF((PyObject *) pvs);
+    Py_DECREF((PyObject *) is);
     return 0;
 }
 
 /* display the current picture, if any */
 static void video_display(PyMovie *is)
 {
+    Py_INCREF((PyObject *) is);
     PyVideoStream *pvs = (PyVideoStream *)PySequence_GetItem(is->streams, (Py_ssize_t) is->video_stream);
     Py_INCREF((PyObject *) pvs);
     
     if (!pvs->out_surf||!pvs->bmp)
         video_open(is);
 
-    else if (is->video_stream>0)
+    else if (is->vid_stream_ix>0)
         video_image_display(is);
     Py_DECREF((PyObject *) pvs);
+    Py_DECREF((PyObject *) is);
 }
 
 static Uint32 sdl_refresh_timer_cb(Uint32 interval, void *opaque)
 {
+    Py_INCREF((PyObject *) opaque);
     SDL_Event event;
     event.type = FF_REFRESH_EVENT;
     event.user.data1 = opaque;
     SDL_PushEvent(&event);
+    Py_DECREF((PyObject *) opaque);
     return 0; /* 0 means stop timer */
 }
 
 /* schedule a video refresh in 'delay' ms */
 static void schedule_refresh(PyMovie *is, int delay)
 {
+    Py_INCREF((PyObject *) is);
     if(!delay) delay=1; //SDL seems to be buggy when the delay is 0
     SDL_AddTimer(delay, sdl_refresh_timer_cb, is);
+    Py_DECREF((PyObject *) is);
 }
 
+
 static int audio_write_get_buf_size(PyMovie *is)
 {
+    Py_INCREF((PyObject *) 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);
+    Py_DECREF((PyObject *) is);
     return temp;
 }
 
 /* get the current audio clock value */
 static double get_audio_clock(PyMovie *is)
 {
+    Py_INCREF((PyObject *) is);
     double pts;
     int hw_buf_size, bytes_per_sec;
 
     if (bytes_per_sec)
         pts -= (double)hw_buf_size / bytes_per_sec;
     Py_DECREF((PyObject *) pas);
+    Py_DECREF((PyObject *) is);
     return pts;
 }
 
 /* get the current video clock value */
 static double get_video_clock(PyMovie *is)
 {
+    Py_INCREF((PyObject *) is);
     double delta;
     PyVideoStream *pvs = (PyVideoStream *)PySequence_GetItem(is->streams, (Py_ssize_t) is->video_stream);
     Py_INCREF((PyObject *)pvs);
     }
     double temp = pvs->video_current_pts+delta;
     Py_DECREF((PyObject *) pvs);
+    Py_DECREF((PyObject *) is);
     return temp;
 }
 
 /* get the current external clock value */
 static double get_external_clock(PyMovie *is)
 {
+    Py_INCREF((PyObject *) is);
     int64_t ti;
     ti = av_gettime();
-    return is->external_clock + ((ti - is->external_clock_time) * 1e-6);
+    double res = is->external_clock + ((ti - is->external_clock_time) * 1e-6);
+    Py_DECREF((PyObject *) is);
+    return res;
 }
 
 /* get the current master clock value */
 static double get_master_clock(PyMovie *is)
 {
-    
+    Py_INCREF((PyObject *) is);
     double val;
     PyVideoStream *pvs;
     PyAudioStream *pas;
     }
     Py_DECREF((PyObject *)pvs);
     Py_DECREF((PyObject *)pas);
+    Py_DECREF((PyObject *) is);
     return val;
 }
 
 /* seek in the stream */
 static void stream_seek(PyMovie *is, int64_t pos, int rel)
 {
+    Py_INCREF((PyObject *) is);
     if (!is->seek_req) {
         is->seek_pos = pos;
         is->seek_flags = rel < 0 ? AVSEEK_FLAG_BACKWARD : 0;
 
         is->seek_req = 1;
     }
+    Py_DECREF((PyObject *) is);
 }
 
 /* pause or resume the video */
 static void stream_pause(PyMovie *is)
 {
+    Py_INCREF((PyObject *) is);
     is->paused = !is->paused;
     if (!is->paused) {
         PyVideoStream *pvs;
         Py_DECREF((PyObject *) pvs);
         Py_DECREF((PyObject *) pas);
     }
+    Py_DECREF((PyObject *) is);
 }
 
 static double compute_frame_delay(double frame_current_pts, PyMovie *is)
 {
+    Py_INCREF((PyObject *) is);
+
     double actual_delay, delay, sync_threshold, ref_clock, diff;
 
     /* compute nominal delay */
 #endif
     Py_DECREF((PyObject *) pvs);
     Py_DECREF((PyObject *) pas);
+    Py_DECREF((PyObject *) is);
     return actual_delay;
 }
 
 static void video_refresh_timer(void *opaque)
 {
     PyMovie *is = opaque;
+    Py_INCREF((PyObject *) is);
+    
     VideoPicture *vp;
 
     SubPicture *sp, *sp2;
             video_display(is);
 
             /* update queue size and signal for next picture */
-            if (pvs++->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE)
+            pvs->pictq_rindex++;
+            if (pvs->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE)
                 pvs->pictq_rindex = 0;
 
             SDL_LockMutex(pvs->pictq_mutex);
     }
     Py_DECREF((PyObject *) pvs);
     Py_DECREF((PyObject *) pas);
+    Py_DECREF((PyObject *) is);
 }
 
 /* allocate a picture (needs to do that in main thread to avoid
 static void alloc_picture(void *opaque)
 {
     PyMovie *is = opaque;
+    Py_INCREF((PyObject *) is);
     VideoPicture *vp;
     
     PyVideoStream *pvs;
     SDL_CondSignal(pvs->pictq_cond);
     SDL_UnlockMutex(pvs->pictq_mutex);
     Py_DECREF((PyObject *) pvs);
+    Py_DECREF((PyObject *) is);
 }
 
 /**
  */
 static int queue_picture(PyMovie *is, AVFrame *src_frame, double pts)
 {
+    Py_INCREF((PyObject *) is);
     VideoPicture *vp;
 
     PyVideoStream *pvs;
         SDL_UnlockMutex(pvs->pictq_mutex);
     }
     Py_DECREF((PyObject *) pvs);
+    Py_DECREF((PyObject *) is);
     return 0;
 }
 
  */
 static int output_picture2(PyMovie *is, AVFrame *src_frame, double pts1)
 {
+    Py_INCREF((PyObject *) is);
+    
     double frame_delay, pts;
 
     pts = pts1;
     }
 #endif
     Py_DECREF((PyObject *)pvs);
+    Py_DECREF((PyObject *) is);
     return queue_picture(is, src_frame, pts);
 }
 
 static int video_thread(void *arg)
 {
     PyMovie *is = arg;
+    Py_DECREF((PyObject *) is);
     AVPacket pkt1, *pkt = &pkt1;
     int len1, got_picture;
     AVFrame *frame= avcodec_alloc_frame();
     }
  the_end:
     Py_DECREF((PyObject *) pvs);
+    Py_DECREF((PyObject *) is);
     av_free(frame);
     return 0;
 }
 static int subtitle_thread(void *arg)
 {
     PyMovie *is = arg;
+    Py_INCREF((PyObject *) is);
     SubPicture *sp;
     AVPacket pkt1, *pkt = &pkt1;
     int len1, got_subtitle;
     }
  the_end:
     Py_DECREF((PyObject *) pss);
+    Py_DECREF((PyObject *) is);
     return 0;
 }
 
 static int synchronize_audio(PyMovie *is, short *samples,
                              int samples_size1, double pts)
 {
+    Py_INCREF((PyObject *) is);
+    
     int n, samples_size;
     double ref_clock;
 
     }
     Py_DECREF((PyObject *)pas);
     Py_DECREF((PyObject *)pvs);
+    Py_DECREF((PyObject *) is);
     return samples_size;
 }
 
 /* decode one audio frame and returns its uncompressed size */
 static int audio_decode_frame(PyMovie *is, double *pts_ptr)
 {
+    Py_INCREF((PyObject *) is);
     PyAudioStream   *pas;
 
     pas = (PyAudioStream *)PySequence_GetItem(is->streams, (Py_ssize_t) is->audio_stream);
         }
     }
     Py_DECREF((PyObject *) pas);
+    Py_DECREF((PyObject *) is);
 }
 
 
 static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
 {
     PyMovie *is = opaque;
+    Py_INCREF((PyObject *) is);
     int audio_size, len1;
     double pts;
 
         pas->audio_buf_index += len1;
     }
     Py_DECREF((PyObject *) pas);
+    Py_DECREF((PyObject *) is);
 }
 
 /* open a given stream. Return 0 if OK */
 static int stream_component_open(PyMovie *is, int stream_index)
 {
+    Py_INCREF((PyObject *) is);
     AVFormatContext *ic = is->ic;
     AVCodecContext *enc;
     AVCodec *codec;
     default:
         break;
     }
+    Py_DECREF((PyObject *) is);
     return 0;
 }
 
 static void stream_component_close(PyMovie *is, int stream_index)
 {
+    Py_INCREF((PyObject *) is);
     AVFormatContext *ic = is->ic;
     AVCodecContext *enc;
 
         PySequence_SetItem(is->streams, (Py_ssize_t)is->audio_stream, Py_None);
         is->audio_stream = -1;
         Py_DECREF((PyObject *) pas);
-        _dealloc_aud_stream(pas);
+        //_dealloc_aud_stream(pas);
         break;
     case CODEC_TYPE_VIDEO:
         pvs->video_st = NULL;
         PySequence_SetItem(is->streams, (Py_ssize_t)is->video_stream, Py_None);
         is->video_stream = -1;
         Py_DECREF((PyObject *) pvs);
-        _dealloc_vid_stream(pvs);
+        //_dealloc_vid_stream(pvs);
         break;
     case CODEC_TYPE_SUBTITLE:
         pss->subtitle_st = NULL;
         PySequence_SetItem(is->streams, (Py_ssize_t)is->subtitle_stream, Py_None);
         Py_DECREF(pss);
         is->subtitle_stream = -1;
-        _dealloc_sub_stream(pss);
+        //_dealloc_sub_stream(pss);
         break;
     default:
         break;
     }
+    Py_DECREF((PyObject *) is);
 }
 
 static int decode_interrupt_cb(void)
 static int decode_thread(void *arg)
 {
     PyMovie *is = arg;
+    Py_INCREF((PyObject *) is);
     AVFormatContext *ic;
     int err, i, ret, video_index, audio_index, subtitle_index;
     AVPacket pkt1, *pkt = &pkt1;
 
     err = av_open_input_file(&ic, is->filename, is->iformat, 0, ap);
     if (err < 0) {
-        //TODO:Python exception here please
         PyErr_Format(PyExc_IOError, "There was a problem opening up %s", is->filename);
         //print_error(is->filename, err);
         ret = -1;
         is->loops--;
         is->parse_tid = SDL_CreateThread(decode_thread, is);
     }
+    Py_DECREF((PyObject *) is);
     return 0;
 }
 
     schedule_refresh(is, 40);
 
     is->av_sync_type = av_sync_type;
+    Py_INCREF((PyObject *) is);
     is->parse_tid = SDL_CreateThread(decode_thread, is);
     if (!is->parse_tid) {
         PyErr_SetString(PyExc_MemoryError, "Could not spawn a new thread.");
         Py_DECREF((PyObject *) is);
-        PyMem_Free((void *)is);
+        is->ob_type->tp_free((PyObject *) is);
+        //PyMem_Free((void *)is);
         return NULL;
     }
     return is;
     Py_DECREF(is->streams);
     is->streams =NULL;
     Py_DECREF(pyo);
-    PyMem_Free(pyo);
+    //PyMem_Free(pyo);
     
     Py_DECREF((PyObject *)is);
-    PyMem_Free((PyObject *)is);
+
 }
 
 static void stream_cycle_channel(PyMovie *is, int codec_type)
 
 static void _dealloc_aud_stream(PyAudioStream *pas)
 {
-    
-    PyMem_Free((void *)pas);
+    pas->ob_type->tp_free((PyObject *) pas);
+    //PyMem_Free((void *)pas);
 }
 
 static void _dealloc_vid_stream(PyVideoStream *pvs)
 {
-    if(!pvs)
-        return;
+
     if(pvs->out_surf)
     { 
         SDL_FreeSurface(pvs->out_surf);
         SDL_FreeYUVOverlay(pvs->bmp);
         pvs->bmp=NULL;
     }
-    PyMem_Free((void *) pvs);
+    pvs->ob_type->tp_free((PyObject *) pvs);
+    //PyMem_Free((void *) pvs);
 }
 
 static void _dealloc_sub_stream(PySubtitleStream *pss)
 {
-    PyMem_Free((void *) pss);
+    pss->ob_type->tp_free((PyObject *) pss);
+    //PyMem_Free((void *) pss);
 }
 
 /* Python C-API stuff */
     0,                          /* tp_descr_get */
     0,                          /* tp_descr_set */
     0,                          /* tp_dictoffset */
-    0,                          /* tp_init */
+    (initproc) _movie_init,                          /* tp_init */
     0,                          /* tp_alloc */
-    (newfunc )_movie_new,                 /* tp_new */
+    0,                 /* tp_new */
     0,                          /* tp_free */
     0,                          /* tp_is_gc */
     0,                          /* tp_bases */
 
 
 
-static PyObject* _movie_new_internal(PyTypeObject *type, char *filename, PyObject* surface)
+static PyObject* _movie_init_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);
     return (PyObject *)movie;
 }
     
-static PyObject* _movie_new (PyTypeObject *type, PyObject *args)
+static int _movie_init (PyTypeObject *type, PyObject *args)
 {
     PyObject *obj;
     PyObject *obj2;
         PyErr_SetString(PyExc_TypeError, "Could not find a filename.");
         Py_RETURN_NONE;
     }
-    return _movie_new_internal(type, &obj, &obj2);
+    PyObject *mov;
+    mov = _movie_init_internal(type, &obj, &obj2);
+    PyObject *er;
+    er = PyErr_Occurred();
+    if(er)
+    {
+        PyErr_Print();
+    }
+    if(!mov)
+    {
+        PyErr_SetString(PyExc_IOError, "No movie object created.");
+        PyErr_Print();
+    }
     
-}
+    return 0;
+}   
 
 static void _movie_dealloc(PyMovie *movie)
 {
     stream_close(movie);
+    movie->ob_type->tp_free((PyObject *) movie);
 }
 
 static PyObject* _movie_repr (PyMovie *movie)
     }
 
     // Fill in some slots in the type, and make it ready
-   //PyVector_Type.tp_new = PyType_GenericNew;
+   PyMovie_Type.tp_new = PyType_GenericNew;
    if (PyType_Ready(&PyMovie_Type) < 0) {
       MODINIT_ERROR;
    }

File src/ff_movie.h

View file
  • Ignore whitespace
 } PyMovie;
 
 /*class methods and internals */
-static PyObject* _movie_new_internal(PyTypeObject *type, char *filename, PyObject* surface); 
-static PyObject* _movie_new (PyTypeObject *type, PyObject *args);
+static PyObject* _movie_init_internal(PyTypeObject *type, char *filename, PyObject* surface); 
+static int _movie_init (PyTypeObject *type, PyObject *args);
 static void _movie_dealloc (PyMovie *movie);
 static PyObject* _movie_repr (PyMovie *movie);
 static PyObject* _movie_str (PyMovie *movie);