Commits

zeroth  committed ca7326a

Added proper loading of the pts to the frame, according to page 5 of the
ffmpeg tutorial

  • Participants
  • Parent commits d4c1e04
  • Branches tylerthemovie

Comments (0)

Files changed (3)

File src/_gmovie.c

     return ret;
 }
 
+uint64_t global_video_pkt_pts = AV_NOPTS_VALUE;
+
+/* These are called whenever we allocate a frame
+ * buffer. We use this to store the global_pts in
+ * a frame at the time it is allocated.
+ */
+int ff_get_buffer(struct AVCodecContext *c, AVFrame *pic) {
+  int ret = avcodec_default_get_buffer(c, pic);
+  uint64_t *pts = av_malloc(sizeof(uint64_t));
+  *pts = global_video_pkt_pts;
+  pic->opaque = pts;
+  return ret;
+}
+void ff_release_buffer(struct AVCodecContext *c, AVFrame *pic) {
+  if(pic) av_freep(&pic->opaque);
+  avcodec_default_release_buffer(c, pic);
+}
+
+
  void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect, int imgw, int imgh)
 {
     int wrap, wrap3, width2, skip2;
             SDL_Delay(10);
         }
         int64_t t_before = av_gettime();
-        if (packet_queue_get(&movie->videoq, pkt, 1) < 0)
-            break;
+        if (packet_queue_get(&movie->videoq, pkt, 0) < 0)
+            continue;
 
         if(pkt->data == flush_pkt.data){
             avcodec_flush_buffers(movie->video_st->codec);
       	if(!THREADFREE)
 	        movie->video_tid = SDL_CreateThread(video_thread, movie);
 		
+		enc->get_buffer = ff_get_buffer;
+    	enc->release_buffer = ff_release_buffer;
+		
         break;
     case CODEC_TYPE_SUBTITLE:
     	PySys_WriteStdout("stream_component_open: subtitle stream\n");
         }
         /*if (pkt->stream_index == is->audio_stream) {
             packet_queue_put(&is->audioq, pkt);
-        } else*/ if (pkt->stream_index == is->video_stream) {
+        } else*/ 
+        if (pkt->stream_index == is->video_stream) {
             packet_queue_put(&is->videoq, pkt);
         //} else if (pkt->stream_index == is->subtitle_stream) {
         //    packet_queue_put(&is->subtitleq, pkt);
-        } else {
+        } else if(pkt) {
             av_free_packet(pkt);
         }
         
         //if(movie->timing>0)
         //	break;
         int64_t t_before = av_gettime();
-        if (packet_queue_get(&movie->videoq, pkt, 1) < 0)
+        if (packet_queue_get(&movie->videoq, pkt, 0) <=0)
             break;
-
+		
         if(pkt->data == flush_pkt.data){
             avcodec_flush_buffers(movie->video_st->codec);
             continue;
 
         /* NOTE: ipts is the PTS of the _first_ picture beginning in
            this packet, if any */
+        global_video_pkt_pts = pkt->pts;
         movie->video_st->codec->reordered_opaque= pkt->pts;
 		//int64_t t_before = av_gettime();
         

File src/_gmovie.h

  void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect, int imgw, int imgh);
  void free_subpicture(SubPicture *sp);
  double calc_ca(int64_t diff, double ca, double i);
+ int ff_get_buffer(struct AVCodecContext *c, AVFrame *pic);
+ void ff_release_buffer(struct AVCodecContext *c, AVFrame *pic);
 
 
 /* 		Video Management */

File test/midi_test.py

           # Note: in the current release, the default is simply the first device
           #     (the input or output device with the lowest PmDeviceID).
 
-        c = pygame.midi.get_default_input_id() 
+        c = pygame.midi.get_default_input_id()
+        # if there is a not None return make sure it is an int.
         self.assertEqual(type(c), type(1))
-        self.failUnless(c >= 0)
+        self.failUnless(c >= 0 or c == -1)
+
 
 
     def test_get_default_output_id(self):
           # Note: in the current release, the default is simply the first device
           #     (the input or output device with the lowest PmDeviceID).
 
-        c = pygame.midi.get_default_output_id() 
-        self.assertEqual(type(c), type(1))
-        self.failUnless(c >= 0)
+        c = pygame.midi.get_default_output_id()
+        if not (c is None):
+            # if there is a not None return make sure it is an int.
+
+            self.assertEqual(type(c), type(1))
+            self.failUnless(c >= 0 or c == -1)
 
 
 
           # 
           # If the id is out of range, the function returns None.
 
-        an_id = pygame.midi.get_default_output_id() 
-        interf, name, input, output, opened = pygame.midi.get_device_info(an_id)
-        #print interf
-        #print name
-        #print input, output, opened
+        an_id = pygame.midi.get_default_output_id()
+        if an_id != -1:
+            interf, name, input, output, opened = pygame.midi.get_device_info(an_id)
+            #print interf
+            #print name
+            #print input, output, opened
 
-        self.assertEqual(output, 1)
-        self.assertEqual(input, 0)
-        self.assertEqual(opened, 0)
+            self.assertEqual(output, 1)
+            self.assertEqual(input, 0)
+            self.assertEqual(opened, 0)
 
 
         an_in_id = pygame.midi.get_default_input_id() 
-        interf, name, input, output, opened = pygame.midi.get_device_info(an_in_id)
-        self.assertEqual(output, 0)
-        self.assertEqual(input, 1)
-        self.assertEqual(opened, 0)
+        if an_id != -1:
+            interf, name, input, output, opened = pygame.midi.get_device_info(an_in_id)
+            self.assertEqual(output, 0)
+            self.assertEqual(input, 1)
+            self.assertEqual(opened, 0)