X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fmm.c;h=8c9cbd79d2d254997fed18aaf4d0113bcaa605b5;hb=eb8b05a3824a9fa85e20d603595ac8a3b83505d4;hp=443b709294c6c23966e39e4980debfb8e590698e;hpb=fead30d4440bc7b75006ae60f2742c63a05168b3;p=ffmpeg diff --git a/libavformat/mm.c b/libavformat/mm.c index 443b709294c..8c9cbd79d2d 100644 --- a/libavformat/mm.c +++ b/libavformat/mm.c @@ -2,27 +2,27 @@ * American Laser Games MM Format Demuxer * Copyright (c) 2006 Peter Ross * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav 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, + * Libav 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** - * @file mm.c + * @file * American Laser Games MM Format Demuxer - * by Peter Ross (suxen_drol at hotmail dot com) + * by Peter Ross (pross@xvid.org) * * The MM format was used by IBM-PC ports of ALG's "arcade shooter" games, * including Mad Dog McCree and Crime Patrol. @@ -31,7 +31,10 @@ * http://wiki.multimedia.cx/index.php?title=American_Laser_Games_MM */ +#include "libavutil/channel_layout.h" +#include "libavutil/intreadwrite.h" #include "avformat.h" +#include "internal.h" #define MM_PREAMBLE_SIZE 6 @@ -52,93 +55,98 @@ #define MM_PALETTE_SIZE (MM_PALETTE_COUNT*3) typedef struct { - AVPaletteControl palette_control; unsigned int audio_pts, video_pts; } MmDemuxContext; -static int mm_probe(AVProbeData *p) +static int probe(AVProbeData *p) { - /* the first chunk is always the header */ - if (p->buf_size < MM_PREAMBLE_SIZE) + int len, type, fps, w, h; + if (p->buf_size < MM_HEADER_LEN_AV + MM_PREAMBLE_SIZE) return 0; + /* the first chunk is always the header */ if (AV_RL16(&p->buf[0]) != MM_TYPE_HEADER) return 0; - if (AV_RL32(&p->buf[2]) != MM_HEADER_LEN_V && AV_RL32(&p->buf[2]) != MM_HEADER_LEN_AV) + len = AV_RL32(&p->buf[2]); + if (len != MM_HEADER_LEN_V && len != MM_HEADER_LEN_AV) + return 0; + fps = AV_RL16(&p->buf[8]); + w = AV_RL16(&p->buf[12]); + h = AV_RL16(&p->buf[14]); + if (!fps || fps > 60 || !w || w > 2048 || !h || h > 2048) + return 0; + type = AV_RL16(&p->buf[len]); + if (!type || type > 0x31) return 0; /* only return half certainty since this check is a bit sketchy */ - return AVPROBE_SCORE_MAX / 2; + return AVPROBE_SCORE_EXTENSION; } -static int mm_read_header(AVFormatContext *s, - AVFormatParameters *ap) +static int read_header(AVFormatContext *s) { - MmDemuxContext *mm = (MmDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + MmDemuxContext *mm = s->priv_data; + AVIOContext *pb = s->pb; AVStream *st; unsigned int type, length; unsigned int frame_rate, width, height; - type = get_le16(pb); - length = get_le32(pb); + type = avio_rl16(pb); + length = avio_rl32(pb); if (type != MM_TYPE_HEADER) return AVERROR_INVALIDDATA; /* read header */ - get_le16(pb); /* total number of chunks */ - frame_rate = get_le16(pb); - get_le16(pb); /* ibm-pc video bios mode */ - width = get_le16(pb); - height = get_le16(pb); - url_fseek(pb, length - 10, SEEK_CUR); /* unknown data */ + avio_rl16(pb); /* total number of chunks */ + frame_rate = avio_rl16(pb); + avio_rl16(pb); /* ibm-pc video bios mode */ + width = avio_rl16(pb); + height = avio_rl16(pb); + avio_skip(pb, length - 10); /* unknown data */ /* video stream */ - st = av_new_stream(s, 0); + st = avformat_new_stream(s, NULL); if (!st) - return AVERROR_NOMEM; - st->codec->codec_type = CODEC_TYPE_VIDEO; - st->codec->codec_id = CODEC_ID_MMVIDEO; + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = AV_CODEC_ID_MMVIDEO; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = width; st->codec->height = height; - st->codec->palctrl = &mm->palette_control; - av_set_pts_info(st, 64, 1, frame_rate); + avpriv_set_pts_info(st, 64, 1, frame_rate); /* audio stream */ if (length == MM_HEADER_LEN_AV) { - st = av_new_stream(s, 0); + st = avformat_new_stream(s, NULL); if (!st) - return AVERROR_NOMEM; - st->codec->codec_type = CODEC_TYPE_AUDIO; + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_tag = 0; /* no fourcc */ - st->codec->codec_id = CODEC_ID_PCM_U8; + st->codec->codec_id = AV_CODEC_ID_PCM_U8; st->codec->channels = 1; + st->codec->channel_layout = AV_CH_LAYOUT_MONO; st->codec->sample_rate = 8000; - av_set_pts_info(st, 64, 1, 8000); /* 8000 hz */ + avpriv_set_pts_info(st, 64, 1, 8000); /* 8000 hz */ } - mm->palette_control.palette_changed = 0; mm->audio_pts = 0; mm->video_pts = 0; return 0; } -static int mm_read_packet(AVFormatContext *s, +static int read_packet(AVFormatContext *s, AVPacket *pkt) { - MmDemuxContext *mm = (MmDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + MmDemuxContext *mm = s->priv_data; + AVIOContext *pb = s->pb; unsigned char preamble[MM_PREAMBLE_SIZE]; - unsigned char pal[MM_PALETTE_SIZE]; unsigned int type, length; - int i; while(1) { - if (get_buffer(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) { - return AVERROR_IO; + if (avio_read(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) { + return AVERROR(EIO); } type = AV_RL16(&preamble[0]); @@ -146,22 +154,6 @@ static int mm_read_packet(AVFormatContext *s, switch(type) { case MM_TYPE_PALETTE : - url_fseek(pb, 4, SEEK_CUR); /* unknown data */ - if (get_buffer(pb, pal, MM_PALETTE_SIZE) != MM_PALETTE_SIZE) - return AVERROR_IO; - url_fseek(pb, length - (4 + MM_PALETTE_SIZE), SEEK_CUR); - - for (i=0; ipalette_control.palette[i] = (r << 16) | (g << 8) | (b); - /* repeat palette, where each components is multiplied by four */ - mm->palette_control.palette[i+128] = (r << 18) | (g << 10) | (b<<2); - } - mm->palette_control.palette_changed = 1; - break; - case MM_TYPE_INTER : case MM_TYPE_INTRA : case MM_TYPE_INTRA_HH : @@ -170,43 +162,37 @@ static int mm_read_packet(AVFormatContext *s, case MM_TYPE_INTER_HHV : /* output preamble + data */ if (av_new_packet(pkt, length + MM_PREAMBLE_SIZE)) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); memcpy(pkt->data, preamble, MM_PREAMBLE_SIZE); - if (get_buffer(pb, pkt->data + MM_PREAMBLE_SIZE, length) != length) - return AVERROR_IO; + if (avio_read(pb, pkt->data + MM_PREAMBLE_SIZE, length) != length) + return AVERROR(EIO); pkt->size = length + MM_PREAMBLE_SIZE; pkt->stream_index = 0; - pkt->pts = mm->video_pts++; + pkt->pts = mm->video_pts; + if (type!=MM_TYPE_PALETTE) + mm->video_pts++; return 0; case MM_TYPE_AUDIO : - if (av_get_packet(&s->pb, pkt, length)<0) - return AVERROR_NOMEM; + if (av_get_packet(s->pb, pkt, length)<0) + return AVERROR(ENOMEM); pkt->size = length; pkt->stream_index = 1; pkt->pts = mm->audio_pts++; return 0; default : - av_log(NULL, AV_LOG_INFO, "mm: unknown chunk type 0x%x\n", type); - url_fseek(pb, length, SEEK_CUR); + av_log(s, AV_LOG_INFO, "unknown chunk type 0x%x\n", type); + avio_skip(pb, length); } } - - return 0; -} - -static int mm_read_close(AVFormatContext *s) -{ - return 0; } -AVInputFormat mm_demuxer = { - "mm", - "American Laser Games MM format", - sizeof(MmDemuxContext), - mm_probe, - mm_read_header, - mm_read_packet, - mm_read_close, +AVInputFormat ff_mm_demuxer = { + .name = "mm", + .long_name = NULL_IF_CONFIG_SMALL("American Laser Games MM"), + .priv_data_size = sizeof(MmDemuxContext), + .read_probe = probe, + .read_header = read_header, + .read_packet = read_packet, };