1 |
chithanh 13/11/23 13:52:37 |
2 |
|
3 |
Added: lightspark-0.7.2-ffmpeg20.patch |
4 |
Log: |
5 |
Add ffmpeg-2 support, bug #492336. |
6 |
|
7 |
(Portage version: 2.2.7/cvs/Linux x86_64, unsigned Manifest commit) |
8 |
|
9 |
Revision Changes Path |
10 |
1.1 www-plugins/lightspark/files/lightspark-0.7.2-ffmpeg20.patch |
11 |
|
12 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-plugins/lightspark/files/lightspark-0.7.2-ffmpeg20.patch?rev=1.1&view=markup |
13 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-plugins/lightspark/files/lightspark-0.7.2-ffmpeg20.patch?rev=1.1&content-type=text/plain |
14 |
|
15 |
Index: lightspark-0.7.2-ffmpeg20.patch |
16 |
=================================================================== |
17 |
From fff7e63650c1569908bf80f11a123e051e993f31 Mon Sep 17 00:00:00 2001 |
18 |
From: =?UTF-8?q?Ludger=20Kr=C3=A4mer?= <dbluelle@××××××××××××××××××.de> |
19 |
Date: Fri, 16 Aug 2013 20:30:28 +0200 |
20 |
Subject: [PATCH] fix compilation with ffmpeg 2.0 avcodec_decode_audio4 seems |
21 |
not to deliver data in AV_SAMPLE_FMT_S16 format, so we have to use |
22 |
libavresample for resampling |
23 |
|
24 |
--- |
25 |
CMakeLists.txt | 2 +- |
26 |
conf/FindFFMpeg.cmake | 6 ++++- |
27 |
src/backends/decoder.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++------ |
28 |
src/backends/decoder.h | 8 ++++++ |
29 |
4 files changed, 70 insertions(+), 10 deletions(-) |
30 |
|
31 |
diff --git a/CMakeLists.txt b/CMakeLists.txt |
32 |
index 33dbb85..d3a964b 100644 |
33 |
--- a/CMakeLists.txt |
34 |
+++ b/CMakeLists.txt |
35 |
@@ -286,7 +286,7 @@ IF(AUDIO_BACKEND) |
36 |
ENDIF(AUDIO_BACKEND) |
37 |
|
38 |
IF(ENABLE_LIBAVCODEC) |
39 |
- pkg_check_modules(FFMPEG libavcodec libavutil libavformat) |
40 |
+ pkg_check_modules(FFMPEG libavcodec libavutil libavformat libavresample) |
41 |
IF(NOT(FFMPEG_FOUND)) |
42 |
INCLUDE(FindFFMpeg REQUIRED) |
43 |
ENDIF(NOT(FFMPEG_FOUND)) |
44 |
diff --git a/conf/FindFFMpeg.cmake b/conf/FindFFMpeg.cmake |
45 |
index 2b4dd98..8246c15 100644 |
46 |
--- a/conf/FindFFMpeg.cmake |
47 |
+++ b/conf/FindFFMpeg.cmake |
48 |
@@ -23,7 +23,11 @@ FIND_LIBRARY(FFMPEG_AVFORMAT_LIBRARY NAMES |
49 |
avformat |
50 |
) |
51 |
|
52 |
-SET(FFMPEG_LIBRARY ${FFMPEG_AVCODEC_LIBRARY} ${FFMPEG_AVUTIL_LIBRARY} ${FFMPEG_AVFORMAT_LIBRARY}) |
53 |
+FIND_LIBRARY(FFMPEG_AVRESAMPLE_LIBRARY NAMES |
54 |
+ avresample |
55 |
+) |
56 |
+ |
57 |
+SET(FFMPEG_LIBRARY ${FFMPEG_AVCODEC_LIBRARY} ${FFMPEG_AVUTIL_LIBRARY} ${FFMPEG_AVFORMAT_LIBRARY} ${FFMPEG_AVRESAMPLE_LIBRARY}) |
58 |
MARK_AS_ADVANCED(FFMPEG_LIBRARY) |
59 |
|
60 |
# handle the QUIETLY and REQUIRED arguments and set FFMPEG_FOUND to TRUE if |
61 |
diff --git a/src/backends/decoder.cpp b/src/backends/decoder.cpp |
62 |
index 22eac2e..4b3148c 100755 |
63 |
--- a/src/backends/decoder.cpp |
64 |
+++ b/src/backends/decoder.cpp |
65 |
@@ -295,6 +295,8 @@ bool FFMpegVideoDecoder::decodePacket(AVPacket* pkt, uint32_t time) |
66 |
#else |
67 |
int ret=avcodec_decode_video(codecContext, frameIn, &frameOk, pkt->data, pkt->size); |
68 |
#endif |
69 |
+ if (ret < 0) |
70 |
+ return false; |
71 |
|
72 |
assert_and_throw(ret==(int)pkt->size); |
73 |
if(frameOk) |
74 |
@@ -612,10 +614,33 @@ uint32_t FFMpegAudioDecoder::decodeData(uint8_t* data, int32_t datalen, uint32_t |
75 |
ret=-1; |
76 |
else |
77 |
{ |
78 |
- //This is suboptimal but equivalent to what libavcodec |
79 |
- //does for the compatibility version of avcodec_decode_audio3 |
80 |
- memcpy(curTail.samples, frameIn->extended_data[0], frameIn->linesize[0]); |
81 |
- maxLen=frameIn->linesize[0]; |
82 |
+ if (frameIn->format != AV_SAMPLE_FMT_S16) |
83 |
+ { |
84 |
+ AVAudioResampleContext * avr = avresample_alloc_context(); |
85 |
+ av_opt_set_int(avr, "in_channel_layout", frameIn->channel_layout, 0); |
86 |
+ av_opt_set_int(avr, "out_channel_layout", frameIn->channel_layout, 0); |
87 |
+ av_opt_set_int(avr, "in_sample_rate", frameIn->sample_rate, 0); |
88 |
+ av_opt_set_int(avr, "out_sample_rate", frameIn->sample_rate, 0); |
89 |
+ av_opt_set_int(avr, "in_sample_fmt", frameIn->format, 0); |
90 |
+ av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); |
91 |
+ avresample_open(avr); |
92 |
+ |
93 |
+ uint8_t *output; |
94 |
+ int out_linesize; |
95 |
+ int out_samples = avresample_available(avr) + av_rescale_rnd(avresample_get_delay(avr) + frameIn->linesize[0], frameIn->sample_rate, frameIn->sample_rate, AV_ROUND_UP); |
96 |
+ av_samples_alloc(&output, &out_linesize, frameIn->nb_samples, out_samples, AV_SAMPLE_FMT_S16, 0); |
97 |
+ maxLen = avresample_convert(avr, &output, out_linesize, out_samples, frameIn->extended_data, frameIn->linesize[0], frameIn->nb_samples)*4; |
98 |
+ memcpy(curTail.samples, output, maxLen); |
99 |
+ av_freep(&output); |
100 |
+ avresample_free(&avr); |
101 |
+ } |
102 |
+ else |
103 |
+ { |
104 |
+ //This is suboptimal but equivalent to what libavcodec |
105 |
+ //does for the compatibility version of avcodec_decode_audio3 |
106 |
+ memcpy(curTail.samples, frameIn->extended_data[0], frameIn->linesize[0]); |
107 |
+ maxLen=frameIn->linesize[0]; |
108 |
+ } |
109 |
} |
110 |
#else |
111 |
int32_t ret=avcodec_decode_audio3(codecContext, curTail.samples, &maxLen, &pkt); |
112 |
@@ -660,10 +685,33 @@ uint32_t FFMpegAudioDecoder::decodePacket(AVPacket* pkt, uint32_t time) |
113 |
ret=-1; |
114 |
else |
115 |
{ |
116 |
- //This is suboptimal but equivalent to what libavcodec |
117 |
- //does for the compatibility version of avcodec_decode_audio3 |
118 |
- memcpy(curTail.samples, frameIn->extended_data[0], frameIn->linesize[0]); |
119 |
- maxLen=frameIn->linesize[0]; |
120 |
+ if (frameIn->format != AV_SAMPLE_FMT_S16) |
121 |
+ { |
122 |
+ AVAudioResampleContext * avr = avresample_alloc_context(); |
123 |
+ av_opt_set_int(avr, "in_channel_layout", frameIn->channel_layout, 0); |
124 |
+ av_opt_set_int(avr, "out_channel_layout", frameIn->channel_layout, 0); |
125 |
+ av_opt_set_int(avr, "in_sample_rate", frameIn->sample_rate, 0); |
126 |
+ av_opt_set_int(avr, "out_sample_rate", frameIn->sample_rate, 0); |
127 |
+ av_opt_set_int(avr, "in_sample_fmt", frameIn->format, 0); |
128 |
+ av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); |
129 |
+ avresample_open(avr); |
130 |
+ |
131 |
+ uint8_t *output; |
132 |
+ int out_linesize; |
133 |
+ int out_samples = avresample_available(avr) + av_rescale_rnd(avresample_get_delay(avr) + frameIn->linesize[0], frameIn->sample_rate, frameIn->sample_rate, AV_ROUND_UP); |
134 |
+ av_samples_alloc(&output, &out_linesize, frameIn->nb_samples, out_samples, AV_SAMPLE_FMT_S16, 0); |
135 |
+ maxLen = avresample_convert(avr, &output, out_linesize, out_samples, frameIn->extended_data, frameIn->linesize[0], frameIn->nb_samples)*4; |
136 |
+ memcpy(curTail.samples, output, maxLen); |
137 |
+ av_freep(&output); |
138 |
+ avresample_free(&avr); |
139 |
+ } |
140 |
+ else |
141 |
+ { |
142 |
+ //This is suboptimal but equivalent to what libavcodec |
143 |
+ //does for the compatibility version of avcodec_decode_audio3 |
144 |
+ memcpy(curTail.samples, frameIn->extended_data[0], frameIn->linesize[0]); |
145 |
+ maxLen=frameIn->linesize[0]; |
146 |
+ } |
147 |
} |
148 |
#elif HAVE_AVCODEC_DECODE_AUDIO3 |
149 |
int ret=avcodec_decode_audio3(codecContext, curTail.samples, &maxLen, pkt); |
150 |
diff --git a/src/backends/decoder.h b/src/backends/decoder.h |
151 |
index 93950ad..28bd232 100644 |
152 |
--- a/src/backends/decoder.h |
153 |
+++ b/src/backends/decoder.h |
154 |
@@ -28,6 +28,14 @@ |
155 |
{ |
156 |
#include <libavcodec/avcodec.h> |
157 |
#include <libavformat/avformat.h> |
158 |
+#include <libavresample/avresample.h> |
159 |
+#include <libavutil/opt.h> |
160 |
+#ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE |
161 |
+#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio |
162 |
+#endif |
163 |
+#ifndef CodecID |
164 |
+#define CodecID AVCodecID |
165 |
+#endif |
166 |
#define MAX_AUDIO_FRAME_SIZE AVCODEC_MAX_AUDIO_FRAME_SIZE |
167 |
} |
168 |
#else |
169 |
-- |
170 |
1.8.4 |