annotate ffmpeg/libavformat/cdg.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * CD Graphics Demuxer
yading@11 3 * Copyright (c) 2009 Michael Tison
yading@11 4 *
yading@11 5 * This file is part of FFmpeg.
yading@11 6 *
yading@11 7 * FFmpeg is free software; you can redistribute it and/or
yading@11 8 * modify it under the terms of the GNU Lesser General Public
yading@11 9 * License as published by the Free Software Foundation; either
yading@11 10 * version 2.1 of the License, or (at your option) any later version.
yading@11 11 *
yading@11 12 * FFmpeg is distributed in the hope that it will be useful,
yading@11 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 15 * Lesser General Public License for more details.
yading@11 16 *
yading@11 17 * You should have received a copy of the GNU Lesser General Public
yading@11 18 * License along with FFmpeg; if not, write to the Free Software
yading@11 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 20 */
yading@11 21
yading@11 22 #include "avformat.h"
yading@11 23 #include "internal.h"
yading@11 24
yading@11 25 #define CDG_PACKET_SIZE 24
yading@11 26 #define CDG_COMMAND 0x09
yading@11 27 #define CDG_MASK 0x3F
yading@11 28
yading@11 29 static int read_header(AVFormatContext *s)
yading@11 30 {
yading@11 31 AVStream *vst;
yading@11 32 int ret;
yading@11 33
yading@11 34 vst = avformat_new_stream(s, NULL);
yading@11 35 if (!vst)
yading@11 36 return AVERROR(ENOMEM);
yading@11 37
yading@11 38 vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
yading@11 39 vst->codec->codec_id = AV_CODEC_ID_CDGRAPHICS;
yading@11 40
yading@11 41 /// 75 sectors/sec * 4 packets/sector = 300 packets/sec
yading@11 42 avpriv_set_pts_info(vst, 32, 1, 300);
yading@11 43
yading@11 44 ret = avio_size(s->pb);
yading@11 45 if (ret > 0)
yading@11 46 vst->duration = (ret * vst->time_base.den) / (CDG_PACKET_SIZE * 300);
yading@11 47
yading@11 48 return 0;
yading@11 49 }
yading@11 50
yading@11 51 static int read_packet(AVFormatContext *s, AVPacket *pkt)
yading@11 52 {
yading@11 53 int ret;
yading@11 54
yading@11 55 while (1) {
yading@11 56 ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE);
yading@11 57 if (ret < 1 || (pkt->data[0] & CDG_MASK) == CDG_COMMAND)
yading@11 58 break;
yading@11 59 av_free_packet(pkt);
yading@11 60 }
yading@11 61
yading@11 62 pkt->stream_index = 0;
yading@11 63 pkt->dts=
yading@11 64 pkt->pts= pkt->pos / CDG_PACKET_SIZE;
yading@11 65
yading@11 66 if(ret>5 && (pkt->data[0]&0x3F) == 9 && (pkt->data[1]&0x3F)==1 && !(pkt->data[2+2+1] & 0x0F)){
yading@11 67 pkt->flags = AV_PKT_FLAG_KEY;
yading@11 68 }
yading@11 69 return ret;
yading@11 70 }
yading@11 71
yading@11 72 AVInputFormat ff_cdg_demuxer = {
yading@11 73 .name = "cdg",
yading@11 74 .long_name = NULL_IF_CONFIG_SMALL("CD Graphics"),
yading@11 75 .read_header = read_header,
yading@11 76 .read_packet = read_packet,
yading@11 77 .flags = AVFMT_GENERIC_INDEX,
yading@11 78 .extensions = "cdg",
yading@11 79 };