• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • 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 FFmpeg.
00006  *
00007  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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     pkt->dts=pkt->pts= s->streams[0]->cur_dts;
00064 
00065     if(ret>5 && (pkt->data[0]&0x3F) == 9 && (pkt->data[1]&0x3F)==1 && !(pkt->data[2+2+1] & 0x0F)){
00066         pkt->flags = AV_PKT_FLAG_KEY;
00067     }
00068     return ret;
00069 }
00070 
00071 AVInputFormat ff_cdg_demuxer = {
00072     .name           = "cdg",
00073     .long_name      = NULL_IF_CONFIG_SMALL("CD Graphics Format"),
00074     .read_header    = read_header,
00075     .read_packet    = read_packet,
00076     .flags= AVFMT_GENERIC_INDEX,
00077     .extensions = "cdg"
00078 };
Generated on Fri Feb 1 2013 14:34:51 for FFmpeg by doxygen 1.7.1