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: 3c3cccdae34a8a916b00ecf68fe7d57bda17e14b (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 *      Copyright (C) 2011 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, 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; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *  http://www.gnu.org/copyleft/gpl.html
 */

#pragma once

#include <deque>

#include "StreamInfo.h"

#define DSHOW_TIME_BASE 10000000        // DirectShow times are in 100ns units
#define NO_SUBTITLE_PID DWORD_MAX

struct ILAVFSettings;

// Data Packet for queue storage
class Packet
{
public:
  static const REFERENCE_TIME INVALID_TIME = _I64_MIN;

  DWORD StreamId;
  BOOL bDiscontinuity, bSyncPoint, bAppendable;
  REFERENCE_TIME rtStart, rtStop;
  LONGLONG bPosition;
  AM_MEDIA_TYPE* pmt;

#define LAV_PACKET_PARSED 0x0001
  DWORD dwFlags;

  Packet() { pmt = NULL; m_pbData = NULL; bDiscontinuity = bSyncPoint = bAppendable = FALSE; rtStart = rtStop = INVALID_TIME; m_dwSize = 0; m_dwBlockSize = 0; bPosition = -1; dwFlags = 0; }
  ~Packet() { DeleteMediaType(pmt); SAFE_CO_FREE(m_pbData); }

  // Getter
  DWORD GetDataSize() const { return m_dwSize; }
  BYTE *GetData() { return m_pbData; }
  BYTE GetAt(DWORD pos) const { return m_pbData[pos]; }
  bool IsEmpty() const { return m_dwSize == 0; }

  // Setter
  void SetDataSize(DWORD len) { m_dwSize = len; if (m_dwSize > m_dwBlockSize) { m_pbData = (BYTE *)CoTaskMemRealloc(m_pbData, m_dwSize); m_dwBlockSize = m_dwSize; }}
  void SetData(const void* ptr, DWORD len) { SetDataSize(len); memcpy(m_pbData, ptr, len); }
  void Clear() { m_dwSize = m_dwBlockSize = 0; SAFE_CO_FREE(m_pbData); }

  // Append the data of the package to our data buffer
  void Append(Packet *ptr) {
    AppendData(ptr->GetData(), ptr->GetDataSize());
  }

  void AppendData(const void* ptr, DWORD len) {
    DWORD prevSize = m_dwSize;
    SetDataSize(m_dwSize + len);
    memcpy(m_pbData+prevSize, ptr, len);
  }

  // Remove count bytes from position index
  void RemoveHead(DWORD count) {
    count = min(count, m_dwSize);
    memmove(m_pbData, m_pbData+count, m_dwSize-count);
    SetDataSize(m_dwSize - count);
  }

private:
  DWORD m_dwSize;
  DWORD m_dwBlockSize;
  BYTE *m_pbData;
};

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

  DECLARE_IUNKNOWN

  // Demuxing Methods (pure virtual)

  // Open the file
  virtual STDMETHODIMP Open(LPCOLESTR pszFileName) = 0;
  // 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;
  // Create Stream Description
  virtual HRESULT StreamInfo(DWORD streamId, LCID *plcid, WCHAR **ppszName) const = 0;

  // Select the active title
  virtual STDMETHODIMP SetTitle(uint32_t idx) { return E_NOTIMPL; }
  // Get Title Info
  virtual STDMETHODIMP GetTitleInfo(uint32_t idx, REFERENCE_TIME *rtDuration, WCHAR **ppszName) { return E_NOTIMPL; }
  // Title count
  virtual STDMETHODIMP GetNumTitles(uint32_t *count) { return E_NOTIMPL; }
  
  // 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(ILAVFSettings *pSettings) {};

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

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


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

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;
  
  // Subtitle modes
#define SUBMODE_NO_SUBS 0
#define SUBMODE_FORCED_SUBS 1
#define SUBMODE_ALWAYS_SUBS 2
  // Select the best subtitle stream
  virtual const stream* SelectSubtitleStream(std::list<std::string> prefLanguages, int subtitleMode, BOOL bOnlyMatching) = 0;

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