[FFmpeg-devel] [PATCH 2/2] MxPEG decoder

Michael Niedermayer michaelni
Fri Nov 5 23:50:53 CET 2010


On Fri, Nov 05, 2010 at 09:50:36PM +0300, Anatoly Nenashev wrote:
> On 05.11.2010 18:29, Michael Niedermayer wrote:
>> On Thu, Nov 04, 2010 at 05:43:51PM +0300, Anatoly Nenashev wrote:
>>    
>>
>>> +
>>> +        if (mxg->state == 0xffd9) {             /* EOI marker */
>>> +            found_frame_end = mxg->current_pos;
>>>      
>>    
>>> +        } else if (mxg->state == 0xffd8) {      /* SOI marker */
>>> +            if (mxg->vop_found) {
>>> +                /* emulating frame end */
>>> +                url_fseek(s->pb, -2, SEEK_CUR);
>>> +                mxg->current_pos -= 2;
>>> +                found_frame_end = mxg->current_pos;
>>> +            } else {
>>> +                mxg->vop_found = 1;
>>> +            }
>>>      
>> why is this needed?
>> isnt handling of the EOI enough to detect the end?
>>    
>
> It was done for more robustness but now i've removed it.
>
>
>> also where is most time spent?
>> if its in the outer loop then the 0xFF startcode search must be split out
>> and implemented similar to ff_avc_find_startcode_internal()
>> i dont remember if jpeg had size values after the major parts to skip them
>> quickly ...
>>
>>    
> Reimplemented. See attachment.
>

>  Makefile     |    1 
>  allformats.c |    1 
>  mxg.c        |  191 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 193 insertions(+)
> e51bfcd5ad8dd85538f1aacbb37cc9a62ce109af  mxg_v11.patch
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index e62a5ea..d3e3cd0 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -147,6 +147,7 @@ OBJS-$(CONFIG_MTV_DEMUXER)               += mtv.o
>  OBJS-$(CONFIG_MVI_DEMUXER)               += mvi.o
>  OBJS-$(CONFIG_MXF_DEMUXER)               += mxfdec.o mxf.o
>  OBJS-$(CONFIG_MXF_MUXER)                 += mxfenc.o mxf.o audiointerleave.o
> +OBJS-$(CONFIG_MXG_DEMUXER)               += mxg.o
>  OBJS-$(CONFIG_NC_DEMUXER)                += ncdec.o
>  OBJS-$(CONFIG_NSV_DEMUXER)               += nsvdec.o
>  OBJS-$(CONFIG_NULL_MUXER)                += nullenc.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index e35f4f8..4afbef5 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -142,6 +142,7 @@ void av_register_all(void)
>      REGISTER_DEMUXER  (MVI, mvi);
>      REGISTER_MUXDEMUX (MXF, mxf);
>      REGISTER_MUXER    (MXF_D10, mxf_d10);
> +    REGISTER_DEMUXER  (MXG, mxg);
>      REGISTER_DEMUXER  (NC, nc);
>      REGISTER_DEMUXER  (NSV, nsv);
>      REGISTER_MUXER    (NULL, null);
> diff --git a/libavformat/mxg.c b/libavformat/mxg.c
> new file mode 100644
> index 0000000..9d4a38b
> --- /dev/null
> +++ b/libavformat/mxg.c
> @@ -0,0 +1,191 @@
> +/*
> + * MxPEG clip file demuxer
> + * Copyright (c) 2010 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
> + */
> +
> +#include "libavutil/intreadwrite.h"
> +#include "avformat.h"
> +#include "avio.h"
> +
> +#define VIDEO_STREAM_INDEX 0
> +#define AUDIO_STREAM_INDEX 1
> +#define DEFAULT_PACKET_SIZE 1024
> +
> +typedef struct MXGContext {
> +    uint8_t *buffer;
> +    unsigned int buffer_size;
> +    unsigned int current_pos;
> +    int64_t dts;
> +} MXGContext;
> +
> +static int mxg_read_header(AVFormatContext *s, AVFormatParameters *ap)
> +{
> +    AVStream *video_st = 0, *audio_st = 0;
> +    MXGContext *mxg = s->priv_data;
> +
> +    /* video parameters will be extracted from the compressed bitstream */
> +    video_st = av_new_stream(s, VIDEO_STREAM_INDEX);
> +    if (!video_st)
> +        return AVERROR(ENOMEM);
> +    video_st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
> +    video_st->codec->codec_id = CODEC_ID_MXPEG;
> +    av_set_pts_info(video_st, 64, 1, 1000000);
> +
> +    audio_st = av_new_stream(s, AUDIO_STREAM_INDEX);
> +    if (!audio_st)
> +        return AVERROR(ENOMEM);
> +    audio_st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
> +    audio_st->codec->codec_id = CODEC_ID_PCM_ALAW;
> +    audio_st->codec->channels = 1;
> +    audio_st->codec->sample_rate = 8000;
> +    audio_st->codec->bits_per_coded_sample = 8;
> +    audio_st->codec->block_align = 1;
> +    av_set_pts_info(audio_st, 64, 1, 1000000);
> +
> +    mxg->buffer = av_malloc(DEFAULT_PACKET_SIZE);
> +    if (!mxg->buffer)
> +        return AVERROR(ENOMEM);
> +
> +    mxg->buffer_size = DEFAULT_PACKET_SIZE;
> +    mxg->current_pos = 0;
> +    mxg->dts = AV_NOPTS_VALUE;
> +
> +    return 0;
> +}
> +
> +static int mxg_read_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> +    int ret, size;
> +    MXGContext *mxg = s->priv_data;
> +
> +    while (!url_feof(s->pb) && !url_ferror(s->pb)) {
> +        uint8_t data = 0;
> +        unsigned int current_pad;
> +
> +        /* search for start marker - 0xff */
> +        while (mxg->current_pos + FF_INPUT_BUFFER_PADDING_SIZE < mxg->buffer_size) {
> +            data = get_byte(s->pb);
> +            mxg->buffer[mxg->current_pos++] = data;
> +            if (data == 0xff) break;
> +        }

you can check 4 bytes at a time with something like:
(x&~(x+0x01010101)) & 0x80808080
this should be faster

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Many things microsoft did are stupid, but not doing something just because
microsoft did it is even more stupid. If everything ms did were stupid they
would be bankrupt already.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101105/b1f79427/attachment.pgp>



More information about the ffmpeg-devel mailing list