diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-07-22 22:10:41 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-07-22 22:18:18 +0200 |
commit | 9023de342f88e961a3741753aff68925eebf884e (patch) | |
tree | c45518b146273fb14210f02cd41fa2c52624e39d /libavcodec | |
parent | 4f4eb380f0f96dbb7cdd2b812fa92b8b47a0f27c (diff) | |
parent | 1470ce21cec5ee26e106e2a884c26bbf84e5aaea (diff) | |
download | ffmpeg-9023de342f88e961a3741753aff68925eebf884e.tar.gz |
Merge commit '1470ce21cec5ee26e106e2a884c26bbf84e5aaea'
* commit '1470ce21cec5ee26e106e2a884c26bbf84e5aaea':
Bump libavcodec and libavformat minor versions for G.723.1 decoder and demuxer
G.723.1 demuxer and decoder
Add a shift parameter to celp_lp_synthesis_filter()
libopenjpeg: K&R formatting cosmetics
yadif: use emms_c() instead of inline assembly for emms invocations.
ac3: don't use different names for option tables in the template file.
lavfi: use const for AVFilterPad declarations in all filters.
adpcm: don't duplicate identical AVSampleFmt array for each encoder.
configure: cosmetics: Group test dependencies together
configure: add more passthrough flags in tms470 filter
configure: move flag filtering functions out of if/else blocks
Conflicts:
Changelog
configure
doc/general.texi
libavcodec/Makefile
libavcodec/ac3enc_fixed.c
libavcodec/allcodecs.c
libavcodec/eac3enc.c
libavcodec/g723_1.c
libavcodec/g723_1_data.h
libavcodec/libopenjpegdec.c
libavcodec/libopenjpegenc.c
libavcodec/v210dec.h
libavcodec/version.h
libavfilter/af_anull.c
libavfilter/asrc_anullsrc.c
libavfilter/f_settb.c
libavfilter/fifo.c
libavfilter/split.c
libavfilter/src_movie.c
libavfilter/vf_aspect.c
libavfilter/vf_blackframe.c
libavfilter/vf_boxblur.c
libavfilter/vf_copy.c
libavfilter/vf_crop.c
libavfilter/vf_cropdetect.c
libavfilter/vf_delogo.c
libavfilter/vf_drawbox.c
libavfilter/vf_drawtext.c
libavfilter/vf_fade.c
libavfilter/vf_fieldorder.c
libavfilter/vf_format.c
libavfilter/vf_frei0r.c
libavfilter/vf_gradfun.c
libavfilter/vf_hflip.c
libavfilter/vf_hqdn3d.c
libavfilter/vf_libopencv.c
libavfilter/vf_lut.c
libavfilter/vf_null.c
libavfilter/vf_overlay.c
libavfilter/vf_pad.c
libavfilter/vf_pixdesctest.c
libavfilter/vf_scale.c
libavfilter/vf_select.c
libavfilter/vf_setpts.c
libavfilter/vf_showinfo.c
libavfilter/vf_slicify.c
libavfilter/vf_transpose.c
libavfilter/vf_unsharp.c
libavfilter/vf_vflip.c
libavfilter/vf_yadif.c
libavfilter/vsrc_color.c
libavfilter/vsrc_testsrc.c
libavformat/Makefile
libavformat/allformats.c
libavformat/g723_1.c
libavformat/version.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/ac3enc_fixed.c | 2 | ||||
-rw-r--r-- | libavcodec/ac3enc_opts_template.c | 6 | ||||
-rw-r--r-- | libavcodec/adpcmenc.c | 6 | ||||
-rw-r--r-- | libavcodec/eac3enc.c | 2 | ||||
-rw-r--r-- | libavcodec/g723_1.c | 91 | ||||
-rw-r--r-- | libavcodec/g723_1_data.h | 22 | ||||
-rw-r--r-- | libavcodec/libopenjpegdec.c | 97 | ||||
-rw-r--r-- | libavcodec/libopenjpegenc.c | 36 | ||||
-rw-r--r-- | libavcodec/version.h | 2 |
9 files changed, 137 insertions, 127 deletions
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c index 399b238800..8293ecd34d 100644 --- a/libavcodec/ac3enc_fixed.c +++ b/libavcodec/ac3enc_fixed.c @@ -38,7 +38,7 @@ static const AVClass ac3enc_class = { .class_name = "Fixed-Point AC-3 Encoder", .item_name = av_default_item_name, - .option = ac3fixed_options, + .option = ac3_options, .version = LIBAVUTIL_VERSION_INT, }; diff --git a/libavcodec/ac3enc_opts_template.c b/libavcodec/ac3enc_opts_template.c index fa8984476e..1c67aa4164 100644 --- a/libavcodec/ac3enc_opts_template.c +++ b/libavcodec/ac3enc_opts_template.c @@ -23,13 +23,7 @@ #include "internal.h" #include "ac3.h" -#if AC3ENC_TYPE == AC3ENC_TYPE_AC3_FIXED -static const AVOption ac3fixed_options[] = { -#elif AC3ENC_TYPE == AC3ENC_TYPE_AC3 static const AVOption ac3_options[] = { -#else /* AC3ENC_TYPE_EAC3 */ -static const AVOption eac3_options[] = { -#endif /* Metadata Options */ {"per_frame_metadata", "Allow Changing Metadata Per-Frame", OFFSET(allow_per_frame_metadata), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM}, #if AC3ENC_TYPE != AC3ENC_TYPE_EAC3 diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c index 6dde9e71a7..4a0023231e 100644 --- a/libavcodec/adpcmenc.c +++ b/libavcodec/adpcmenc.c @@ -717,6 +717,9 @@ error: return AVERROR(ENOMEM); } +static const enum AVSampleFormat sample_fmts[] = { + AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE +}; #define ADPCM_ENCODER(id_, name_, long_name_) \ AVCodec ff_ ## name_ ## _encoder = { \ @@ -727,8 +730,7 @@ AVCodec ff_ ## name_ ## _encoder = { \ .init = adpcm_encode_init, \ .encode2 = adpcm_encode_frame, \ .close = adpcm_encode_close, \ - .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, \ - AV_SAMPLE_FMT_NONE }, \ + .sample_fmts = sample_fmts, \ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ } diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c index 9f4a6a78f0..e11b29c161 100644 --- a/libavcodec/eac3enc.c +++ b/libavcodec/eac3enc.c @@ -36,7 +36,7 @@ static const AVClass eac3enc_class = { .class_name = "E-AC-3 Encoder", .item_name = av_default_item_name, - .option = eac3_options, + .option = ac3_options, .version = LIBAVUTIL_VERSION_INT, }; diff --git a/libavcodec/g723_1.c b/libavcodec/g723_1.c index ce3793dffe..8c5407e9d8 100644 --- a/libavcodec/g723_1.c +++ b/libavcodec/g723_1.c @@ -25,23 +25,27 @@ * G.723.1 compatible decoder */ -#include "avcodec.h" #define BITSTREAM_READER_LE +#include "libavutil/audioconvert.h" +#include "libavutil/lzo.h" +#include "libavutil/opt.h" +#include "avcodec.h" #include "internal.h" #include "get_bits.h" #include "acelp_vectors.h" #include "celp_filters.h" #include "celp_math.h" #include "lsp.h" -#include "libavutil/lzo.h" #include "g723_1_data.h" typedef struct g723_1_context { + AVClass *class; AVFrame frame; + G723_1_Subframe subframe[4]; - FrameType cur_frame_type; - FrameType past_frame_type; - Rate cur_rate; + enum FrameType cur_frame_type; + enum FrameType past_frame_type; + enum Rate cur_rate; uint8_t lsp_index[LSP_BANDS]; int pitch_lag[2]; int erased_frames; @@ -62,6 +66,7 @@ typedef struct g723_1_context { int pf_gain; ///< formant postfilter ///< gain scaling unit memory + int postfilter; int16_t prev_data[HALF_FRAME_LEN]; int16_t prev_weight_sig[PITCH_MAX]; @@ -80,11 +85,12 @@ static av_cold int g723_1_decode_init(AVCodecContext *avctx) avctx->sample_fmt = AV_SAMPLE_FMT_S16; p->pf_gain = 1 << 12; - memcpy(p->prev_lsp, dc_lsp, LPC_ORDER * sizeof(int16_t)); avcodec_get_frame_defaults(&p->frame); avctx->coded_frame = &p->frame; + memcpy(p->prev_lsp, dc_lsp, LPC_ORDER * sizeof(*p->prev_lsp)); + return 0; } @@ -108,7 +114,7 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf, info_bits = get_bits(&gb, 2); if (info_bits == 3) { - p->cur_frame_type = UntransmittedFrame; + p->cur_frame_type = UNTRANSMITTED_FRAME; return 0; } @@ -118,14 +124,14 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf, p->lsp_index[0] = get_bits(&gb, 8); if (info_bits == 2) { - p->cur_frame_type = SIDFrame; + p->cur_frame_type = SID_FRAME; p->subframe[0].amp_index = get_bits(&gb, 6); return 0; } /* Extract the info common to both rates */ - p->cur_rate = info_bits ? Rate5k3 : Rate6k3; - p->cur_frame_type = ActiveFrame; + p->cur_rate = info_bits ? RATE_5300 : RATE_6300; + p->cur_frame_type = ACTIVE_FRAME; p->pitch_lag[0] = get_bits(&gb, 7); if (p->pitch_lag[0] > 123) /* test if forbidden code */ @@ -146,9 +152,9 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf, temp = get_bits(&gb, 12); ad_cb_len = 170; p->subframe[i].dirac_train = 0; - if (p->cur_rate == Rate6k3 && p->pitch_lag[i >> 1] < SUBFRAME_LEN - 2) { + if (p->cur_rate == RATE_6300 && p->pitch_lag[i >> 1] < SUBFRAME_LEN - 2) { p->subframe[i].dirac_train = temp >> 11; - temp &= 0x7ff; + temp &= 0x7FF; ad_cb_len = 85; } p->subframe[i].ad_cb_gain = FASTDIV(temp, GAIN_LEVELS); @@ -165,7 +171,7 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf, p->subframe[2].grid_index = get_bits1(&gb); p->subframe[3].grid_index = get_bits1(&gb); - if (p->cur_rate == Rate6k3) { + if (p->cur_rate == RATE_6300) { skip_bits1(&gb); /* skip reserved bit */ /* Compute pulse_pos index using the 13-bit combined position index */ @@ -192,7 +198,7 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf, p->subframe[1].pulse_sign = get_bits(&gb, 5); p->subframe[2].pulse_sign = get_bits(&gb, 6); p->subframe[3].pulse_sign = get_bits(&gb, 5); - } else { /* Rate5k3 */ + } else { /* 5300 bps */ p->subframe[0].pulse_pos = get_bits(&gb, 12); p->subframe[1].pulse_pos = get_bits(&gb, 12); p->subframe[2].pulse_pos = get_bits(&gb, 12); @@ -333,7 +339,7 @@ static void inverse_quant(int16_t *cur_lsp, int16_t *prev_lsp, break; } if (!stable) - memcpy(cur_lsp, prev_lsp, LPC_ORDER * sizeof(int16_t)); + memcpy(cur_lsp, prev_lsp, LPC_ORDER * sizeof(*cur_lsp)); } /** @@ -432,7 +438,7 @@ static void lsp_interpolate(int16_t *lpc, int16_t *cur_lsp, int16_t *prev_lsp) 8192, 8192, 1 << 13, 14, LPC_ORDER); ff_acelp_weighted_vector_sum(lpc + 2 * LPC_ORDER, cur_lsp, prev_lsp, 12288, 4096, 1 << 13, 14, LPC_ORDER); - memcpy(lpc + 3 * LPC_ORDER, cur_lsp, LPC_ORDER * sizeof(int16_t)); + memcpy(lpc + 3 * LPC_ORDER, cur_lsp, LPC_ORDER * sizeof(*lpc)); for (i = 0; i < SUBFRAMES; i++) { lsp2lpc(lpc_ptr); @@ -448,7 +454,7 @@ static void gen_dirac_train(int16_t *buf, int pitch_lag) int16_t vector[SUBFRAME_LEN]; int i, j; - memcpy(vector, buf, SUBFRAME_LEN * sizeof(int16_t)); + memcpy(vector, buf, SUBFRAME_LEN * sizeof(*vector)); for (i = pitch_lag; i < SUBFRAME_LEN; i += pitch_lag) { for (j = 0; j < SUBFRAME_LEN - i; j++) buf[i + j] += vector[j]; @@ -465,13 +471,13 @@ static void gen_dirac_train(int16_t *buf, int pitch_lag) * @param index current subframe index */ static void gen_fcb_excitation(int16_t *vector, G723_1_Subframe subfrm, - Rate cur_rate, int pitch_lag, int index) + enum Rate cur_rate, int pitch_lag, int index) { int temp, i, j; - memset(vector, 0, SUBFRAME_LEN * sizeof(int16_t)); + memset(vector, 0, SUBFRAME_LEN * sizeof(*vector)); - if (cur_rate == Rate6k3) { + if (cur_rate == RATE_6300) { if (subfrm.pulse_pos >= max_pos[index]) return; @@ -495,7 +501,7 @@ static void gen_fcb_excitation(int16_t *vector, G723_1_Subframe subfrm, } if (subfrm.dirac_train == 1) gen_dirac_train(vector, pitch_lag); - } else { /* Rate5k3 */ + } else { /* 5300 bps */ int cb_gain = fixed_cb_gain[subfrm.amp_index]; int cb_shift = subfrm.grid_index; int cb_sign = subfrm.pulse_sign; @@ -554,7 +560,7 @@ static void gen_acb_excitation(int16_t *vector, int16_t *prev_excitation, get_residual(residual, prev_excitation, lag); /* Select quantization table */ - if (cur_rate == Rate6k3 && pitch_lag < SUBFRAME_LEN - 2) { + if (cur_rate == RATE_6300 && pitch_lag < SUBFRAME_LEN - 2) { cb_ptr = adaptive_cb_gain85; } else cb_ptr = adaptive_cb_gain170; @@ -608,7 +614,7 @@ static int autocorr_max(G723_1_Context *p, int offset, int *ccr_max, * @param ccr cross-correlation * @param res_eng residual energy */ -static void comp_ppf_gains(int lag, PPFParam *ppf, Rate cur_rate, +static void comp_ppf_gains(int lag, PPFParam *ppf, enum Rate cur_rate, int tgt_eng, int ccr, int res_eng) { int pf_residual; /* square of postfiltered residual */ @@ -657,7 +663,7 @@ static void comp_ppf_gains(int lag, PPFParam *ppf, Rate cur_rate, * @param cur_rate current bitrate */ static void comp_ppf_coeff(G723_1_Context *p, int offset, int pitch_lag, - PPFParam *ppf, Rate cur_rate) + PPFParam *ppf, enum Rate cur_rate) { int16_t scale; @@ -795,15 +801,15 @@ static void residual_interp(int16_t *buf, int16_t *out, int lag, /* Attenuate */ for (i = 0; i < lag; i++) vector_ptr[i - lag] = vector_ptr[i - lag] * 3 >> 2; - av_memcpy_backptr((uint8_t*)vector_ptr, lag * sizeof(int16_t), - FRAME_LEN * sizeof(int16_t)); - memcpy(out, vector_ptr, FRAME_LEN * sizeof(int16_t)); + av_memcpy_backptr((uint8_t*)vector_ptr, lag * sizeof(*vector_ptr), + FRAME_LEN * sizeof(*vector_ptr)); + memcpy(out, vector_ptr, FRAME_LEN * sizeof(*vector_ptr)); } else { /* Unvoiced */ for (i = 0; i < FRAME_LEN; i++) { *rseed = *rseed * 521 + 259; out[i] = gain * *rseed >> 15; } - memset(buf, 0, (FRAME_LEN + PITCH_MAX) * sizeof(int16_t)); + memset(buf, 0, (FRAME_LEN + PITCH_MAX) * sizeof(*buf)); } } @@ -889,8 +895,8 @@ static void formant_postfilter(G723_1_Context *p, int16_t *lpc, int16_t *buf) int filter_signal[LPC_ORDER + FRAME_LEN], *signal_ptr; int i, j, k; - memcpy(buf, p->fir_mem, LPC_ORDER * sizeof(int16_t)); - memcpy(filter_signal, p->iir_mem, LPC_ORDER * sizeof(int)); + memcpy(buf, p->fir_mem, LPC_ORDER * sizeof(*buf)); + memcpy(filter_signal, p->iir_mem, LPC_ORDER * sizeof(*filter_signal)); for (i = LPC_ORDER, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) { for (k = 0; k < LPC_ORDER; k++) { @@ -977,8 +983,8 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data, if (unpack_bitstream(p, buf, buf_size) < 0) { bad_frame = 1; - p->cur_frame_type = p->past_frame_type == ActiveFrame ? - ActiveFrame : UntransmittedFrame; + p->cur_frame_type = p->past_frame_type == ACTIVE_FRAME ? + ACTIVE_FRAME : UNTRANSMITTED_FRAME; } p->frame.nb_samples = FRAME_LEN + LPC_ORDER; @@ -989,20 +995,21 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data, out= (int16_t*)p->frame.data[0]; - if(p->cur_frame_type == ActiveFrame) { - if (!bad_frame) { + if(p->cur_frame_type == ACTIVE_FRAME) { + if (!bad_frame) p->erased_frames = 0; - } else if(p->erased_frames != 3) + else if(p->erased_frames != 3) p->erased_frames++; inverse_quant(cur_lsp, p->prev_lsp, p->lsp_index, bad_frame); lsp_interpolate(lpc, cur_lsp, p->prev_lsp); /* Save the lsp_vector for the next frame */ - memcpy(p->prev_lsp, cur_lsp, LPC_ORDER * sizeof(int16_t)); + memcpy(p->prev_lsp, cur_lsp, LPC_ORDER * sizeof(*p->prev_lsp)); /* Generate the excitation for the frame */ - memcpy(p->excitation, p->prev_excitation, PITCH_MAX * sizeof(int16_t)); + memcpy(p->excitation, p->prev_excitation, + PITCH_MAX * sizeof(*p->excitation)); vector_ptr = p->excitation + PITCH_MAX; if (!p->erased_frames) { /* Update interpolation gain memory */ @@ -1118,7 +1125,7 @@ static av_cold int g723_1_encode_init(AVCodecContext *avctx) } if (avctx->bit_rate == 6300) { - p->cur_rate = Rate6k3; + p->cur_rate = RATE_6300; } else if (avctx->bit_rate == 5300) { av_log(avctx, AV_LOG_ERROR, "Bitrate not supported yet, use 6.3k\n"); return AVERROR_PATCHWELCOME; @@ -2041,7 +2048,7 @@ static int pack_bitstream(G723_1_Context *p, unsigned char *frame, int size) init_put_bits(&pb, frame, size); - if (p->cur_rate == Rate6k3) { + if (p->cur_rate == RATE_6300) { info_bits = 0; put_bits(&pb, 2, info_bits); } @@ -2059,7 +2066,7 @@ static int pack_bitstream(G723_1_Context *p, unsigned char *frame, int size) for (i = 0; i < SUBFRAMES; i++) { temp = p->subframe[i].ad_cb_gain * GAIN_LEVELS + p->subframe[i].amp_index; - if (p->cur_rate == Rate6k3) + if (p->cur_rate == RATE_6300) temp += p->subframe[i].dirac_train << 11; put_bits(&pb, 12, temp); } @@ -2069,7 +2076,7 @@ static int pack_bitstream(G723_1_Context *p, unsigned char *frame, int size) put_bits(&pb, 1, p->subframe[2].grid_index); put_bits(&pb, 1, p->subframe[3].grid_index); - if (p->cur_rate == Rate6k3) { + if (p->cur_rate == RATE_6300) { skip_put_bits(&pb, 1); /* reserved bit */ /* Write 13 bit combined position index */ @@ -2192,7 +2199,7 @@ static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, /* Reconstruct the excitation */ gen_acb_excitation(impulse_resp, p->prev_excitation, p->pitch_lag[i >> 1], - p->subframe[i], Rate6k3); + p->subframe[i], RATE_6300); memmove(p->prev_excitation, p->prev_excitation + SUBFRAME_LEN, sizeof(int16_t) * (PITCH_MAX - SUBFRAME_LEN)); diff --git a/libavcodec/g723_1_data.h b/libavcodec/g723_1_data.h index 34221e3349..66a032490b 100644 --- a/libavcodec/g723_1_data.h +++ b/libavcodec/g723_1_data.h @@ -25,8 +25,8 @@ * G723.1 compatible decoder data tables */ -#ifndef AVCODEC_G729_DATA_H -#define AVCODEC_G729_DATA_H +#ifndef AVCODEC_G729_1_DATA_H +#define AVCODEC_G729_1_DATA_H #include <stdint.h> @@ -49,23 +49,23 @@ /** * G723.1 frame types */ -typedef enum { - ActiveFrame, ///< Active speech - SIDFrame, ///< Silence Insertion Descriptor frame - UntransmittedFrame +typedef enum FrameType { + ACTIVE_FRAME, ///< Active speech + SID_FRAME, ///< Silence Insertion Descriptor frame + UNTRANSMITTED_FRAME } FrameType; static const uint8_t frame_size[4] = {24, 20, 4, 1}; -typedef enum { - Rate6k3, - Rate5k3 +typedef enum Rate { + RATE_6300, + RATE_5300 } Rate; /** * G723.1 unpacked data subframe */ -typedef struct { +typedef struct G723_1_Subframe { int ad_cb_lag; ///< adaptive codebook lag int ad_cb_gain; int dirac_train; @@ -1319,4 +1319,4 @@ static const int16_t percept_flt_tbl[2][LPC_ORDER] = { {16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32} }; -#endif /* AVCODEC_G729_DATA_H */ +#endif /* AVCODEC_G729_1_DATA_H */ diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c index e7a7d8d8d4..333955feb0 100644 --- a/libavcodec/libopenjpegdec.c +++ b/libavcodec/libopenjpegdec.c @@ -20,18 +20,19 @@ */ /** -* @file -* JPEG 2000 decoder using libopenjpeg -*/ + * @file + * JPEG 2000 decoder using libopenjpeg + */ + +#define OPJ_STATIC +#include <openjpeg.h> -#include "libavutil/opt.h" #include "libavutil/imgutils.h" #include "libavutil/pixfmt.h" -#include "avcodec.h" #include "libavutil/intreadwrite.h" +#include "libavutil/opt.h" +#include "avcodec.h" #include "thread.h" -#define OPJ_STATIC -#include <openjpeg.h> #define JP2_SIG_TYPE 0x6A502020 #define JP2_SIG_VALUE 0x0D0A870A @@ -61,7 +62,8 @@ typedef struct { int lowqual; } LibOpenJPEGContext; -static inline int libopenjpeg_matches_pix_fmt(const opj_image_t *image, enum PixelFormat pix_fmt){ +static inline int libopenjpeg_matches_pix_fmt(const opj_image_t *image, enum PixelFormat pix_fmt) +{ AVPixFmtDescriptor descriptor = av_pix_fmt_descriptors[pix_fmt]; int match = 1; @@ -129,7 +131,7 @@ static inline int libopenjpeg_ispacked(enum PixelFormat pix_fmt) { return 0; component_plane = av_pix_fmt_descriptors[pix_fmt].comp[0].plane; - for(i = 1; i < av_pix_fmt_descriptors[pix_fmt].nb_components; i++) { + for (i = 1; i < av_pix_fmt_descriptors[pix_fmt].nb_components; i++) { if (component_plane != av_pix_fmt_descriptors[pix_fmt].comp[i].plane) return 0; } @@ -139,11 +141,11 @@ static inline int libopenjpeg_ispacked(enum PixelFormat pix_fmt) { static inline void libopenjpeg_copy_to_packed8(AVFrame *picture, opj_image_t *image) { uint8_t *img_ptr; int index, x, y, c; - for(y = 0; y < picture->height; y++) { + for (y = 0; y < picture->height; y++) { index = y*picture->width; img_ptr = picture->data[0] + y*picture->linesize[0]; - for(x = 0; x < picture->width; x++, index++) { - for(c = 0; c < image->numcomps; c++) { + for (x = 0; x < picture->width; x++, index++) { + for (c = 0; c < image->numcomps; c++) { *img_ptr++ = image->comps[c].data[index]; } } @@ -154,9 +156,9 @@ static inline void libopenjpeg_copy_to_packed16(AVFrame *picture, opj_image_t *i uint16_t *img_ptr; int index, x, y, c; int adjust[4]; - for (x = 0; x < image->numcomps; x++) { + for (x = 0; x < image->numcomps; x++) adjust[x] = FFMAX(FFMIN(16 - image->comps[x].prec, 8), 0); - } + for (y = 0; y < picture->height; y++) { index = y*picture->width; img_ptr = (uint16_t*) (picture->data[0] + y*picture->linesize[0]); @@ -173,11 +175,11 @@ static inline void libopenjpeg_copyto8(AVFrame *picture, opj_image_t *image) { uint8_t *img_ptr; int index, x, y; - for(index = 0; index < image->numcomps; index++) { + for (index = 0; index < image->numcomps; index++) { comp_data = image->comps[index].data; - for(y = 0; y < image->comps[index].h; y++) { + for (y = 0; y < image->comps[index].h; y++) { img_ptr = picture->data[index] + y * picture->linesize[index]; - for(x = 0; x < image->comps[index].w; x++) { + for (x = 0; x < image->comps[index].w; x++) { *img_ptr = (uint8_t) *comp_data; img_ptr++; comp_data++; @@ -190,11 +192,11 @@ static inline void libopenjpeg_copyto16(AVFrame *picture, opj_image_t *image) { int *comp_data; uint16_t *img_ptr; int index, x, y; - for(index = 0; index < image->numcomps; index++) { + for (index = 0; index < image->numcomps; index++) { comp_data = image->comps[index].data; - for(y = 0; y < image->comps[index].h; y++) { + for (y = 0; y < image->comps[index].h; y++) { img_ptr = (uint16_t*) (picture->data[index] + y * picture->linesize[index]); - for(x = 0; x < image->comps[index].w; x++) { + for (x = 0; x < image->comps[index].w; x++) { *img_ptr = *comp_data; img_ptr++; comp_data++; @@ -240,49 +242,55 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, *data_size = 0; // Check if input is a raw jpeg2k codestream or in jp2 wrapping - if((AV_RB32(buf) == 12) && - (AV_RB32(buf + 4) == JP2_SIG_TYPE) && - (AV_RB32(buf + 8) == JP2_SIG_VALUE)) { + if ((AV_RB32(buf) == 12) && + (AV_RB32(buf + 4) == JP2_SIG_TYPE) && + (AV_RB32(buf + 8) == JP2_SIG_VALUE)) { dec = opj_create_decompress(CODEC_JP2); } else { - // If the AVPacket contains a jp2c box, then skip to - // the starting byte of the codestream. + /* 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(CODEC_J2K); } - if(!dec) { + if (!dec) { av_log(avctx, AV_LOG_ERROR, "Error initializing decoder.\n"); return -1; } opj_set_event_mgr((opj_common_ptr)dec, NULL, NULL); ctx->dec_params.cp_limit_decoding = LIMIT_TO_MAIN_HEADER; - ctx->dec_params.cp_layer = ctx->lowqual; + ctx->dec_params.cp_layer = ctx->lowqual; // 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"); + + if (!stream) { + av_log(avctx, AV_LOG_ERROR, + "Codestream could not be opened for reading.\n"); opj_destroy_decompress(dec); return -1; } - // Decode the header only + // Decode the header only. image = opj_decode_with_info(dec, stream, NULL); opj_cio_close(stream); - if(!image) { + + if (!image) { av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n"); opj_destroy_decompress(dec); return -1; } + width = image->x1 - image->x0; height = image->y1 - image->y0; - if(av_image_check_size(width, height, 0, avctx) < 0) { - av_log(avctx, AV_LOG_ERROR, "%dx%d dimension invalid.\n", width, height); + if (av_image_check_size(width, height, 0, avctx) < 0) { + av_log(avctx, AV_LOG_ERROR, + "%dx%d dimension invalid.\n", width, height); goto done; } + avcodec_set_dimensions(avctx, width, height); if (avctx->pix_fmt != PIX_FMT_NONE) { @@ -303,29 +311,30 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, if (image->comps[i].prec > avctx->bits_per_raw_sample) avctx->bits_per_raw_sample = image->comps[i].prec; - if(picture->data[0]) + if (picture->data[0]) ff_thread_release_buffer(avctx, picture); - if(ff_thread_get_buffer(avctx, picture) < 0){ + if (ff_thread_get_buffer(avctx, picture) < 0) { av_log(avctx, AV_LOG_ERROR, "ff_thread_get_buffer() failed\n"); goto done; } ctx->dec_params.cp_limit_decoding = NO_LIMITATION; ctx->dec_params.cp_reduce = avctx->lowres; - // Tie decoder with decoding parameters + // 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"); + if (!stream) { + av_log(avctx, AV_LOG_ERROR, + "Codestream could not be opened for reading.\n"); goto done; } opj_image_destroy(image); - // Decode the codestream + // Decode the codestream. image = opj_decode_with_info(dec, stream, NULL); opj_cio_close(stream); - if(!image) { + if (!image) { av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n"); goto done; } @@ -367,7 +376,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, *output = ctx->image; *data_size = sizeof(AVPicture); - ret = buf_size; + ret = buf_size; done: opj_image_destroy(image); @@ -379,16 +388,16 @@ static av_cold int libopenjpeg_decode_close(AVCodecContext *avctx) { LibOpenJPEGContext *ctx = avctx->priv_data; - if(ctx->image.data[0]) + if (ctx->image.data[0]) ff_thread_release_buffer(avctx, &ctx->image); - return 0 ; + return 0; } #define OFFSET(x) offsetof(LibOpenJPEGContext, x) #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM static const AVOption options[] = { - { "lowqual", "Limit the number of layers used for decoding", OFFSET(lowqual), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, VD }, + { "lowqual", "Limit the number of layers used for decoding", OFFSET(lowqual), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, VD }, { NULL }, }; diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c index bd741df985..82d28665b5 100644 --- a/libavcodec/libopenjpegenc.c +++ b/libavcodec/libopenjpegenc.c @@ -20,18 +20,18 @@ */ /** -* @file -* JPEG 2000 encoder using libopenjpeg -*/ + * @file + * JPEG 2000 encoder using libopenjpeg + */ #define OPJ_STATIC #include <openjpeg.h> -#include "libavutil/opt.h" -#include "libavutil/imgutils.h" #include "libavutil/avassert.h" -#include "avcodec.h" +#include "libavutil/imgutils.h" #include "libavutil/intreadwrite.h" +#include "libavutil/opt.h" +#include "avcodec.h" #include "internal.h" typedef struct { @@ -284,9 +284,8 @@ static int libopenjpeg_copy_unpacked8(AVCodecContext *avctx, const AVFrame *fram for (y = 0; y < height; ++y) { image_index = y * width; frame_index = y * frame->linesize[compno]; - for (x = 0; x < width; ++x) { + for (x = 0; x < width; ++x) image->comps[compno].data[image_index++] = frame->data[compno][frame_index++]; - } } } @@ -319,9 +318,8 @@ static int libopenjpeg_copy_unpacked16(AVCodecContext *avctx, const AVFrame *fra for (y = 0; y < height; ++y) { image_index = y * width; frame_index = y * (frame->linesize[compno] / 2); - for (x = 0; x < width; ++x) { + for (x = 0; x < width; ++x) image->comps[compno].data[image_index++] = frame_ptr[frame_index++]; - } } } @@ -333,7 +331,7 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, { LibOpenJPEGContext *ctx = avctx->priv_data; opj_cinfo_t *compress = ctx->compress; - opj_image_t *image = ctx->image; + opj_image_t *image = ctx->image; opj_cio_t *stream; int cpyresult = 0; int ret, len; @@ -342,7 +340,7 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, // x1, y1 is the width, height of the reference grid image->x0 = 0; image->y0 = 0; - image->x1 = (avctx->width - 1) * ctx->enc_params.subsampling_dx + 1; + image->x1 = (avctx->width - 1) * ctx->enc_params.subsampling_dx + 1; image->y1 = (avctx->height - 1) * ctx->enc_params.subsampling_dy + 1; switch (avctx->pix_fmt) { @@ -432,7 +430,7 @@ static av_cold int libopenjpeg_encode_close(AVCodecContext *avctx) opj_destroy_compress(ctx->compress); opj_image_destroy(ctx->image); av_freep(&avctx->coded_frame); - return 0 ; + return 0; } #define OFFSET(x) offsetof(LibOpenJPEGContext, x) @@ -456,11 +454,11 @@ static const AVOption options[] = { { "rpcl", NULL, 0, AV_OPT_TYPE_CONST, { RPCL }, 0, 0, VE, "prog_order" }, { "pcrl", NULL, 0, AV_OPT_TYPE_CONST, { PCRL }, 0, 0, VE, "prog_order" }, { "cprl", NULL, 0, AV_OPT_TYPE_CONST, { CPRL }, 0, 0, VE, "prog_order" }, - { "numresolution", NULL, OFFSET(numresolution), AV_OPT_TYPE_INT, { 6 }, 1, 10, VE }, - { "numlayers", NULL, OFFSET(numlayers), AV_OPT_TYPE_INT, { 1 }, 1, 10, VE }, - { "disto_alloc", NULL, OFFSET(disto_alloc), AV_OPT_TYPE_INT, { 1 }, 0, 1, VE }, - { "fixed_alloc", NULL, OFFSET(fixed_alloc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, - { "fixed_quality", NULL, OFFSET(fixed_quality), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, + { "numresolution", NULL, OFFSET(numresolution), AV_OPT_TYPE_INT, { 6 }, 1, 10, VE }, + { "numlayers", NULL, OFFSET(numlayers), AV_OPT_TYPE_INT, { 1 }, 1, 10, VE }, + { "disto_alloc", NULL, OFFSET(disto_alloc), AV_OPT_TYPE_INT, { 1 }, 0, 1, VE }, + { "fixed_alloc", NULL, OFFSET(fixed_alloc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, + { "fixed_quality", NULL, OFFSET(fixed_quality), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, { NULL }, }; @@ -480,7 +478,7 @@ AVCodec ff_libopenjpeg_encoder = { .encode2 = libopenjpeg_encode_frame, .close = libopenjpeg_encode_close, .capabilities = 0, - .pix_fmts = (const enum PixelFormat[]){ + .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_RGB24, PIX_FMT_RGBA, PIX_FMT_RGB48, PIX_FMT_RGBA64, PIX_FMT_GRAY8, PIX_FMT_GRAY8A, PIX_FMT_GRAY16, PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUVA420P, diff --git a/libavcodec/version.h b/libavcodec/version.h index 47e6ff938b..2e2d6979b3 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -27,7 +27,7 @@ */ #define LIBAVCODEC_VERSION_MAJOR 54 -#define LIBAVCODEC_VERSION_MINOR 43 +#define LIBAVCODEC_VERSION_MINOR 44 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |