Commit 279dc407 authored by Michael Bradshaw's avatar Michael Bradshaw

lavc: drop support for OpenJPEG 1.3-2.0

We now require 2.1+ with pkg-config.
Signed-off-by: 's avatarMichael Bradshaw <mjbshaw@google.com>
parent 07cf2026
......@@ -3,6 +3,8 @@ releases are sorted from youngest to oldest.
version <next>:
- Bitstream filters for editing metadata in H.264, HEVC and MPEG-2 streams
- Dropped support for OpenJPEG versions 2.0 and below. Using OpenJPEG now
requires 2.1 (or later) and pkg-config.
version 3.4:
......
......@@ -1938,11 +1938,6 @@ HEADERS_LIST="
machine_ioctl_meteor_h
malloc_h
opencv2_core_core_c_h
openjpeg_2_3_openjpeg_h
openjpeg_2_2_openjpeg_h
openjpeg_2_1_openjpeg_h
openjpeg_2_0_openjpeg_h
openjpeg_1_5_openjpeg_h
OpenGL_gl3_h
poll_h
soundcard_h
......@@ -6034,16 +6029,8 @@ enabled libopencv && { check_header opencv2/core/core_c.h &&
require libopencv opencv2/core/core_c.h cvCreateImageHeader -lopencv_core -lopencv_imgproc; } ||
require_pkg_config libopencv opencv opencv/cxcore.h cvCreateImageHeader; }
enabled libopenh264 && require_pkg_config libopenh264 openh264 wels/codec_api.h WelsGetCodecVersion
enabled libopenjpeg && { { check_lib libopenjpeg openjpeg-2.3/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
check_lib libopenjpeg openjpeg-2.3/openjpeg.h opj_version -lopenjp2 ||
{ check_lib libopenjpeg openjpeg-2.2/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
check_lib libopenjpeg openjpeg-2.2/openjpeg.h opj_version -lopenjp2 ||
{ check_lib libopenjpeg openjpeg-2.1/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
check_lib libopenjpeg openjpeg-2.1/openjpeg.h opj_version -lopenjp2 ||
{ check_lib libopenjpeg openjpeg-2.0/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
{ check_lib libopenjpeg openjpeg-1.5/openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
{ check_lib libopenjpeg openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
die "ERROR: libopenjpeg not found"; }
enabled libopenjpeg && { use_pkg_config libopenjpeg "libopenjp2 >= 2.1.0" openjpeg.h opj_version ||
{ require_pkg_config libopenjpeg "libopenjp2 >= 2.1.0" openjpeg.h opj_version -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } }
enabled libopenmpt && require_pkg_config libopenmpt "libopenmpt >= 0.2.6557" libopenmpt/libopenmpt.h openmpt_module_create -lstdc++ && append libopenmpt_extralibs "-lstdc++"
enabled libopus && {
enabled libopus_decoder && {
......
......@@ -34,27 +34,7 @@
#include "internal.h"
#include "thread.h"
#if HAVE_OPENJPEG_2_3_OPENJPEG_H
# include <openjpeg-2.3/openjpeg.h>
#elif HAVE_OPENJPEG_2_2_OPENJPEG_H
# include <openjpeg-2.2/openjpeg.h>
#elif HAVE_OPENJPEG_2_1_OPENJPEG_H
# include <openjpeg-2.1/openjpeg.h>
#elif HAVE_OPENJPEG_2_0_OPENJPEG_H
# include <openjpeg-2.0/openjpeg.h>
#elif HAVE_OPENJPEG_1_5_OPENJPEG_H
# include <openjpeg-1.5/openjpeg.h>
#else
# include <openjpeg.h>
#endif
#if HAVE_OPENJPEG_2_3_OPENJPEG_H || HAVE_OPENJPEG_2_2_OPENJPEG_H || HAVE_OPENJPEG_2_1_OPENJPEG_H || HAVE_OPENJPEG_2_0_OPENJPEG_H
# define OPENJPEG_MAJOR_VERSION 2
# define OPJ(x) OPJ_##x
#else
# define OPENJPEG_MAJOR_VERSION 1
# define OPJ(x) x
#endif
#include <openjpeg.h>
#define JP2_SIG_TYPE 0x6A502020
#define JP2_SIG_VALUE 0x0D0A870A
......@@ -97,9 +77,6 @@ static const enum AVPixelFormat libopenjpeg_all_pix_fmts[] = {
typedef struct LibOpenJPEGContext {
AVClass *class;
opj_dparameters_t dec_params;
#if OPENJPEG_MAJOR_VERSION == 1
opj_event_mgr_t event_mgr;
#endif // OPENJPEG_MAJOR_VERSION == 1
int lowqual;
} LibOpenJPEGContext;
......@@ -118,7 +95,6 @@ static void info_callback(const char *msg, void *data)
av_log(data, AV_LOG_DEBUG, "%s", msg);
}
#if OPENJPEG_MAJOR_VERSION == 2
typedef struct BufferReader {
int pos;
int size;
......@@ -176,7 +152,6 @@ static OPJ_BOOL stream_seek(OPJ_OFF_T nb_bytes, void *user_data)
reader->pos = (int)nb_bytes;
return OPJ_TRUE;
}
#endif // OPENJPEG_MAJOR_VERSION == 2
static inline int libopenjpeg_matches_pix_fmt(const opj_image_t *image, enum AVPixelFormat pix_fmt)
{
......@@ -221,15 +196,15 @@ static inline enum AVPixelFormat libopenjpeg_guess_pix_fmt(const opj_image_t *im
int possible_fmts_nb = 0;
switch (image->color_space) {
case OPJ(CLRSPC_SRGB):
case OPJ_CLRSPC_SRGB:
possible_fmts = libopenjpeg_rgb_pix_fmts;
possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_rgb_pix_fmts);
break;
case OPJ(CLRSPC_GRAY):
case OPJ_CLRSPC_GRAY:
possible_fmts = libopenjpeg_gray_pix_fmts;
possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_gray_pix_fmts);
break;
case OPJ(CLRSPC_SYCC):
case OPJ_CLRSPC_SYCC:
possible_fmts = libopenjpeg_yuv_pix_fmts;
possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_yuv_pix_fmts);
break;
......@@ -356,14 +331,9 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
int ispacked = 0;
int i;
opj_image_t *image = NULL;
#if OPENJPEG_MAJOR_VERSION == 1
opj_dinfo_t *dec = NULL;
opj_cio_t *stream = NULL;
#else // OPENJPEG_MAJOR_VERSION == 2
BufferReader reader = {0, avpkt->size, avpkt->data};
opj_codec_t *dec = NULL;
opj_stream_t *stream = NULL;
#endif // OPENJPEG_MAJOR_VERSION == 1
*got_frame = 0;
......@@ -371,13 +341,13 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
if ((AV_RB32(buf) == 12) &&
(AV_RB32(buf + 4) == JP2_SIG_TYPE) &&
(AV_RB32(buf + 8) == JP2_SIG_VALUE)) {
dec = opj_create_decompress(OPJ(CODEC_JP2));
dec = opj_create_decompress(OPJ_CODEC_JP2);
} else {
/* If the AVPacket contains a jp2c box, then skip to
* the starting byte of the codestream. */
if (AV_RB32(buf + 4) == AV_RB32("jp2c"))
buf += 8;
dec = opj_create_decompress(OPJ(CODEC_J2K));
dec = opj_create_decompress(OPJ_CODEC_J2K);
}
if (!dec) {
......@@ -386,15 +356,6 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
goto done;
}
#if OPENJPEG_MAJOR_VERSION == 1
memset(&ctx->event_mgr, 0, sizeof(ctx->event_mgr));
ctx->event_mgr.info_handler = info_callback;
ctx->event_mgr.error_handler = error_callback;
ctx->event_mgr.warning_handler = warning_callback;
opj_set_event_mgr((opj_common_ptr) dec, &ctx->event_mgr, avctx);
ctx->dec_params.cp_limit_decoding = LIMIT_TO_MAIN_HEADER;
ctx->dec_params.cp_layer = ctx->lowqual;
#else // OPENJPEG_MAJOR_VERSION == 2
if (!opj_set_error_handler(dec, error_callback, avctx) ||
!opj_set_warning_handler(dec, warning_callback, avctx) ||
!opj_set_info_handler(dec, info_callback, avctx)) {
......@@ -405,16 +366,11 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
ctx->dec_params.cp_layer = ctx->lowqual;
ctx->dec_params.cp_reduce = avctx->lowres;
#endif // OPENJPEG_MAJOR_VERSION == 1
// Tie decoder with decoding parameters
opj_setup_decoder(dec, &ctx->dec_params);
#if OPENJPEG_MAJOR_VERSION == 1
stream = opj_cio_open((opj_common_ptr) dec, buf, buf_size);
#else // OPENJPEG_MAJOR_VERSION == 2
stream = opj_stream_default_create(OPJ_STREAM_READ);
#endif // OPENJPEG_MAJOR_VERSION == 1
if (!stream) {
av_log(avctx, AV_LOG_ERROR,
......@@ -423,27 +379,13 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
goto done;
}
#if OPENJPEG_MAJOR_VERSION == 1
// Decode the header only.
image = opj_decode_with_info(dec, stream, NULL);
opj_cio_close(stream);
stream = NULL;
ret = !image;
#else // OPENJPEG_MAJOR_VERSION == 2
opj_stream_set_read_function(stream, stream_read);
opj_stream_set_skip_function(stream, stream_skip);
opj_stream_set_seek_function(stream, stream_seek);
#if HAVE_OPENJPEG_2_3_OPENJPEG_H || HAVE_OPENJPEG_2_2_OPENJPEG_H || HAVE_OPENJPEG_2_1_OPENJPEG_H
opj_stream_set_user_data(stream, &reader, NULL);
#elif HAVE_OPENJPEG_2_0_OPENJPEG_H
opj_stream_set_user_data(stream, &reader);
#else
#error Missing call to opj_stream_set_user_data
#endif
opj_stream_set_user_data_length(stream, avpkt->size);
// Decode the header only.
ret = !opj_read_header(stream, dec, &image);
#endif // OPENJPEG_MAJOR_VERSION == 1
if (ret) {
av_log(avctx, AV_LOG_ERROR, "Error decoding codestream header.\n");
......@@ -477,25 +419,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
goto done;
#if OPENJPEG_MAJOR_VERSION == 1
ctx->dec_params.cp_limit_decoding = NO_LIMITATION;
ctx->dec_params.cp_reduce = avctx->lowres;
// Tie decoder with decoding parameters.
opj_setup_decoder(dec, &ctx->dec_params);
stream = opj_cio_open((opj_common_ptr) dec, buf, buf_size);
if (!stream) {
av_log(avctx, AV_LOG_ERROR,
"Codestream could not be opened for reading.\n");
ret = AVERROR_EXTERNAL;
goto done;
}
opj_image_destroy(image);
// Decode the codestream
image = opj_decode_with_info(dec, stream, NULL);
ret = !image;
#else // OPENJPEG_MAJOR_VERSION == 2
ret = !opj_decode(dec, stream, image);
#endif // OPENJPEG_MAJOR_VERSION == 1
if (ret) {
av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n");
......@@ -556,25 +480,11 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
done:
opj_image_destroy(image);
#if OPENJPEG_MAJOR_VERSION == 2
opj_stream_destroy(stream);
opj_destroy_codec(dec);
#else
opj_cio_close(stream);
opj_destroy_decompress(dec);
#endif
return ret;
}
static av_cold void libopenjpeg_static_init(AVCodec *codec)
{
const char *version = opj_version();
int major, minor;
if (sscanf(version, "%d.%d", &major, &minor) == 2 && 1000*major + minor <= 1003)
codec->capabilities |= AV_CODEC_CAP_EXPERIMENTAL;
}
#define OFFSET(x) offsetof(LibOpenJPEGContext, x)
#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
......@@ -602,5 +512,4 @@ AVCodec ff_libopenjpeg_decoder = {
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
.max_lowres = 31,
.priv_class = &openjpeg_class,
.init_static_data = libopenjpeg_static_init,
};
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment