all repos — mgba @ 16ff5802b6fed375b86d3261fe6dd1913c9008a0

mGBA Game Boy Advance Emulator

FFmpeg: Maybe actually fix build on FFmpeg 3.0
Jeffrey Pfau jeffrey@endrift.com
Sat, 17 Sep 2016 01:00:52 -0700
commit

16ff5802b6fed375b86d3261fe6dd1913c9008a0

parent

c280d8efa62247084bee013523484aed8d8dfb5c

2 files changed, 25 insertions(+), 22 deletions(-)

jump to
M src/feature/ffmpeg/ffmpeg-encoder.csrc/feature/ffmpeg/ffmpeg-encoder.c

@@ -214,13 +214,8 @@ encoder->context->oformat = oformat;

#endif if (acodec) { -#if LIBAVFORMAT_VERSION_MAJOR >= 56 encoder->audioStream = avformat_new_stream(encoder->context, NULL); encoder->audio = avcodec_alloc_context3(acodec); -#else - encoder->audioStream = avformat_new_stream(encoder->context, acodec); - encoder->audio = encoder->audioStream->codec; -#endif encoder->audio->bit_rate = encoder->audioBitrate; encoder->audio->channels = 2; encoder->audio->channel_layout = AV_CH_LAYOUT_STEREO;

@@ -263,7 +258,7 @@ (strcasecmp(encoder->containerFormat, "mp4") ||

strcasecmp(encoder->containerFormat, "m4v") || strcasecmp(encoder->containerFormat, "mov"))) { // MP4 container doesn't support the raw ADTS AAC format that the encoder spits out -#if LIBAVCODEC_VERSION_MAJOR >= 57 +#ifdef FFMPEG_USE_NEW_BSF av_bsf_alloc(av_bsf_get_by_name("aac_adtstoasc"), &encoder->absf); avcodec_parameters_from_context(encoder->absf->par_in, encoder->audio); av_bsf_init(encoder->absf);

@@ -271,18 +266,13 @@ #else

encoder->absf = av_bitstream_filter_init("aac_adtstoasc"); #endif } -#if LIBAVCODEC_VERSION_MAJOR >= 57 +#ifdef FFMPEG_USE_NEW_BSF avcodec_parameters_from_context(encoder->audioStream->codecpar, encoder->audio); #endif } -#if LIBAVFORMAT_VERSION_MAJOR >= 56 encoder->videoStream = avformat_new_stream(encoder->context, NULL); encoder->video = avcodec_alloc_context3(vcodec); -#else - encoder->videoStream = avformat_new_stream(encoder->context, vcodec); - encoder->video = encoder->videoStream->codec; -#endif encoder->video->bit_rate = encoder->videoBitrate; encoder->video->width = encoder->width; encoder->video->height = encoder->height;

@@ -316,7 +306,7 @@ encoder->videoFrame->height = encoder->video->height;

encoder->videoFrame->pts = 0; _ffmpegSetVideoDimensions(&encoder->d, encoder->iwidth, encoder->iheight); av_image_alloc(encoder->videoFrame->data, encoder->videoFrame->linesize, encoder->video->width, encoder->video->height, encoder->video->pix_fmt, 32); -#if LIBAVCODEC_VERSION_MAJOR >= 57 +#ifdef FFMPEG_USE_NEW_BSF avcodec_parameters_from_context(encoder->videoStream->codecpar, encoder->video); #endif

@@ -348,7 +338,7 @@ avresample_close(encoder->resampleContext);

} if (encoder->absf) { -#if LIBAVCODEC_VERSION_MAJOR >= 57 +#ifdef FFMPEG_USE_NEW_BSF av_bsf_free(&encoder->absf); #else av_bitstream_filter_close(encoder->absf);

@@ -413,7 +403,7 @@ av_init_packet(&packet);

packet.data = 0; packet.size = 0; int gotData; -#if LIBAVCODEC_VERSION_MAJOR >= 57 +#ifdef FFMPEG_USE_PACKETS avcodec_send_frame(encoder->audio, encoder->audioFrame); gotData = avcodec_receive_packet(encoder->audio, &packet) == 0; #else

@@ -423,7 +413,7 @@ if (gotData) {

if (encoder->absf) { AVPacket tempPacket = packet; -#if LIBAVCODEC_VERSION_MAJOR >= 57 +#ifdef FFMPEG_USE_NEW_BSF int success = av_bsf_send_packet(encoder->absf, &packet) && av_bsf_receive_packet(encoder->absf, &packet); #else int success = av_bitstream_filter_filter(encoder->absf, encoder->audio, 0,

@@ -434,7 +424,7 @@ if (success > 0) {

#if LIBAVUTIL_VERSION_MAJOR >= 53 tempPacket.buf = av_buffer_create(tempPacket.data, tempPacket.size, av_buffer_default_free, 0, 0); #endif -#if LIBAVCODEC_VERSION_MAJOR >= 57 +#ifdef FFMPEG_USE_PACKET_UNREF av_packet_unref(&packet); #else av_free_packet(&packet);

@@ -445,7 +435,7 @@ }

packet.stream_index = encoder->audioStream->index; av_interleaved_write_frame(encoder->context, &packet); } -#if LIBAVCODEC_VERSION_MAJOR >= 57 +#ifdef FFMPEG_USE_PACKET_UNREF av_packet_unref(&packet); #else av_free_packet(&packet);

@@ -473,14 +463,14 @@

sws_scale(encoder->scaleContext, (const uint8_t* const*) &pixels, (const int*) &stride, 0, encoder->iheight, encoder->videoFrame->data, encoder->videoFrame->linesize); int gotData; -#if LIBAVCODEC_VERSION_MAJOR >= 57 +#ifdef FFMPEG_USE_PACKETS avcodec_send_frame(encoder->video, encoder->videoFrame); gotData = avcodec_receive_packet(encoder->video, &packet) == 0; #else avcodec_encode_video2(encoder->video, &packet, encoder->videoFrame, &gotData); #endif if (gotData) { -#if LIBAVCODEC_VERSION_MAJOR < 57 +#ifndef FFMPEG_USE_PACKET_UNREF if (encoder->video->coded_frame->key_frame) { packet.flags |= AV_PKT_FLAG_KEY; }

@@ -488,7 +478,7 @@ #endif

packet.stream_index = encoder->videoStream->index; av_interleaved_write_frame(encoder->context, &packet); } -#if LIBAVCODEC_VERSION_MAJOR >= 57 +#ifdef FFMPEG_USE_PACKET_UNREF av_packet_unref(&packet); #else av_free_packet(&packet);
M src/feature/ffmpeg/ffmpeg-encoder.hsrc/feature/ffmpeg/ffmpeg-encoder.h

@@ -9,6 +9,19 @@

#include "gba/gba.h" #include <libavformat/avformat.h> +#include <libavcodec/version.h> + +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 100) +#define FFMPEG_USE_PACKETS +#endif + +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 15, 0) +#define FFMPEG_USE_NEW_BSF +#endif + +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 8, 0) +#define FFMPEG_USE_PACKET_UNREF +#endif struct FFmpegEncoder { struct mAVStream d;

@@ -34,7 +47,7 @@ size_t currentAudioSample;

int64_t currentAudioFrame; int64_t nextAudioPts; struct AVAudioResampleContext* resampleContext; -#if LIBAVCODEC_VERSION_MAJOR >= 57 +#ifdef FFMPEG_USE_NEW_BSF struct AVBSFContext* absf; // Needed for AAC in MP4 #else struct AVBitStreamFilterContext* absf; // Needed for AAC in MP4