View | Details | Raw Unified | Return to bug 214190 | Differences between
and this patch

Collapse All | Expand All

(-)b/emulators/visualboyadvance-m/Makefile (+1 lines)
Lines 3-8 Link Here
3
3
4
PORTNAME=	visualboyadvance-m
4
PORTNAME=	visualboyadvance-m
5
PORTVERSION=	2.0.0b2
5
PORTVERSION=	2.0.0b2
6
PORTREVISION=	1
6
CATEGORIES=	emulators
7
CATEGORIES=	emulators
7
8
8
MAINTAINER=	root@cooltrainer.org
9
MAINTAINER=	root@cooltrainer.org
(-)b/emulators/visualboyadvance-m/files/patch-src_common_ffmpeg.cpp (+173 lines)
Added Link Here
1
https://github.com/visualboyadvance-m/visualboyadvance-m/commit/502de18
2
https://github.com/visualboyadvance-m/visualboyadvance-m/commit/a3a07d2
3
https://github.com/visualboyadvance-m/visualboyadvance-m/commit/029a5fc
4
https://github.com/visualboyadvance-m/visualboyadvance-m/commit/3f3c385
5
6
--- src/common/ffmpeg.cpp.orig	2015-09-19 15:58:26 UTC
7
+++ src/common/ffmpeg.cpp
8
@@ -53,6 +53,26 @@ static void avformat_free_context(AVFormatContext *ctx)
9
 #endif
10
 }
11
 
12
+// For compatibility with 3.0+ ffmpeg
13
+#include <libavutil/version.h>
14
+#ifndef PixelFormat
15
+#define PixelFormat AVPixelFormat
16
+#endif
17
+#if LIBAVCODEC_VERSION_MAJOR > 56
18
+#define CODEC_ID_NONE AV_CODEC_ID_NONE
19
+#define CODEC_ID_PCM_S16LE AV_CODEC_ID_PCM_S16LE
20
+#define CODEC_ID_PCM_S16BE AV_CODEC_ID_PCM_S16BE
21
+#define CODEC_ID_PCM_U16LE AV_CODEC_ID_PCM_U16LE
22
+#define CODEC_ID_PCM_U16BE AV_CODEC_ID_PCM_U16BE
23
+#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
24
+#endif
25
+#if LIBAVUTIL_VERSION_MAJOR > 54
26
+#define avcodec_alloc_frame av_frame_alloc
27
+#define PIX_FMT_RGB565LE AV_PIX_FMT_RGB565LE
28
+#define PIX_FMT_RGB24 AV_PIX_FMT_RGB24
29
+#define PIX_FMT_RGBA AV_PIX_FMT_RGBA
30
+#endif
31
+
32
 #define priv_AVFormatContext AVFormatContext
33
 #define priv_AVStream AVStream
34
 #define priv_AVOutputFormat AVOutputFormat
35
@@ -103,10 +123,16 @@ MediaRet MediaRecorder::setup_sound_stream(const char *fname, AVOutputFormat *fm
36
 	oc = NULL;
37
 	return MRET_ERR_NOMEM;
38
     }
39
+
40
+    AVCodec *codec = avcodec_find_encoder(fmt->audio_codec);
41
+
42
     ctx = aud_st->codec;
43
     ctx->codec_id = fmt->audio_codec;
44
     ctx->codec_type = AVMEDIA_TYPE_AUDIO;
45
-    ctx->sample_fmt = AV_SAMPLE_FMT_S16;
46
+    // Some encoders don't like s16 (SAMPLE_FMT_S16)
47
+    ctx->sample_fmt = codec->sample_fmts[0];
48
+    // This was changed in the initial ffmpeg 3.0 update,
49
+    // but shouldn't (as far as I'm aware) cause problems with older versions
50
     ctx->bit_rate = 128000; // arbitrary; in case we're generating mp3
51
     ctx->sample_rate = soundGetSampleRate();
52
     ctx->channels = 2;
53
@@ -115,7 +141,6 @@ MediaRet MediaRecorder::setup_sound_stream(const char *fname, AVOutputFormat *fm
54
     if(fmt->flags & AVFMT_GLOBALHEADER)
55
 	ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
56
 
57
-    AVCodec *codec = avcodec_find_encoder(fmt->audio_codec);
58
 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53,6,0)
59
     if(!codec || avcodec_open(ctx, codec)) {
60
 #else
61
@@ -369,6 +394,7 @@ MediaRecorder::~MediaRecorder()
62
     Stop();
63
 }
64
 
65
+// Still needs updating for avcodec_encode_video2
66
 MediaRet MediaRecorder::AddFrame(const u8 *vid)
67
 {
68
     if(!oc || !vid_st)
69
@@ -376,6 +402,9 @@ MediaRet MediaRecorder::AddFrame(const u8 *vid)
70
 
71
     AVCodecContext *ctx = vid_st->codec;
72
     AVPacket pkt;
73
+#if LIBAVCODEC_VERSION_MAJOR > 56
74
+    int ret, got_packet = 0;
75
+#endif
76
 
77
     // strip borders.  inconsistent between depths for some reason
78
     // but fortunately consistent between gb/gba.
79
@@ -413,7 +442,20 @@ MediaRet MediaRecorder::AddFrame(const u8 *vid)
80
 	pkt.data = f->data[0];
81
 	pkt.size = linesize * ctx->height;
82
     } else {
83
+#if LIBAVCODEC_VERSION_MAJOR > 56
84
+        pkt.data = video_buf;
85
+        pkt.size = VIDEO_BUF_LEN;
86
+        f->format = ctx->pix_fmt;
87
+        f->width = ctx->width;
88
+        f->height = ctx->height;
89
+        ret = avcodec_encode_video2(ctx, &pkt, f, &got_packet);
90
+        if(!ret && got_packet && ctx->coded_frame) {
91
+            ctx->coded_frame->pts = pkt.pts;
92
+            ctx->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY);
93
+        }
94
+#else
95
 	pkt.size = avcodec_encode_video(ctx, video_buf, VIDEO_BUF_LEN, f);
96
+#endif
97
 	if(!pkt.size)
98
 	    return MRET_OK;
99
 	if(ctx->coded_frame && ctx->coded_frame->pts != AV_NOPTS_VALUE)
100
@@ -438,6 +480,53 @@ MediaRet MediaRecorder::AddFrame(const u8 *vid)
101
     return MRET_OK;
102
 }
103
 
104
+#if LIBAVCODEC_VERSION_MAJOR > 56
105
+/* FFmpeg depricated avcodec_encode_audio.
106
+ * It was removed completely in 3.0.
107
+ * This will at least get audio recording *working*
108
+ */
109
+static inline int MediaRecorderEncodeAudio(AVCodecContext *ctx,
110
+                                           AVPacket *pkt,
111
+                                           uint8_t *buf, int buf_size,
112
+                                           const short *samples)
113
+{
114
+    AVFrame *frame;
115
+    av_init_packet(pkt);
116
+    int ret, samples_size, got_packet = 0;
117
+
118
+    pkt->data = buf;
119
+    pkt->size = buf_size;
120
+    if (samples) {
121
+        frame = frame = av_frame_alloc();
122
+        if (ctx->frame_size) {
123
+            frame->nb_samples = ctx->frame_size;
124
+        } else {
125
+            frame->nb_samples = (int64_t)buf_size * 8 /
126
+                            (av_get_bits_per_sample(ctx->codec_id) *
127
+                            ctx->channels);
128
+        }
129
+        frame->format = ctx->sample_fmt;
130
+        frame->channel_layout = ctx->channel_layout;
131
+        samples_size = av_samples_get_buffer_size(NULL, ctx->channels,
132
+                        frame->nb_samples, ctx->sample_fmt, 1);
133
+        avcodec_fill_audio_frame(frame, ctx->channels, ctx->sample_fmt,
134
+                        (const uint8_t *)samples, samples_size, 1);
135
+        //frame->pts = AV_NOPTS_VALUE;
136
+    } else {
137
+        frame = NULL;
138
+    }
139
+        ret = avcodec_encode_audio2(ctx, pkt, frame, &got_packet);
140
+    if (!ret && got_packet && ctx->coded_frame) {
141
+        ctx->coded_frame->pts = pkt->pts;
142
+        ctx->coded_frame->key_frame = !!(pkt->flags & AV_PKT_FLAG_KEY);
143
+    }
144
+        if (frame && frame->extended_data != frame->data)
145
+        av_freep(&frame->extended_data);
146
+        return ret;
147
+
148
+}
149
+#endif
150
+
151
 MediaRet MediaRecorder::AddFrame(const u16 *aud)
152
 {
153
     if(!oc || !aud_st)
154
@@ -465,13 +554,19 @@ MediaRet MediaRecorder::AddFrame(const u16 *aud)
155
     }
156
     while(len + in_audio_buf2 >= frame_len) {
157
 	av_init_packet(&pkt);
158
+	#if LIBAVCODEC_VERSION_MAJOR > 56
159
+	MediaRecorderEncodeAudio(ctx, &pkt, audio_buf, frame_len,
160
+	#else
161
 	pkt.size = avcodec_encode_audio(ctx, audio_buf, frame_len,
162
+	#endif
163
 					(const short *)(in_audio_buf2 ? audio_buf2 : aud));
164
 	if(ctx->coded_frame && ctx->coded_frame->pts != AV_NOPTS_VALUE)
165
 	    pkt.pts = av_rescale_q(ctx->coded_frame->pts, ctx->time_base, aud_st->time_base);
166
 	pkt.flags |= AV_PKT_FLAG_KEY;
167
 	pkt.stream_index = aud_st->index;
168
+	#if LIBAVCODEC_VERSION_MAJOR < 57
169
 	pkt.data = audio_buf;
170
+	#endif
171
 	if(av_interleaved_write_frame(oc, &pkt) < 0) {
172
 	    avformat_free_context(oc);
173
 	    oc = NULL;

Return to bug 214190