X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fiff.c;h=52c7e97280305fadbf72d6ac6e9f352a9182a978;hb=46278ec90ac5ad1dab5e85991f176afe49003fee;hp=66224456907c5ed900d93ac373cff1985b66be89;hpb=e356fc57a2e9887370caec58d8aafeafd1f336dc;p=ffmpeg diff --git a/libavformat/iff.c b/libavformat/iff.c index 66224456907..52c7e972803 100644 --- a/libavformat/iff.c +++ b/libavformat/iff.c @@ -4,20 +4,20 @@ * Copyright (c) 2010 Peter Ross * Copyright (c) 2010 Sebastian Vater * - * 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 */ @@ -29,8 +29,13 @@ * http://wiki.multimedia.cx/index.php?title=IFF */ +#include + +#include "libavutil/channel_layout.h" #include "libavutil/intreadwrite.h" +#include "libavutil/dict.h" #include "avformat.h" +#include "internal.h" #define ID_8SVX MKTAG('8','S','V','X') #define ID_VHDR MKTAG('V','H','D','R') @@ -58,8 +63,6 @@ #define RIGHT 4 #define STEREO 6 -#define PACKET_SIZE 1024 - typedef enum { COMP_NONE, COMP_FIB, @@ -71,26 +74,13 @@ typedef enum { BITMAP_BYTERUN1 } bitmap_compression_type; -typedef struct { +typedef struct IffDemuxContext { uint64_t body_pos; uint32_t body_size; uint32_t sent_bytes; - uint32_t audio_frame_count; } IffDemuxContext; -static void interleave_stereo(const uint8_t *src, uint8_t *dest, int size) -{ - uint8_t *end = dest + size; - size = size>>1; - - while(dest < end) { - *dest++ = *src; - *dest++ = *(src+size); - src++; - } -} - /* Metadata string read */ static int get_metadata(AVFormatContext *s, const char *const tag, @@ -106,7 +96,7 @@ static int get_metadata(AVFormatContext *s, return AVERROR(EIO); } buf[data_size] = 0; - av_metadata_set2(&s->metadata, tag, buf, AV_METADATA_DONT_STRDUP_VAL); + av_dict_set(&s->metadata, tag, buf, AV_DICT_DONT_STRDUP_VAL); return 0; } @@ -120,8 +110,7 @@ static int iff_probe(AVProbeData *p) return 0; } -static int iff_read_header(AVFormatContext *s, - AVFormatParameters *ap) +static int iff_read_header(AVFormatContext *s) { IffDemuxContext *iff = s->priv_data; AVIOContext *pb = s->pb; @@ -129,71 +118,83 @@ static int iff_read_header(AVFormatContext *s, uint32_t chunk_id, data_size; int compression = -1; - st = av_new_stream(s, 0); + st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->channels = 1; - avio_seek(pb, 8, SEEK_CUR); + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + avio_skip(pb, 8); // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content - st->codec->codec_tag = avio_rl32(pb); + st->codecpar->codec_tag = avio_rl32(pb); - while(!url_feof(pb)) { + while(!pb->eof_reached) { uint64_t orig_pos; int res; const char *metadata_tag = NULL; chunk_id = avio_rl32(pb); data_size = avio_rb32(pb); - orig_pos = url_ftell(pb); + orig_pos = avio_tell(pb); switch(chunk_id) { case ID_VHDR: - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; if (data_size < 14) return AVERROR_INVALIDDATA; - avio_seek(pb, 12, SEEK_CUR); - st->codec->sample_rate = avio_rb16(pb); + avio_skip(pb, 12); + st->codecpar->sample_rate = avio_rb16(pb); if (data_size >= 16) { - avio_seek(pb, 1, SEEK_CUR); + avio_skip(pb, 1); compression = avio_r8(pb); } break; case ID_BODY: - iff->body_pos = url_ftell(pb); + iff->body_pos = avio_tell(pb); iff->body_size = data_size; break; case ID_CHAN: if (data_size < 4) return AVERROR_INVALIDDATA; - st->codec->channels = (avio_rb32(pb) < 6) ? 1 : 2; + if (avio_rb32(pb) < 6) { + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + } else { + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + } break; case ID_CMAP: - st->codec->extradata_size = data_size; - st->codec->extradata = av_malloc(data_size); - if (!st->codec->extradata) + if (data_size < 3 || data_size > 768 || data_size % 3) { + av_log(s, AV_LOG_ERROR, "Invalid CMAP chunk size %"PRIu32"\n", + data_size); + return AVERROR_INVALIDDATA; + } + st->codecpar->extradata_size = data_size; + st->codecpar->extradata = av_malloc(data_size); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - if (avio_read(pb, st->codec->extradata, data_size) < 0) + if (avio_read(pb, st->codecpar->extradata, data_size) < 0) return AVERROR(EIO); break; case ID_BMHD: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; if (data_size <= 8) return AVERROR_INVALIDDATA; - st->codec->width = avio_rb16(pb); - st->codec->height = avio_rb16(pb); - avio_seek(pb, 4, SEEK_CUR); // x, y offset - st->codec->bits_per_coded_sample = avio_r8(pb); + st->codecpar->width = avio_rb16(pb); + st->codecpar->height = avio_rb16(pb); + avio_skip(pb, 4); // x, y offset + st->codecpar->bits_per_coded_sample = avio_r8(pb); if (data_size >= 11) { - avio_seek(pb, 1, SEEK_CUR); // masking + avio_skip(pb, 1); // masking compression = avio_r8(pb); } if (data_size >= 16) { - avio_seek(pb, 3, SEEK_CUR); // paddding, transparent + avio_skip(pb, 3); // padding, transparent st->sample_aspect_ratio.num = avio_r8(pb); st->sample_aspect_ratio.den = avio_r8(pb); } @@ -223,42 +224,42 @@ static int iff_read_header(AVFormatContext *s, return res; } } - avio_seek(pb, data_size - (url_ftell(pb) - orig_pos) + (data_size & 1), SEEK_CUR); + avio_skip(pb, data_size - (avio_tell(pb) - orig_pos) + (data_size & 1)); } avio_seek(pb, iff->body_pos, SEEK_SET); - switch(st->codec->codec_type) { + switch(st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: - av_set_pts_info(st, 32, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate); switch(compression) { case COMP_NONE: - st->codec->codec_id = CODEC_ID_PCM_S8; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S8_PLANAR; break; case COMP_FIB: - st->codec->codec_id = CODEC_ID_8SVX_FIB; + st->codecpar->codec_id = AV_CODEC_ID_8SVX_FIB; break; case COMP_EXP: - st->codec->codec_id = CODEC_ID_8SVX_EXP; + st->codecpar->codec_id = AV_CODEC_ID_8SVX_EXP; break; default: av_log(s, AV_LOG_ERROR, "unknown compression method\n"); return -1; } - st->codec->bits_per_coded_sample = 8; - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_coded_sample; - st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; + st->codecpar->bits_per_coded_sample = 8; + st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample; + st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample; break; case AVMEDIA_TYPE_VIDEO: switch (compression) { case BITMAP_RAW: - st->codec->codec_id = CODEC_ID_IFF_ILBM; + st->codecpar->codec_id = AV_CODEC_ID_IFF_ILBM; break; case BITMAP_BYTERUN1: - st->codec->codec_id = CODEC_ID_IFF_BYTERUN1; + st->codecpar->codec_id = AV_CODEC_ID_IFF_BYTERUN1; break; default: av_log(s, AV_LOG_ERROR, "unknown compression method\n"); @@ -277,48 +278,28 @@ static int iff_read_packet(AVFormatContext *s, { IffDemuxContext *iff = s->priv_data; AVIOContext *pb = s->pb; - AVStream *st = s->streams[0]; int ret; if(iff->sent_bytes >= iff->body_size) - return AVERROR(EIO); + return AVERROR_EOF; - if(st->codec->channels == 2) { - uint8_t sample_buffer[PACKET_SIZE]; - - ret = avio_read(pb, sample_buffer, PACKET_SIZE); - if(av_new_packet(pkt, PACKET_SIZE) < 0) { - av_log(s, AV_LOG_ERROR, "cannot allocate packet\n"); - return AVERROR(ENOMEM); - } - interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE); - } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - ret = av_get_packet(pb, pkt, iff->body_size); - } else { - ret = av_get_packet(pb, pkt, PACKET_SIZE); - } + ret = av_get_packet(pb, pkt, iff->body_size); + if (ret < 0) + return ret; if(iff->sent_bytes == 0) pkt->flags |= AV_PKT_FLAG_KEY; + iff->sent_bytes = iff->body_size; - if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - iff->sent_bytes += PACKET_SIZE; - } else { - iff->sent_bytes = iff->body_size; - } pkt->stream_index = 0; - if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - pkt->pts = iff->audio_frame_count; - iff->audio_frame_count += ret / st->codec->channels; - } return ret; } AVInputFormat ff_iff_demuxer = { - "IFF", - NULL_IF_CONFIG_SMALL("IFF format"), - sizeof(IffDemuxContext), - iff_probe, - iff_read_header, - iff_read_packet, + .name = "iff", + .long_name = NULL_IF_CONFIG_SMALL("IFF (Interchange File Format)"), + .priv_data_size = sizeof(IffDemuxContext), + .read_probe = iff_probe, + .read_header = iff_read_header, + .read_packet = iff_read_packet, };