PageRenderTime 28ms CodeModel.GetById 18ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecText.cpp

http://github.com/xbmc/xbmc
C++ | 154 lines | 114 code | 20 blank | 20 comment | 27 complexity | 2f8711950f752c4aed0e6b034aefdeb3 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 "system.h"
 22#include "DVDClock.h"
 23#include "DVDOverlayCodecText.h"
 24#include "DVDOverlayText.h"
 25#include "DVDStreamInfo.h"
 26#include "DVDCodecs/DVDCodecs.h"
 27#include "utils/log.h"
 28#include "cores/dvdplayer/DVDSubtitles/DVDSubtitleTagSami.h"
 29
 30CDVDOverlayCodecText::CDVDOverlayCodecText() : CDVDOverlayCodec("Text Subtitle Decoder")
 31{
 32  m_pOverlay = NULL;
 33  m_bIsSSA = false;
 34}
 35
 36CDVDOverlayCodecText::~CDVDOverlayCodecText()
 37{
 38  if(m_pOverlay)
 39    SAFE_RELEASE(m_pOverlay);
 40}
 41
 42bool CDVDOverlayCodecText::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options)
 43{
 44  m_bIsSSA = (hints.codec == AV_CODEC_ID_SSA);
 45  if(hints.codec == AV_CODEC_ID_TEXT || hints.codec == AV_CODEC_ID_SSA)
 46    return true;
 47  if(hints.codec == AV_CODEC_ID_SUBRIP)
 48    return true;
 49  return false;
 50}
 51
 52void CDVDOverlayCodecText::Dispose()
 53{
 54  if(m_pOverlay)
 55    SAFE_RELEASE(m_pOverlay);
 56}
 57
 58int CDVDOverlayCodecText::Decode(DemuxPacket *pPacket)
 59{
 60  if(m_pOverlay)
 61    SAFE_RELEASE(m_pOverlay);
 62
 63  if(!pPacket)
 64    return OC_ERROR;
 65  
 66  uint8_t *data = pPacket->pData;
 67  int      size = pPacket->iSize;
 68  
 69  m_pOverlay = new CDVDOverlayText();
 70  CDVDOverlayCodec::GetAbsoluteTimes(m_pOverlay->iPTSStartTime, m_pOverlay->iPTSStopTime, pPacket, m_pOverlay->replace);
 71
 72  char *start, *end, *p;
 73  start = (char*)data;
 74  end   = (char*)data + size;
 75  p     = (char*)data;
 76
 77  if (m_bIsSSA)
 78  {
 79    // currently just skip the prefixed ssa fields (8 fields)
 80    int nFieldCount = 8;
 81    while (nFieldCount > 0 && start < end)
 82    {
 83      if (*start == ',')
 84        nFieldCount--;
 85
 86      start++;
 87      p++;
 88    }
 89  }
 90
 91  CDVDSubtitleTagSami TagConv;
 92  bool Taginit = TagConv.Init();
 93
 94  while(p<end)
 95  {
 96    if(*p == '{')
 97    {
 98      if(p>start)
 99      {
100        if(Taginit)
101          TagConv.ConvertLine(m_pOverlay, start, p-start);
102        else
103          m_pOverlay->AddElement(new CDVDOverlayText::CElementText(start, p-start));
104      }
105      start = p+1;
106
107      while(*p != '}' && p<end)
108        p++;
109
110      char* override = (char*)malloc(p-start + 1);
111      memcpy(override, start, p-start);
112      override[p-start] = '\0';
113      CLog::Log(LOGINFO, "%s - Skipped formatting tag %s", __FUNCTION__, override);
114      free(override);
115
116      start = p+1;
117    }
118    p++;
119  }
120  if(p>start)
121  {
122    if(Taginit)
123    {
124      TagConv.ConvertLine(m_pOverlay, start, p-start);
125      TagConv.CloseTag(m_pOverlay);
126    }
127    else
128      m_pOverlay->AddElement(new CDVDOverlayText::CElementText(start, p-start));
129  }
130  return OC_OVERLAY;
131}
132
133void CDVDOverlayCodecText::Reset()
134{
135  if(m_pOverlay)
136    SAFE_RELEASE(m_pOverlay);
137}
138
139void CDVDOverlayCodecText::Flush()
140{
141  if(m_pOverlay)
142    SAFE_RELEASE(m_pOverlay);
143}
144
145CDVDOverlay* CDVDOverlayCodecText::GetOverlay()
146{
147  if(m_pOverlay)
148  {
149    CDVDOverlay* overlay = m_pOverlay;
150    m_pOverlay = NULL;
151    return overlay;
152  }
153  return NULL;
154}