Hi! The previous version of this patch got lost in all the noise. Also it needs some changes to new API. Here is the last version of MxPEG decoder patch. Regards, Anatoly.
On Mon, Feb 14, 2011 at 02:46:28PM +0300, Anatoly Nenashev wrote:
The previous version of this patch got lost in all the noise. Also it needs some changes to new API. Here is the last version of MxPEG decoder patch.
How much sense would it make to move the mxpeg decoding code into a separate file?
--- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -794,12 +864,15 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, i
for(mb_y = 0; mb_y < s->mb_height; mb_y++) { for(mb_x = 0; mb_x < s->mb_width; mb_x++) { + const int copy_mb = use_mxm_bitmask && !get_bits1(&mxm_bitmask_gb); + if (copy_mb && !use_reference) continue;
Please place the statement on the next line.
@@ -1260,6 +1413,23 @@ found:
+static int mxpeg_check_dimensions(MXpegDecodeContext *mxctx) +{ + AVFrame *picture_ptr = &mxctx->pictures[mxctx->picture_index], + *reference_ptr = &mxctx->pictures[mxctx->picture_index ^ 1]; + int i; + + if (mxctx->mxm_bitmask && reference_ptr->data[0]) { + for (i = 0; i < MAX_COMPONENTS; ++i) { + if ( (!reference_ptr->data[i] ^ !picture_ptr->data[i]) ||
nit: Drop the space after '('.
@@ -1267,11 +1437,14 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx,
s->got_picture = 0; // picture from previous image can not be reused + if (mxctx) mxctx->mxm_bitmask = 0;
Please break this line as well.
@@ -1565,3 +1773,18 @@ AVCodec ff_thp_decoder = { + +AVCodec ff_mxpeg_decoder = { + "mxpeg", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_MXPEG, + sizeof(MXpegDecodeContext), + ff_mjpeg_decode_init, + NULL, + ff_mjpeg_decode_end, + ff_mjpeg_decode_frame, + CODEC_CAP_DR1, + NULL, + .max_lowres = 3, + .long_name = NULL_IF_CONFIG_SMALL("Mobotix MxPEG video"), +};
I think this declaration should be #ifdeffed to guard against the case that mxpeg is disabled. The same goes for the mxpeg-specific functions/code. I'm not sure how much work it would be to split this off more cleanly into a separate file, but it might be worth investigating.
--- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -107,6 +107,19 @@ typedef struct MJpegDecodeContext {
+typedef struct MXpegDecodeContext { + MJpegDecodeContext jpgctx; + int got_sof_data; /* true if SOF data successfully parsed */ + uint8_t *comment_buffer; /* temporary comment buffer */ + uint8_t *mxm_bitmask; /* bitmask buffer */ + int32_t bitmask_size; /* size of bitmask */ + uint8_t has_complete_frame; /* true if has complete frame */ + uint8_t *completion_bitmask; /* completion bitmask of macroblocks */ + int mb_width, mb_height; /* size of picture in MB's from MXM header */ + AVFrame pictures[2]; /* pictures array */ + int picture_index; /* index of current picture, other picture is reference */ +} MXpegDecodeContext;
IIUC this is only used in mjpegdec.c, no need to place it in the header then. Diego
On 14.02.2011 15:34, Diego Biurrun wrote:
On Mon, Feb 14, 2011 at 02:46:28PM +0300, Anatoly Nenashev wrote:
The previous version of this patch got lost in all the noise. Also it needs some changes to new API. Here is the last version of MxPEG decoder patch.
How much sense would it make to move the mxpeg decoding code into a separate file?
[...]
I think this declaration should be #ifdeffed to guard against the case that mxpeg is disabled.
The same goes for the mxpeg-specific functions/code. I'm not sure how much work it would be to split this off more cleanly into a separate file, but it might be worth investigating.
Ok. I'll think about it.
Diego Biurrun <diego at biurrun.de> writes:
On Mon, Feb 14, 2011 at 02:46:28PM +0300, Anatoly Nenashev wrote:
The previous version of this patch got lost in all the noise. Also it needs some changes to new API. Here is the last version of MxPEG decoder patch.
How much sense would it make to move the mxpeg decoding code into a separate file?
That would require duplicating lots of functions with only minor changes. -- M?ns Rullg?rd mans at mansr.com
On 14.02.2011 15:34, Diego Biurrun wrote:
On Mon, Feb 14, 2011 at 02:46:28PM +0300, Anatoly Nenashev wrote:
The previous version of this patch got lost in all the noise. Also it needs some changes to new API. Here is the last version of MxPEG decoder patch.
How much sense would it make to move the mxpeg decoding code into a separate file?
I think I've made it. There are 4 patches below.
On 16.02.2011 23:48, Anatoly Nenashev wrote:
On 14.02.2011 15:34, Diego Biurrun wrote:
On Mon, Feb 14, 2011 at 02:46:28PM +0300, Anatoly Nenashev wrote:
The previous version of this patch got lost in all the noise. Also it needs some changes to new API. Here is the last version of MxPEG decoder patch. How much sense would it make to move the mxpeg decoding code into a separate file?
I think I've made it. There are 4 patches below. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
Ping.
Anatoly Nenashev skrev 2011-02-16 21:51:
> From b2a9360bbab34f831eb9522fd6fcb91514b84bda Mon Sep 17 00:00:00 2001
> From: anatoly <anatoly.nenashev at ovsoft.ru>
> Date: Tue, 15 Feb 2011 01:39:32 +0300
> Subject: [PATCH 1/4] Support reference picture defined by bitmask in
MJPEG's SOS decoder
>
> +static int mjpeg_decode_scan(MJpegDecodeContext *s, int
nb_components, int Ah, int Al,
> + const uint8_t *mb_bitmask, const
AVFrame *reference){
> int i, mb_x, mb_y;
> uint8_t* data[MAX_COMPONENTS];
> + const uint8_t *reference_data[MAX_COMPONENTS];
> int linesize[MAX_COMPONENTS];
> + GetBitContext mb_bitmask_gb;
> +
> + if (mb_bitmask) {
> + init_get_bits(&mb_bitmask_gb, mb_bitmask,
s->mb_width*s->mb_height);
> + }
>
> if(s->flipped && s->avctx->flags & CODEC_FLAG_EMU_EDGE) {
> av_log(s->avctx, AV_LOG_ERROR, "Can not flip image with
CODEC_FLAG_EMU_EDGE set!\n");
> @@ -783,23 +805,31 @@ static int mjpeg_decode_scan(MJpegDecodeContext
*s, int nb_components, int Ah, i
> for(i=0; i < nb_components; i++) {
> int c = s->comp_index[i];
> data[c] = s->picture.data[c];
> + reference_data[c] = reference ? reference->data[c] : 0;
> linesize[c]=s->linesize[c];
> s->coefs_finished[c] |= 1;
> if(s->flipped) {
> //picture should be flipped upside-down for this codec
> - data[c] += (linesize[c] * (s->v_scount[i] * (8 *
s->mb_height -((s->height/s->v_max)&7)) - 1 ));
> + int offset = (linesize[c] * (s->v_scount[i] * (8 *
s->mb_height -((s->height/s->v_max)&7)) - 1 ));
> + data[c] += offset;
> + reference_data[c] += offset;
> linesize[c] *= -1;
> }
> }
>
> for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
> for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
> + const int copy_mb = mb_bitmask &&
!get_bits1(&mb_bitmask_gb);
> + if (copy_mb && !reference)
> + continue;
Is having mb_bitmask != NULL and reference == NULL actually allowed? If
not, maybe put a check in PATCH 4/4 for "if (s->got_mxm_bitmask &&
!reference_ptr)"
> +
> if (s->restart_interval && !s->restart_count)
> s->restart_count = s->restart_interval;
>
> for(i=0;i<nb_components;i++) {
> uint8_t *ptr;
> int n, h, v, x, y, c, j;
> + int block_offset;
> n = s->nb_blocks[i];
> c = s->comp_index[i];
> h = s->h_scount[i];
> @@ -807,12 +837,16 @@ static int mjpeg_decode_scan(MJpegDecodeContext
*s, int nb_components, int Ah, i
> x = 0;
> y = 0;
> for(j=0;j<n;j++) {
> - ptr = data[c] +
> - (((linesize[c] * (v * mb_y + y) * 8) +
> - (h * mb_x + x) * 8) >> s->avctx->lowres);
> + block_offset = (((linesize[c] * (v * mb_y + y) *
8) +
> + (h * mb_x + x) * 8) >>
s->avctx->lowres);
> +
> if(s->interlaced && s->bottom_field)
> - ptr += linesize[c] >> 1;
> + block_offset += linesize[c] >> 1;
> + ptr = data[c] + block_offset;
> if(!s->progressive) {
> + if (copy_mb) {
> + mjpeg_copy_block(ptr, reference_data[c]
+ block_offset, linesize[c], s->avctx->lowres);
> + } else {
> s->dsp.clear_block(s->block);
> if(decode_block(s, s->block, i,
> s->dc_index[i], s->ac_index[i],
> @@ -821,6 +855,7 @@ static int mjpeg_decode_scan(MJpegDecodeContext
*s, int nb_components, int Ah, i
> return -1;
> }
> s->dsp.idct_put(ptr, linesize[c], s->block);
> + }
> } else {
> int block_idx = s->block_stride[c] * (v *
mb_y + y) + (h * mb_x + x);
> DCTELEM *block = s->blocks[c][block_idx];
> @@ -851,29 +886,45 @@ static int mjpeg_decode_scan(MJpegDecodeContext
*s, int nb_components, int Ah, i
> return 0;
> }
Looks OK, but won't the extra "if"s make the mjpeg decoder slower?
Probably not a big issue though, since I guess the decoder spends most
of its time doing block decoding and DSP stuff anyway.
> -static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s,
int ss, int se, int Ah, int Al){
> +static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s,
int ss, int se, int Ah, int Al,
> + const uint8_t
*mb_bitmask, const AVFrame *reference){
> int mb_x, mb_y;
> int EOBRUN = 0;
> int c = s->comp_index[0];
> uint8_t* data = s->picture.data[c];
> + const uint8_t *reference_data = reference ? reference->data[c] : 0;
Nit: NULL?
> int linesize = s->linesize[c];
> int last_scan = 0;
> int16_t *quant_matrix = s->quant_matrixes[ s->quant_index[c] ];
> + GetBitContext mb_bitmask_gb;
> +
> + if (mb_bitmask) {
> + init_get_bits(&mb_bitmask_gb, mb_bitmask,
s->mb_width*s->mb_height);
> + }
>
> if(!Al) {
> s->coefs_finished[c] |= (1LL<<(se+1))-(1LL<<ss);
> last_scan = !~s->coefs_finished[c];
> }
>
> - if(s->interlaced && s->bottom_field)
> - data += linesize >> 1;
> + if(s->interlaced && s->bottom_field) {
> + int offset = linesize >> 1;
> + data += offset;
> + reference_data += offset;
> + }
>
> for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
> - uint8_t *ptr = data + (mb_y*linesize*8 >> s->avctx->lowres);
> + int block_offset = (mb_y*linesize*8 >> s->avctx->lowres);
> + uint8_t *ptr = data + block_offset;
> int block_idx = mb_y * s->block_stride[c];
> DCTELEM (*block)[64] = &s->blocks[c][block_idx];
> uint8_t *last_nnz = &s->last_nnz[c][block_idx];
> for(mb_x = 0; mb_x < s->mb_width; mb_x++, block++, last_nnz++) {
> + const int copy_mb = mb_bitmask &&
!get_bits1(&mb_bitmask_gb);
> + if (copy_mb && !reference)
> + continue;
> +
> + if (!copy_mb) {
> int ret;
> if(Ah)
> ret = decode_block_refinement(s, *block, last_nnz,
s->ac_index[0],
> @@ -885,16 +936,23 @@ static int
mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, int s
> av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n",
mb_y, mb_x);
> return -1;
> }
> + }
> +
> if(last_scan) {
> + if (copy_mb) {
> + mjpeg_copy_block(ptr, reference_data +
block_offset, linesize, s->avctx->lowres);
> + } else {
> s->dsp.idct_put(ptr, linesize, *block);
> ptr += 8 >> s->avctx->lowres;
> + }
> }
> }
> }
> return 0;
> }
Look OK. Again, maybe a bit slower, but might not matter.
The rest looks OK AFAICT.
/Tomas
On 17.02.2011 12:39, Tomas H?rdin wrote:
Anatoly Nenashev skrev 2011-02-16 21:51:
From b2a9360bbab34f831eb9522fd6fcb91514b84bda Mon Sep 17 00:00:00 2001 From: anatoly <anatoly.nenashev at ovsoft.ru> Date: Tue, 15 Feb 2011 01:39:32 +0300 Subject: [PATCH 1/4] Support reference picture defined by bitmask in MJPEG's SOS decoder
[...]
for(mb_y = 0; mb_y < s->mb_height; mb_y++) { for(mb_x = 0; mb_x < s->mb_width; mb_x++) { + const int copy_mb = mb_bitmask &&
!get_bits1(&mb_bitmask_gb);
+ if (copy_mb && !reference) + continue;
Is having mb_bitmask != NULL and reference == NULL actually allowed? If not, maybe put a check in PATCH 4/4 for "if (s->got_mxm_bitmask && !reference_ptr)"
Yes, it is actually allowed. Input stream may not start from full JPEG image. In this situation the first frame consists of parts defined by bitmask and thus reference_ptr=NULL.
+ if (s->restart_interval && !s->restart_count)
[...]> + const uint8_t *reference_data = reference ? reference->data[c] : 0;
Nit: NULL?
Of course. There are other places with this style nit. I'll fix it.
On 16.02.2011 23:51, Anatoly Nenashev wrote:
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
Fix style nit.
On 18.02.2011 13:11, Anatoly Nenashev wrote:
On 16.02.2011 23:51, Anatoly Nenashev wrote:
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
Fix style nit.
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel Remove check that reference picture is not NULL.
On 16.02.2011 23:52, Anatoly Nenashev wrote:
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
Fix style nit.
Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> writes:
From 38608bf9c49c2ce2c7b3edbfb4d4641ca160a990 Mon Sep 17 00:00:00 2001 From: anatoly <anatoly.nenashev at ovsoft.ru> Date: Tue, 15 Feb 2011 11:33:56 +0300 Subject: [PATCH 3/4] Implement dynamic memory allocation for MJPEG's picture
--- libavcodec/jpeglsdec.c | 18 +++++++++--------- libavcodec/mjpegbdec.c | 2 +- libavcodec/mjpegdec.c | 44 +++++++++++++++++++++++++++----------------- libavcodec/mjpegdec.h | 2 +- 4 files changed, 38 insertions(+), 28 deletions(-)
[...]
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 9792616..2db6760 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -81,6 +81,13 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) { MJpegDecodeContext *s = avctx->priv_data;
+ if (!s->picture_ptr) { + s->picture_ptr = av_mallocz(sizeof(AVFrame)); + if (!s->picture_ptr) + return AVERROR(ENOMEM); + s->picture_ptr->reference = 0; + } + s->avctx = avctx; dsputil_init(&s->dsp, avctx); ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct);
[...]
diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 9c78ab2..a1dee59 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -80,7 +80,7 @@ typedef struct MJpegDecodeContext { int h_max, v_max; /* maximum h and v counts */ int quant_index[4]; /* quant table index for each component */ int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ - AVFrame picture; /* picture structure */ + AVFrame *picture_ptr; /* pointer to picture structure */ int got_picture; ///< we found a SOF and picture is valid, too. int linesize[MAX_COMPONENTS]; ///< linesize << interlaced int8_t *qscale_table; --
Why don't you simply make an array: AVFrame picture[2]? -- M?ns Rullg?rd mans at mansr.com
On 17.02.2011 00:38, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
From 38608bf9c49c2ce2c7b3edbfb4d4641ca160a990 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Tue, 15 Feb 2011 11:33:56 +0300 Subject: [PATCH 3/4] Implement dynamic memory allocation for MJPEG's picture
--- libavcodec/jpeglsdec.c | 18 +++++++++--------- libavcodec/mjpegbdec.c | 2 +- libavcodec/mjpegdec.c | 44 +++++++++++++++++++++++++++----------------- libavcodec/mjpegdec.h | 2 +- 4 files changed, 38 insertions(+), 28 deletions(-)
[...]
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 9792616..2db6760 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -81,6 +81,13 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) { MJpegDecodeContext *s = avctx->priv_data;
+ if (!s->picture_ptr) { + s->picture_ptr = av_mallocz(sizeof(AVFrame)); + if (!s->picture_ptr) + return AVERROR(ENOMEM); + s->picture_ptr->reference = 0; + } + s->avctx = avctx; dsputil_init(&s->dsp, avctx); ff_init_scantable(s->dsp.idct_permutation,&s->scantable, ff_zigzag_direct);
[...]
diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 9c78ab2..a1dee59 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -80,7 +80,7 @@ typedef struct MJpegDecodeContext { int h_max, v_max; /* maximum h and v counts */ int quant_index[4]; /* quant table index for each component */ int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ - AVFrame picture; /* picture structure */ + AVFrame *picture_ptr; /* pointer to picture structure */ int got_picture; ///< we found a SOF and picture is valid, too. int linesize[MAX_COMPONENTS]; ///< linesize<< interlaced int8_t *qscale_table; --
Why don't you simply make an array: AVFrame picture[2]?
Because in this case this isn't enough. I should also add "picture_index" field and implement switching between pictures. I don't think this must be done in this file.
Hi, On Wed, Feb 16, 2011 at 5:02 PM, Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> wrote:
On 17.02.2011 00:38, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> ?writes:
?From 38608bf9c49c2ce2c7b3edbfb4d4641ca160a990 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Tue, 15 Feb 2011 11:33:56 +0300 Subject: [PATCH 3/4] Implement dynamic memory allocation for MJPEG's picture
--- ?libavcodec/jpeglsdec.c | ? 18 +++++++++--------- ?libavcodec/mjpegbdec.c | ? ?2 +- ?libavcodec/mjpegdec.c ?| ? 44 +++++++++++++++++++++++++++----------------- ?libavcodec/mjpegdec.h ?| ? ?2 +- ?4 files changed, 38 insertions(+), 28 deletions(-)
[...]
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 9792616..2db6760 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -81,6 +81,13 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) ?{ ? ? ?MJpegDecodeContext *s = avctx->priv_data;
+ ? ?if (!s->picture_ptr) { + ? ? ? ?s->picture_ptr = av_mallocz(sizeof(AVFrame)); + ? ? ? ?if (!s->picture_ptr) + ? ? ? ? ? ? ?return AVERROR(ENOMEM); + ? ? ? ?s->picture_ptr->reference = 0; + ? ?} + ? ? ?s->avctx = avctx; ? ? ?dsputil_init(&s->dsp, avctx); ? ? ?ff_init_scantable(s->dsp.idct_permutation,&s->scantable, ff_zigzag_direct);
[...]
diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 9c78ab2..a1dee59 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -80,7 +80,7 @@ typedef struct MJpegDecodeContext { ? ? ?int h_max, v_max; /* maximum h and v counts */ ? ? ?int quant_index[4]; ? /* quant table index for each component */ ? ? ?int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ - ? ?AVFrame picture; /* picture structure */ + ? ?AVFrame *picture_ptr; /* pointer to picture structure */ ? ? ?int got_picture; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?///< ?we found a SOF and picture is valid, too. ? ? ?int linesize[MAX_COMPONENTS]; ? ? ? ? ? ? ? ? ? ///< ?linesize<< ?interlaced ? ? ?int8_t *qscale_table; --
Why don't you simply make an array: AVFrame picture[2]?
Because in this case this isn't enough. I should also add "picture_index" field and implement switching between pictures. I don't think this must be done in this file.
For mxpeg, and that's why that's in another patch (4/4) and file. But this is mjpeg.c. You remove picture and replace it with picture_ptr, and then allocate picture_ptr. Why not leave picture, add picture_ptr so no extra allocation is needed? Ronald
On 26.02.2011 22:05, Ronald S. Bultje wrote:
Hi,
On Wed, Feb 16, 2011 at 5:02 PM, Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> wrote:
On 17.02.2011 00:38, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
From 38608bf9c49c2ce2c7b3edbfb4d4641ca160a990 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Tue, 15 Feb 2011 11:33:56 +0300 Subject: [PATCH 3/4] Implement dynamic memory allocation for MJPEG's picture
--- libavcodec/jpeglsdec.c | 18 +++++++++--------- libavcodec/mjpegbdec.c | 2 +- libavcodec/mjpegdec.c | 44 +++++++++++++++++++++++++++----------------- libavcodec/mjpegdec.h | 2 +- 4 files changed, 38 insertions(+), 28 deletions(-)
[...]
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 9792616..2db6760 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -81,6 +81,13 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) { MJpegDecodeContext *s = avctx->priv_data;
+ if (!s->picture_ptr) { + s->picture_ptr = av_mallocz(sizeof(AVFrame)); + if (!s->picture_ptr) + return AVERROR(ENOMEM); + s->picture_ptr->reference = 0; + } + s->avctx = avctx; dsputil_init(&s->dsp, avctx); ff_init_scantable(s->dsp.idct_permutation,&s->scantable, ff_zigzag_direct);
[...]
diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 9c78ab2..a1dee59 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -80,7 +80,7 @@ typedef struct MJpegDecodeContext { int h_max, v_max; /* maximum h and v counts */ int quant_index[4]; /* quant table index for each component */ int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ - AVFrame picture; /* picture structure */ + AVFrame *picture_ptr; /* pointer to picture structure */ int got_picture; ///< we found a SOF and picture is valid, too. int linesize[MAX_COMPONENTS]; ///< linesize<< interlaced int8_t *qscale_table; --
Why don't you simply make an array: AVFrame picture[2]?
Because in this case this isn't enough. I should also add "picture_index" field and implement switching between pictures. I don't think this must be done in this file.
For mxpeg, and that's why that's in another patch (4/4) and file.
But this is mjpeg.c. You remove picture and replace it with picture_ptr, and then allocate picture_ptr. Why not leave picture, add picture_ptr so no extra allocation is needed?
Ronald
Because in this case this isn't enough. I should also add "picture_index" field and implement switching between pictures. I don't think this must be done in this file.
On 26.02.2011 22:05, Ronald S. Bultje wrote:
Hi,
On Wed, Feb 16, 2011 at 5:02 PM, Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> wrote:
On 17.02.2011 00:38, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
From 38608bf9c49c2ce2c7b3edbfb4d4641ca160a990 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Tue, 15 Feb 2011 11:33:56 +0300 Subject: [PATCH 3/4] Implement dynamic memory allocation for MJPEG's picture
--- libavcodec/jpeglsdec.c | 18 +++++++++--------- libavcodec/mjpegbdec.c | 2 +- libavcodec/mjpegdec.c | 44 +++++++++++++++++++++++++++----------------- libavcodec/mjpegdec.h | 2 +- 4 files changed, 38 insertions(+), 28 deletions(-)
[...]
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 9792616..2db6760 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -81,6 +81,13 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) { MJpegDecodeContext *s = avctx->priv_data;
+ if (!s->picture_ptr) { + s->picture_ptr = av_mallocz(sizeof(AVFrame)); + if (!s->picture_ptr) + return AVERROR(ENOMEM); + s->picture_ptr->reference = 0; + } + s->avctx = avctx; dsputil_init(&s->dsp, avctx); ff_init_scantable(s->dsp.idct_permutation,&s->scantable, ff_zigzag_direct);
[...]
diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 9c78ab2..a1dee59 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -80,7 +80,7 @@ typedef struct MJpegDecodeContext { int h_max, v_max; /* maximum h and v counts */ int quant_index[4]; /* quant table index for each component */ int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ - AVFrame picture; /* picture structure */ + AVFrame *picture_ptr; /* pointer to picture structure */ int got_picture; ///< we found a SOF and picture is valid, too. int linesize[MAX_COMPONENTS]; ///< linesize<< interlaced int8_t *qscale_table; --
Why don't you simply make an array: AVFrame picture[2]?
Because in this case this isn't enough. I should also add "picture_index" field and implement switching between pictures. I don't think this must be done in this file.
For mxpeg, and that's why that's in another patch (4/4) and file.
But this is mjpeg.c. You remove picture and replace it with picture_ptr, and then allocate picture_ptr. Why not leave picture, add picture_ptr so no extra allocation is needed?
Ronald _______________________________________________
Sorry, previous post was copypasted from the wrong place. That's my answer: In this case I should add a lot of checks like "codec_id == CODEC_ID_MXPEG" and then use "picture_ptr" if "true", otherwise use "picture". I don't think this solution makes code clearer. Also use of picture_ptr instead of picture is not ugly. For example, mpegvideo decoder uses current_picture_ptr, next_picture_ptr, last_picture_ptr.
On 26.02.2011 22:05, Ronald S. Bultje wrote:
Hi,
On Wed, Feb 16, 2011 at 5:02 PM, Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> wrote:
On 17.02.2011 00:38, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
From 38608bf9c49c2ce2c7b3edbfb4d4641ca160a990 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Tue, 15 Feb 2011 11:33:56 +0300 Subject: [PATCH 3/4] Implement dynamic memory allocation for MJPEG's picture
--- libavcodec/jpeglsdec.c | 18 +++++++++--------- libavcodec/mjpegbdec.c | 2 +- libavcodec/mjpegdec.c | 44 +++++++++++++++++++++++++++----------------- libavcodec/mjpegdec.h | 2 +- 4 files changed, 38 insertions(+), 28 deletions(-)
[...]
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 9792616..2db6760 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -81,6 +81,13 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) { MJpegDecodeContext *s = avctx->priv_data;
+ if (!s->picture_ptr) { + s->picture_ptr = av_mallocz(sizeof(AVFrame)); + if (!s->picture_ptr) + return AVERROR(ENOMEM); + s->picture_ptr->reference = 0; + } + s->avctx = avctx; dsputil_init(&s->dsp, avctx); ff_init_scantable(s->dsp.idct_permutation,&s->scantable, ff_zigzag_direct);
[...]
diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 9c78ab2..a1dee59 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -80,7 +80,7 @@ typedef struct MJpegDecodeContext { int h_max, v_max; /* maximum h and v counts */ int quant_index[4]; /* quant table index for each component */ int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ - AVFrame picture; /* picture structure */ + AVFrame *picture_ptr; /* pointer to picture structure */ int got_picture; ///< we found a SOF and picture is valid, too. int linesize[MAX_COMPONENTS]; ///< linesize<< interlaced int8_t *qscale_table; --
Why don't you simply make an array: AVFrame picture[2]?
Because in this case this isn't enough. I should also add "picture_index" field and implement switching between pictures. I don't think this must be done in this file.
For mxpeg, and that's why that's in another patch (4/4) and file.
But this is mjpeg.c. You remove picture and replace it with picture_ptr, and then allocate picture_ptr. Why not leave picture, add picture_ptr so no extra allocation is needed?
Ronald
Ok. Dynamic memory allocation removed.
On 28.02.2011 17:13, Anatoly Nenashev wrote:
On 26.02.2011 22:05, Ronald S. Bultje wrote:
Hi,
On Wed, Feb 16, 2011 at 5:02 PM, Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> wrote:
On 17.02.2011 00:38, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
From 38608bf9c49c2ce2c7b3edbfb4d4641ca160a990 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Tue, 15 Feb 2011 11:33:56 +0300 Subject: [PATCH 3/4] Implement dynamic memory allocation for MJPEG's picture
--- libavcodec/jpeglsdec.c | 18 +++++++++--------- libavcodec/mjpegbdec.c | 2 +- libavcodec/mjpegdec.c | 44 +++++++++++++++++++++++++++----------------- libavcodec/mjpegdec.h | 2 +- 4 files changed, 38 insertions(+), 28 deletions(-)
[...]
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 9792616..2db6760 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -81,6 +81,13 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) { MJpegDecodeContext *s = avctx->priv_data;
+ if (!s->picture_ptr) { + s->picture_ptr = av_mallocz(sizeof(AVFrame)); + if (!s->picture_ptr) + return AVERROR(ENOMEM); + s->picture_ptr->reference = 0; + } + s->avctx = avctx; dsputil_init(&s->dsp, avctx); ff_init_scantable(s->dsp.idct_permutation,&s->scantable, ff_zigzag_direct);
[...]
diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 9c78ab2..a1dee59 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -80,7 +80,7 @@ typedef struct MJpegDecodeContext { int h_max, v_max; /* maximum h and v counts */ int quant_index[4]; /* quant table index for each component */ int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ - AVFrame picture; /* picture structure */ + AVFrame *picture_ptr; /* pointer to picture structure */ int got_picture; ///< we found a SOF and picture is valid, too. int linesize[MAX_COMPONENTS]; ///< linesize<< interlaced int8_t *qscale_table; --
Why don't you simply make an array: AVFrame picture[2]? Because in this case this isn't enough. I should also add "picture_index" field and implement switching between pictures. I don't think this must be done in this file. For mxpeg, and that's why that's in another patch (4/4) and file.
But this is mjpeg.c. You remove picture and replace it with picture_ptr, and then allocate picture_ptr. Why not leave picture, add picture_ptr so no extra allocation is needed?
Ronald
Ok. Dynamic memory allocation removed.
Simplify condition in decode_end.
Hi, On Mon, Feb 28, 2011 at 9:19 AM, Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> wrote:
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index d146973..7f2d907 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -81,6 +81,11 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) { MJpegDecodeContext *s = avctx->priv_data;
+ if (!s->picture_ptr) { + s->picture_ptr = &s->picture;
Why the if?
+ s->picture_ptr->reference = 0;
Unnecessary, all memory is zero'ed on init. Ronald
On 28.02.2011 18:34, Ronald S. Bultje wrote:
Hi,
On Mon, Feb 28, 2011 at 9:19 AM, Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> wrote:
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index d146973..7f2d907 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -81,6 +81,11 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) { MJpegDecodeContext *s = avctx->priv_data;
+ if (!s->picture_ptr) { + s->picture_ptr =&s->picture;
Why the if?
Because I don't know that s->picture_ptr is set or not. Some external decoders can setup s->picture_ptr before or after call of ff_mjpeg_decode_init. This check is just for robustness.
+ s->picture_ptr->reference = 0;
Unnecessary, all memory is zero'ed on init.
Ronald
Ok. I've removed it.
Hi, On Mon, Feb 28, 2011 at 10:41 AM, Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> wrote:
On 28.02.2011 18:34, Ronald S. Bultje wrote:
On Mon, Feb 28, 2011 at 9:19 AM, Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> ?wrote:
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index d146973..7f2d907 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -81,6 +81,11 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) ?{ ? ? ?MJpegDecodeContext *s = avctx->priv_data;
+ ? ?if (!s->picture_ptr) { + ? ? ? ?s->picture_ptr =&s->picture;
Why the if?
Because I don't know that s->picture_ptr is set or not. Some external decoders can setup s->picture_ptr before or after call of ff_mjpeg_decode_init. This check is just for robustness.
+ ? ? ? ?s->picture_ptr->reference = 0;
Unnecessary, all memory is zero'ed on init.
Ok. I've removed it.
This version looks OK to me. I'll check the others later. Ronald
On 16.02.2011 23:53, Anatoly Nenashev wrote:
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
Fix style nit.
Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> writes:
From e6a735d5d70e4ab64053e6223cb5a6296145cb26 Mon Sep 17 00:00:00 2001 From: anatoly <anatoly.nenashev at ovsoft.ru> Date: Wed, 16 Feb 2011 23:28:07 +0300 Subject: [PATCH 4/4] Add MxPEG decoder
--- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/mxpegdec.c | 326 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 328 insertions(+), 0 deletions(-) create mode 100644 libavcodec/mxpegdec.c
This duplicates a lot of code from mjpegdec.c. That is not good. -- M?ns Rullg?rd mans at mansr.com
On 17.02.2011 00:40, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
From e6a735d5d70e4ab64053e6223cb5a6296145cb26 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Wed, 16 Feb 2011 23:28:07 +0300 Subject: [PATCH 4/4] Add MxPEG decoder
--- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/mxpegdec.c | 326 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 328 insertions(+), 0 deletions(-) create mode 100644 libavcodec/mxpegdec.c
This duplicates a lot of code from mjpegdec.c. That is not good.
I'm not agree with it. What part exactly was copypasted from original code?
Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> writes:
On 17.02.2011 00:40, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
From e6a735d5d70e4ab64053e6223cb5a6296145cb26 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Wed, 16 Feb 2011 23:28:07 +0300 Subject: [PATCH 4/4] Add MxPEG decoder
--- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/mxpegdec.c | 326 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 328 insertions(+), 0 deletions(-) create mode 100644 libavcodec/mxpegdec.c
This duplicates a lot of code from mjpegdec.c. That is not good.
I'm not agree with it. What part exactly was copypasted from original code?
The big loop in decode_frame() is largely duplicated. Your original patch only added a few small bits to it. -- M?ns Rullg?rd mans at mansr.com
On 17.02.2011 01:07, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
On 17.02.2011 00:40, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
From e6a735d5d70e4ab64053e6223cb5a6296145cb26 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Wed, 16 Feb 2011 23:28:07 +0300 Subject: [PATCH 4/4] Add MxPEG decoder
--- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/mxpegdec.c | 326 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 328 insertions(+), 0 deletions(-) create mode 100644 libavcodec/mxpegdec.c
This duplicates a lot of code from mjpegdec.c. That is not good.
I'm not agree with it. What part exactly was copypasted from original code?
The big loop in decode_frame() is largely duplicated. Your original patch only added a few small bits to it.
Hmm... Let's compare them in details: 1) mxpeg_decode_app is simpler than mjpeg_decode_app 2) EOI processing is simpler 3) COM processing is much different 4) only SOF0 marker are supported, other SOFx markers are ignored 5) there is no restart_marker support 6) there is no DRI marker support 7) SOS processing is much different 8) the code at the label "the_end" is also different. The only common parts are main loop "while" and case's names in "switch". To implement all this stuff in original mjpeg code I should add a lot of "if else" in each "case" body. I don't think it makes code clearer and faster.
Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> writes:
On 17.02.2011 01:07, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
On 17.02.2011 00:40, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
From e6a735d5d70e4ab64053e6223cb5a6296145cb26 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Wed, 16 Feb 2011 23:28:07 +0300 Subject: [PATCH 4/4] Add MxPEG decoder
--- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/mxpegdec.c | 326 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 328 insertions(+), 0 deletions(-) create mode 100644 libavcodec/mxpegdec.c
This duplicates a lot of code from mjpegdec.c. That is not good.
I'm not agree with it. What part exactly was copypasted from original code?
The big loop in decode_frame() is largely duplicated. Your original patch only added a few small bits to it.
Hmm... Let's compare them in details: 1) mxpeg_decode_app is simpler than mjpeg_decode_app 2) EOI processing is simpler 3) COM processing is much different 4) only SOF0 marker are supported, other SOFx markers are ignored 5) there is no restart_marker support 6) there is no DRI marker support 7) SOS processing is much different 8) the code at the label "the_end" is also different.
The only common parts are main loop "while" and case's names in "switch". To implement all this stuff in original mjpeg code I should add a lot of "if else" in each "case" body. I don't think it makes code clearer and faster.
OK, it's more different that it seemed at a glance. Sorry for the noise. -- M?ns Rullg?rd mans at mansr.com
On 16.02.2011 23:54, Anatoly Nenashev wrote:
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
Fix style nit.
On 18.02.2011 13:12, Anatoly Nenashev wrote:
On 16.02.2011 23:54, Anatoly Nenashev wrote:
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
Fix style nit.
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel Add allocation of dummy reference picture.
On 14.02.2011 15:34, Diego Biurrun wrote:
On Mon, Feb 14, 2011 at 02:46:28PM +0300, Anatoly Nenashev wrote:
The previous version of this patch got lost in all the noise. Also it needs some changes to new API. Here is the last version of MxPEG decoder patch.
How much sense would it make to move the mxpeg decoding code into a separate file?
Ping. This feature is implemented. Please finish review process.
On date Monday 2011-02-14 14:46:28 +0300, Anatoly Nenashev encoded:
Hi! The previous version of this patch got lost in all the noise. Also it needs some changes to new API. Here is the last version of MxPEG decoder patch.
Regards, Anatoly.
From 502f988b95f6f721613da6ab4b1de5c3ae9ce4bf Mon Sep 17 00:00:00 2001 From: anatoly <anatoly.nenashev at ovsoft.ru> Date: Mon, 14 Feb 2011 14:40:44 +0300 Subject: [PATCH] Add MxPEG video decoder
--- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/mjpegdec.c | 275 +++++++++++++++++++++++++++++++++++++++++++----- libavcodec/mjpegdec.h | 13 +++ 4 files changed, 264 insertions(+), 26 deletions(-) [...] +static int mxpeg_allocate_picture(MXpegDecodeContext *mxctx, MJpegDecodeContext* s) +{ + AVFrame *picture_ptr, *reference_ptr; + if (s->first_picture) { + av_log(s->avctx, AV_LOG_WARNING, "First picture has no SOF, skipping\n"); + return -1; + } + if (!mxctx->got_sof_data) { + av_log(s->avctx, AV_LOG_WARNING, "Can not process SOS after broken SOF, skipping\n"); + return -1; + } + if (!mxctx->mxm_bitmask) { + av_log(s->avctx, AV_LOG_WARNING, "Non-key frame has no MXM, skipping\n"); + return -1; + }
Please return meaningful error codes, here and below. [...]
@@ -859,6 +947,14 @@ static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, int s int linesize = s->linesize[c]; int last_scan = 0; int16_t *quant_matrix = s->quant_matrixes[ s->quant_index[c] ]; + MXpegDecodeContext *mxctx = (s->avctx->codec_id == CODEC_ID_MXPEG) ? s->avctx->priv_data : 0; + + if (mxctx) { + //FIXME implement progressive mode for MxPEG if needed (no samples available now) + av_log(s->avctx, AV_LOG_ERROR,
+ "Progressive mode doesn't implemented in MxPEG decoder\n");
Grammar: "Progressive mode is not implemented in MxPEG decoder\n"
+ return -1;
AVERROR_PATCHWELCOME? [...]
@@ -1565,3 +1773,18 @@ AVCodec ff_thp_decoder = { .max_lowres = 3, .long_name = NULL_IF_CONFIG_SMALL("Nintendo Gamecube THP video"), }; + +AVCodec ff_mxpeg_decoder = { + "mxpeg", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_MXPEG, + sizeof(MXpegDecodeContext), + ff_mjpeg_decode_init, + NULL, + ff_mjpeg_decode_end, + ff_mjpeg_decode_frame, + CODEC_CAP_DR1, + NULL, + .max_lowres = 3, + .long_name = NULL_IF_CONFIG_SMALL("Mobotix MxPEG video"), +};
Please use always designated field init (.foo = "bar"), more readable and more robust. -- FFmpeg = Forgiving and Fiendish Muttering Philosofic EniGma
Ping.
Hi! All features requested by reviewers are implemented. Please finish review process (or make a request for a new feature). Regards, Anatoly.
Ping.
On date Sunday 2011-03-27 21:08:08 +0400, Anatoly Nenashev encoded:
Ping.
I ask you to be patient one more time and re-post the last version of the patch. Thanks, and sorry for the long wait for getting this integrated. -- FFmpeg = Fundamentalist & Faithless Mere Patchable Exciting God
On 27.03.2011 21:28, Stefano Sabatini wrote:
On date Sunday 2011-03-27 21:08:08 +0400, Anatoly Nenashev encoded:
Ping.
I ask you to be patient one more time and re-post the last version of the patch. Thanks, and sorry for the long wait for getting this integrated.
Ok. New patch series follows.
On Mon, Mar 28, 2011 at 12:01:40AM +0400, Anatoly Nenashev wrote: [...]
@@ -851,29 +884,43 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, i return 0; }
-static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, int se, int Ah, int Al){ +static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, int se, int Ah, int Al, + const uint8_t *mb_bitmask, const AVFrame *reference){ int mb_x, mb_y; int EOBRUN = 0; int c = s->comp_index[0]; uint8_t* data = s->picture.data[c]; + const uint8_t *reference_data = reference ? reference->data[c] : NULL; int linesize = s->linesize[c]; int last_scan = 0; int16_t *quant_matrix = s->quant_matrixes[ s->quant_index[c] ]; + GetBitContext mb_bitmask_gb; + + if (mb_bitmask) { + init_get_bits(&mb_bitmask_gb, mb_bitmask, s->mb_width*s->mb_height); + }
if(!Al) { s->coefs_finished[c] |= (1LL<<(se+1))-(1LL<<ss); last_scan = !~s->coefs_finished[c]; }
- if(s->interlaced && s->bottom_field) - data += linesize >> 1; + if(s->interlaced && s->bottom_field) { + int offset = linesize >> 1; + data += offset; + reference_data += offset; + }
for(mb_y = 0; mb_y < s->mb_height; mb_y++) { - uint8_t *ptr = data + (mb_y*linesize*8 >> s->avctx->lowres); + int block_offset = (mb_y*linesize*8 >> s->avctx->lowres); + uint8_t *ptr = data + block_offset; int block_idx = mb_y * s->block_stride[c]; DCTELEM (*block)[64] = &s->blocks[c][block_idx]; uint8_t *last_nnz = &s->last_nnz[c][block_idx]; for(mb_x = 0; mb_x < s->mb_width; mb_x++, block++, last_nnz++) { + const int copy_mb = mb_bitmask && !get_bits1(&mb_bitmask_gb); + + if (!copy_mb) { int ret; if(Ah) ret = decode_block_refinement(s, *block, last_nnz, s->ac_index[0], @@ -885,16 +932,23 @@ static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, int s av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x); return -1; } + } + if(last_scan) { + if (copy_mb) { + mjpeg_copy_block(ptr, reference_data + block_offset, linesize, s->avctx->lowres); + } else { s->dsp.idct_put(ptr, linesize, *block); ptr += 8 >> s->avctx->lowres; + } } } } return 0; }
-int ff_mjpeg_decode_sos(MJpegDecodeContext *s) +int ff_mjpeg_decode_sos(MJpegDecodeContext *s, + const uint8_t *mb_bitmask, const AVFrame *reference) { int len, nb_components, i, h, v, predictor, point_transform; int index, id; @@ -996,10 +1050,12 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s) } }else{ if(s->progressive && predictor) { - if(mjpeg_decode_scan_progressive_ac(s, predictor, ilv, prev_shift, point_transform) < 0) + if(mjpeg_decode_scan_progressive_ac(s, predictor, ilv, prev_shift, point_transform, + mb_bitmask, reference) < 0) return -1; } else { - if(mjpeg_decode_scan(s, nb_components, prev_shift, point_transform) < 0) + if(mjpeg_decode_scan(s, nb_components, prev_shift, point_transform, + mb_bitmask, reference) < 0) return -1; } }
does progressive mxpeg samples exist? if not the related changes are unneeded and unneccesarily increase code complexity and decrease speed [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I am the wisest man alive, for I know one thing, and that is that I know nothing. -- Socrates
On Mon, Mar 28, 2011 at 12:01:40AM +0400, Anatoly Nenashev wrote:
[...]
}
- if(s->interlaced && s->bottom_field) - data += linesize >> 1; + if(s->interlaced && s->bottom_field) { + int offset = linesize >> 1; + data += offset; + reference_data += offset; + }
This doesnt fit together with:
+ if (jpg->interlaced) { + av_log(avctx, AV_LOG_ERROR, "Interlaced mode not supported in MxPEG\n"); + return AVERROR(EINVAL); + }
do interlaced mxpeg exist / is it allowed? if so it should be supported, if not theres no need to partially implement it Not a major issue but it seems inconsistent [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Dictatorship naturally arises out of democracy, and the most aggravated form of tyranny and slavery out of the most extreme liberty. -- Plato
On 31.03.2011 14:58, Michael Niedermayer wrote:
On Mon, Mar 28, 2011 at 12:01:40AM +0400, Anatoly Nenashev wrote:
[...]
}
- if(s->interlaced&& s->bottom_field) - data += linesize>> 1; + if(s->interlaced&& s->bottom_field) { + int offset = linesize>> 1; + data += offset; + reference_data += offset; + }
This doesnt fit together with:
+ if (jpg->interlaced) { + av_log(avctx, AV_LOG_ERROR, "Interlaced mode not supported in MxPEG\n"); + return AVERROR(EINVAL); + }
do interlaced mxpeg exist / is it allowed? if so it should be supported, if not theres no need to partially implement it
Not a major issue but it seems inconsistent
Hmm... Interlaced mode is not supported in Mobotix's SDK for MxPEG and progressive mode too. I don't know if they will be implemented later. So, you right, I will remove this parts from code. Anatoly.
On Mon, Mar 28, 2011 at 12:02:31AM +0400, Anatoly Nenashev wrote:
mjpegdec.c | 84 +++++++++++++++++++++++++++++++++++++------------------------ mjpegdec.h | 3 ++ 2 files changed, 55 insertions(+), 32 deletions(-) 7efd0c478594f6c0dd77d6f590983c57da5df856 0002-Move-MJPEG-s-input-buffer-preprocessing-in-separate-.patch From dde3000acae8c0cc35e5219daf83df406ac5c4a2 Mon Sep 17 00:00:00 2001 From: anatoly <anatoly.nenashev@ovsoft.ru> Date: Thu, 17 Feb 2011 12:06:22 +0300 Subject: [PATCH 2/4] Move MJPEG's input buffer preprocessing in separate public function
patch looks good to me [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The greatest way to live with honor in this world is to be what we pretend to be. -- Socrates
On Mon, Mar 28, 2011 at 12:03:23AM +0400, Anatoly Nenashev wrote:
jpeglsdec.c | 18 +++++++++--------- mjpegbdec.c | 2 +- mjpegdec.c | 36 +++++++++++++++++++----------------- mjpegdec.h | 1 + 4 files changed, 30 insertions(+), 27 deletions(-) 154603a3e502b15fb2abe006c29ce927ac0874c9 0003-Add-support-for-picture_ptr-field-in-MJpegDecodeCont.patch From cf7ac8d2f285cfa2fc35502a81d5643cf03c39d0 Mon Sep 17 00:00:00 2001 From: anatoly <anatoly.nenashev@ovsoft.ru> Date: Mon, 28 Feb 2011 18:40:59 +0300 Subject: [PATCH 3/4] Add support for picture_ptr field in MJpegDecodeContext
--- libavcodec/jpeglsdec.c | 18 +++++++++--------- libavcodec/mjpegbdec.c | 2 +- libavcodec/mjpegdec.c | 36 +++++++++++++++++++----------------- libavcodec/mjpegdec.h | 1 + 4 files changed, 30 insertions(+), 27 deletions(-)
diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c index 7278e02..a5fb729 100644 --- a/libavcodec/jpeglsdec.c +++ b/libavcodec/jpeglsdec.c @@ -262,9 +262,9 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor JLSState *state; int off = 0, stride = 1, width, shift;
- zero = av_mallocz(s->picture.linesize[0]); + zero = av_mallocz(s->picture_ptr->linesize[0]); last = zero; - cur = s->picture.data[0]; + cur = s->picture_ptr->data[0];
state = av_mallocz(sizeof(JLSState)); /* initialize JPEG-LS state from JPEG parameters */ @@ -299,7 +299,7 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor t = *((uint16_t*)last); } last = cur; - cur += s->picture.linesize[0]; + cur += s->picture_ptr->linesize[0];
if (s->restart_interval && !--s->restart_count) { align_get_bits(&s->gb); @@ -309,7 +309,7 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor } else if(ilv == 1) { /* line interleaving */ int j; int Rc[3] = {0, 0, 0}; - memset(cur, 0, s->picture.linesize[0]); + memset(cur, 0, s->picture_ptr->linesize[0]); width = s->width * 3; for(i = 0; i < s->height; i++) { for(j = 0; j < 3; j++) { @@ -322,7 +322,7 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor } } last = cur; - cur += s->picture.linesize[0]; + cur += s->picture_ptr->linesize[0]; } } else if(ilv == 2) { /* sample interleaving */ av_log(s->avctx, AV_LOG_ERROR, "Sample interleaved images are not supported.\n"); @@ -337,22 +337,22 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor w = s->width * s->nb_components;
if(s->bits <= 8){ - uint8_t *src = s->picture.data[0]; + uint8_t *src = s->picture_ptr->data[0];
for(i = 0; i < s->height; i++){ for(x = off; x < w; x+= stride){ src[x] <<= shift; } - src += s->picture.linesize[0]; + src += s->picture_ptr->linesize[0]; } }else{ - uint16_t *src = (uint16_t*) s->picture.data[0]; + uint16_t *src = (uint16_t*) s->picture_ptr->data[0];
for(i = 0; i < s->height; i++){ for(x = 0; x < w; x++){ src[x] <<= shift; } - src += s->picture.linesize[0]/2; + src += s->picture_ptr->linesize[0]/2; } } } diff --git a/libavcodec/mjpegbdec.c b/libavcodec/mjpegbdec.c index fc045ba..5f86343 100644 --- a/libavcodec/mjpegbdec.c +++ b/libavcodec/mjpegbdec.c @@ -129,7 +129,7 @@ read_header:
//XXX FIXME factorize, this looks very similar to the EOI code
- *picture= s->picture; + *picture= *s->picture_ptr; *data_size = sizeof(AVFrame);
if(!s->lossless){
The above changes should be unneeded. jpeg-ls isnt mxpeg if i understand it correctly the changes cause a tiny slowdown though due to extra dereference its a pity the libav developers choose to apply this without technical review. Id like to appologize for not having had the time to review this sooner But i would suggest that patches be reviewed by someone before applying them. That doesnt need to be ffmpeg developers if we are all busy but ideally it should be the author/maintainer of the respective code as he knows it best.
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index d146973..eb5443c 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -81,6 +81,9 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) { MJpegDecodeContext *s = avctx->priv_data;
+ if (!s->picture_ptr) + s->picture_ptr = &s->picture; + s->avctx = avctx; dsputil_init(&s->dsp, avctx); ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct); @@ -282,8 +285,8 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) s->height < ((s->org_height * 3) / 4)) { s->interlaced = 1; s->bottom_field = s->interlace_polarity; - s->picture.interlaced_frame = 1; - s->picture.top_field_first = !s->interlace_polarity; + s->picture_ptr->interlaced_frame = 1; + s->picture_ptr->top_field_first = !s->interlace_polarity; height *= 2; }
@@ -342,20 +345,19 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) s->avctx->pix_fmt = PIX_FMT_GRAY16; }
- if(s->picture.data[0]) - s->avctx->release_buffer(s->avctx, &s->picture); + if(s->picture_ptr->data[0]) + s->avctx->release_buffer(s->avctx, s->picture_ptr);
- s->picture.reference= 0; - if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){ + if(s->avctx->get_buffer(s->avctx, s->picture_ptr) < 0){ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } - s->picture.pict_type= FF_I_TYPE; - s->picture.key_frame= 1; + s->picture_ptr->pict_type= FF_I_TYPE; + s->picture_ptr->key_frame= 1; s->got_picture = 1;
for(i=0; i<3; i++){ - s->linesize[i]= s->picture.linesize[i] << s->interlaced; + s->linesize[i]= s->picture_ptr->linesize[i] << s->interlaced; }
// printf("%d %d %d %d %d %d\n", s->width, s->height, s->linesize[0], s->linesize[1], s->interlaced, s->avctx->height); @@ -635,7 +637,7 @@ static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point } for(mb_y = 0; mb_y < s->mb_height; mb_y++) { const int modified_predictor= mb_y ? predictor : 1; - uint8_t *ptr = s->picture.data[0] + (linesize * mb_y); + uint8_t *ptr = s->picture_ptr->data[0] + (linesize * mb_y);
if (s->interlaced && s->bottom_field) ptr += linesize >> 1; @@ -712,7 +714,7 @@ static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, int point for(j=0; j<n; j++) { int pred;
- ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap + ptr = s->picture_ptr->data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap if(y==0 && mb_y==0){ if(x==0 && mb_x==0){ pred= 128 << point_transform; @@ -752,7 +754,7 @@ static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, int point for(j=0; j<n; j++) { int pred;
- ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap + ptr = s->picture_ptr->data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform); if (++x == h) { @@ -804,7 +806,7 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, i } for(i=0; i < nb_components; i++) { int c = s->comp_index[i]; - data[c] = s->picture.data[c]; + data[c] = s->picture_ptr->data[c]; reference_data[c] = reference ? reference->data[c] : NULL; linesize[c]=s->linesize[c]; s->coefs_finished[c] |= 1; @@ -889,7 +891,7 @@ static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, int s int mb_x, mb_y; int EOBRUN = 0; int c = s->comp_index[0]; - uint8_t* data = s->picture.data[c]; + uint8_t* data = s->picture_ptr->data[c]; const uint8_t *reference_data = reference ? reference->data[c] : NULL; int linesize = s->linesize[c]; int last_scan = 0; @@ -1521,7 +1523,7 @@ eoi_parser:
as above, i think several of these are unneeded and cause a tiny slowdown. The mxpeg case should also check that none of the unneeded cases actually happen, this reduces the possible code pathes and reduces the chances of missed security issues in the relatively compelex mjpeg code [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB You can kill me, but you cannot change the truth.
On Mon, Mar 28, 2011 at 12:03:58AM +0400, Anatoly Nenashev wrote:
Makefile | 1 allcodecs.c | 1 mxpegdec.c | 331 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 333 insertions(+) f93a443bb32785eb87051e3922ab1be311cb0a41 0004-Add-MxPEG-decoder.patch From 91ec98dfacc4e3e46d05cc63da256eea17ee2a80 Mon Sep 17 00:00:00 2001 From: anatoly <anatoly.nenashev@ovsoft.ru> Date: Thu, 24 Feb 2011 12:22:52 +0300 Subject: [PATCH 4/4] Add MxPEG decoder
--- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/mxpegdec.c | 331 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 333 insertions(+), 0 deletions(-) create mode 100644 libavcodec/mxpegdec.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile index ef91ee3..67fe868 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -271,6 +271,7 @@ OBJS-$(CONFIG_MSMPEG4V3_ENCODER) += msmpeg4.o msmpeg4data.o h263dec.o \ OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o msrledec.o OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o OBJS-$(CONFIG_MSZH_DECODER) += lcldec.o +OBJS-$(CONFIG_MXPEG_DECODER) += mxpegdec.o OBJS-$(CONFIG_NELLYMOSER_DECODER) += nellymoserdec.o nellymoser.o OBJS-$(CONFIG_NELLYMOSER_ENCODER) += nellymoserenc.o nellymoser.o OBJS-$(CONFIG_NUV_DECODER) += nuv.o rtjpeg.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 861f8c7..c60bccd 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -156,6 +156,7 @@ void avcodec_register_all(void) REGISTER_DECODER (MSRLE, msrle); REGISTER_DECODER (MSVIDEO1, msvideo1); REGISTER_DECODER (MSZH, mszh); + REGISTER_DECODER (MXPEG, mxpeg); REGISTER_DECODER (NUV, nuv); REGISTER_ENCDEC (PAM, pam); REGISTER_ENCDEC (PBM, pbm); diff --git a/libavcodec/mxpegdec.c b/libavcodec/mxpegdec.c new file mode 100644 index 0000000..ba0c23d --- /dev/null +++ b/libavcodec/mxpegdec.c @@ -0,0 +1,331 @@ +/* + * MxPEG decoder + * Copyright (c) 2011 Anatoly Nenashev + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +/** + * @file + * MxPEG decoder. + */ + +#include "mjpeg.h" +#include "mjpegdec.h" +
+int ff_mxpeg_decode_init(AVCodecContext *avctx); +int ff_mxpeg_decode_end(AVCodecContext *avctx); +int ff_mxpeg_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *avpkt);
these 3 should be removed, they are unneeded, the functions should be static
+ +typedef struct MXpegDecodeContext { + MJpegDecodeContext jpg; + AVFrame picture[2]; /* pictures array */ + int picture_index; /* index of current picture */ + int got_sof_data; /* true if SOF data successfully parsed */ + int got_mxm_bitmask; /* true if MXM bitmask available */ + uint8_t *mxm_bitmask; /* bitmask buffer */ + unsigned bitmask_size; /* size of bitmask */ + int has_complete_frame; /* true if has complete frame */ + uint8_t *completion_bitmask; /* completion bitmask of macroblocks */ + unsigned mb_width, mb_height; /* size of picture in MB's from MXM header */ +} MXpegDecodeContext;
The comments should be made doxygen compatible (///< ...) for example see: http://ffmpeg.org/doxygen/trunk/ for our daily generated doxygen docs from trunk (there are of course also ones for the releases) ill try to review the rest of this patch in the next days i sadly dont have the time ATM [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I am the wisest man alive, for I know one thing, and that is that I know nothing. -- Socrates
On 31.03.2011 04:41, Michael Niedermayer wrote:
On Mon, Mar 28, 2011 at 12:03:58AM +0400, Anatoly Nenashev wrote:
Makefile | 1 allcodecs.c | 1 mxpegdec.c | 331 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 333 insertions(+) f93a443bb32785eb87051e3922ab1be311cb0a41 0004-Add-MxPEG-decoder.patch From 91ec98dfacc4e3e46d05cc63da256eea17ee2a80 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev@ovsoft.ru> Date: Thu, 24 Feb 2011 12:22:52 +0300 Subject: [PATCH 4/4] Add MxPEG decoder
--- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/mxpegdec.c | 331 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 333 insertions(+), 0 deletions(-) create mode 100644 libavcodec/mxpegdec.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile index ef91ee3..67fe868 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -271,6 +271,7 @@ OBJS-$(CONFIG_MSMPEG4V3_ENCODER) += msmpeg4.o msmpeg4data.o h263dec.o \ OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o msrledec.o OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o OBJS-$(CONFIG_MSZH_DECODER) += lcldec.o +OBJS-$(CONFIG_MXPEG_DECODER) += mxpegdec.o OBJS-$(CONFIG_NELLYMOSER_DECODER) += nellymoserdec.o nellymoser.o OBJS-$(CONFIG_NELLYMOSER_ENCODER) += nellymoserenc.o nellymoser.o OBJS-$(CONFIG_NUV_DECODER) += nuv.o rtjpeg.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 861f8c7..c60bccd 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -156,6 +156,7 @@ void avcodec_register_all(void) REGISTER_DECODER (MSRLE, msrle); REGISTER_DECODER (MSVIDEO1, msvideo1); REGISTER_DECODER (MSZH, mszh); + REGISTER_DECODER (MXPEG, mxpeg); REGISTER_DECODER (NUV, nuv); REGISTER_ENCDEC (PAM, pam); REGISTER_ENCDEC (PBM, pbm); diff --git a/libavcodec/mxpegdec.c b/libavcodec/mxpegdec.c new file mode 100644 index 0000000..ba0c23d --- /dev/null +++ b/libavcodec/mxpegdec.c @@ -0,0 +1,331 @@ +/* + * MxPEG decoder + * Copyright (c) 2011 Anatoly Nenashev + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +/** + * @file + * MxPEG decoder. + */ + +#include "mjpeg.h" +#include "mjpegdec.h" +
+int ff_mxpeg_decode_init(AVCodecContext *avctx); +int ff_mxpeg_decode_end(AVCodecContext *avctx); +int ff_mxpeg_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *avpkt);
these 3 should be removed, they are unneeded, the functions should be static
These changes are done by commiter to libav (Anton Khirnov).
+ +typedef struct MXpegDecodeContext { + MJpegDecodeContext jpg; + AVFrame picture[2]; /* pictures array */ + int picture_index; /* index of current picture */ + int got_sof_data; /* true if SOF data successfully parsed */ + int got_mxm_bitmask; /* true if MXM bitmask available */ + uint8_t *mxm_bitmask; /* bitmask buffer */ + unsigned bitmask_size; /* size of bitmask */ + int has_complete_frame; /* true if has complete frame */ + uint8_t *completion_bitmask; /* completion bitmask of macroblocks */ + unsigned mb_width, mb_height; /* size of picture in MB's from MXM header */ +} MXpegDecodeContext;
The comments should be made doxygen compatible (///< ...)
for example see: http://ffmpeg.org/doxygen/trunk/ for our daily generated doxygen docs from trunk (there are of course also ones for the releases)
Ok. I'll correct these comments.
ill try to review the rest of this patch in the next days i sadly dont have the time ATM
Ok, thank you. I will make these and other changes but MxPEG patch is just pushed to Libav so I don't want to support two versions of patch. Do you know any solution for this situation? Anatoly.
On Thu, Mar 31, 2011 at 04:55:04PM +0400, Anatoly Nenashev wrote:
On 31.03.2011 04:41, Michael Niedermayer wrote:
On Mon, Mar 28, 2011 at 12:03:58AM +0400, Anatoly Nenashev wrote: [...]
+ +typedef struct MXpegDecodeContext { + MJpegDecodeContext jpg; + AVFrame picture[2]; /* pictures array */ + int picture_index; /* index of current picture */ + int got_sof_data; /* true if SOF data successfully parsed */ + int got_mxm_bitmask; /* true if MXM bitmask available */ + uint8_t *mxm_bitmask; /* bitmask buffer */ + unsigned bitmask_size; /* size of bitmask */ + int has_complete_frame; /* true if has complete frame */ + uint8_t *completion_bitmask; /* completion bitmask of macroblocks */ + unsigned mb_width, mb_height; /* size of picture in MB's from MXM header */ +} MXpegDecodeContext;
The comments should be made doxygen compatible (///< ...) for example see: http://ffmpeg.org/doxygen/trunk/ for our daily generated doxygen docs from trunk (there are of course also ones for the releases)
Ok. I'll correct these comments.
ill try to review the rest of this patch in the next days i sadly dont have the time ATM
Ok, thank you. I will make these and other changes but MxPEG patch is just pushed to Libav so I don't want to support two versions of patch. Do you know any solution for this situation?
yes, each part of ffmpeg has a person who knows it well, and does proper technical reviews. (well ideally that is, in reality there are parts where theres noone and very few where there are multiple) This person is called a maintainer by us (and also for example the kernel). (In libav, maintainer seems to be more a political position than a technical one.) Well that (technical) maintainer should review and approve patches for the area of his maintainership/knowledge. Bypassing the most knowledgeable person is generally a bad idea but if he is busy for weeks its surely justified to find someone else to do review and commit. How does that awnser the ffmpeg vs. libav question? Well it doesnt and IMHO it doesnt have to. when you have a patch for ac3 look in MAINTAINERS, it lists Justin Ruggles he is subscribed to both libav-devel and ffmpeg-devel so you can send ac3 patches to either list and get a review by the most qualified person. how about mjpeg? i know that best, so i should do the review. (and the just found security issue shows why) [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The real ebay dictionary, page 3 "Rare item" - "Common item with rare defect or maybe just a lie" "Professional" - "'Toy' made in china, not functional except as doorstop" "Experts will know" - "The seller hopes you are not an expert"
On Mon, Mar 28, 2011 at 12:03:58AM +0400, Anatoly Nenashev wrote: [...]
+static int mxpeg_decode_mxm(MXpegDecodeContext *s, const uint8_t *buf_ptr, int buf_size) +{ + unsigned bitmask_size, mb_count; + int i; + + s->mb_width = AV_RL16(buf_ptr+4); + s->mb_height = AV_RL16(buf_ptr+6); + mb_count = s->mb_width * s->mb_height; + + bitmask_size = (mb_count + 7) >> 3; + if (bitmask_size > buf_size - 12) { + av_log(s->jpg.avctx, AV_LOG_ERROR, "MXM bitmask is not complete\n"); + return AVERROR(EINVAL); + } + + if (s->bitmask_size != bitmask_size) { + av_freep(&s->mxm_bitmask); + s->mxm_bitmask = av_malloc(bitmask_size); + if (!s->mxm_bitmask) { + av_log(s->jpg.avctx, AV_LOG_ERROR, "MXM bitmask memory allocation error\n"); + return AVERROR(ENOMEM); + } + + av_freep(&s->completion_bitmask); + s->completion_bitmask = av_mallocz(bitmask_size); + if (!s->completion_bitmask) { + av_log(s->jpg.avctx, AV_LOG_ERROR, "Completion bitmask memory allocation error\n"); + return AVERROR(ENOMEM); + } + + s->bitmask_size = bitmask_size; + } + + memcpy(s->mxm_bitmask, buf_ptr + 12, bitmask_size); + s->got_mxm_bitmask = 1;
This is another security issue. Lets assume on the first frame this passes and both arrays are allocated with 1000 2nd frame decreases bitmask_size to 500 and lets assume the 2nd malloc() fails and the decoding of frame 2 fails as a result. At this point s->bitmask_size is 1000 and the first array is 500, the second NULL 3rd frame we assume that mb_width/height have returned to the first frame values so s->bitmask_size == bitmask_size and the memcpy now copies 500 bytes of user choosen data over the end of the first array [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Its not that you shouldnt use gotos but rather that you should write readable code and code with gotos often but not always is less readable
participants (10)
-
Anatoly Nenashev -
anatoly.nenashev@ovsoft.ru -
diego@biurrun.de -
mans@mansr.com -
Michael Niedermayer -
nenashev_as@mail.ru -
rsbultje@gmail.com -
Stefano Sabatini -
stefano.sabatini-lala@poste.it -
tomas.hardin@codemill.se