]> git.sesse.net Git - nageru/commitdiff
Fix compilation with FFmpeg _before_ version 5.0.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 6 Feb 2022 14:41:27 +0000 (15:41 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 6 Feb 2022 15:01:05 +0000 (16:01 +0100)
nageru/kaeru.cpp
nageru/video_encoder.cpp
shared/ffmpeg_raii.cpp

index ce58aef9473f3da33112ca5d72e5d8ca5da24ded..9ff672d0f16ab946f1b7e03dce85f068af67f01d 100644 (file)
@@ -66,7 +66,7 @@ int write_packet(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType ty
 unique_ptr<Mux> create_mux(HTTPD *httpd, const AVOutputFormat *oformat, X264Encoder *x264_encoder, AudioEncoder *audio_encoder)
 {
        AVFormatContext *avctx = avformat_alloc_context();
-       avctx->oformat = oformat;
+       avctx->oformat = const_cast<decltype(avctx->oformat)>(oformat);  // const_cast is a hack to work in FFmpeg both before and after 5.0.
 
        uint8_t *buf = (uint8_t *)av_malloc(MUX_BUFFER_SIZE);
        avctx->pb = avio_alloc_context(buf, MUX_BUFFER_SIZE, 1, httpd, nullptr, nullptr, nullptr);
index 8138e76a42c99a7cf984d030ea7241423d99599d..c75c4e3f365f851a0aa056fdebb3bacd7701bf9a 100644 (file)
@@ -191,7 +191,7 @@ RefCountedGLsync VideoEncoder::end_frame()
 void VideoEncoder::open_output_stream()
 {
        AVFormatContext *avctx = avformat_alloc_context();
-       avctx->oformat = oformat;
+       avctx->oformat = const_cast<decltype(avctx->oformat)>(oformat);  // const_cast is a hack to work in FFmpeg both before and after 5.0.
 
        uint8_t *buf = (uint8_t *)av_malloc(MUX_BUFFER_SIZE);
        avctx->pb = avio_alloc_context(buf, MUX_BUFFER_SIZE, 1, this, nullptr, nullptr, nullptr);
index f2948e9feba8908f88ee529daaf43e99d1f2b518..0e087c27b063a03ef80e909f22ec1d2c9516fbde 100644 (file)
@@ -31,7 +31,11 @@ AVFormatContextWithCloser avformat_open_input_unique(
 {
        AVFormatContext *format_ctx = avformat_alloc_context();
        format_ctx->interrupt_callback = interrupt_cb;
+#ifdef ff_const59
+       if (avformat_open_input(&format_ctx, pathname, const_cast<ff_const59 AVInputFormat *>(fmt), options) != 0) {
+#else
        if (avformat_open_input(&format_ctx, pathname, fmt, options) != 0) {
+#endif
                format_ctx = nullptr;
        }
        return AVFormatContextWithCloser(format_ctx);
@@ -48,7 +52,11 @@ AVFormatContextWithCloser avformat_open_input_unique(
        unsigned char *buf = (unsigned char *)av_malloc(buf_size);
        format_ctx->pb = avio_alloc_context(buf, buf_size, /*write_flag=*/false, opaque,
                read_packet, /*write_packet=*/nullptr, /*seek=*/nullptr);
+#ifdef ff_const59
+       if (avformat_open_input(&format_ctx, "", const_cast<ff_const59 AVInputFormat *>(fmt), options) != 0) {
+#else
        if (avformat_open_input(&format_ctx, "", fmt, options) != 0) {
+#endif
                format_ctx = nullptr;
        }
        return AVFormatContextWithCloser(format_ctx);