[FFmpeg-devel] NC camera patch

Stefano Sabatini stefano.sabatini-lala
Sat Jan 10 12:01:42 CET 2009


On date Friday 2009-01-09 22:39:19 -0500, nicolas martin encoded:
[...]
> The new patch is attached.
>
> Nicolas

> Index: libavformat/ncdec.c
> ===================================================================
> --- libavformat/ncdec.c	(revision 0)
> +++ libavformat/ncdec.c	(revision 0)
> @@ -0,0 +1,88 @@
> +/*
> + * NC cameras feed demuxer.
> + * Copyright (c) 2008  Nicolas Martin <martinic at iro.umontreal.ca>, Edouard Auvinet
> + *
> + * 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 "avformat.h"
> +
> +#define NC_VIDEO_FLAG 0xA5010000
> +
> +static int nc_probe(AVProbeData *probe_packet)
> +{
> +    return (AV_RL32(probe_packet->buf)==NC_VIDEO_FLAG?AVPROBE_SCORE_MAX:0);

Please use spaces for increased readability:
       return AV_RL32(probe_packet->buf) == NC_VIDEO_FLAG ? AVPROBE_SCORE_MAX : 0;

> +}
> +
> +static int nc_read_header(AVFormatContext *s, AVFormatParameters *ap)
> +{
> +    AVStream *st = av_new_stream(s, 0);
> +    if (!st)
> +        return AVERROR(ENOMEM);
> +
> +    st->codec->codec_type = CODEC_TYPE_VIDEO;
> +    st->codec->codec_id = CODEC_ID_MPEG4;
> +    st->need_parsing = AVSTREAM_PARSE_FULL;
> +    av_set_pts_info(st, 64, 1, 25);
> +
> +    return 0;
> +}
> +
> +static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> +    int size, ret;
> +    uint32_t flag = get_le32(s->pb);
> +    if (flag != NC_VIDEO_FLAG) {
> +        av_log(NULL, AV_LOG_DEBUG, "wrong flag for nc video format : %u\n", flag);

Use the format context for logging, also as far as I remember most
messages in libav* starts with a Capitalized char, also if you use the
format context the "nc video format" is redundant.                  

> +        return AVERROR_INVALIDDATA;
> +    }
> +
> +    get_byte(s->pb);
> +
> +    size = get_le16(s->pb);
> +    url_fskip(s->pb, 9);
> +
> +    if (size <= 0) {
> +        av_log(NULL, AV_LOG_DEBUG, "wrong size for nc video format : %d\n", size);

Same here.

> +        return AVERROR_INVALIDDATA;
> +    }
> +
> +    if (av_new_packet(pkt, size) < 0)
> +        return AVERROR(EIO);
> +
> +    pkt->pos = url_ftell(s->pb);
> +    pkt->stream_index = 0;
> +
> +    ret = get_buffer(s->pb, pkt->data, size);
> +    if (ret<=0) {
> +        av_free_packet(pkt);
> +        return AVERROR(EIO);
> +    }

The ret var can be avoided, just use:
if (get_buffer(...) <= 0) ...

[...]

Regards.
-- 
FFmpeg = Foolish and Furious Mere Patchable Enhancing God




More information about the ffmpeg-devel mailing list