summarylogtreecommitdiffstats
path: root/fix-ffmpeg-build-for-tgcalls.patch
blob: c8c9ee5e3a1532ecc5e1f336ba9ec9ba1d6ead74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
From da288b3cf4f91937da5bb8de0570dfa64871f4d9 Mon Sep 17 00:00:00 2001
From: Nicholas Guriev <nicholas@guriev.su>
Date: Mon, 7 Mar 2022 11:52:01 +0300
Subject: [PATCH] Fix build against FFmpeg v5.0

It has been released on January 17th. This patch keeps source compatibility
with older versions.
---
 tgcalls/group/AudioStreamingPartInternal.cpp          | 5 ++++-
 tgcalls/group/AudioStreamingPartPersistentDecoder.cpp | 2 +-
 tgcalls/group/VideoStreamingPart.cpp                  | 5 ++++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/tgcalls/group/AudioStreamingPartInternal.cpp b/tgcalls/group/AudioStreamingPartInternal.cpp
index 27a71cb..5639036 100644
--- a/tgcalls/group/AudioStreamingPartInternal.cpp
+++ b/tgcalls/group/AudioStreamingPartInternal.cpp
@@ -104,6 +104,9 @@ _avIoContext(std::move(fileData)) {
 
     _frame = av_frame_alloc();
 
+#if LIBAVFORMAT_VERSION_MAJOR >= 59
+    const
+#endif
     AVInputFormat *inputFormat = av_find_input_format(container.c_str());
     if (!inputFormat) {
         _didReadToEnd = true;
@@ -144,7 +147,7 @@ _avIoContext(std::move(fileData)) {
         
         _streamId = i;
 
-        _durationInMilliseconds = (int)((inStream->duration + inStream->first_dts) * 1000 / 48000);
+        _durationInMilliseconds = (int)(inStream->duration * av_q2d(inStream->time_base) * 1000);
 
         if (inStream->metadata) {
             AVDictionaryEntry *entry = av_dict_get(inStream->metadata, "TG_META", nullptr, 0);
diff --git a/tgcalls/group/AudioStreamingPartPersistentDecoder.cpp b/tgcalls/group/AudioStreamingPartPersistentDecoder.cpp
index e79d430..63ef475 100644
--- a/tgcalls/group/AudioStreamingPartPersistentDecoder.cpp
+++ b/tgcalls/group/AudioStreamingPartPersistentDecoder.cpp
@@ -32,7 +32,7 @@ class AudioStreamingPartPersistentDecoderState {
     AudioStreamingPartPersistentDecoderState(AVCodecParameters const *codecParameters, AVRational timeBase) :
     _codecParameters(codecParameters),
     _timeBase(timeBase) {
-        AVCodec *codec = avcodec_find_decoder(codecParameters->codec_id);
+        const AVCodec *codec = avcodec_find_decoder(codecParameters->codec_id);
         if (codec) {
             _codecContext = avcodec_alloc_context3(codec);
             int ret = avcodec_parameters_to_context(_codecContext, codecParameters);
diff --git a/tgcalls/group/VideoStreamingPart.cpp b/tgcalls/group/VideoStreamingPart.cpp
index a67514a..10457eb 100644
--- a/tgcalls/group/VideoStreamingPart.cpp
+++ b/tgcalls/group/VideoStreamingPart.cpp
@@ -280,6 +280,9 @@ class VideoStreamingPartInternal {
 
         int ret = 0;
 
+#if LIBAVFORMAT_VERSION_MAJOR >= 59
+        const
+#endif
         AVInputFormat *inputFormat = av_find_input_format(container.c_str());
         if (!inputFormat) {
             _didReadToEnd = true;
@@ -323,7 +326,7 @@ class VideoStreamingPartInternal {
         }
 
         if (videoCodecParameters && videoStream) {
-            AVCodec *codec = avcodec_find_decoder(videoCodecParameters->codec_id);
+            const AVCodec *codec = avcodec_find_decoder(videoCodecParameters->codec_id);
             if (codec) {
                 _codecContext = avcodec_alloc_context3(codec);
                 ret = avcodec_parameters_to_context(_codecContext, videoCodecParameters);