X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fc93.c;h=3f2a98fcc4e8ad0211bd4a65fa2cc6463555e97d;hb=0bacfa8d37710b904897e7cbeb8d6f96fbf75e2e;hp=996012f6edd7aba2bd9acf457e12514f439c5328;hpb=899681cd1dbf4cd7c3b86af23bca25e20a54f4d0;p=ffmpeg diff --git a/libavformat/c93.c b/libavformat/c93.c index 996012f6edd..3f2a98fcc4e 100644 --- a/libavformat/c93.c +++ b/libavformat/c93.c @@ -2,25 +2,27 @@ * Interplay C93 demuxer * Copyright (c) 2007 Anssi Hannula * - * 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 + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" +#include "internal.h" #include "voc.h" +#include "libavutil/intreadwrite.h" typedef struct { uint16_t index; @@ -29,7 +31,7 @@ typedef struct { } C93BlockRecord; typedef struct { - voc_dec_context_t voc; + VocDecContext voc; C93BlockRecord block_records[512]; int current_block; @@ -43,28 +45,30 @@ typedef struct { static int probe(AVProbeData *p) { - if (p->buf[0] == 0x01 && p->buf[1] == 0x00 && - p->buf[4] == 0x01 + p->buf[2] && - p->buf[8] == p->buf[4] + p->buf[6] && - p->buf[12] == p->buf[8] + p->buf[10]) - return AVPROBE_SCORE_MAX; - - return 0; + int i; + int index = 1; + if (p->buf_size < 16) + return 0; + for (i = 0; i < 16; i += 4) { + if (AV_RL16(p->buf + i) != index || !p->buf[i + 2] || !p->buf[i + 3]) + return 0; + index += p->buf[i + 2]; + } + return AVPROBE_SCORE_MAX; } -static int read_header(AVFormatContext *s, - AVFormatParameters *ap) +static int read_header(AVFormatContext *s) { AVStream *video; - ByteIOContext *pb = s->pb; + AVIOContext *pb = s->pb; C93DemuxContext *c93 = s->priv_data; int i; int framecount = 0; for (i = 0; i < 512; i++) { - c93->block_records[i].index = get_le16(pb); - c93->block_records[i].length = get_byte(pb); - c93->block_records[i].frames = get_byte(pb); + c93->block_records[i].index = avio_rl16(pb); + c93->block_records[i].length = avio_r8(pb); + c93->block_records[i].frames = avio_r8(pb); if (c93->block_records[i].frames > 32) { av_log(s, AV_LOG_ERROR, "too many frames in block\n"); return AVERROR_INVALIDDATA; @@ -75,17 +79,17 @@ static int read_header(AVFormatContext *s, /* Audio streams are added if audio packets are found */ s->ctx_flags |= AVFMTCTX_NOHEADER; - video = av_new_stream(s, 0); + video = avformat_new_stream(s, NULL); if (!video) return AVERROR(ENOMEM); - video->codec->codec_type = CODEC_TYPE_VIDEO; - video->codec->codec_id = CODEC_ID_C93; + video->codec->codec_type = AVMEDIA_TYPE_VIDEO; + video->codec->codec_id = AV_CODEC_ID_C93; video->codec->width = 320; video->codec->height = 192; /* 4:3 320x200 with 8 empty lines */ - video->codec->sample_aspect_ratio = (AVRational) { 5, 6 }; - video->time_base = (AVRational) { 2, 25 }; + video->sample_aspect_ratio = (AVRational) { 5, 6 }; + avpriv_set_pts_info(video, 64, 2, 25); video->nb_frames = framecount; video->duration = framecount; video->start_time = 0; @@ -101,7 +105,7 @@ static int read_header(AVFormatContext *s, static int read_packet(AVFormatContext *s, AVPacket *pkt) { - ByteIOContext *pb = s->pb; + AVIOContext *pb = s->pb; C93DemuxContext *c93 = s->priv_data; C93BlockRecord *br = &c93->block_records[c93->current_block]; int datasize; @@ -110,19 +114,19 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) if (c93->next_pkt_is_audio) { c93->current_frame++; c93->next_pkt_is_audio = 0; - datasize = get_le16(pb); + datasize = avio_rl16(pb); if (datasize > 42) { if (!c93->audio) { - c93->audio = av_new_stream(s, 1); + c93->audio = avformat_new_stream(s, NULL); if (!c93->audio) return AVERROR(ENOMEM); - c93->audio->codec->codec_type = CODEC_TYPE_AUDIO; + c93->audio->codec->codec_type = AVMEDIA_TYPE_AUDIO; } - url_fskip(pb, 26); /* VOC header */ - ret = voc_get_packet(s, pkt, c93->audio, datasize - 26); + avio_skip(pb, 26); /* VOC header */ + ret = ff_voc_get_packet(s, pkt, c93->audio, datasize - 26); if (ret > 0) { pkt->stream_index = 1; - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; return ret; } } @@ -136,15 +140,15 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) } if (c93->current_frame == 0) { - url_fseek(pb, br->index * 2048, SEEK_SET); + avio_seek(pb, br->index * 2048, SEEK_SET); for (i = 0; i < 32; i++) { - c93->frame_offsets[i] = get_le32(pb); + c93->frame_offsets[i] = avio_rl32(pb); } } - url_fseek(pb,br->index * 2048 + + avio_seek(pb,br->index * 2048 + c93->frame_offsets[c93->current_frame], SEEK_SET); - datasize = get_le16(pb); /* video frame size */ + datasize = avio_rl16(pb); /* video frame size */ ret = av_new_packet(pkt, datasize + 768 + 1); if (ret < 0) @@ -152,13 +156,13 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) pkt->data[0] = 0; pkt->size = datasize + 1; - ret = get_buffer(pb, pkt->data + 1, datasize); + ret = avio_read(pb, pkt->data + 1, datasize); if (ret < datasize) { ret = AVERROR(EIO); goto fail; } - datasize = get_le16(pb); /* palette size */ + datasize = avio_rl16(pb); /* palette size */ if (datasize) { if (datasize != 768) { av_log(s, AV_LOG_ERROR, "invalid palette size %u\n", datasize); @@ -166,7 +170,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) goto fail; } pkt->data[0] |= C93_HAS_PALETTE; - ret = get_buffer(pb, pkt->data + pkt->size, datasize); + ret = avio_read(pb, pkt->data + pkt->size, datasize); if (ret < datasize) { ret = AVERROR(EIO); goto fail; @@ -178,7 +182,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) /* only the first frame is guaranteed to not reference previous frames */ if (c93->current_block == 0 && c93->current_frame == 0) { - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; pkt->data[0] |= C93_FIRST_FRAME; } return 0; @@ -188,11 +192,11 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) return ret; } -AVInputFormat c93_demuxer = { - "c93", - "Interplay C93", - sizeof(C93DemuxContext), - probe, - read_header, - read_packet, +AVInputFormat ff_c93_demuxer = { + .name = "c93", + .long_name = NULL_IF_CONFIG_SMALL("Interplay C93"), + .priv_data_size = sizeof(C93DemuxContext), + .read_probe = probe, + .read_header = read_header, + .read_packet = read_packet, };