[FFmpeg-devel] [PATCH 1/3] Mobotix MxPEG decoder, parser, demuxer

Michael Niedermayer michaelni
Tue Aug 17 19:48:36 CEST 2010


On Sat, Aug 14, 2010 at 03:30:48AM +0400, Anatoly Nenashev wrote:
[...]
> @@ -789,6 +799,14 @@
>  
>      for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
>          for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
> +            if ((s->avctx->codec_id == CODEC_ID_MXPEG) &&
> +                 !s->picture.key_frame) {

redudnant checks



> +                int mb_index = mb_y * s->mb_width + mb_x;
> +                int mb_selected = (s->mxctx.mxm_bitmask[mb_index >> 3] << (mb_index & 7)) & 0x80;

reimplementation of get_bits()


> +
> +                if (!mb_selected) continue;
> +            }
> +
>              if (s->restart_interval && !s->restart_count)
>                  s->restart_count = s->restart_interval;
>  

> @@ -1163,6 +1181,68 @@
>      return 0;
>  }
>  
> +static int mxpeg_decode_com(MJpegDecodeContext *s, char *buf, int len)
> +{
> +    int i;
> +
> +    if (!strncmp(buf, "MXM", 3)){
> +        int mb_width, mb_height, bitmask_size;
> +        uint32_t mb_count;
> +
> +        mb_width  = AV_RL16(&buf[4]);
> +        mb_height = AV_RL16(&buf[6]);
> +        mb_count = (uint32_t)mb_width*mb_height;
> +
> +        if (mb_count > 0x7FFFFFFF) {
> +            av_log(s->avctx, AV_LOG_ERROR, "MXM too big macroblocks count");
> +            return AVERROR(EINVAL);
> +        }
> +        bitmask_size = (int)mb_count >> 3;
> +
> +        if (bitmask_size > (len - 12)) {
> +            av_log(s->avctx, AV_LOG_ERROR, "MXM bitmask is not complete");
> +            return AVERROR(EINVAL);
> +        }
> +
> +        av_freep(&s->mxctx.comment_buffer);
> +        s->mxctx.comment_buffer = buf;
> +        s->mxctx.mxm_bitmask = buf + 12;
> +
> +        if (!s->got_picture && s->picture.data[0]) {
> +            if(s->avctx->reget_buffer(s->avctx, &s->picture) < 0) {
> +                av_log(s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
> +                return -1;
> +            }
> +            s->got_picture = 1;
> +        }
> +
> +        s->picture.pict_type = FF_P_TYPE;
> +        s->picture.key_frame = 0;
> +
> +        if (!s->mxctx.has_complete_frame &&
> +            !(s->avctx->flags & CODEC_FLAG_LOW_DELAY)) {
> +            if (!s->mxctx.completion_bitmask ||
> +                (s->mxctx.completion_bitmask_size < bitmask_size)) {
> +                av_freep(&s->mxctx.completion_bitmask);
> +                s->mxctx.completion_bitmask = av_mallocz(bitmask_size);
> +                if (!s->mxctx.completion_bitmask)
> +                    return AVERROR(ENOMEM);
> +                s->mxctx.completion_bitmask_size = bitmask_size;
> +            }
> +
> +            s->mxctx.has_complete_frame = 1;
> +            for (i = 0; i < bitmask_size; ++i) {
> +                s->mxctx.completion_bitmask[i] |= s->mxctx.mxm_bitmask[i];
> +                s->mxctx.has_complete_frame &= !(uint8_t)~s->mxctx.completion_bitmask[i];
> +            }
> +        }
> +
> +        return bitmask_size;
> +    }
> +
> +    return 0;
> +}
> +
>  static int mjpeg_decode_com(MJpegDecodeContext *s)
>  {
>      int len = get_bits(&s->gb, 16);
> @@ -1180,9 +1260,12 @@
>              if(s->avctx->debug & FF_DEBUG_PICT_INFO)
>                  av_log(s->avctx, AV_LOG_INFO, "mjpeg comment: '%s'\n", cbuf);
>  
> +            if (s->avctx->codec_id == CODEC_ID_MXPEG) {
> +                if (mxpeg_decode_com(s, cbuf, len - 2) > 0)
> +                    return 0;
> +            }

duplicate checks

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The bravest are surely those who have the clearest vision
of what is before them, glory and danger alike, and yet
notwithstanding go out to meet it. -- Thucydides
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100817/f4971911/attachment.pgp>



More information about the ffmpeg-devel mailing list