• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavformat/ivfdec.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010 David Conrad
00003  *
00004  * This file is part of Libav.
00005  *
00006  * Libav is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * Libav is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with Libav; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #include "avformat.h"
00022 #include "internal.h"
00023 #include "riff.h"
00024 #include "libavutil/intreadwrite.h"
00025 
00026 static int probe(AVProbeData *p)
00027 {
00028     if (AV_RL32(p->buf) == MKTAG('D','K','I','F')
00029         && !AV_RL16(p->buf+4) && AV_RL16(p->buf+6) == 32)
00030         return AVPROBE_SCORE_MAX-2;
00031 
00032     return 0;
00033 }
00034 
00035 static int read_header(AVFormatContext *s, AVFormatParameters *ap)
00036 {
00037     AVStream *st;
00038     AVRational time_base;
00039 
00040     avio_rl32(s->pb); // DKIF
00041     avio_rl16(s->pb); // version
00042     avio_rl16(s->pb); // header size
00043 
00044     st = avformat_new_stream(s, NULL);
00045     if (!st)
00046         return AVERROR(ENOMEM);
00047 
00048 
00049     st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00050     st->codec->codec_tag  = avio_rl32(s->pb);
00051     st->codec->codec_id   = ff_codec_get_id(ff_codec_bmp_tags, st->codec->codec_tag);
00052     st->codec->width      = avio_rl16(s->pb);
00053     st->codec->height     = avio_rl16(s->pb);
00054     time_base.den         = avio_rl32(s->pb);
00055     time_base.num         = avio_rl32(s->pb);
00056     st->duration          = avio_rl64(s->pb);
00057 
00058     st->need_parsing      = AVSTREAM_PARSE_HEADERS;
00059 
00060     if (!time_base.den || !time_base.num) {
00061         av_log(s, AV_LOG_ERROR, "Invalid frame rate\n");
00062         return AVERROR_INVALIDDATA;
00063     }
00064 
00065     avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
00066 
00067     return 0;
00068 }
00069 
00070 static int read_packet(AVFormatContext *s, AVPacket *pkt)
00071 {
00072     int ret, size = avio_rl32(s->pb);
00073     int64_t   pts = avio_rl64(s->pb);
00074 
00075     ret = av_get_packet(s->pb, pkt, size);
00076     pkt->stream_index = 0;
00077     pkt->pts          = pts;
00078     pkt->pos         -= 12;
00079 
00080     return ret;
00081 }
00082 
00083 AVInputFormat ff_ivf_demuxer = {
00084     .name           = "ivf",
00085     .long_name      = NULL_IF_CONFIG_SMALL("On2 IVF"),
00086     .read_probe     = probe,
00087     .read_header    = read_header,
00088     .read_packet    = read_packet,
00089     .flags= AVFMT_GENERIC_INDEX,
00090     .codec_tag = (const AVCodecTag*[]){ff_codec_bmp_tags, 0},
00091 };
Generated on Thu Jul 11 2013 15:38:23 for Libav by doxygen 1.7.1