-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
emulators/emu64: Fix build with ffmpeg 6
While here, also add missing dependency on Qt5Network and switch from PORTVERSION to preferred DISTVERSION. PR: 270200 Approved by: tcberner (mentor) Differential Revision: https://reviews.freebsd.org/D39175
- Loading branch information
Showing
2 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
From e09e645a88f37fa2a81d754cb9c86c4a584941a1 Mon Sep 17 00:00:00 2001 | ||
From: Felix Palmen <felix@palmen-it.de> | ||
Date: Mon, 20 Mar 2023 09:42:43 +0100 | ||
Subject: [PATCH] Fix build with ffmpeg 6 | ||
|
||
This doesn't attempt to replace deprecated functions, it only replaces | ||
functions that are gone (avcodec_encode_[audio|video]2) with | ||
straight-forward replacement code. | ||
|
||
It fixes the build with the latest 6.0 release and still builds fine | ||
with ffmpeg 4.4 | ||
--- src/video_capture_class.cpp.orig 2021-07-08 16:55:15 UTC | ||
+++ src/video_capture_class.cpp | ||
@@ -87,7 +87,9 @@ bool VideoCaptureClass::StartCapture(const char *filen | ||
|
||
int ret; | ||
|
||
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100) | ||
av_register_all(); | ||
+#endif | ||
|
||
// | ||
avformat_alloc_output_context2(&format_ctx, nullptr, nullptr, filename); | ||
@@ -267,7 +269,7 @@ int VideoCaptureClass::GetRecordedFrameCount() | ||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
-void VideoCaptureClass::AddStream(OutputStream *ost, AVFormatContext *oc, AVCodec **codec, enum AVCodecID codec_id) | ||
+void VideoCaptureClass::AddStream(OutputStream *ost, AVFormatContext *oc, const AVCodec **codec, enum AVCodecID codec_id) | ||
{ | ||
AVCodecContext *c; | ||
int i; | ||
@@ -363,7 +365,7 @@ void VideoCaptureClass::CloseStream(OutputStream *ost) | ||
swr_free(&ost->swr_ctx); | ||
} | ||
|
||
-bool VideoCaptureClass::OpenVideo(AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg) | ||
+bool VideoCaptureClass::OpenVideo(const AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg) | ||
{ | ||
int ret; | ||
AVCodecContext *c = ost->enc; | ||
@@ -431,7 +433,7 @@ AVFrame* VideoCaptureClass::AllocPicture(enum AVPixelF | ||
return picture; | ||
} | ||
|
||
-bool VideoCaptureClass::OpenAudio(AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg) | ||
+bool VideoCaptureClass::OpenAudio(const AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg) | ||
{ | ||
AVCodecContext *c; | ||
int nb_samples; | ||
@@ -532,7 +534,10 @@ int VideoCaptureClass::WriteVideoFrame(AVFormatContext | ||
av_init_packet(&pkt); | ||
|
||
/* encode the image */ | ||
- ret = avcodec_encode_video2(c, &pkt, frame, &got_packet); | ||
+ ret = avcodec_receive_packet(c, &pkt); | ||
+ if (ret == 0) got_packet = 1; | ||
+ if (ret == AVERROR(EAGAIN)) ret = 0; | ||
+ if (ret == 0) ret = avcodec_send_frame(c, frame); | ||
if (ret < 0) | ||
{ | ||
char err_msg[AV_ERROR_MAX_STRING_SIZE]; | ||
@@ -562,7 +567,7 @@ int VideoCaptureClass::WriteAudioFrame(AVFormatContext | ||
AVPacket pkt = {}; // data and size must be 0; | ||
AVFrame *frame; | ||
int64_t ret; | ||
- int got_packet; | ||
+ int got_packet = 0; | ||
int64_t dst_nb_samples; | ||
av_init_packet(&pkt); | ||
c = ost->enc; | ||
@@ -595,7 +600,10 @@ int VideoCaptureClass::WriteAudioFrame(AVFormatContext | ||
frame->pts = av_rescale_q(ost->samples_count, AVRational{1, c->sample_rate}, c->time_base); | ||
ost->samples_count += dst_nb_samples; | ||
} | ||
- ret = avcodec_encode_audio2(c, &pkt, frame, &got_packet); | ||
+ ret = avcodec_receive_packet(c, &pkt); | ||
+ if (ret == 0) got_packet = 1; | ||
+ if (ret == AVERROR(EAGAIN)) ret = 0; | ||
+ if (ret == 0) ret = avcodec_send_frame(c, frame); | ||
|
||
if (ret < 0) | ||
{ | ||
--- src/video_capture_class.h.orig 2021-07-08 16:55:15 UTC | ||
+++ src/video_capture_class.h | ||
@@ -31,6 +31,7 @@ using namespace std; | ||
|
||
extern "C" | ||
{ | ||
+ #include <libavcodec/avcodec.h> | ||
#include <libavutil/avassert.h> | ||
#include <libavutil/channel_layout.h> | ||
#include <libavutil/opt.h> | ||
@@ -84,11 +85,11 @@ class VideoCaptureClass (public) | ||
bool mutex_01; | ||
|
||
private: | ||
- void AddStream(OutputStream *ost, AVFormatContext *oc, AVCodec **codec, enum AVCodecID codec_id); | ||
+ void AddStream(OutputStream *ost, AVFormatContext *oc, const AVCodec **codec, enum AVCodecID codec_id); | ||
void CloseStream(OutputStream *ost); | ||
- bool OpenVideo(AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg); | ||
+ bool OpenVideo(const AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg); | ||
AVFrame* AllocPicture(enum AVPixelFormat pix_fmt, int width, int height); | ||
- bool OpenAudio(AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg); | ||
+ bool OpenAudio(const AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg); | ||
AVFrame* AllocAudioFrame(enum AVSampleFormat sample_fmt, uint64_t channel_layout, int sample_rate, int nb_samples); | ||
int WriteFrame(AVFormatContext *fmt_ctx, const AVRational *time_base, AVStream *st, AVPacket *pkt); | ||
|
||
@@ -110,9 +111,9 @@ class VideoCaptureClass (public) | ||
int video_bitrate, audio_bitrate; | ||
|
||
|
||
- AVOutputFormat *output_format; | ||
+ const AVOutputFormat *output_format; | ||
OutputStream audio_stream; | ||
- AVCodec *video_codec, *audio_codec; | ||
+ const AVCodec *video_codec, *audio_codec; | ||
AVDictionary *options; | ||
|
||
uint8_t* source_video_data; |