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

libavformat/cdg.c

Go to the documentation of this file.
00001 /*
00002  * CD Graphics Demuxer
00003  * Copyright (c) 2009 Michael Tison
00004  *
00005  * This file is part of Libav.
00006  *
00007  * Libav is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * Libav is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with Libav; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "avformat.h"
00023 #include "internal.h"
00024 
00025 #define CDG_PACKET_SIZE    24
00026 #define CDG_COMMAND        0x09
00027 #define CDG_MASK           0x3F
00028 
00029 static int read_header(AVFormatContext *s, AVFormatParameters *ap)
00030 {
00031     AVStream *vst;
00032     int ret;
00033 
00034     vst = avformat_new_stream(s, NULL);
00035     if (!vst)
00036         return AVERROR(ENOMEM);
00037 
00038     vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00039     vst->codec->codec_id   = CODEC_ID_CDGRAPHICS;
00040 
00042     avpriv_set_pts_info(vst, 32, 1, 300);
00043 
00044     ret = avio_size(s->pb);
00045     if (ret > 0)
00046         vst->duration = (ret * vst->time_base.den) / (CDG_PACKET_SIZE * 300);
00047 
00048     return 0;
00049 }
00050 
00051 static int read_packet(AVFormatContext *s, AVPacket *pkt)
00052 {
00053     int ret;
00054 
00055     while (1) {
00056         ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE);
00057         if (ret < 1 || (pkt->data[0] & CDG_MASK) == CDG_COMMAND)
00058             break;
00059         av_free_packet(pkt);
00060     }
00061 
00062     pkt->stream_index = 0;
00063     return ret;
00064 }
00065 
00066 AVInputFormat ff_cdg_demuxer = {
00067     .name           = "cdg",
00068     .long_name      = NULL_IF_CONFIG_SMALL("CD Graphics Format"),
00069     .read_header    = read_header,
00070     .read_packet    = read_packet,
00071     .extensions = "cdg"
00072 };
Generated on Sun Apr 22 2012 21:54:07 for Libav by doxygen 1.7.1