typedef struct LibOpenJPEGContext {
AVClass *class;
opj_dparameters_t dec_params;
+ opj_event_mgr_t event_mgr;
int lowqual;
} LibOpenJPEGContext;
+static void error_callback(const char *msg, void *data)
+{
+ av_log(data, AV_LOG_ERROR, "%s", msg);
+}
+
+static void warning_callback(const char *msg, void *data)
+{
+ av_log(data, AV_LOG_WARNING, "%s", msg);
+}
+
+static void info_callback(const char *msg, void *data)
+{
+ av_log(data, AV_LOG_DEBUG, "%s", msg);
+}
+
static inline int libopenjpeg_matches_pix_fmt(const opj_image_t *image, enum AVPixelFormat pix_fmt)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
av_log(avctx, AV_LOG_ERROR, "Error initializing decoder.\n");
return AVERROR_UNKNOWN;
}
- opj_set_event_mgr((opj_common_ptr) dec, NULL, NULL);
+ 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;
// Tie decoder with decoding parameters
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 |= CODEC_CAP_EXPERIMENTAL;
+}
+
#define OFFSET(x) offsetof(LibOpenJPEGContext, x)
#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
.capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
.max_lowres = 31,
.priv_class = &openjpeg_class,
+ .init_static_data = libopenjpeg_static_init,
};