aboutsummaryrefslogtreecommitdiff
path: root/games/alephone/r5009.diff
blob: 39f9e648cf0780a7bc131a6b2544e7a8f053eef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
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;