PageRenderTime 43ms CodeModel.GetById 16ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 0ms

/xbmc/cores/dvdplayer/DVDSubtitles/DVDSubtitleParserSubrip.cpp

http://github.com/xbmc/xbmc
C++ | 94 lines | 58 code | 15 blank | 21 comment | 11 complexity | 4fc1e95adbe6664d2b86b21d3fc530cd MD5 | raw file
 1/*
 2 *      Copyright (C) 2005-2013 Team XBMC
 3 *      http://xbmc.org
 4 *
 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)
 8 *  any later version.
 9 *
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.
14 *
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/>.
18 *
19 */
20
21#include "DVDSubtitleParserSubrip.h"
22#include "DVDCodecs/Overlay/DVDOverlayText.h"
23#include "DVDClock.h"
24#include "utils/StdString.h"
25#include "DVDSubtitleTagSami.h"
26
27using namespace std;
28
29CDVDSubtitleParserSubrip::CDVDSubtitleParserSubrip(CDVDSubtitleStream* pStream, const string& strFile)
30    : CDVDSubtitleParserText(pStream, strFile)
31{
32}
33
34CDVDSubtitleParserSubrip::~CDVDSubtitleParserSubrip()
35{
36  Dispose();
37}
38
39bool CDVDSubtitleParserSubrip::Open(CDVDStreamInfo &hints)
40{
41  if (!CDVDSubtitleParserText::Open())
42    return false;
43
44  CDVDSubtitleTagSami TagConv;
45  if (!TagConv.Init())
46    return false;
47
48  char line[1024];
49  CStdString strLine;
50
51  while (m_pStream->ReadLine(line, sizeof(line)))
52  {
53    strLine = line;
54    strLine.Trim();
55
56    if (strLine.length() > 0)
57    {
58      char sep;
59      int hh1, mm1, ss1, ms1, hh2, mm2, ss2, ms2;
60      int c = sscanf(strLine.c_str(), "%d%c%d%c%d%c%d --> %d%c%d%c%d%c%d\n",
61                     &hh1, &sep, &mm1, &sep, &ss1, &sep, &ms1,
62                     &hh2, &sep, &mm2, &sep, &ss2, &sep, &ms2);
63
64      if (c == 1)
65      {
66        // numbering, skip it
67      }
68      else if (c == 14) // time info
69      {
70        CDVDOverlayText* pOverlay = new CDVDOverlayText();
71        pOverlay->Acquire(); // increase ref count with one so that we can hold a handle to this overlay
72
73        pOverlay->iPTSStartTime = ((double)(((hh1 * 60 + mm1) * 60) + ss1) * 1000 + ms1) * (DVD_TIME_BASE / 1000);
74        pOverlay->iPTSStopTime  = ((double)(((hh2 * 60 + mm2) * 60) + ss2) * 1000 + ms2) * (DVD_TIME_BASE / 1000);
75
76        while (m_pStream->ReadLine(line, sizeof(line)))
77        {
78          strLine = line;
79          strLine.Trim();
80
81          // empty line, next subtitle is about to start
82          if (strLine.length() <= 0) break;
83
84          TagConv.ConvertLine(pOverlay, strLine.c_str(), strLine.length());
85        }
86        TagConv.CloseTag(pOverlay);
87        m_collection.Add(pOverlay);
88      }
89    }
90  }
91  m_collection.Sort();
92  return true;
93}
94