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

VobSubFileRipper.h « Subtitles « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cd857c91e33485b4809164fe1dc8c5d99032f8ea (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * (C) 2003-2006 Gabest
 * (C) 2006-2013 see Authors.txt
 *
 * This file is part of MPC-HC.
 *
 * MPC-HC 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 3 of the License, or
 * (at your option) any later version.
 *
 * MPC-HC 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, see <http://www.gnu.org/licenses/>.
 *
 */

#pragma once

#include <atlcoll.h>
#include "../DeCSS/VobFile.h"
#include "../DSUtil/DSUtil.h"
#include "VobSubFile.h"

#pragma pack(push, 1)
typedef struct {
    WORD perm_displ  : 2;
    WORD ratio       : 2;
    WORD system      : 2;
    WORD compression : 2;
    WORD mode        : 1;
    WORD letterboxed : 1;
    WORD source_res  : 2;
    WORD cbrvbr      : 2;
    WORD line21_2    : 1;
    WORD line21_1    : 1;
} vidinfo;

typedef struct {
    BYTE vob, cell;
    DWORD tTime, tOffset, tTotal;
    DWORD start, end;
    int iAngle;
    bool fDiscontinuity;
} vc_t;

typedef struct {
    int nAngles;
    CAtlArray<vc_t> angles[10];
    int iSelAngle;
    RGBQUAD pal[16];
    WORD ids[32];
} PGC;

typedef struct VSFRipperData_t {
    CSize vidsize;
    vidinfo vidinfo;
    CAtlArray<PGC> pgcs;
    int iSelPGC;
    bool fResetTime, fClosedCaption, fForcedOnly;

    bool fClose, fBeep, fAuto; // only used by the UI externally, but may be set through the parameter file
    bool fCloseIgnoreError;

    CAtlArray<UINT> selvcs;
    CAtlMap<BYTE, bool> selids;

    void Reset();
    void Copy(struct VSFRipperData_t& rd);

} VSFRipperData;

typedef struct {
    __int64 start, end;
    DWORD vc;
} vcchunk;

#pragma pack(pop)

// note: these interfaces only meant to be used internally with static linking

//
// IVSFRipperCallback
//

interface __declspec(uuid("9E2EBB5C-AD7C-452f-A48B-38685716AC46"))
IVSFRipperCallback :
public IUnknown {
    STDMETHOD(OnMessage)(LPCTSTR msg) PURE;
    STDMETHOD(OnProgress)(double progress /*0->1*/) PURE;
    STDMETHOD(OnFinished)(bool fSucceeded) PURE;
};

// IVSFRipperCallbackImpl

class IVSFRipperCallbackImpl : public CUnknown, public IVSFRipperCallback
{
protected:
    DECLARE_IUNKNOWN
    STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv) {
        return
            QI(IVSFRipperCallback)
            __super::NonDelegatingQueryInterface(riid, ppv);
    }

    // IVSFRipperCallback
    STDMETHODIMP OnMessage(LPCTSTR msg) { return S_FALSE; }
    STDMETHODIMP OnProgress(double progress /*0->1*/) { return S_FALSE; }
    STDMETHODIMP OnFinished(bool fSucceeded) { return S_FALSE; }

public:
    IVSFRipperCallbackImpl() : CUnknown(NAME("IVSFRipperCallbackImpl"), nullptr) {}
};

//
// IVSFRipper
//

interface __declspec(uuid("69F935BB-B8D0-43f5-AA2E-BBD0851CC9A6"))
IVSFRipper :
public IUnknown {
    STDMETHOD(SetCallBack)(IVSFRipperCallback * pCallback) PURE;
    STDMETHOD(LoadParamFile)(CString fn) PURE;
    STDMETHOD(SetInput)(CString infn) PURE;
    STDMETHOD(SetOutput)(CString outfn) PURE;
    STDMETHOD(GetRipperData)(VSFRipperData & rd) PURE;
    STDMETHOD(UpdateRipperData)(VSFRipperData & rd) PURE;
    STDMETHOD(Index)() PURE;
    STDMETHOD(IsIndexing)() PURE;
    STDMETHOD(Abort)(bool fSavePartial) PURE;
};

class CVobSubFileRipper : public CVobSubFile, protected CAMThread, public IVSFRipper
{
private:
    bool m_fThreadActive, m_fBreakThread, m_fIndexing;
    enum { CMD_EXIT, CMD_INDEX };
    DWORD ThreadProc();
    bool Create();

    //

    typedef enum {
        LOG_INFO,
        LOG_WARNING,
        LOG_ERROR
    } log_t;
    void Log(log_t type, LPCTSTR lpszFormat, ...);
    void Progress(double progress);
    void Finished(bool fSucceeded);

    //

    CCritSec m_csAccessLock;
    CString m_infn, m_outfn;
    CVobFile m_vob;
    VSFRipperData m_rd;

    bool LoadIfo(CString fn);
    bool LoadVob(CString fn);
    bool LoadChunks(CAtlArray<vcchunk>& chunks);
    bool SaveChunks(CAtlArray<vcchunk>& chunks);

    //

    CCritSec m_csCallback;
    CComPtr<IVSFRipperCallback> m_pCallback;

public:
    CVobSubFileRipper();
    virtual ~CVobSubFileRipper();

    DECLARE_IUNKNOWN
    STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);

    // IVSFRipper
    STDMETHODIMP SetCallBack(IVSFRipperCallback* pCallback);
    STDMETHODIMP LoadParamFile(CString fn);
    STDMETHODIMP SetInput(CString infn);
    STDMETHODIMP SetOutput(CString outfn);
    STDMETHODIMP GetRipperData(VSFRipperData& rd);
    STDMETHODIMP UpdateRipperData(VSFRipperData& rd);
    STDMETHODIMP Index();
    STDMETHODIMP IsIndexing();
    STDMETHODIMP Abort(bool fSavePartial);
};