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

DVBSub.h « Subtitles « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e2be340502a7f84e288e98cbf8121dcbfd8ae96e (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
/*
 * (C) 2009-2015 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 "RLECodedSubtitle.h"
#include "CompositionObject.h"
#include <list>
#include <memory>

class CGolombBuffer;

class CDVBSub : public CRLECodedSubtitle
{
public:
    CDVBSub(CCritSec* pLock, const CString& name, LCID lcid);
    ~CDVBSub();

    // ISubPicProvider
    STDMETHODIMP_(POSITION)       GetStartPosition(REFERENCE_TIME rt, double fps);
    STDMETHODIMP_(POSITION)       GetNext(POSITION pos);
    STDMETHODIMP_(REFERENCE_TIME) GetStart(POSITION pos, double fps);
    STDMETHODIMP_(REFERENCE_TIME) GetStop(POSITION pos, double fps);
    STDMETHODIMP_(bool)           IsAnimated(POSITION pos);
    STDMETHODIMP                  Render(SubPicDesc& spd, REFERENCE_TIME rt, double fps, RECT& bbox);
    STDMETHODIMP                  GetTextureSize(POSITION pos, SIZE& MaxTextureSize, SIZE& VirtualSize, POINT& VirtualTopLeft);

    virtual HRESULT ParseSample(REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, BYTE* pData, size_t nLen);
    virtual void    EndOfStream();
    virtual void    Reset();

private:
    // EN 300-743, table 2
    enum DVB_SEGMENT_TYPE {
        NO_SEGMENT     = 0xFFFF,
        PAGE           = 0x10,
        REGION         = 0x11,
        CLUT           = 0x12,
        OBJECT         = 0x13,
        DISPLAY        = 0x14,
        END_OF_DISPLAY = 0x80
    };

    // EN 300-743, table 6
    enum DVB_OBJECT_TYPE {
        OT_BASIC_BITMAP     = 0x00,
        OT_BASIC_CHAR       = 0x01,
        OT_COMPOSITE_STRING = 0x02
    };

    enum DVB_PAGE_STATE {
        DPS_NORMAL      = 0x00,
        DPS_ACQUISITION = 0x01,
        DPS_MODE_CHANGE = 0x02,
        DPS_RESERVED    = 0x03
    };

    struct DVB_CLUT {
        BYTE id = 0;
        BYTE version_number = 0;
        BYTE size = 0;

        std::array<HDMV_PALETTE, 256> palette;

        DVB_CLUT()
            : palette() {
        }
    };

    struct DVB_DISPLAY {
        // Default value (section 5.1.3)
        BYTE  version_number = 0;
        BYTE  display_window_flag = 0;
        short width = 720;
        short height = 576;
        short horizontal_position_minimun = 0;
        short horizontal_position_maximum = 0;
        short vertical_position_minimun = 0;
        short vertical_position_maximum = 0;
    };

    struct DVB_OBJECT {
        short object_id = 0;
        BYTE  object_type = 0;
        BYTE  object_provider_flag = 0;
        short object_horizontal_position = 0;
        short object_vertical_position = 0;
        BYTE  foreground_pixel_code = 0;
        BYTE  background_pixel_code = 0;
    };

    struct DVB_REGION_POS {
        BYTE id = 0;
        WORD horizAddr = 0;
        WORD vertAddr = 0;
    };

    struct DVB_REGION {
        BYTE id = 0;
        BYTE version_number = 0;
        BYTE fill_flag = 0;
        WORD width = 0;
        WORD height = 0;
        BYTE level_of_compatibility = 0;
        BYTE depth = 0;
        BYTE CLUT_id = 0;
        BYTE _8_bit_pixel_code = 0;
        BYTE _4_bit_pixel_code = 0;
        BYTE _2_bit_pixel_code = 0;
        std::list<DVB_OBJECT> objects;
    };

    using RegionList = std::list<std::unique_ptr<DVB_REGION>>;
    using CompositionObjectList = std::list<std::unique_ptr<CompositionObject>>;
    using ClutList = std::list<std::unique_ptr<DVB_CLUT>>;

    class DVB_PAGE
    {
    public:
        REFERENCE_TIME rtStart = 0;
        REFERENCE_TIME rtStop = 0;
        BYTE           pageTimeOut = 0;
        BYTE           pageVersionNumber = 0;
        BYTE           pageState = 0;
        std::list<DVB_REGION_POS> regionsPos;
        RegionList                regions;
        CompositionObjectList     objects;
        ClutList                  CLUTs;
        bool           rendered = false;
    };

    size_t                 m_nBufferSize;
    size_t                 m_nBufferReadPos;
    size_t                 m_nBufferWritePos;
    BYTE*                  m_pBuffer;
    CAutoPtrList<DVB_PAGE> m_pages;
    CAutoPtr<DVB_PAGE>     m_pCurrentPage;
    DVB_DISPLAY            m_displayInfo;

    HRESULT  AddToBuffer(BYTE* pData, size_t nSize);

    POSITION FindPage(REFERENCE_TIME rt) const;
    RegionList::const_iterator FindRegion(const CAutoPtr<DVB_PAGE>& pPage, BYTE bRegionId) const;
    ClutList::const_iterator   FindClut(const CAutoPtr<DVB_PAGE>& pPage, BYTE bClutId) const;
    CompositionObjectList::const_iterator FindObject(const CAutoPtr<DVB_PAGE>& pPage, short sObjectId) const;

    HRESULT  ParsePage(CGolombBuffer& gb, WORD wSegLength, CAutoPtr<DVB_PAGE>& pPage);
    HRESULT  ParseDisplay(CGolombBuffer& gb, WORD wSegLength);
    HRESULT  ParseRegion(CGolombBuffer& gb, WORD wSegLength);
    HRESULT  ParseClut(CGolombBuffer& gb, WORD wSegLength);
    HRESULT  ParseObject(CGolombBuffer& gb, WORD wSegLength);

    HRESULT  EnqueuePage(REFERENCE_TIME rtStop);
    HRESULT  UpdateTimeStamp(REFERENCE_TIME rtStop);

    void     RemoveOldPages(REFERENCE_TIME rt);
};