2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "DVDSubtitleParserMPL2.h"
22 #include "DVDCodecs/Overlay/DVDOverlayText.h"
24 #include "utils/RegExp.h"
25 #include "DVDStreamInfo.h"
26 #include "utils/StdString.h"
27 #include "DVDSubtitleTagMicroDVD.h"
31 CDVDSubtitleParserMPL2::CDVDSubtitleParserMPL2(CDVDSubtitleStream* stream, const string& filename)
32 : CDVDSubtitleParserText(stream, filename), m_framerate(DVD_TIME_BASE / 10.0)
37 CDVDSubtitleParserMPL2::~CDVDSubtitleParserMPL2()
42 bool CDVDSubtitleParserMPL2::Open(CDVDStreamInfo &hints)
44 if (!CDVDSubtitleParserText::Open())
47 // MPL2 is time-based, with 0.1s accuracy
48 m_framerate = DVD_TIME_BASE / 10.0;
53 if (!reg.RegComp("\\[([0-9]+)\\]\\[([0-9]+)\\]"))
55 CDVDSubtitleTagMicroDVD TagConv;
57 while (m_pStream->ReadLine(line, sizeof(line)))
59 if ((strlen(line) > 0) && (line[strlen(line) - 1] == '\r'))
60 line[strlen(line) - 1] = 0;
62 int pos = reg.RegFind(line);
65 const char* text = line + pos + reg.GetFindLen();
66 std::string startFrame = reg.GetReplaceString("\\1");
67 std::string endFrame = reg.GetReplaceString("\\2");
68 CDVDOverlayText* pOverlay = new CDVDOverlayText();
69 pOverlay->Acquire(); // increase ref count with one so that we can hold a handle to this overlay
71 pOverlay->iPTSStartTime = m_framerate * atoi(startFrame.c_str());
72 pOverlay->iPTSStopTime = m_framerate * atoi(endFrame.c_str());
74 TagConv.ConvertLine(pOverlay, text, strlen(text));
75 m_collection.Add(pOverlay);