ffmpeg-php (0.6.0-2.2) fix_ftbfs_libav-0.7.patch

Summary

 ffmpeg_movie.c |   77 +++++++++++++++++++++++++++++----------------------------
 1 file changed, 40 insertions(+), 37 deletions(-)

    
download this patch

Patch contents

Description: Fix FTFS with libav 0.7 because of undefined CODEC_TYPE_*,
 PKT_FLAG_KEY, hurry_up and MAX_STREAMS variables as well as datas (comment,
 title, author, album, copyright, genre, track, year) in AVFormatContext
 (replaced by av_dict_get functions)
Author: Fabrice Coutadeur <fabricesp@ubuntu.com>

--- a/ffmpeg_movie.c
+++ b/ffmpeg_movie.c
@@ -45,6 +45,10 @@
 
 #include "ffmpeg_frame.h"
 #include "ffmpeg_movie.h"
+
+#if LIBAVFORMAT_VERSION_MAJOR >= 53
+#define MAX_STREAMS 20	/* arbitrary sanity check value */
+#endif
    
 #define GET_MOVIE_RESOURCE(ff_movie_ctx) {\
     zval **_tmp_zval;\
@@ -149,7 +153,7 @@ static int _php_get_stream_index(AVForma
  */
 static AVStream *_php_get_video_stream(AVFormatContext *fmt_ctx)
 {
-    int i = _php_get_stream_index(fmt_ctx, CODEC_TYPE_VIDEO);
+    int i = _php_get_stream_index(fmt_ctx, AVMEDIA_TYPE_VIDEO);
     
     return i < 0 ? NULL : fmt_ctx->streams[i];
 }
@@ -162,7 +166,7 @@ static AVStream *_php_get_video_stream(A
  */
 static AVStream *_php_get_audio_stream(AVFormatContext *fmt_ctx)
 {
-    int i = _php_get_stream_index(fmt_ctx, CODEC_TYPE_AUDIO);
+    int i = _php_get_stream_index(fmt_ctx, AVMEDIA_TYPE_AUDIO);
     
     return i < 0 ? NULL : fmt_ctx->streams[i];
 }
@@ -481,7 +485,7 @@ static AVCodecContext* _php_get_decoder_
     stream_index = _php_get_stream_index(ffmovie_ctx->fmt_ctx, stream_type);
     if (stream_index < 0) {
         // FIXME: factor out the conditional.
-        if (stream_type == CODEC_TYPE_VIDEO) {
+        if (stream_type == AVMEDIA_TYPE_VIDEO) {
             zend_error(E_WARNING, "Can't find video stream in %s", 
                     _php_get_filename(ffmovie_ctx));
             return NULL;
@@ -528,8 +532,8 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getComme
 
     GET_MOVIE_RESOURCE(ffmovie_ctx);
     
-    RETURN_STRINGL(ffmovie_ctx->fmt_ctx->comment,
-            strlen(ffmovie_ctx->fmt_ctx->comment), 1);
+    RETURN_STRINGL(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "comment", NULL, 0)->value,
+            strlen(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "comment", NULL, 0)->value), 1);
 }
 /* }}} */
 
@@ -543,8 +547,8 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getTitle
     
     GET_MOVIE_RESOURCE(ffmovie_ctx);
 
-    RETURN_STRINGL(ffmovie_ctx->fmt_ctx->title,
-            strlen(ffmovie_ctx->fmt_ctx->title), 1);
+    RETURN_STRINGL(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "title", NULL, 0)->value,
+            strlen(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "title", NULL, 0)->value), 1);
 }
 /* }}} */
 
@@ -558,8 +562,8 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getAutho
     
     GET_MOVIE_RESOURCE(ffmovie_ctx);
 
-    RETURN_STRINGL(ffmovie_ctx->fmt_ctx->author,
-            strlen(ffmovie_ctx->fmt_ctx->author), 1);
+    RETURN_STRINGL(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "artist", NULL, 0)->value,
+            strlen(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "artist", NULL, 0)->value), 1);
 }
 /* }}} */
 
@@ -572,8 +576,8 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getCopyr
     
     GET_MOVIE_RESOURCE(ffmovie_ctx);
 
-    RETURN_STRINGL(ffmovie_ctx->fmt_ctx->copyright,
-            strlen(ffmovie_ctx->fmt_ctx->copyright), 1);
+    RETURN_STRINGL(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "copyright", NULL, 0)->value,
+            strlen(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "copyright", NULL, 0)->value), 1);
 }
 /* }}} */
 
@@ -587,8 +591,8 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getAlbum
     
     GET_MOVIE_RESOURCE(ffmovie_ctx);
 
-    RETURN_STRINGL(ffmovie_ctx->fmt_ctx->album,
-            strlen(ffmovie_ctx->fmt_ctx->album), 1);
+    RETURN_STRINGL(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "album", NULL, 0)->value,
+            strlen(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "album", NULL, 0)->value), 1);
 }
 /* }}} */
 
@@ -601,8 +605,8 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getGenre
     
     GET_MOVIE_RESOURCE(ffmovie_ctx);
 
-    RETURN_STRINGL(ffmovie_ctx->fmt_ctx->genre,
-            strlen(ffmovie_ctx->fmt_ctx->genre), 1);
+    RETURN_STRINGL(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "genre", NULL, 0)->value,
+            strlen(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "genre", NULL, 0)->value), 1);
 }
 /* }}} */
 
@@ -616,7 +620,7 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getTrack
     
     GET_MOVIE_RESOURCE(ffmovie_ctx);
     
-    RETURN_LONG(ffmovie_ctx->fmt_ctx->track);
+    RETURN_LONG(strtol(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "track", NULL, 0)->value, NULL, 10));
 }
 /* }}} */
 
@@ -629,7 +633,7 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getYear)
     
     GET_MOVIE_RESOURCE(ffmovie_ctx);
     
-    RETURN_LONG(ffmovie_ctx->fmt_ctx->year);
+    RETURN_LONG(strtol(av_dict_get(ffmovie_ctx->fmt_ctx->metadata, "date", NULL, 0)->value, NULL, 10));
 }
 /* }}} */
 
@@ -675,7 +679,7 @@ static float _php_get_framerate(ff_movie
     }
 
 #if LIBAVCODEC_BUILD > 4753 
-    if (GET_CODEC_FIELD(st->codec, codec_type) == CODEC_TYPE_VIDEO){
+    if (GET_CODEC_FIELD(st->codec, codec_type) == AVMEDIA_TYPE_VIDEO){
         if (st->r_frame_rate.den && st->r_frame_rate.num) {
             rate = av_q2d(st->r_frame_rate);
         } else {
@@ -807,7 +811,7 @@ static long _php_get_framenumber(ff_movi
 {
     AVCodecContext *decoder_ctx = NULL;
 
-    decoder_ctx = _php_get_decoder_context(ffmovie_ctx, CODEC_TYPE_VIDEO);
+    decoder_ctx = _php_get_decoder_context(ffmovie_ctx, AVMEDIA_TYPE_VIDEO);
     if (!decoder_ctx) {
         return 0;
     }
@@ -847,7 +851,7 @@ static int _php_get_pixelformat(ff_movie
 {
     AVCodecContext *decoder_ctx;
     
-    decoder_ctx = _php_get_decoder_context(ffmovie_ctx, CODEC_TYPE_VIDEO);
+    decoder_ctx = _php_get_decoder_context(ffmovie_ctx, AVMEDIA_TYPE_VIDEO);
 
     return decoder_ctx ? decoder_ctx->pix_fmt : 0;
 }
@@ -960,7 +964,7 @@ static const char* _php_get_codec_name(f
         codec_name = decoder_ctx->codec_name;
     } else {
         /* output avi tags */
-        if (decoder_ctx->codec_type == CODEC_TYPE_VIDEO) {
+        if (decoder_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
             snprintf(buf1, sizeof(buf1), "%c%c%c%c",
                     decoder_ctx->codec_tag & 0xff,
                     (decoder_ctx->codec_tag >> 8) & 0xff,
@@ -986,7 +990,7 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getVideo
 
     GET_MOVIE_RESOURCE(ffmovie_ctx);
 
-    codec_name = (char*)_php_get_codec_name(ffmovie_ctx, CODEC_TYPE_VIDEO);
+    codec_name = (char*)_php_get_codec_name(ffmovie_ctx, AVMEDIA_TYPE_VIDEO);
  
     if (codec_name) {
         RETURN_STRINGL(codec_name, strlen(codec_name), 1);
@@ -1006,7 +1010,7 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getAudio
 
     GET_MOVIE_RESOURCE(ffmovie_ctx);
 
-    codec_name = (char*)_php_get_codec_name(ffmovie_ctx, CODEC_TYPE_AUDIO);
+    codec_name = (char*)_php_get_codec_name(ffmovie_ctx, AVMEDIA_TYPE_AUDIO);
  
     if (codec_name) {
         RETURN_STRINGL(codec_name, strlen(codec_name), 1);
@@ -1026,7 +1030,7 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getVideo
     
     GET_MOVIE_RESOURCE(ffmovie_ctx);
    
-    stream_id= _php_get_stream_index(ffmovie_ctx->fmt_ctx, CODEC_TYPE_VIDEO); 
+    stream_id= _php_get_stream_index(ffmovie_ctx->fmt_ctx, AVMEDIA_TYPE_VIDEO);
 
 	if( stream_id == -1 )
 	{
@@ -1048,7 +1052,7 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getAudio
     
     GET_MOVIE_RESOURCE(ffmovie_ctx);
    
-    stream_id= _php_get_stream_index(ffmovie_ctx->fmt_ctx, CODEC_TYPE_AUDIO); 
+    stream_id= _php_get_stream_index(ffmovie_ctx->fmt_ctx, AVMEDIA_TYPE_AUDIO);
 
 	if( stream_id == -1 )
 	{
@@ -1086,7 +1090,7 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getAudio
 
     GET_MOVIE_RESOURCE(ffmovie_ctx);
 
-    channels = _php_get_codec_channels(ffmovie_ctx, CODEC_TYPE_AUDIO);
+    channels = _php_get_codec_channels(ffmovie_ctx, AVMEDIA_TYPE_AUDIO);
  
     if (channels) {
         RETURN_LONG(channels);
@@ -1122,7 +1126,7 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getAudio
 
     GET_MOVIE_RESOURCE(ffmovie_ctx);
 
-    sample_rate = _php_get_codec_sample_rate(ffmovie_ctx, CODEC_TYPE_AUDIO);
+    sample_rate = _php_get_codec_sample_rate(ffmovie_ctx, AVMEDIA_TYPE_AUDIO);
  
     if (sample_rate) {
         RETURN_LONG(sample_rate);
@@ -1158,7 +1162,7 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getAudio
 
     GET_MOVIE_RESOURCE(ffmovie_ctx);
 
-    bit_rate = _php_get_codec_bit_rate(ffmovie_ctx, CODEC_TYPE_AUDIO);
+    bit_rate = _php_get_codec_bit_rate(ffmovie_ctx, AVMEDIA_TYPE_AUDIO);
  
     if (bit_rate) {
         RETURN_LONG(bit_rate);
@@ -1178,7 +1182,7 @@ FFMPEG_PHP_METHOD(ffmpeg_movie, getVideo
 
     GET_MOVIE_RESOURCE(ffmovie_ctx);
 
-    bit_rate = _php_get_codec_bit_rate(ffmovie_ctx, CODEC_TYPE_VIDEO);
+    bit_rate = _php_get_codec_bit_rate(ffmovie_ctx, AVMEDIA_TYPE_VIDEO);
  
     if (bit_rate) {
         RETURN_LONG(bit_rate);
@@ -1201,7 +1205,7 @@ static AVFrame* _php_read_av_frame(ff_mo
     int got_frame; 
 
     video_stream = _php_get_stream_index(ffmovie_ctx->fmt_ctx, 
-            CODEC_TYPE_VIDEO);
+            AVMEDIA_TYPE_VIDEO);
     if (video_stream < 0) {
         return NULL;
     }
@@ -1212,11 +1216,10 @@ static AVFrame* _php_read_av_frame(ff_mo
     while (av_read_frame(ffmovie_ctx->fmt_ctx, &packet) >= 0) {
         if (packet.stream_index == video_stream) {
         
-            avcodec_decode_video(decoder_ctx, frame, &got_frame,
-                    packet.data, packet.size);
+            avcodec_decode_video2(decoder_ctx, frame, &got_frame, &packet);
         
             if (got_frame) {
-                *is_keyframe = (packet.flags & PKT_FLAG_KEY);
+                *is_keyframe = (packet.flags & AV_PKT_FLAG_KEY);
                 *pts = packet.pts;
                 av_free_packet(&packet);
                 return frame;
@@ -1243,7 +1246,7 @@ static AVFrame* _php_get_av_frame(ff_mov
     AVCodecContext *decoder_ctx = NULL;
     AVFrame *frame = NULL;
 
-    decoder_ctx = _php_get_decoder_context(ffmovie_ctx, CODEC_TYPE_VIDEO);
+    decoder_ctx = _php_get_decoder_context(ffmovie_ctx, AVMEDIA_TYPE_VIDEO);
     if (decoder_ctx == NULL) {
         return NULL;
     }
@@ -1279,9 +1282,9 @@ static AVFrame* _php_get_av_frame(ff_mov
                 wanted_frame != GETFRAME_NEXTFRAME &&
                 wanted_frame - ffmovie_ctx->frame_number > 
                 decoder_ctx->gop_size + 1) {
-            decoder_ctx->hurry_up = 1;
+            decoder_ctx->skip_frame = AVDISCARD_NONREF;
         } else {
-            decoder_ctx->hurry_up = 0;
+            decoder_ctx->skip_frame = AVDISCARD_DEFAULT;
         }
         ffmovie_ctx->frame_number++; 
 
@@ -1440,7 +1443,7 @@ static double _php_get_sample_aspect_rat
     AVCodecContext *decoder_ctx;
 	
 
-    decoder_ctx = _php_get_decoder_context(ffmovie_ctx, CODEC_TYPE_VIDEO);
+    decoder_ctx = _php_get_decoder_context(ffmovie_ctx, AVMEDIA_TYPE_VIDEO);
     if (!decoder_ctx) {
         return -1;
     }