Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BaseDemuxer.h « Demuxers « demuxer - github.com/mpc-hc/LAVFilters.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fd38ac2095d372728c5421d36beef35786a0fe8f (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 *      Copyright (C) 2010-2013 Hendrik Leppkes
 *      http://www.1f0.de
 *
 *  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 of the License, 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 this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#pragma once

#include <deque>

#include "StreamInfo.h"
#include "Packet.h"

#define DSHOW_TIME_BASE 10000000        // DirectShow times are in 100ns units
#define NO_SUBTITLE_PID DWORD_MAX
#define FORCED_SUBTITLE_PID (NO_SUBTITLE_PID - 1)

#define FORCED_SUB_STRING L"Forced Subtitles (auto)"

struct ILAVFSettingsInternal;

typedef struct CSubtitleSelector {
  std::string audioLanguage;
  std::string subtitleLanguage;

#define SUBTITLE_FLAG_DEFAULT  0x0001
#define SUBTITLE_FLAG_FORCED   0x0002
#define SUBTITLE_FLAG_NORMAL   0x0004
#define SUBTITLE_FLAG_IMPAIRED 0x0008

// Values above 0xFF are special
#define SUBTITLE_FLAG_PGS      0x8000
  DWORD dwFlags;
} CSubtitleSelector;

class CBaseDemuxer : public CUnknown
{
public:
  enum StreamType {video, audio, subpic, unknown};

  typedef struct stream {
    CStreamInfo *streamInfo;
    DWORD pid;
    std::string language;
    struct stream() { streamInfo = NULL; pid = 0; }
    operator DWORD() const { return pid; }
    bool operator == (const struct stream& s) const { return (DWORD)*this == (DWORD)s; }
  } stream;

  DECLARE_IUNKNOWN

  // Demuxing Methods (pure virtual)

  // Open the file
  virtual STDMETHODIMP Open(LPCOLESTR pszFileName) = 0;
  // Start the demuxer
  virtual STDMETHODIMP Start() { return E_NOTIMPL; }
  // Abort opening the file
  virtual STDMETHODIMP AbortOpening(int mode = 1) { return E_NOTIMPL; }
  // Get Duration
  virtual REFERENCE_TIME GetDuration() const = 0;
  // Get the next packet from the file
  virtual STDMETHODIMP GetNextPacket(Packet **ppPacket) = 0;
  // Seek to the given position
  virtual STDMETHODIMP Seek(REFERENCE_TIME rTime) = 0;
  // Get the container format
  virtual const char *GetContainerFormat() const = 0;
  // Get Container Flags
#define LAVFMT_TS_DISCONT 0x0001
  virtual DWORD GetContainerFlags() { return 0; }
  // Create Stream Description
  virtual HRESULT StreamInfo(const CBaseDemuxer::stream &s, LCID *plcid, WCHAR **ppszName) const = 0;

  // Select the active title
  virtual STDMETHODIMP SetTitle(int idx) { return E_NOTIMPL; }
  // Query the active title
  virtual STDMETHODIMP_(int) GetTitle() { return 0; }
  // Get Title Info
  virtual STDMETHODIMP GetTitleInfo(int idx, REFERENCE_TIME *rtDuration, WCHAR **ppszName) { return E_NOTIMPL; }
  // Title count
  virtual STDMETHODIMP_(int) GetNumTitles() { return 0; }
  
  // Set the currently active stream of one type
  // The demuxers can use this to filter packets before returning back to the caller on GetNextPacket
  // This functionality is optional however, so the caller should not rely on only receiving packets
  // for active streams.
  virtual HRESULT SetActiveStream(StreamType type, int pid) { m_dActiveStreams[type] = pid; return S_OK; }

  // Called when the settings of the splitter change
  virtual void SettingsChanged(ILAVFSettingsInternal *pSettings) {};

  virtual STDMETHODIMP_(DWORD) GetStreamFlags(DWORD dwStream) { return 0; }
  virtual STDMETHODIMP_(int) GetPixelFormat(DWORD dwStream) { return PIX_FMT_NONE; }
  virtual STDMETHODIMP_(int) GetHasBFrames(DWORD dwStream) { return -1; }

public:
  class CStreamList : public std::deque<stream>
  {
  public:
    ~CStreamList() { Clear(); }
    static const WCHAR* ToStringW(int type);
    static const CHAR* ToString(int type);
    stream* FindStream(DWORD pid);
    void Clear();
  };


protected:
  CBaseDemuxer(LPCTSTR pName, CCritSec *pLock);
  void CreateNoSubtitleStream();
  void CreatePGSForcedSubtitleStream();

public:
  // Get the StreamList of the correponding type
  virtual CStreamList *GetStreams(StreamType type) { return &m_streams[type]; }

  
  // Select the best video stream
  virtual const stream* SelectVideoStream() = 0;
  
  // Select the best audio stream
  virtual const stream* SelectAudioStream(std::list<std::string> prefLanguages) = 0;

  // Select the best subtitle stream
  virtual const stream* SelectSubtitleStream(std::list<CSubtitleSelector> subtitleSelectors, std::string audioLanguage) = 0;

protected:
  CCritSec *m_pLock;
  CStreamList m_streams[unknown];
  int m_dActiveStreams[unknown];
};