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

Michael Niedermayer michaelni
Fri Nov 5 16:29:16 CET 2010


On Thu, Nov 04, 2010 at 05:43:51PM +0300, Anatoly Nenashev wrote:
> On 04.11.2010 03:02, Michael Niedermayer wrote:
>> On Wed, Nov 03, 2010 at 11:29:55PM +0300, Anatoly Nenashev wrote:
>>    
>>
>>> +        if (mxg->state == 0xffd9) {
>>> +            found_frame_end = mxg->current_pos;
>>> +        } else if (mxg->state == 0xffd8) {
>>> +            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;
>>> +            }
>>> +        } else if (mxg->state == 0xfffe) {
>>>      
>> these numeric things need comments that say what each is
>>
>>    
>
> Comments are added. See attachment.

thanks that makes it easier for me to see what the code does exactly



>  Makefile     |    1 
>  allformats.c |    1 
>  mxg.c        |  201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 203 insertions(+)
> c30b4e20e01b1e0b5c2ba7ac5dd5eee3d687e73b  mxg_v10.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..e0e21b0
> --- /dev/null
> +++ b/libavformat/mxg.c
> @@ -0,0 +1,201 @@
> +/*
> + * 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;
> +    uint16_t state;
> +    int vop_found;
> +    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->state = 0;
> +    mxg->vop_found = 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)) {
> +        const uint8_t data = get_byte(s->pb);
> +        unsigned int found_frame_end = 0, current_pad;
> +        mxg->state = (mxg->state << 8) | data;
> +        mxg->buffer[mxg->current_pos++] = data;
> +
> +        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?

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 ...

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

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein
-------------- 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/7a645b56/attachment.pgp>



More information about the ffmpeg-devel mailing list