00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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)
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 = AV_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=
00064 pkt->pts= pkt->pos / CDG_PACKET_SIZE;
00065
00066 if(ret>5 && (pkt->data[0]&0x3F) == 9 && (pkt->data[1]&0x3F)==1 && !(pkt->data[2+2+1] & 0x0F)){
00067 pkt->flags = AV_PKT_FLAG_KEY;
00068 }
00069 return ret;
00070 }
00071
00072 AVInputFormat ff_cdg_demuxer = {
00073 .name = "cdg",
00074 .long_name = NULL_IF_CONFIG_SMALL("CD Graphics"),
00075 .read_header = read_header,
00076 .read_packet = read_packet,
00077 .flags = AVFMT_GENERIC_INDEX,
00078 .extensions = "cdg",
00079 };