From 41fec44c3418b099f4ec43260e139c84b13faade Mon Sep 17 00:00:00 2001
From: Elliu <elliu@hashi.re>
Date: Thu, 28 Apr 2022 21:58:57 +0200
Subject: [PATCH] FIX: avcodec_find_decoder() now return pointer to constant

---
 src/Lib/AbstractMediaContext.hh | 6 +++---
 src/Lib/Audio.cc                | 2 +-
 src/Lib/Audio.hh                | 2 +-
 src/Lib/Video.cc                | 2 +-
 src/Lib/Video.hh                | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/Lib/AbstractMediaContext.hh b/src/Lib/AbstractMediaContext.hh
index 07e7fb40..8fbaff3d 100644
--- a/src/Lib/AbstractMediaContext.hh
+++ b/src/Lib/AbstractMediaContext.hh
@@ -59,7 +59,7 @@ protected:
     using Super = AbstractMediaStream<AVMEDIA_TYPE>;
 
 protected:
-    AbstractMediaStream(AVCodec *streamCodec, AVFormatContext *formatArg, AVStream *streamArg,
+    AbstractMediaStream(const AVCodec *streamCodec, AVFormatContext *formatArg, AVStream *streamArg,
                         int index)
         : codecId(streamArg->codecpar->codec_id)
         , codec(streamCodec)
@@ -103,7 +103,7 @@ public:
 protected:
     // Codec related informations
     AVCodecID codecId{ AV_CODEC_ID_NONE };
-    AVCodec *codec{ nullptr };
+    const AVCodec *codec{ nullptr };
     AVCodecParameters *codecParams{ nullptr };
     AVCodecContextPtr codecContext{ nullptr };
     AVFormatContext *dataFormat{ nullptr };
@@ -153,7 +153,7 @@ public:
         for (uint i = 0; i < format->nb_streams; ++i) {
             AVStream *itFmt           = format->streams[i];
             AVCodecParameters *params = itFmt->codecpar;
-            AVCodec *streamCodec      = avcodec_find_decoder(params->codec_id);
+            const AVCodec *streamCodec      = avcodec_find_decoder(params->codec_id);
             if (streamCodec && streamCodec->type == avMediaType)
                 audioStreams.insert(i, std::make_shared<Stream>(streamCodec, formatPtr, itFmt, i));
         }
diff --git a/src/Lib/Audio.cc b/src/Lib/Audio.cc
index 290af835..71cddce7 100644
--- a/src/Lib/Audio.cc
+++ b/src/Lib/Audio.cc
@@ -26,7 +26,7 @@ AudioContext::getProperties() const noexcept
 // AudioStream class implementation
 
 // Constructor, need an AVFormat and an AVStream
-AudioStream::AudioStream(AVCodec *streamCodec, AVFormatContext *formatPtr, AVStream *streamArg,
+AudioStream::AudioStream(const AVCodec *streamCodec, AVFormatContext *formatPtr, AVStream *streamArg,
                          int index)
     : Super(streamCodec, formatPtr, streamArg, index)
 {
diff --git a/src/Lib/Audio.hh b/src/Lib/Audio.hh
index 0c478c67..689de303 100644
--- a/src/Lib/Audio.hh
+++ b/src/Lib/Audio.hh
@@ -17,7 +17,7 @@ class AudioStream final : public AbstractMediaStream<AVMEDIA_TYPE_AUDIO> {
     VIVY_UNMOVABLE_OBJECT(AudioStream)
 
 public:
-    AudioStream(AVCodec *, AVFormatContext *, AVStream *, int index);
+    AudioStream(const AVCodec *, AVFormatContext *, AVStream *, int index);
     ~AudioStream() noexcept override;
 
     // Decode the stream
diff --git a/src/Lib/Video.cc b/src/Lib/Video.cc
index db1bd987..cc8d6031 100644
--- a/src/Lib/Video.cc
+++ b/src/Lib/Video.cc
@@ -4,7 +4,7 @@
 
 using namespace Vivy;
 
-VideoStream::VideoStream(AVCodec *streamCodec, AVFormatContext *formatArg, AVStream *streamArg,
+VideoStream::VideoStream(const AVCodec *streamCodec, AVFormatContext *formatArg, AVStream *streamArg,
                          int index)
     : Super(streamCodec, formatArg, streamArg, index)
 {
diff --git a/src/Lib/Video.hh b/src/Lib/Video.hh
index 765f5691..f8da55e4 100644
--- a/src/Lib/Video.hh
+++ b/src/Lib/Video.hh
@@ -15,7 +15,7 @@ class VideoStream final : public AbstractMediaStream<AVMEDIA_TYPE_VIDEO> {
     VIVY_UNMOVABLE_OBJECT(VideoStream)
 
 public:
-    VideoStream(AVCodec *, AVFormatContext *, AVStream *, int index);
+    VideoStream(const AVCodec *, AVFormatContext *, AVStream *, int index);
     ~VideoStream() noexcept override = default;
 
     int getWidth() const noexcept;
-- 
GitLab