summaryrefslogtreecommitdiffstats
path: root/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxVobsub.h
blob: 0c75c4adbd5a02467946b854bf4689c575239db9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#pragma once

/*
 *      Copyright (C) 2005-2013 Team XBMC
 *      http://xbmc.org
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with XBMC; see the file COPYING.  If not, see
 *  <http://www.gnu.org/licenses/>.
 *
 */

#include "DVDDemux.h"

#include <memory>
#include <vector>

class CDVDOverlayCodecFFmpeg;
class CDVDInputStream;
class CDVDDemuxFFmpeg;

class CDVDDemuxVobsub : public CDVDDemux
{
public:
  CDVDDemuxVobsub();
  virtual ~CDVDDemuxVobsub();

  virtual bool          Open(const std::string& filename, const std::string& subfilename = "");
  virtual void          Reset();
  virtual void          Abort() {};
  virtual void          Flush();
  virtual DemuxPacket*  Read();
  virtual bool          SeekTime(int time, bool backwords, double* startpts = NULL);
  virtual void          SetSpeed(int speed) {}
  virtual CDemuxStream* GetStream(int index) { return m_Streams[index]; }
  virtual int           GetNrOfStreams()     { return m_Streams.size(); }
  virtual int           GetStreamLength()    { return 0; }
  virtual std::string   GetFileName()        { return m_Filename; }

private:
  class CStream
    : public CDemuxStreamSubtitle
  {
  public:
    CStream(CDVDDemuxVobsub* parent)
      : m_discard(AVDISCARD_NONE), m_parent(parent)
    {}
    virtual void      SetDiscard(AVDiscard discard) { m_discard = discard; }
    virtual AVDiscard GetDiscard()                  { return m_discard; }

    AVDiscard        m_discard;
    CDVDDemuxVobsub* m_parent;
  };

  typedef struct STimestamp
  {
    int64_t pos;
    double  pts;
    int     id;
  } STimestamp;

  std::string                        m_Filename;
  std::unique_ptr<CDVDInputStream>     m_Input;
  std::unique_ptr<CDVDDemuxFFmpeg>     m_Demuxer;
  std::vector<STimestamp>            m_Timestamps;
  std::vector<STimestamp>::iterator  m_Timestamp;
  std::vector<CStream*> m_Streams;

  typedef struct SState
  {
    int         id;
    double      delay;
    std::string extra;
  } SState;

  struct sorter
  {
    bool operator()(const STimestamp &p1, const STimestamp &p2)
    {
      return p1.pts < p2.pts || (p1.pts == p2.pts && p1.id < p2.id);
    }
  };

  bool ParseLangIdx(SState& state, char* line);
  bool ParseDelay(SState& state, char* line);
  bool ParseId(SState& state, char* line);
  bool ParseExtra(SState& state, char* line);
  bool ParseTimestamp(SState& state, char* line);
};