We now require 2.1+ with pkg-config.
Signed-off-by: Michael Bradshaw <mjbshaw@google.com>
... | ... |
@@ -3,6 +3,8 @@ releases are sorted from youngest to oldest. |
3 | 3 |
|
4 | 4 |
version <next>: |
5 | 5 |
- Bitstream filters for editing metadata in H.264, HEVC and MPEG-2 streams |
6 |
+- Dropped support for OpenJPEG versions 2.0 and below. Using OpenJPEG now |
|
7 |
+ requires 2.1 (or later) and pkg-config. |
|
6 | 8 |
|
7 | 9 |
|
8 | 10 |
version 3.4: |
... | ... |
@@ -1938,11 +1938,6 @@ HEADERS_LIST=" |
1938 | 1938 |
machine_ioctl_meteor_h |
1939 | 1939 |
malloc_h |
1940 | 1940 |
opencv2_core_core_c_h |
1941 |
- openjpeg_2_3_openjpeg_h |
|
1942 |
- openjpeg_2_2_openjpeg_h |
|
1943 |
- openjpeg_2_1_openjpeg_h |
|
1944 |
- openjpeg_2_0_openjpeg_h |
|
1945 |
- openjpeg_1_5_openjpeg_h |
|
1946 | 1941 |
OpenGL_gl3_h |
1947 | 1942 |
poll_h |
1948 | 1943 |
soundcard_h |
... | ... |
@@ -6034,16 +6029,8 @@ enabled libopencv && { check_header opencv2/core/core_c.h && |
6034 | 6034 |
require libopencv opencv2/core/core_c.h cvCreateImageHeader -lopencv_core -lopencv_imgproc; } || |
6035 | 6035 |
require_pkg_config libopencv opencv opencv/cxcore.h cvCreateImageHeader; } |
6036 | 6036 |
enabled libopenh264 && require_pkg_config libopenh264 openh264 wels/codec_api.h WelsGetCodecVersion |
6037 |
-enabled libopenjpeg && { { check_lib libopenjpeg openjpeg-2.3/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } || |
|
6038 |
- check_lib libopenjpeg openjpeg-2.3/openjpeg.h opj_version -lopenjp2 || |
|
6039 |
- { check_lib libopenjpeg openjpeg-2.2/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } || |
|
6040 |
- check_lib libopenjpeg openjpeg-2.2/openjpeg.h opj_version -lopenjp2 || |
|
6041 |
- { check_lib libopenjpeg openjpeg-2.1/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } || |
|
6042 |
- check_lib libopenjpeg openjpeg-2.1/openjpeg.h opj_version -lopenjp2 || |
|
6043 |
- { check_lib libopenjpeg openjpeg-2.0/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } || |
|
6044 |
- { check_lib libopenjpeg openjpeg-1.5/openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } || |
|
6045 |
- { check_lib libopenjpeg openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } || |
|
6046 |
- die "ERROR: libopenjpeg not found"; } |
|
6037 |
+enabled libopenjpeg && { use_pkg_config libopenjpeg "libopenjp2 >= 2.1.0" openjpeg.h opj_version || |
|
6038 |
+ { require_pkg_config libopenjpeg "libopenjp2 >= 2.1.0" openjpeg.h opj_version -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } } |
|
6047 | 6039 |
enabled libopenmpt && require_pkg_config libopenmpt "libopenmpt >= 0.2.6557" libopenmpt/libopenmpt.h openmpt_module_create -lstdc++ && append libopenmpt_extralibs "-lstdc++" |
6048 | 6040 |
enabled libopus && { |
6049 | 6041 |
enabled libopus_decoder && { |
... | ... |
@@ -34,27 +34,7 @@ |
34 | 34 |
#include "internal.h" |
35 | 35 |
#include "thread.h" |
36 | 36 |
|
37 |
-#if HAVE_OPENJPEG_2_3_OPENJPEG_H |
|
38 |
-# include <openjpeg-2.3/openjpeg.h> |
|
39 |
-#elif HAVE_OPENJPEG_2_2_OPENJPEG_H |
|
40 |
-# include <openjpeg-2.2/openjpeg.h> |
|
41 |
-#elif HAVE_OPENJPEG_2_1_OPENJPEG_H |
|
42 |
-# include <openjpeg-2.1/openjpeg.h> |
|
43 |
-#elif HAVE_OPENJPEG_2_0_OPENJPEG_H |
|
44 |
-# include <openjpeg-2.0/openjpeg.h> |
|
45 |
-#elif HAVE_OPENJPEG_1_5_OPENJPEG_H |
|
46 |
-# include <openjpeg-1.5/openjpeg.h> |
|
47 |
-#else |
|
48 |
-# include <openjpeg.h> |
|
49 |
-#endif |
|
50 |
- |
|
51 |
-#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 |
|
52 |
-# define OPENJPEG_MAJOR_VERSION 2 |
|
53 |
-# define OPJ(x) OPJ_##x |
|
54 |
-#else |
|
55 |
-# define OPENJPEG_MAJOR_VERSION 1 |
|
56 |
-# define OPJ(x) x |
|
57 |
-#endif |
|
37 |
+#include <openjpeg.h> |
|
58 | 38 |
|
59 | 39 |
#define JP2_SIG_TYPE 0x6A502020 |
60 | 40 |
#define JP2_SIG_VALUE 0x0D0A870A |
... | ... |
@@ -97,9 +77,6 @@ static const enum AVPixelFormat libopenjpeg_all_pix_fmts[] = { |
97 | 97 |
typedef struct LibOpenJPEGContext { |
98 | 98 |
AVClass *class; |
99 | 99 |
opj_dparameters_t dec_params; |
100 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
101 |
- opj_event_mgr_t event_mgr; |
|
102 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
103 | 100 |
int lowqual; |
104 | 101 |
} LibOpenJPEGContext; |
105 | 102 |
|
... | ... |
@@ -118,7 +95,6 @@ static void info_callback(const char *msg, void *data) |
118 | 118 |
av_log(data, AV_LOG_DEBUG, "%s", msg); |
119 | 119 |
} |
120 | 120 |
|
121 |
-#if OPENJPEG_MAJOR_VERSION == 2 |
|
122 | 121 |
typedef struct BufferReader { |
123 | 122 |
int pos; |
124 | 123 |
int size; |
... | ... |
@@ -176,7 +152,6 @@ static OPJ_BOOL stream_seek(OPJ_OFF_T nb_bytes, void *user_data) |
176 | 176 |
reader->pos = (int)nb_bytes; |
177 | 177 |
return OPJ_TRUE; |
178 | 178 |
} |
179 |
-#endif // OPENJPEG_MAJOR_VERSION == 2 |
|
180 | 179 |
|
181 | 180 |
static inline int libopenjpeg_matches_pix_fmt(const opj_image_t *image, enum AVPixelFormat pix_fmt) |
182 | 181 |
{ |
... | ... |
@@ -221,15 +196,15 @@ static inline enum AVPixelFormat libopenjpeg_guess_pix_fmt(const opj_image_t *im |
221 | 221 |
int possible_fmts_nb = 0; |
222 | 222 |
|
223 | 223 |
switch (image->color_space) { |
224 |
- case OPJ(CLRSPC_SRGB): |
|
224 |
+ case OPJ_CLRSPC_SRGB: |
|
225 | 225 |
possible_fmts = libopenjpeg_rgb_pix_fmts; |
226 | 226 |
possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_rgb_pix_fmts); |
227 | 227 |
break; |
228 |
- case OPJ(CLRSPC_GRAY): |
|
228 |
+ case OPJ_CLRSPC_GRAY: |
|
229 | 229 |
possible_fmts = libopenjpeg_gray_pix_fmts; |
230 | 230 |
possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_gray_pix_fmts); |
231 | 231 |
break; |
232 |
- case OPJ(CLRSPC_SYCC): |
|
232 |
+ case OPJ_CLRSPC_SYCC: |
|
233 | 233 |
possible_fmts = libopenjpeg_yuv_pix_fmts; |
234 | 234 |
possible_fmts_nb = FF_ARRAY_ELEMS(libopenjpeg_yuv_pix_fmts); |
235 | 235 |
break; |
... | ... |
@@ -356,14 +331,9 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, |
356 | 356 |
int ispacked = 0; |
357 | 357 |
int i; |
358 | 358 |
opj_image_t *image = NULL; |
359 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
360 |
- opj_dinfo_t *dec = NULL; |
|
361 |
- opj_cio_t *stream = NULL; |
|
362 |
-#else // OPENJPEG_MAJOR_VERSION == 2 |
|
363 | 359 |
BufferReader reader = {0, avpkt->size, avpkt->data}; |
364 | 360 |
opj_codec_t *dec = NULL; |
365 | 361 |
opj_stream_t *stream = NULL; |
366 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
367 | 362 |
|
368 | 363 |
*got_frame = 0; |
369 | 364 |
|
... | ... |
@@ -371,13 +341,13 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, |
371 | 371 |
if ((AV_RB32(buf) == 12) && |
372 | 372 |
(AV_RB32(buf + 4) == JP2_SIG_TYPE) && |
373 | 373 |
(AV_RB32(buf + 8) == JP2_SIG_VALUE)) { |
374 |
- dec = opj_create_decompress(OPJ(CODEC_JP2)); |
|
374 |
+ dec = opj_create_decompress(OPJ_CODEC_JP2); |
|
375 | 375 |
} else { |
376 | 376 |
/* If the AVPacket contains a jp2c box, then skip to |
377 | 377 |
* the starting byte of the codestream. */ |
378 | 378 |
if (AV_RB32(buf + 4) == AV_RB32("jp2c")) |
379 | 379 |
buf += 8; |
380 |
- dec = opj_create_decompress(OPJ(CODEC_J2K)); |
|
380 |
+ dec = opj_create_decompress(OPJ_CODEC_J2K); |
|
381 | 381 |
} |
382 | 382 |
|
383 | 383 |
if (!dec) { |
... | ... |
@@ -386,15 +356,6 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, |
386 | 386 |
goto done; |
387 | 387 |
} |
388 | 388 |
|
389 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
390 |
- memset(&ctx->event_mgr, 0, sizeof(ctx->event_mgr)); |
|
391 |
- ctx->event_mgr.info_handler = info_callback; |
|
392 |
- ctx->event_mgr.error_handler = error_callback; |
|
393 |
- ctx->event_mgr.warning_handler = warning_callback; |
|
394 |
- opj_set_event_mgr((opj_common_ptr) dec, &ctx->event_mgr, avctx); |
|
395 |
- ctx->dec_params.cp_limit_decoding = LIMIT_TO_MAIN_HEADER; |
|
396 |
- ctx->dec_params.cp_layer = ctx->lowqual; |
|
397 |
-#else // OPENJPEG_MAJOR_VERSION == 2 |
|
398 | 389 |
if (!opj_set_error_handler(dec, error_callback, avctx) || |
399 | 390 |
!opj_set_warning_handler(dec, warning_callback, avctx) || |
400 | 391 |
!opj_set_info_handler(dec, info_callback, avctx)) { |
... | ... |
@@ -405,16 +366,11 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, |
405 | 405 |
|
406 | 406 |
ctx->dec_params.cp_layer = ctx->lowqual; |
407 | 407 |
ctx->dec_params.cp_reduce = avctx->lowres; |
408 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
409 | 408 |
|
410 | 409 |
// Tie decoder with decoding parameters |
411 | 410 |
opj_setup_decoder(dec, &ctx->dec_params); |
412 | 411 |
|
413 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
414 |
- stream = opj_cio_open((opj_common_ptr) dec, buf, buf_size); |
|
415 |
-#else // OPENJPEG_MAJOR_VERSION == 2 |
|
416 | 412 |
stream = opj_stream_default_create(OPJ_STREAM_READ); |
417 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
418 | 413 |
|
419 | 414 |
if (!stream) { |
420 | 415 |
av_log(avctx, AV_LOG_ERROR, |
... | ... |
@@ -423,27 +379,13 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, |
423 | 423 |
goto done; |
424 | 424 |
} |
425 | 425 |
|
426 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
427 |
- // Decode the header only. |
|
428 |
- image = opj_decode_with_info(dec, stream, NULL); |
|
429 |
- opj_cio_close(stream); |
|
430 |
- stream = NULL; |
|
431 |
- ret = !image; |
|
432 |
-#else // OPENJPEG_MAJOR_VERSION == 2 |
|
433 | 426 |
opj_stream_set_read_function(stream, stream_read); |
434 | 427 |
opj_stream_set_skip_function(stream, stream_skip); |
435 | 428 |
opj_stream_set_seek_function(stream, stream_seek); |
436 |
-#if HAVE_OPENJPEG_2_3_OPENJPEG_H || HAVE_OPENJPEG_2_2_OPENJPEG_H || HAVE_OPENJPEG_2_1_OPENJPEG_H |
|
437 | 429 |
opj_stream_set_user_data(stream, &reader, NULL); |
438 |
-#elif HAVE_OPENJPEG_2_0_OPENJPEG_H |
|
439 |
- opj_stream_set_user_data(stream, &reader); |
|
440 |
-#else |
|
441 |
-#error Missing call to opj_stream_set_user_data |
|
442 |
-#endif |
|
443 | 430 |
opj_stream_set_user_data_length(stream, avpkt->size); |
444 | 431 |
// Decode the header only. |
445 | 432 |
ret = !opj_read_header(stream, dec, &image); |
446 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
447 | 433 |
|
448 | 434 |
if (ret) { |
449 | 435 |
av_log(avctx, AV_LOG_ERROR, "Error decoding codestream header.\n"); |
... | ... |
@@ -477,25 +419,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, |
477 | 477 |
if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0) |
478 | 478 |
goto done; |
479 | 479 |
|
480 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
481 |
- ctx->dec_params.cp_limit_decoding = NO_LIMITATION; |
|
482 |
- ctx->dec_params.cp_reduce = avctx->lowres; |
|
483 |
- // Tie decoder with decoding parameters. |
|
484 |
- opj_setup_decoder(dec, &ctx->dec_params); |
|
485 |
- stream = opj_cio_open((opj_common_ptr) dec, buf, buf_size); |
|
486 |
- if (!stream) { |
|
487 |
- av_log(avctx, AV_LOG_ERROR, |
|
488 |
- "Codestream could not be opened for reading.\n"); |
|
489 |
- ret = AVERROR_EXTERNAL; |
|
490 |
- goto done; |
|
491 |
- } |
|
492 |
- opj_image_destroy(image); |
|
493 |
- // Decode the codestream |
|
494 |
- image = opj_decode_with_info(dec, stream, NULL); |
|
495 |
- ret = !image; |
|
496 |
-#else // OPENJPEG_MAJOR_VERSION == 2 |
|
497 | 480 |
ret = !opj_decode(dec, stream, image); |
498 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
499 | 481 |
|
500 | 482 |
if (ret) { |
501 | 483 |
av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n"); |
... | ... |
@@ -556,25 +480,11 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, |
556 | 556 |
|
557 | 557 |
done: |
558 | 558 |
opj_image_destroy(image); |
559 |
-#if OPENJPEG_MAJOR_VERSION == 2 |
|
560 | 559 |
opj_stream_destroy(stream); |
561 | 560 |
opj_destroy_codec(dec); |
562 |
-#else |
|
563 |
- opj_cio_close(stream); |
|
564 |
- opj_destroy_decompress(dec); |
|
565 |
-#endif |
|
566 | 561 |
return ret; |
567 | 562 |
} |
568 | 563 |
|
569 |
-static av_cold void libopenjpeg_static_init(AVCodec *codec) |
|
570 |
-{ |
|
571 |
- const char *version = opj_version(); |
|
572 |
- int major, minor; |
|
573 |
- |
|
574 |
- if (sscanf(version, "%d.%d", &major, &minor) == 2 && 1000*major + minor <= 1003) |
|
575 |
- codec->capabilities |= AV_CODEC_CAP_EXPERIMENTAL; |
|
576 |
-} |
|
577 |
- |
|
578 | 564 |
#define OFFSET(x) offsetof(LibOpenJPEGContext, x) |
579 | 565 |
#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM |
580 | 566 |
|
... | ... |
@@ -602,5 +512,4 @@ AVCodec ff_libopenjpeg_decoder = { |
602 | 602 |
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, |
603 | 603 |
.max_lowres = 31, |
604 | 604 |
.priv_class = &openjpeg_class, |
605 |
- .init_static_data = libopenjpeg_static_init, |
|
606 | 605 |
}; |
... | ... |
@@ -31,38 +31,11 @@ |
31 | 31 |
#include "libavutil/opt.h" |
32 | 32 |
#include "avcodec.h" |
33 | 33 |
#include "internal.h" |
34 |
- |
|
35 |
-#if HAVE_OPENJPEG_2_3_OPENJPEG_H |
|
36 |
-# include <openjpeg-2.3/openjpeg.h> |
|
37 |
-#elif HAVE_OPENJPEG_2_2_OPENJPEG_H |
|
38 |
-# include <openjpeg-2.2/openjpeg.h> |
|
39 |
-#elif HAVE_OPENJPEG_2_1_OPENJPEG_H |
|
40 |
-# include <openjpeg-2.1/openjpeg.h> |
|
41 |
-#elif HAVE_OPENJPEG_2_0_OPENJPEG_H |
|
42 |
-# include <openjpeg-2.0/openjpeg.h> |
|
43 |
-#elif HAVE_OPENJPEG_1_5_OPENJPEG_H |
|
44 |
-# include <openjpeg-1.5/openjpeg.h> |
|
45 |
-#else |
|
46 |
-# include <openjpeg.h> |
|
47 |
-#endif |
|
48 |
- |
|
49 |
-#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 |
|
50 |
-# define OPENJPEG_MAJOR_VERSION 2 |
|
51 |
-# define OPJ(x) OPJ_##x |
|
52 |
-#else |
|
53 |
-# define OPENJPEG_MAJOR_VERSION 1 |
|
54 |
-# define OPJ(x) x |
|
55 |
-#endif |
|
34 |
+#include <openjpeg.h> |
|
56 | 35 |
|
57 | 36 |
typedef struct LibOpenJPEGContext { |
58 | 37 |
AVClass *avclass; |
59 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
60 |
- opj_image_t *image; |
|
61 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
62 | 38 |
opj_cparameters_t enc_params; |
63 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
64 |
- opj_event_mgr_t event_mgr; |
|
65 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
66 | 39 |
int format; |
67 | 40 |
int profile; |
68 | 41 |
int prog_order; |
... | ... |
@@ -88,7 +61,6 @@ static void info_callback(const char *msg, void *data) |
88 | 88 |
av_log(data, AV_LOG_DEBUG, "%s\n", msg); |
89 | 89 |
} |
90 | 90 |
|
91 |
-#if OPENJPEG_MAJOR_VERSION == 2 |
|
92 | 91 |
typedef struct PacketWriter { |
93 | 92 |
int pos; |
94 | 93 |
AVPacket *packet; |
... | ... |
@@ -158,7 +130,6 @@ static OPJ_BOOL stream_seek(OPJ_OFF_T nb_bytes, void *user_data) |
158 | 158 |
writer->pos = (int)nb_bytes; |
159 | 159 |
return OPJ_TRUE; |
160 | 160 |
} |
161 |
-#endif // OPENJPEG_MAJOR_VERSION == 2 |
|
162 | 161 |
|
163 | 162 |
static void cinema_parameters(opj_cparameters_t *p) |
164 | 163 |
{ |
... | ... |
@@ -182,7 +153,7 @@ static void cinema_parameters(opj_cparameters_t *p) |
182 | 182 |
p->csty |= 0x01; |
183 | 183 |
|
184 | 184 |
/* The progression order shall be CPRL */ |
185 |
- p->prog_order = OPJ(CPRL); |
|
185 |
+ p->prog_order = OPJ_CPRL; |
|
186 | 186 |
|
187 | 187 |
/* No ROI */ |
188 | 188 |
p->roi_compno = -1; |
... | ... |
@@ -206,7 +177,7 @@ static opj_image_t *mj2_create_image(AVCodecContext *avctx, opj_cparameters_t *p |
206 | 206 |
int sub_dx[4]; |
207 | 207 |
int sub_dy[4]; |
208 | 208 |
int numcomps; |
209 |
- OPJ_COLOR_SPACE color_space = OPJ(CLRSPC_UNKNOWN); |
|
209 |
+ OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_UNKNOWN; |
|
210 | 210 |
|
211 | 211 |
sub_dx[0] = sub_dx[3] = 1; |
212 | 212 |
sub_dy[0] = sub_dy[3] = 1; |
... | ... |
@@ -220,7 +191,7 @@ static opj_image_t *mj2_create_image(AVCodecContext *avctx, opj_cparameters_t *p |
220 | 220 |
case AV_PIX_FMT_YA8: |
221 | 221 |
case AV_PIX_FMT_GRAY16: |
222 | 222 |
case AV_PIX_FMT_YA16: |
223 |
- color_space = OPJ(CLRSPC_GRAY); |
|
223 |
+ color_space = OPJ_CLRSPC_GRAY; |
|
224 | 224 |
break; |
225 | 225 |
case AV_PIX_FMT_RGB24: |
226 | 226 |
case AV_PIX_FMT_RGBA: |
... | ... |
@@ -233,7 +204,7 @@ static opj_image_t *mj2_create_image(AVCodecContext *avctx, opj_cparameters_t *p |
233 | 233 |
case AV_PIX_FMT_GBRP14: |
234 | 234 |
case AV_PIX_FMT_GBRP16: |
235 | 235 |
case AV_PIX_FMT_XYZ12: |
236 |
- color_space = OPJ(CLRSPC_SRGB); |
|
236 |
+ color_space = OPJ_CLRSPC_SRGB; |
|
237 | 237 |
break; |
238 | 238 |
case AV_PIX_FMT_YUV410P: |
239 | 239 |
case AV_PIX_FMT_YUV411P: |
... | ... |
@@ -268,7 +239,7 @@ static opj_image_t *mj2_create_image(AVCodecContext *avctx, opj_cparameters_t *p |
268 | 268 |
case AV_PIX_FMT_YUVA420P16: |
269 | 269 |
case AV_PIX_FMT_YUVA422P16: |
270 | 270 |
case AV_PIX_FMT_YUVA444P16: |
271 |
- color_space = OPJ(CLRSPC_SYCC); |
|
271 |
+ color_space = OPJ_CLRSPC_SYCC; |
|
272 | 272 |
break; |
273 | 273 |
default: |
274 | 274 |
av_log(avctx, AV_LOG_ERROR, |
... | ... |
@@ -309,7 +280,6 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx) |
309 | 309 |
|
310 | 310 |
opj_set_default_encoder_parameters(&ctx->enc_params); |
311 | 311 |
|
312 |
-#if HAVE_OPENJPEG_2_3_OPENJPEG_H || HAVE_OPENJPEG_2_2_OPENJPEG_H || HAVE_OPENJPEG_2_1_OPENJPEG_H |
|
313 | 312 |
switch (ctx->cinema_mode) { |
314 | 313 |
case OPJ_CINEMA2K_24: |
315 | 314 |
ctx->enc_params.rsiz = OPJ_PROFILE_CINEMA_2K; |
... | ... |
@@ -348,12 +318,8 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx) |
348 | 348 |
if (err) { |
349 | 349 |
av_log(avctx, AV_LOG_ERROR, |
350 | 350 |
"Invalid parameter pairing: cinema_mode and profile conflict.\n"); |
351 |
- goto fail; |
|
351 |
+ return err; |
|
352 | 352 |
} |
353 |
-#else |
|
354 |
- ctx->enc_params.cp_rsiz = ctx->profile; |
|
355 |
- ctx->enc_params.cp_cinema = ctx->cinema_mode; |
|
356 |
-#endif |
|
357 | 353 |
|
358 | 354 |
if (!ctx->numresolution) { |
359 | 355 |
ctx->numresolution = 6; |
... | ... |
@@ -373,23 +339,7 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx) |
373 | 373 |
cinema_parameters(&ctx->enc_params); |
374 | 374 |
} |
375 | 375 |
|
376 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
377 |
- ctx->image = mj2_create_image(avctx, &ctx->enc_params); |
|
378 |
- if (!ctx->image) { |
|
379 |
- av_log(avctx, AV_LOG_ERROR, "Error creating the mj2 image\n"); |
|
380 |
- err = AVERROR(EINVAL); |
|
381 |
- goto fail; |
|
382 |
- } |
|
383 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
384 |
- |
|
385 | 376 |
return 0; |
386 |
- |
|
387 |
-fail: |
|
388 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
389 |
- opj_image_destroy(ctx->image); |
|
390 |
- ctx->image = NULL; |
|
391 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
392 |
- return err; |
|
393 | 377 |
} |
394 | 378 |
|
395 | 379 |
static int libopenjpeg_copy_packed8(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image) |
... | ... |
@@ -602,12 +552,6 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
602 | 602 |
int ret; |
603 | 603 |
AVFrame *gbrframe; |
604 | 604 |
int cpyresult = 0; |
605 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
606 |
- opj_image_t *image = ctx->image; |
|
607 |
- opj_cinfo_t *compress = NULL; |
|
608 |
- opj_cio_t *stream = NULL; |
|
609 |
- int len; |
|
610 |
-#else // OPENJPEG_MAJOR_VERSION == 2 |
|
611 | 605 |
PacketWriter writer = { 0 }; |
612 | 606 |
opj_codec_t *compress = NULL; |
613 | 607 |
opj_stream_t *stream = NULL; |
... | ... |
@@ -617,7 +561,6 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
617 | 617 |
ret = AVERROR(EINVAL); |
618 | 618 |
goto done; |
619 | 619 |
} |
620 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
621 | 620 |
|
622 | 621 |
switch (avctx->pix_fmt) { |
623 | 622 |
case AV_PIX_FMT_RGB24: |
... | ... |
@@ -712,11 +655,9 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
712 | 712 |
goto done; |
713 | 713 |
} |
714 | 714 |
|
715 |
-#if OPENJPEG_MAJOR_VERSION == 2 |
|
716 | 715 |
if ((ret = ff_alloc_packet2(avctx, pkt, 1024, 0)) < 0) { |
717 | 716 |
goto done; |
718 | 717 |
} |
719 |
-#endif // OPENJPEG_MAJOR_VERSION == 2 |
|
720 | 718 |
|
721 | 719 |
compress = opj_create_compress(ctx->format); |
722 | 720 |
if (!compress) { |
... | ... |
@@ -725,10 +666,6 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
725 | 725 |
goto done; |
726 | 726 |
} |
727 | 727 |
|
728 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
729 |
- opj_setup_encoder(compress, &ctx->enc_params, image); |
|
730 |
- stream = opj_cio_open((opj_common_ptr) compress, NULL, 0); |
|
731 |
-#else // OPENJPEG_MAJOR_VERSION == 2 |
|
732 | 728 |
if (!opj_set_error_handler(compress, error_callback, avctx) || |
733 | 729 |
!opj_set_warning_handler(compress, warning_callback, avctx) || |
734 | 730 |
!opj_set_info_handler(compress, info_callback, avctx)) { |
... | ... |
@@ -743,43 +680,18 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
743 | 743 |
goto done; |
744 | 744 |
} |
745 | 745 |
stream = opj_stream_default_create(OPJ_STREAM_WRITE); |
746 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
747 | 746 |
|
748 | 747 |
if (!stream) { |
749 | 748 |
av_log(avctx, AV_LOG_ERROR, "Error creating the cio stream\n"); |
750 | 749 |
ret = AVERROR(ENOMEM); |
751 | 750 |
goto done; |
752 | 751 |
} |
753 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
754 |
- memset(&ctx->event_mgr, 0, sizeof(ctx->event_mgr)); |
|
755 |
- ctx->event_mgr.info_handler = info_callback; |
|
756 |
- ctx->event_mgr.error_handler = error_callback; |
|
757 |
- ctx->event_mgr.warning_handler = warning_callback; |
|
758 |
- opj_set_event_mgr((opj_common_ptr) compress, &ctx->event_mgr, avctx); |
|
759 |
- if (!opj_encode(compress, stream, image, NULL)) { |
|
760 |
- av_log(avctx, AV_LOG_ERROR, "Error during the opj encode\n"); |
|
761 |
- ret = AVERROR_EXTERNAL; |
|
762 |
- goto done; |
|
763 |
- } |
|
764 | 752 |
|
765 |
- len = cio_tell(stream); |
|
766 |
- if ((ret = ff_alloc_packet2(avctx, pkt, len, 0)) < 0) { |
|
767 |
- goto done; |
|
768 |
- } |
|
769 |
- |
|
770 |
- memcpy(pkt->data, stream->buffer, len); |
|
771 |
-#else // OPENJPEG_MAJOR_VERSION == 2 |
|
772 | 753 |
writer.packet = pkt; |
773 | 754 |
opj_stream_set_write_function(stream, stream_write); |
774 | 755 |
opj_stream_set_skip_function(stream, stream_skip); |
775 | 756 |
opj_stream_set_seek_function(stream, stream_seek); |
776 |
-#if HAVE_OPENJPEG_2_3_OPENJPEG_H || HAVE_OPENJPEG_2_2_OPENJPEG_H || HAVE_OPENJPEG_2_1_OPENJPEG_H |
|
777 | 757 |
opj_stream_set_user_data(stream, &writer, NULL); |
778 |
-#elif HAVE_OPENJPEG_2_0_OPENJPEG_H |
|
779 |
- opj_stream_set_user_data(stream, &writer); |
|
780 |
-#else |
|
781 |
-#error Missing call to opj_stream_set_user_data |
|
782 |
-#endif |
|
783 | 758 |
|
784 | 759 |
if (!opj_start_compress(compress, image, stream) || |
785 | 760 |
!opj_encode(compress, stream) || |
... | ... |
@@ -790,56 +702,39 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
790 | 790 |
} |
791 | 791 |
|
792 | 792 |
av_shrink_packet(pkt, writer.pos); |
793 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
794 | 793 |
|
795 | 794 |
pkt->flags |= AV_PKT_FLAG_KEY; |
796 | 795 |
*got_packet = 1; |
797 | 796 |
ret = 0; |
798 | 797 |
|
799 | 798 |
done: |
800 |
-#if OPENJPEG_MAJOR_VERSION == 2 |
|
801 | 799 |
opj_stream_destroy(stream); |
802 | 800 |
opj_destroy_codec(compress); |
803 | 801 |
opj_image_destroy(image); |
804 |
-#else |
|
805 |
- opj_cio_close(stream); |
|
806 |
- opj_destroy_compress(compress); |
|
807 |
-#endif |
|
808 | 802 |
return ret; |
809 | 803 |
} |
810 | 804 |
|
811 |
-static av_cold int libopenjpeg_encode_close(AVCodecContext *avctx) |
|
812 |
-{ |
|
813 |
-#if OPENJPEG_MAJOR_VERSION == 1 |
|
814 |
- LibOpenJPEGContext *ctx = avctx->priv_data; |
|
815 |
- |
|
816 |
- opj_image_destroy(ctx->image); |
|
817 |
- ctx->image = NULL; |
|
818 |
-#endif // OPENJPEG_MAJOR_VERSION == 1 |
|
819 |
- return 0; |
|
820 |
-} |
|
821 |
- |
|
822 | 805 |
#define OFFSET(x) offsetof(LibOpenJPEGContext, x) |
823 | 806 |
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM |
824 | 807 |
static const AVOption options[] = { |
825 |
- { "format", "Codec Format", OFFSET(format), AV_OPT_TYPE_INT, { .i64 = OPJ(CODEC_JP2) }, OPJ(CODEC_J2K), OPJ(CODEC_JP2), VE, "format" }, |
|
826 |
- { "j2k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(CODEC_J2K) }, 0, 0, VE, "format" }, |
|
827 |
- { "jp2", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(CODEC_JP2) }, 0, 0, VE, "format" }, |
|
828 |
- { "profile", NULL, OFFSET(profile), AV_OPT_TYPE_INT, { .i64 = OPJ(STD_RSIZ) }, OPJ(STD_RSIZ), OPJ(CINEMA4K), VE, "profile" }, |
|
829 |
- { "jpeg2000", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(STD_RSIZ) }, 0, 0, VE, "profile" }, |
|
830 |
- { "cinema2k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(CINEMA2K) }, 0, 0, VE, "profile" }, |
|
831 |
- { "cinema4k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(CINEMA4K) }, 0, 0, VE, "profile" }, |
|
832 |
- { "cinema_mode", "Digital Cinema", OFFSET(cinema_mode), AV_OPT_TYPE_INT, { .i64 = OPJ(OFF) }, OPJ(OFF), OPJ(CINEMA4K_24), VE, "cinema_mode" }, |
|
833 |
- { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(OFF) }, 0, 0, VE, "cinema_mode" }, |
|
834 |
- { "2k_24", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(CINEMA2K_24) }, 0, 0, VE, "cinema_mode" }, |
|
835 |
- { "2k_48", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(CINEMA2K_48) }, 0, 0, VE, "cinema_mode" }, |
|
836 |
- { "4k_24", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(CINEMA4K_24) }, 0, 0, VE, "cinema_mode" }, |
|
837 |
- { "prog_order", "Progression Order", OFFSET(prog_order), AV_OPT_TYPE_INT, { .i64 = OPJ(LRCP) }, OPJ(LRCP), OPJ(CPRL), VE, "prog_order" }, |
|
838 |
- { "lrcp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(LRCP) }, 0, 0, VE, "prog_order" }, |
|
839 |
- { "rlcp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(RLCP) }, 0, 0, VE, "prog_order" }, |
|
840 |
- { "rpcl", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(RPCL) }, 0, 0, VE, "prog_order" }, |
|
841 |
- { "pcrl", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(PCRL) }, 0, 0, VE, "prog_order" }, |
|
842 |
- { "cprl", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ(CPRL) }, 0, 0, VE, "prog_order" }, |
|
808 |
+ { "format", "Codec Format", OFFSET(format), AV_OPT_TYPE_INT, { .i64 = OPJ_CODEC_JP2 }, OPJ_CODEC_J2K, OPJ_CODEC_JP2, VE, "format" }, |
|
809 |
+ { "j2k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CODEC_J2K }, 0, 0, VE, "format" }, |
|
810 |
+ { "jp2", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CODEC_JP2 }, 0, 0, VE, "format" }, |
|
811 |
+ { "profile", NULL, OFFSET(profile), AV_OPT_TYPE_INT, { .i64 = OPJ_STD_RSIZ }, OPJ_STD_RSIZ, OPJ_CINEMA4K, VE, "profile" }, |
|
812 |
+ { "jpeg2000", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_STD_RSIZ }, 0, 0, VE, "profile" }, |
|
813 |
+ { "cinema2k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CINEMA2K }, 0, 0, VE, "profile" }, |
|
814 |
+ { "cinema4k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CINEMA4K }, 0, 0, VE, "profile" }, |
|
815 |
+ { "cinema_mode", "Digital Cinema", OFFSET(cinema_mode), AV_OPT_TYPE_INT, { .i64 = OPJ_OFF }, OPJ_OFF, OPJ_CINEMA4K_24, VE, "cinema_mode" }, |
|
816 |
+ { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_OFF }, 0, 0, VE, "cinema_mode" }, |
|
817 |
+ { "2k_24", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CINEMA2K_24 }, 0, 0, VE, "cinema_mode" }, |
|
818 |
+ { "2k_48", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CINEMA2K_48 }, 0, 0, VE, "cinema_mode" }, |
|
819 |
+ { "4k_24", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CINEMA4K_24 }, 0, 0, VE, "cinema_mode" }, |
|
820 |
+ { "prog_order", "Progression Order", OFFSET(prog_order), AV_OPT_TYPE_INT, { .i64 = OPJ_LRCP }, OPJ_LRCP, OPJ_CPRL, VE, "prog_order" }, |
|
821 |
+ { "lrcp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_LRCP }, 0, 0, VE, "prog_order" }, |
|
822 |
+ { "rlcp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_RLCP }, 0, 0, VE, "prog_order" }, |
|
823 |
+ { "rpcl", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_RPCL }, 0, 0, VE, "prog_order" }, |
|
824 |
+ { "pcrl", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_PCRL }, 0, 0, VE, "prog_order" }, |
|
825 |
+ { "cprl", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CPRL }, 0, 0, VE, "prog_order" }, |
|
843 | 826 |
{ "numresolution", NULL, OFFSET(numresolution), AV_OPT_TYPE_INT, { .i64 = 6 }, 0, 33, VE }, |
844 | 827 |
{ "irreversible", NULL, OFFSET(irreversible), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, |
845 | 828 |
{ "disto_alloc", NULL, OFFSET(disto_alloc), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE }, |
... | ... |
@@ -862,7 +757,6 @@ AVCodec ff_libopenjpeg_encoder = { |
862 | 862 |
.priv_data_size = sizeof(LibOpenJPEGContext), |
863 | 863 |
.init = libopenjpeg_encode_init, |
864 | 864 |
.encode2 = libopenjpeg_encode_frame, |
865 |
- .close = libopenjpeg_encode_close, |
|
866 | 865 |
.capabilities = AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_INTRA_ONLY, |
867 | 866 |
.pix_fmts = (const enum AVPixelFormat[]) { |
868 | 867 |
AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA, AV_PIX_FMT_RGB48, |