summaryrefslogtreecommitdiffstats
path: root/games/alephone/r5009.diff
blob: 39f9e648cf0780a7bc131a6b2544e7a8f053eef4 (plain)
Index: Source_Files/Sound/FFmpegDecoder.cpp
===================================================================
--- Source_Files/Sound/FFmpegDecoder.cpp	(revision 5008)
+++ Source_Files/Sound/FFmpegDecoder.cpp	(revision 5009)
@@ -199,10 +199,13 @@
     
     while (pkt_temp.size > 0)
     {
-        AVFrame frame;
-        avcodec_get_frame_defaults(&frame);
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,0)
+        AVFrame *dframe = avcodec_alloc_frame();
+#else
+        AVFrame *dframe = av_frame_alloc();
+#endif
         int got_frame = 0;
-        int bytes_read = avcodec_decode_audio4(dec_ctx, &frame, &got_frame, &pkt_temp);
+        int bytes_read = avcodec_decode_audio4(dec_ctx, dframe, &got_frame, &pkt_temp);
         if (bytes_read < 0)
         {
             av_free_packet(&pkt);
@@ -216,12 +219,12 @@
             
             int stride = -1;
             if (channels > 1 && av_sample_fmt_is_planar(in_fmt))
-                stride = frame.extended_data[1] - frame.extended_data[0];
+                stride = dframe->extended_data[1] - dframe->extended_data[0];
 
-            int written = convert_audio(frame.nb_samples, channels,
+            int written = convert_audio(dframe->nb_samples, channels,
                                         stride,
-                                        in_fmt, frame.extended_data[0],
-                                        frame.nb_samples, channels,
+                                        in_fmt, dframe->extended_data[0],
+                                        dframe->nb_samples, channels,
                                         -1,
                                         out_fmt, av->temp_data);
             
@@ -230,6 +233,12 @@
             pkt_temp.data += bytes_read;
             pkt_temp.size -= bytes_read;
         }
+        
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,0)
+        av_freep(&dframe);
+#else
+        av_frame_free(&dframe);
+#endif
     }
     
     av_free_packet(&pkt);
Index: Source_Files/FFmpeg/Movie.cpp
===================================================================
--- Source_Files/FFmpeg/Movie.cpp	(revision 5008)
+++ Source_Files/FFmpeg/Movie.cpp	(revision 5009)
@@ -85,6 +85,15 @@
 }
 #endif
 
+// FFmpeg compatibility
+#ifndef AV_CODEC_ID_VP8
+#define AV_CODEC_ID_VP8 CODEC_ID_VP8
+#endif
+#ifndef AV_CODEC_ID_VORBIS
+#define AV_CODEC_ID_VORBIS CODEC_ID_VORBIS
+#endif
+
+
 // shamelessly stolen from SDL 2.0
 static int get_cpu_count(void)
 {
@@ -399,7 +408,7 @@
     AVStream *video_stream;
     if (success)
     {
-        video_codec = avcodec_find_encoder(CODEC_ID_VP8);
+        video_codec = avcodec_find_encoder(AV_CODEC_ID_VP8);
         success = video_codec;
         if (!success) err_msg = "Could not find VP8 encoder";
     }
@@ -445,7 +454,11 @@
     }
     if (success)
     {
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,0)
         av->video_frame = avcodec_alloc_frame();
+#else
+        av->video_frame = av_frame_alloc();
+#endif
         success = av->video_frame;
         if (!success) err_msg = "Could not allocate video frame";
     }
@@ -466,7 +479,7 @@
     AVStream *audio_stream;
     if (success)
     {
-        audio_codec = avcodec_find_encoder(CODEC_ID_VORBIS);
+        audio_codec = avcodec_find_encoder(AV_CODEC_ID_VORBIS);
         success = audio_codec;
         if (!success) err_msg = "Could not find Vorbis encoder";
     }
@@ -511,7 +524,11 @@
     }
     if (success)
     {
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,0)
         av->audio_frame = avcodec_alloc_frame();
+#else
+        av->audio_frame = av_frame_alloc();
+#endif
         success = av->audio_frame;
         if (!success) err_msg = "Could not allocate audio frame";
     }
@@ -550,6 +567,7 @@
     // Start movie file
     if (success)
     {
+        video_stream->time_base = (AVRational){1, TICKS_PER_SECOND};
         avformat_write_header(av->fmt_ctx, NULL);
     }
     
@@ -615,13 +633,15 @@
     while (!done)
     {
         // add video
-        int vsize = avcodec_encode_video(vcodec,
-                                         av->video_buf, av->video_bufsize,
-                                         frame);
+        AVPacket pkt;
+        av_init_packet(&pkt);
+        pkt.data = av->video_buf;
+        pkt.size = av->video_bufsize;
+        
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,0,0)
+        int vsize = avcodec_encode_video(vcodec, av->video_buf, av->video_bufsize, frame);
         if (vsize > 0)
         {
-            AVPacket pkt;
-            av_init_packet(&pkt);
             if (vcodec->coded_frame->pts != AV_NOPTS_VALUE)
             {
                 pkt.pts = av_rescale_q(vcodec->coded_frame->pts,
@@ -630,12 +650,19 @@
             }
             if (vcodec->coded_frame->key_frame)
                 pkt.flags |= AV_PKT_FLAG_KEY;
+            pkt.size = vsize;
+        }
+
+#else
+        int got_packet = 0;
+        int vsize = avcodec_encode_video2(vcodec, &pkt, frame, &got_packet);
+#endif
+        if (vsize > 0)
+        {
             pkt.stream_index = vstream->index;
-            pkt.data = av->video_buf;
-            pkt.size = vsize;
             av_interleaved_write_frame(av->fmt_ctx, &pkt);
-            av_free_packet(&pkt);
         }
+        av_free_packet(&pkt);
         
         if (!last || vsize <= 0)
             done = true;
@@ -679,7 +706,11 @@
                       write_samples, acodec->channels, write_samples * write_bps,
                       acodec->sample_fmt, av->audio_data_conv);
                       
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
         avcodec_get_frame_defaults(av->audio_frame);
+#else
+        av_frame_unref(av->audio_frame);
+#endif
         av->audio_frame->nb_samples = write_samples;
         int asize = avcodec_fill_audio_frame(av->audio_frame, acodec->channels,
                                              acodec->sample_fmt,
@@ -695,7 +726,7 @@
             if (0 == avcodec_encode_audio2(acodec, &pkt, av->audio_frame, &got_pkt)
                 && got_pkt)
             {
-                if (acodec->coded_frame->pts != AV_NOPTS_VALUE)
+                if (acodec->coded_frame && acodec->coded_frame->pts != AV_NOPTS_VALUE)
                 {
                     pkt.pts = av_rescale_q(acodec->coded_frame->pts,
                                            acodec->time_base,
Index: Source_Files/FFmpeg/SDL_ffmpeg.c
===================================================================
--- Source_Files/FFmpeg/SDL_ffmpeg.c	(revision 5008)
+++ Source_Files/FFmpeg/SDL_ffmpeg.c	(revision 5009)
@@ -48,6 +48,38 @@
 }
 #endif
 
+// FFmpeg compatibility
+#ifndef AV_CODEC_ID_MPEG1VIDEO
+#define AV_CODEC_ID_MPEG1VIDEO CODEC_ID_MPEG1VIDEO
+#endif
+#ifndef AV_CODEC_ID_MPEG2VIDEO
+#define AV_CODEC_ID_MPEG2VIDEO CODEC_ID_MPEG2VIDEO
+#endif
+#ifndef AV_CODEC_ID_MP2
+#define AV_CODEC_ID_MP2 CODEC_ID_MP2
+#endif
+#ifndef AV_CODEC_ID_DVVIDEO
+#define AV_CODEC_ID_DVVIDEO CODEC_ID_DVVIDEO
+#endif
+#ifndef AV_CODEC_ID_DVAUDIO
+#define AV_CODEC_ID_DVAUDIO CODEC_ID_DVAUDIO
+#endif
+#ifndef AV_CODEC_ID_PCM_S16LE
+#define AV_CODEC_ID_PCM_S16LE CODEC_ID_PCM_S16LE
+#endif
+#ifndef AV_CODEC_ID_PCM_S16BE
+#define AV_CODEC_ID_PCM_S16BE CODEC_ID_PCM_S16BE
+#endif
+#ifndef AV_CODEC_ID_PCM_U16LE
+#define AV_CODEC_ID_PCM_U16LE CODEC_ID_PCM_U16LE
+#endif
+#ifndef AV_CODEC_ID_PCM_U16BE
+#define AV_CODEC_ID_PCM_U16BE CODEC_ID_PCM_U16BE
+#endif
+#ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE
+#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000
+#endif
+
 #include "SDL_ffmpeg.h"
 
 #ifdef MSVC
@@ -169,12 +201,12 @@
 
 const SDL_ffmpegCodec SDL_ffmpegCodecPALDVD =
 {
-    CODEC_ID_MPEG2VIDEO,
+    AV_CODEC_ID_MPEG2VIDEO,
     720, 576,
     1, 25,
     6000000,
     -1, -1,
-    CODEC_ID_MP2,
+    AV_CODEC_ID_MP2,
     2, 48000,
     192000,
     -1, -1
@@ -182,12 +214,12 @@
 
 const SDL_ffmpegCodec SDL_ffmpegCodecPALDV =
 {
-    CODEC_ID_DVVIDEO,
+    AV_CODEC_ID_DVVIDEO,
     720, 576,
     1, 25,
     6553600,
     -1, -1,
-    CODEC_ID_DVAUDIO,
+    AV_CODEC_ID_DVAUDIO,
     2, 48000,
     256000,
     -1, -1
@@ -324,7 +356,11 @@
     {
         if ( file->type == SDL_ffmpegInputStream )
         {
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53,17,0)
             av_close_input_file( file->_ffmpeg );
+#else
+            avformat_close_input( &file->_ffmpeg );
+#endif
         }
         else if ( file->type == SDL_ffmpegOutputStream )
         {
@@ -448,7 +484,11 @@
                 {
                     stream->mutex = SDL_CreateMutex();
 
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,0)
                     stream->decodeFrame = avcodec_alloc_frame();
+#else
+                    stream->decodeFrame = av_frame_alloc();
+#endif
 
                     SDL_ffmpegStream **s = &file->vs;
                     while ( *s )
@@ -1301,11 +1341,17 @@
 {
     if ( stream && stream->_ffmpeg && stream->_ffmpeg->codec )
     {
-        if ( nominator ) *nominator = stream->_ffmpeg->r_frame_rate.num;
+        AVRational frate;
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(55,12,100)
+        frate = stream->_ffmpeg->r_frame_rate;
+#else
+        frate = av_stream_get_r_frame_rate(stream->_ffmpeg);
+#endif
+        if ( nominator ) *nominator = frate.num;
 
-        if ( denominator ) *denominator = stream->_ffmpeg->r_frame_rate.den;
+        if ( denominator ) *denominator = frate.den;
 
-        return ( float )stream->_ffmpeg->r_frame_rate.num / stream->_ffmpeg->r_frame_rate.den;
+        return ( float )frate.num / frate.den;
     }
     else
     {
@@ -1587,13 +1633,13 @@
     stream->codec->pix_fmt = PIX_FMT_YUV420P;
 
     /* set mpeg2 codec parameters */
-    if ( stream->codec->codec_id == CODEC_ID_MPEG2VIDEO )
+    if ( stream->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO )
     {
         stream->codec->max_b_frames = 2;
     }
 
     /* set mpeg1 codec parameters */
-    if ( stream->codec->codec_id == CODEC_ID_MPEG1VIDEO )
+    if ( stream->codec->codec_id == AV_CODEC_ID_MPEG1VIDEO )
     {
         /* needed to avoid using macroblocks in which some coeffs overflow
            this doesnt happen with normal video, it just happens here as the
@@ -1757,10 +1803,10 @@
 
             switch ( stream->codec->codec_id )
             {
-                case CODEC_ID_PCM_S16LE:
-                case CODEC_ID_PCM_S16BE:
-                case CODEC_ID_PCM_U16LE:
-                case CODEC_ID_PCM_U16BE:
+                case AV_CODEC_ID_PCM_S16LE:
+                case AV_CODEC_ID_PCM_S16BE:
+                case AV_CODEC_ID_PCM_U16LE:
+                case AV_CODEC_ID_PCM_U16BE:
                     str->encodeAudioInputSize >>= 1;
                     break;
                 default:
@@ -2032,19 +2078,41 @@
     while ( size > 0 )
     {
         /* Decode the packet */
-
-#if ( LIBAVCODEC_VERSION_MAJOR <= 52 && LIBAVCODEC_VERSION_MINOR <= 20 )
-        int len = avcodec_decode_audio2( file->audioStream->_ffmpeg->codec, ( int16_t* )file->audioStream->sampleBuffer, &audioSize, pack->data, pack->size );
-#else
-        int len = avcodec_decode_audio3( file->audioStream->_ffmpeg->codec, ( int16_t* )file->audioStream->sampleBuffer, &audioSize, pack );
+        AVCodecContext *avctx = file->audioStream->_ffmpeg->codec;
+        AVFrame dframe;
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
+        avcodec_get_frame_defaults(&dframe);
 #endif
-
-        /* if an error occured, we skip the frame */
-        if ( len <= 0 || !audioSize )
+        int got_frame = 0;
+        int len = avcodec_decode_audio4( avctx, &dframe, &got_frame, pack );
+        
+        if (len < 0 || !got_frame)
         {
             SDL_ffmpegSetError( "error decoding audio frame" );
             break;
         }
+        
+        int planar = av_sample_fmt_is_planar( avctx->sample_fmt );
+        int plane_size;
+        int data_size = av_samples_get_buffer_size( &plane_size, avctx->channels, dframe.nb_samples, avctx->sample_fmt, 1 );
+        if ( data_size > 10000 )
+        {
+            SDL_ffmpegSetError( "too much data in decoded audio frame" );
+            break;
+        }
+        memcpy( file->audioStream->sampleBuffer, dframe.extended_data[0], plane_size );
+        audioSize = plane_size;
+        if ( planar && avctx->channels > 1 )
+        {
+            int8_t *out = file->audioStream->sampleBuffer + plane_size;
+            int ch;
+            for ( ch = 1; ch < avctx->channels; ch++ )
+            {
+                memcpy( out, dframe.extended_data[ch], plane_size );
+                out += plane_size;
+                audioSize += plane_size;
+            }
+        }
 
         /* change pointers */
         data += len;