On 30.05.2015 19:09, Michael Bradshaw wrote:
> On Sat, May 30, 2015 at 7:50 AM, Andreas Cadhalpun <
> [email protected]> wrote:
>
>> On 30.05.2015 16:41, Luca Barbato wrote:
>>> Do you happen to know why it does do that?
>>
>> It encounters a problem, but only warns about it and returns the image
>> anyway. The warning is not sent to stdout with libavcodec, but can be seen
>> with j2k_dump:
>> [WARNING] 0000006a: expected a marker instead of 0
>
>
> Then perhaps a opj_event_mgr_t event handler should be registered. The
> openjpeg encoder does this to log all warnings with av_log.
That's a good idea, thanks for the hint. Patch implementing this is attached.
With this and the previous patch the error messages are:
[libopenjpeg @ 0xe48f20] read error: passed the end of the codestream (start =
14964064, current = 14964172, end = 14964172
Last message repeated 1 times
[libopenjpeg @ 0xe48f20] 0000006a: expected a marker instead of 0
[libopenjpeg @ 0xe48f20] read error: passed the end of the codestream (start =
14964064, current = 14964172, end = 14964172
Last message repeated 1 times
[libopenjpeg @ 0xe48f20] 0000006a: expected a marker instead of 0
[libopenjpeg @ 0xe48f20] Image component 0 contains no data.
> But if openjpeg
> is giving back bad data without a warning/error code from the returning
> function, then perhaps this error check is justified.
Well, the function returns a pointer, so the only warning/error code is
returning NULL.
Best regards,
Andreas
>From f8b40fa81ff7a25ceb14e8c107ac7dbcdf2705d7 Mon Sep 17 00:00:00 2001
From: Andreas Cadhalpun <[email protected]>
Date: Sat, 30 May 2015 19:40:22 +0200
Subject: [PATCH] libopenjpegdec: register logging callback functions
Signed-off-by: Andreas Cadhalpun <[email protected]>
---
libavcodec/libopenjpegdec.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c
index ab681f1..bf6730d 100644
--- a/libavcodec/libopenjpegdec.c
+++ b/libavcodec/libopenjpegdec.c
@@ -83,9 +83,25 @@ static const enum AVPixelFormat libopenjpeg_all_pix_fmts[] = {
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);
@@ -286,7 +302,11 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
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(opj_event_mgr_t));
+ 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
--
2.1.4
_______________________________________________
ffmpeg-devel mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel