Skip to content

Commit

Permalink
Merge pull request #144 from spacedriveapp/eng-1895-fix-ffmpeg-for-io…
Browse files Browse the repository at this point in the history
…s-using-private-lzma-symbols

[ENG-1895] Fix remove ffmpeg using lzma private API for iOS
  • Loading branch information
HeavenVolkoff authored Sep 19, 2024
2 parents 70161b8 + a4b1b67 commit 8b7ffbb
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ FROM layer-50 AS layer-99-ffmpeg

RUN --mount=type=cache,target=/root/.cache `
--mount=type=bind,source=stages/99-ffmpeg.sh,target=/srv/stage.sh `
--mount=type=bind,source=patches/99-ffmpeg,target="${PREFIX}/patches" `
/srv/build.sh

FROM layer-45 AS layer-99-heif
Expand Down
115 changes: 115 additions & 0 deletions patches/99-ffmpeg/remove_lzma_apple_non_public_api.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index bfa345b3d8..f445686d0d 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -28,10 +28,6 @@
#if CONFIG_ZLIB
#include <zlib.h>
#endif
-#if CONFIG_LZMA
-#define LZMA_API_STATIC
-#include <lzma.h>
-#endif

#include <float.h>

@@ -559,71 +555,6 @@ static int tiff_unpack_zlib(TiffContext *s, AVFrame *p, uint8_t *dst, int stride
}
#endif

-#if CONFIG_LZMA
-static int tiff_uncompress_lzma(uint8_t *dst, uint64_t *len, const uint8_t *src,
- int size)
-{
- lzma_stream stream = LZMA_STREAM_INIT;
- lzma_ret ret;
-
- stream.next_in = src;
- stream.avail_in = size;
- stream.next_out = dst;
- stream.avail_out = *len;
- ret = lzma_stream_decoder(&stream, UINT64_MAX, 0);
- if (ret != LZMA_OK) {
- av_log(NULL, AV_LOG_ERROR, "LZMA init error: %d\n", ret);
- return ret;
- }
- ret = lzma_code(&stream, LZMA_RUN);
- lzma_end(&stream);
- *len = stream.total_out;
- return ret == LZMA_STREAM_END ? LZMA_OK : ret;
-}
-
-static int tiff_unpack_lzma(TiffContext *s, AVFrame *p, uint8_t *dst, int stride,
- const uint8_t *src, int size, int width, int lines,
- int strip_start, int is_yuv)
-{
- uint64_t outlen = width * (uint64_t)lines;
- int ret, line;
- uint8_t *buf = av_malloc(outlen);
- if (!buf)
- return AVERROR(ENOMEM);
- if (s->fill_order) {
- if ((ret = deinvert_buffer(s, src, size)) < 0) {
- av_free(buf);
- return ret;
- }
- src = s->deinvert_buf;
- }
- ret = tiff_uncompress_lzma(buf, &outlen, src, size);
- if (ret != LZMA_OK) {
- av_log(s->avctx, AV_LOG_ERROR,
- "Uncompressing failed (%"PRIu64" of %"PRIu64") with error %d\n", outlen,
- (uint64_t)width * lines, ret);
- av_free(buf);
- return AVERROR_UNKNOWN;
- }
- src = buf;
- for (line = 0; line < lines; line++) {
- if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
- horizontal_fill(s, s->bpp, dst, 1, src, 0, width, 0);
- } else {
- memcpy(dst, src, width);
- }
- if (is_yuv) {
- unpack_yuv(s, p, dst, strip_start + line);
- line += s->subsampling[1] - 1;
- }
- dst += stride;
- src += width;
- }
- av_free(buf);
- return 0;
-}
-#endif
-
static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride,
const uint8_t *src, int size, int width, int lines)
{
@@ -796,14 +727,9 @@ static int tiff_unpack_strip(TiffContext *s, AVFrame *p, uint8_t *dst, int strid
#endif
}
if (s->compr == TIFF_LZMA) {
-#if CONFIG_LZMA
- return tiff_unpack_lzma(s, p, dst, stride, src, size, width, lines,
- strip_start, is_yuv);
-#else
av_log(s->avctx, AV_LOG_ERROR,
"LZMA support not enabled\n");
return AVERROR(ENOSYS);
-#endif
}
if (s->compr == TIFF_LZW) {
if (s->fill_order) {
@@ -1374,12 +1300,8 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
s->is_jpeg = 1;
break;
case TIFF_LZMA:
-#if CONFIG_LZMA
- break;
-#else
av_log(s->avctx, AV_LOG_ERROR, "LZMA not compiled in\n");
return AVERROR(ENOSYS);
-#endif
default:
av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
s->compr);
5 changes: 5 additions & 0 deletions stages/99-ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ for patch in \
curl "$patch" | patch -F5 -lp1 -d ffmpeg -t
done

if [ "$OS_IPHONE" -gt 0 ]; then
# Patch to remove ffmpeg using non public API on iOS
patch -F5 -lp1 -d ffmpeg -t <"$PREFIX"/patches/remove_lzma_apple_non_public_api.patch
fi

# Backup source
bak_src 'ffmpeg'

Expand Down

0 comments on commit 8b7ffbb

Please sign in to comment.