Commits

illume committed ad1dbba

Trying to improve gmove and _gmovie modules to work with new ffmpeg.

Comments (0)

Files changed (3)

     RELEASEGIL
     AVPacket *pkt = &movie->audio_pkt;
     AVCodecContext *dec= movie->audio_st->codec;
-    int len1, data_size;
+    AVFrame *frame;
+    int len1, data_size, got_frame_ptr;
     int filled =0;
     len1=0;
+
+    frame=avcodec_alloc_frame();
+
+    dec->get_buffer(dec, frame);
+
     for(;;)
     {
         if(movie->stop || movie->audioq.abort_request)
         //fill up the buffer
         while(movie->audio_pkt_size > 0)
         {
+
+            //printf("asdf\n");
+            /* TODO: attempt to fix below... but this is just wrong... */
             data_size = sizeof(movie->audio_buf1);
-            len1 += avcodec_decode_audio2(dec, (int16_t *)movie->audio_buf1, &data_size, movie->audio_pkt_data, movie->audio_pkt_size);
+            len1 = avcodec_decode_audio4(dec, 
+                                         frame, 
+                                         &data_size, 
+                                         pkt);
+
+            movie->audio_pkt_size= frame->nb_samples;
             if (len1 < 0)
             {
-                /* if error, we skip the frame */
+                // if error, we skip the frame 
                 movie->audio_pkt_size = 0;
                 break;
             }
             //reformat_ctx here, but deleted
             filled=1;
 
+
+
+            /* TODO: FIXME uses old functions.
+            data_size = sizeof(movie->audio_buf1);
+            len1 += avcodec_decode_audio2(dec, 
+                                          (int16_t *)movie->audio_buf1, 
+                                          &data_size, 
+                                          movie->audio_pkt_data, 
+                                          movie->audio_pkt_size);
+            if (len1 < 0)
+            {
+                // if error, we skip the frame 
+                movie->audio_pkt_size = 0;
+                break;
+            }
+            movie->audio_pkt_data += len1;
+            movie->audio_pkt_size -= len1;
+            if (data_size <= 0)
+                continue;
+            //reformat_ctx here, but deleted
+            filled=1;
+            */
+
         }
         if(filled)
         {
     enc = ic->streams[stream_index]->codec;
     switch(enc->codec_type)
     {
-    case CODEC_TYPE_AUDIO:
+    case PYG_MEDIA_TYPE_AUDIO:
         movie->audio_stream = stream_index;
         movie->audio_st = ic->streams[stream_index];
         break;
-    case CODEC_TYPE_VIDEO:
+    case PYG_MEDIA_TYPE_VIDEO:
         movie->video_stream = stream_index;
         movie->video_st = ic->streams[stream_index];
         break;
     enc = ic->streams[stream_index]->codec;
     switch(enc->codec_type)
     {
-    case CODEC_TYPE_AUDIO:
+    case PYG_MEDIA_TYPE_AUDIO:
         if(movie->replay)
         {
             movie->audio_st = ic->streams[stream_index];
         soundStart();
         movie->audio_tid = SDL_CreateThread(audio_thread, movie);
         break;
-    case CODEC_TYPE_VIDEO:
+    case PYG_MEDIA_TYPE_VIDEO:
         if(movie->replay)
         {
             movie->video_stream = stream_index;
     //SubPicture *sp;
     switch(enc->codec_type)
     {
-    case CODEC_TYPE_AUDIO:
+    case PYG_MEDIA_TYPE_AUDIO:
         packet_queue_abort(&movie->audioq);
         SDL_WaitThread(movie->audio_tid, NULL);
         SDL_DestroyMutex(movie->audio_mutex);
         memset(&movie->audio_buf1, 0, sizeof(movie->audio_buf1));
         packet_queue_flush(&movie->audioq);
         break;
-    case CODEC_TYPE_VIDEO:
+    case PYG_MEDIA_TYPE_VIDEO:
         for(i=0;i<VIDEO_PICTURE_QUEUE_SIZE;i++)
         {
             vp = &movie->pictq[i];
     int end = movie->loops;
     switch(enc->codec_type)
     {
-    case CODEC_TYPE_AUDIO:
+    case PYG_MEDIA_TYPE_AUDIO:
         soundQuit();
         packet_queue_end(&movie->audioq, end);
         break;
-    case CODEC_TYPE_VIDEO:
+    case PYG_MEDIA_TYPE_VIDEO:
         packet_queue_end(&movie->videoq, end);
         break;
     default:
     avcodec_close(enc);
     switch(enc->codec_type)
     {
-    case CODEC_TYPE_AUDIO:
+    case PYG_MEDIA_TYPE_AUDIO:
         movie->audio_st = NULL;
         movie->audio_stream = -1;
         break;
-    case CODEC_TYPE_VIDEO:
+    case PYG_MEDIA_TYPE_VIDEO:
         movie->video_st = NULL;
         movie->video_stream = -1;
         break;
         movie->ic->streams[i]->discard = AVDISCARD_ALL;
         switch(enc->codec_type)
         {
-        case CODEC_TYPE_AUDIO:
+        case PYG_MEDIA_TYPE_AUDIO:
             if (wanted_audio_stream-- >= 0 && !movie->audio_disable)
                 audio_index = i;
             break;
-        case CODEC_TYPE_VIDEO:
+        case PYG_MEDIA_TYPE_VIDEO:
             if (wanted_video_stream-- >= 0 && !movie->video_disable)
                 video_index = i;
             break;
-        case CODEC_TYPE_SUBTITLE:
+        case PYG_MEDIA_TYPE_SUBTITLE:
             //if(wanted_subti_stream -- >= 0 && !movie->subtitle_disable)
             //	subtitle_index=i;
         default:
     int freq, channels;
     enc = ic->streams[stream_index]->codec;
     /* prepare audio output */
-    if (enc->codec_type == CODEC_TYPE_AUDIO)
+    if (enc->codec_type == PYG_MEDIA_TYPE_AUDIO)
     {
 #if LIBAVCODEC_VERSION_INT>=3412992 //(52<<16)+(20<<8)+0 ie 52.20.0
         if (enc->channels > 0)
         return -1;
     }
     /* prepare audio output */
-    if (enc->codec_type == CODEC_TYPE_AUDIO)
+    if (enc->codec_type == PYG_MEDIA_TYPE_AUDIO)
     {
 
         freq = enc->sample_rate;
     Py_INCREF(movie);
     RELEASEGIL
 
-    if (codec_type == CODEC_TYPE_VIDEO)
+    if (codec_type == PYG_MEDIA_TYPE_VIDEO)
         start_index = movie->video_stream;
-    else if (codec_type == CODEC_TYPE_AUDIO)
+    else if (codec_type == PYG_MEDIA_TYPE_AUDIO)
         start_index = movie->audio_stream;
     stream_index = start_index;
     for(;;)
             /* check that parameters are OK */
             switch(codec_type)
             {
-            case CODEC_TYPE_AUDIO:
+            case PYG_MEDIA_TYPE_AUDIO:
                 if (st->codec->sample_rate != 0 &&
                         st->codec->channels != 0)
                     goto the_end;
                 break;
-            case CODEC_TYPE_VIDEO:
+            case PYG_MEDIA_TYPE_VIDEO:
             default:
                 break;
             }
                         int bytesDecoded, frameFinished;
                         AVFrame *frame;
                         frame=avcodec_alloc_frame();
-                        bytesDecoded = avcodec_decode_video(movie->video_st->codec, frame, &frameFinished, pkt->data, pkt->size);
+                        /* TODO: FIXME avcodec_decode_video is old api.
+                        bytesDecoded = avcodec_decode_video(movie->video_st->codec, 
+                                                            frame, 
+                                                            &frameFinished, 
+                                                            pkt->data, 
+                                                            pkt->size);
+                        */
+                        bytesDecoded = avcodec_decode_video2(movie->video_st->codec, 
+                                                             frame, 
+                                                             &frameFinished, 
+                                                             pkt);
+
                         if(frameFinished)
                         {
                             if((pkt->pts >= vid_seek_target) || (pkt->dts >= vid_seek_target))
 #else
         movie->video_st->codec->reordered_opaque= pkt->pts;
 #endif
+
+        /* TODO: FIXME: avcodec_decode_video is old API.
         len1 = avcodec_decode_video(movie->video_st->codec,
                                     frame, &got_picture,
                                     pkt->data, pkt->size);
+        */
+        len1 = avcodec_decode_video2(movie->video_st->codec,
+                                    frame, &got_picture,
+                                    pkt);
+
+
 #if LIBAVCODEC_VERSION_INT<3412992
 		if((pkt->dts == AV_NOPTS_VALUE)) //(52<<16)+(20<<8)+0 ie 52.20.0
         {
 
 #define BPP 1
 
+
+#define PYG_MEDIA_TYPE_VIDEO AVMEDIA_TYPE_VIDEO
+#define PYG_MEDIA_TYPE_AUDIO AVMEDIA_TYPE_AUDIO
+#define PYG_MEDIA_TYPE_SUBTITLE AVMEDIA_TYPE_SUBTITLE
+
+/*
+#define PYG_MEDIA_TYPE_AUDIO CODEC_TYPE_AUDIO
+#define PYG_MEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
+#define PYG_MEDIA_TYPE_SUBTITLE CODEC_TYPE_SUBTITLE
+*/
+
+
+
+
+/*
+#ifdef AVMEDIA_TYPE_AUDIO
+    #define PYG_MEDIA_TYPE_AUDIO AVMEDIA_TYPE_AUDIO
+#endif
+#if defined(CODEC_TYPE_AUDIO)
+    #define PYG_MEDIA_TYPE_AUDIO CODEC_TYPE_AUDIO
+#endif
+
+#if defined(AVMEDIA_TYPE_VIDEO)
+    #define PYG_MEDIA_TYPE_VIDEO AVMEDIA_TYPE_VIDEO
+#endif
+#if defined(CODEC_TYPE_VIDEO)
+    #define PYG_MEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
+#endif
+
+#if defined(AVMEDIA_TYPE_SUBTITLE)
+    #define PYG_MEDIA_TYPE_SUBTITLE AVMEDIA_TYPE_SUBTITLE
+#endif
+#if defined(CODEC_TYPE_SUBTITLE)
+    #define PYG_MEDIA_TYPE_SUBTITLE CODEC_TYPE_SUBTITLE
+#endif
+*/
+
+
+
+
 //enables profiling info to be gathered
 //#define PROFILE 1
 
 	
         switch(enc->codec_type)
         {
-        case CODEC_TYPE_AUDIO:
+        case PYG_MEDIA_TYPE_AUDIO:
             self->sample_rate=enc->sample_rate;
 	    	self->channels = enc->channels;
 	    	self->aud_codec = (char *)PyMem_Malloc((sizeof(char)*strlen(codec->name))+sizeof(char));
 	    	strncpy(self->aud_codec, codec->name, strlen(codec->name)+1);
 	    	break;
-        case CODEC_TYPE_VIDEO:
+        case PYG_MEDIA_TYPE_VIDEO:
             self->width = enc->width;
 	    	self->height = enc->height;
 	    	self->aspect_ratio = (double)self->width/(double)self->height;
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.