yading@11: /* yading@11: * Copyright (c) 2012 Clément Bœsch yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: /** yading@11: * @file yading@11: * RealText subtitle demuxer yading@11: * @see http://service.real.com/help/library/guides/ProductionGuide/prodguide/htmfiles/realtext.htm yading@11: */ yading@11: yading@11: #include "avformat.h" yading@11: #include "internal.h" yading@11: #include "subtitles.h" yading@11: #include "libavutil/avstring.h" yading@11: #include "libavutil/bprint.h" yading@11: #include "libavutil/intreadwrite.h" yading@11: yading@11: typedef struct { yading@11: FFDemuxSubtitlesQueue q; yading@11: } RealTextContext; yading@11: yading@11: static int realtext_probe(AVProbeData *p) yading@11: { yading@11: const unsigned char *ptr = p->buf; yading@11: yading@11: if (AV_RB24(ptr) == 0xEFBBBF) yading@11: ptr += 3; /* skip UTF-8 BOM */ yading@11: return !av_strncasecmp(ptr, "priv_data; yading@11: AVStream *st = avformat_new_stream(s, NULL); yading@11: AVBPrint buf; yading@11: char c = 0; yading@11: int res = 0, duration = read_ts("60"); // default duration is 60 seconds yading@11: yading@11: if (!st) yading@11: return AVERROR(ENOMEM); yading@11: avpriv_set_pts_info(st, 64, 1, 100); yading@11: st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; yading@11: st->codec->codec_id = AV_CODEC_ID_REALTEXT; yading@11: yading@11: av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); yading@11: yading@11: while (!url_feof(s->pb)) { yading@11: AVPacket *sub; yading@11: const int64_t pos = avio_tell(s->pb) - (c != 0); yading@11: int n = ff_smil_extract_next_chunk(s->pb, &buf, &c); yading@11: yading@11: if (n == 0) yading@11: break; yading@11: yading@11: if (!av_strncasecmp(buf.str, "codec->extradata = av_strdup(buf.str); yading@11: if (!st->codec->extradata) { yading@11: res = AVERROR(ENOMEM); yading@11: goto end; yading@11: } yading@11: st->codec->extradata_size = buf.len + 1; yading@11: } else { yading@11: /* if we just read a