xbmc
DVDSubtitleParser.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "../DVDCodecs/Overlay/DVDOverlay.h"
12 #include "DVDSubtitleLineCollection.h"
13 #include "DVDSubtitleStream.h"
14 
15 #include <memory>
16 #include <stdio.h>
17 #include <string>
18 
19 class CDVDStreamInfo;
20 
22 {
23 public:
24  virtual ~CDVDSubtitleParser() = default;
25  virtual bool Open(CDVDStreamInfo &hints) = 0;
26  virtual void Dispose() = 0;
27  virtual void Reset() = 0;
28  virtual std::shared_ptr<CDVDOverlay> Parse(double iPts) = 0;
29  virtual const std::string& GetName() const = 0;
30 };
31 
33  : public CDVDSubtitleParser
34 {
35 public:
36  explicit CDVDSubtitleParserCollection(const std::string& strFile) : m_filename(strFile) {}
37  ~CDVDSubtitleParserCollection() override = default;
38  std::shared_ptr<CDVDOverlay> Parse(double iPts) override
39  {
40  std::shared_ptr<CDVDOverlay> o = m_collection.Get(iPts);
41  if(o == NULL)
42  return o;
43  return o->Clone();
44  }
45  void Reset() override { m_collection.Reset(); }
46  void Dispose() override { m_collection.Clear(); }
47 
48 protected:
49  CDVDSubtitleLineCollection m_collection;
50  std::string m_filename;
51 };
52 
55 {
56 public:
57  CDVDSubtitleParserText(std::unique_ptr<CDVDSubtitleStream>&& stream,
58  const std::string& filename,
59  const char* name)
60  : CDVDSubtitleParserCollection(filename), m_pStream(std::move(stream)), m_parserName(name)
61  {
62  }
63 
64  ~CDVDSubtitleParserText() override = default;
65 
66  /*
67  * \brief Returns parser name
68  */
69  const std::string& GetName() const override { return m_parserName; }
70 
71 protected:
72  using CDVDSubtitleParserCollection::Open;
73  bool Open()
74  {
75  if(m_pStream)
76  {
77  if (m_pStream->Seek(0))
78  return true;
79  }
80  else
81  m_pStream.reset(new CDVDSubtitleStream());
82 
83  return m_pStream->Open(m_filename);
84  }
85 
86  std::unique_ptr<CDVDSubtitleStream> m_pStream;
87  std::string m_parserName;
88 };
Definition: DVDSubtitleParser.h:53
Definition: DVDStreamInfo.h:23
Definition: DVDSubtitleStream.h:21
Definition: DVDSubtitleParser.h:32
Definition: DVDSubtitleLineCollection.h:20
Definition: DVDSubtitleParser.h:21