⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dvbsubtitlesfilter.h

📁 Teletext module usually used in the DVB area.
💻 H
字号:
/* 

(C) Luke Paton 2004.

Copyright notice:

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., 675 Mass Ave, Cambridge, MA 02139, USA.

*/
extern const AMOVIESETUP_FILTER sudDVBTeletextSubtitles;

#include "TeletextInputPin.h"
#include "TeletextOutputPin.h"

#include <mpeg2data.h>
#include <mpeg2bits.h>


enum ts_status_t
{
	TS_WAITING,
	TS_ERROR,
	TS_IN_PAYLOAD
};

struct STeletextSubtitleLine
{
	int row;
	int column;
	colour_types m_Colour;
    colour_types m_BackgroundColour;
	char text[40];
};

typedef char SPage[25][40];

struct SMagazineLine
{
	bool m_bTransmitted;
	unsigned char m_Line[40];
};

struct SMagazine;
struct SMagazineSubPage
{
	// Construction
public :
    SMagazineSubPage(void);
    SMagazineSubPage(const SMagazineSubPage&);
    SMagazineSubPage& operator=(const SMagazineSubPage&);

// Attributes
public :
	bool m_Valid;
	unsigned char m_Language;
	int m_nValidLines;
	int m_nPage;
    int m_nSubPage;
	SMagazineLine m_PageBuffer[25];
    bool m_Displayed;
    __int64 m_StartMilliseconds;
    __int64 m_EndMilliseconds;

    bool m_bErasePage;
    bool m_bNewsflash;
    bool m_bSubtitle;
    bool m_bSupressHeader;
    bool m_bUpdateIndicator;
    bool m_bInterruptedSequence;
    bool m_bInhibitDisplay;
    bool m_bMagazineSerial;

// Operations
public :
	bool
	SetLine
	(
		int line,
		unsigned char* data,
		int mag,
		int last_line,
        SMagazine* magazine,
        unsigned __int64 program_time_ms
	);

	void ClearPageBuffer(void)
	{
		m_nValidLines = 0;
		for (int line = 0; line < 25; line++)
		{
			m_PageBuffer[line].m_bTransmitted = false;
			memset(m_PageBuffer[line].m_Line, ' ', 40);
		}
	}

    void Clear(void)
    {
		m_StartMilliseconds = 0;
		m_EndMilliseconds = 0;
        m_Displayed = false;
	    m_Valid = false;
	    m_Language = 0;
	    m_nPage = 0;
        m_nSubPage = 0;
        ClearPageBuffer();

        m_bErasePage = false;
        m_bNewsflash = false;
        m_bSubtitle = false;
        m_bSupressHeader = false;
        m_bUpdateIndicator = false;
        m_bInterruptedSequence = false;
        m_bInhibitDisplay = false;
        m_bMagazineSerial = false;
    }

	void GenerateIsoTextLines
	(
		vector<STeletextSubtitleLine>& texts,
        BOOL display_heading_line,
        int last_line
	) const;

	bool HasValidLines(void) const;
	bool operator <(const SMagazineSubPage& compare) const
	{
		if (m_StartMilliseconds == compare.m_StartMilliseconds)
		{
			return m_EndMilliseconds < compare.m_EndMilliseconds;
		}
		else
		{
			return m_StartMilliseconds < compare.m_StartMilliseconds;
		}
	}
};

typedef std::list<SMagazineSubPage> SMagazineSubPageInstances;

struct SMagazinePage
{
    std::map<int, SMagazineSubPageInstances> m_SubPages;

// Operations
public :
    void Clear(void);
    void AddSubPage(SMagazineSubPage& sub_page, int sub_page_number);
    bool HasValidSubPages(void);
    int GetPage(void);
};

struct SMagazine
{
    // Construction
public :
    SMagazine(void);
    SMagazine(const SMagazine& );
    SMagazine& operator=(const SMagazine&);

// Attributes
public :
	SMagazineSubPage m_SubPageUnderConstruction;
    std::map<int, SMagazinePage> m_Pages;

// Operations
public :
	bool 
	SetPageLine
	(
		int line,
		unsigned char* data,
        int desired_page,
		int mag
    );

    void AddPageUnderConstruction(void);
};

class CDVBTeletextSubtitles;

class CDVBTeletextPageEnumerator
:
    public CUnknown
    , public IEnumTeletextPages
{
public :
    CDVBTeletextPageEnumerator(CDVBTeletextSubtitles* filter)
    :
        CUnknown(_T("CDVBTeletextPageEnumerator"), NULL)
        , m_pFilter(filter)
    {
        m_nIndex = 0;
    }

    DECLARE_IUNKNOWN

    CComPtr<CDVBTeletextSubtitles> m_pFilter;
    int m_nIndex;

// 
// CUnknown overrides
//
protected :
	STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);

    // IEnumTeletextPages methods
protected :
    STDMETHOD(Next)
    (
        /*[in]*/ ULONG cRequest,
        /* [size_is][out][in] */ int* pPage,
        /* [out] */ ULONG *pcReceived
    );

    STDMETHOD(Skip)(/*[in]*/ ULONG cRecords);
    STDMETHOD(Reset)(void);
    STDMETHOD(Clone)(/*[out]*/ IEnumTeletextPages** ppIEnumTeletextPages);
};


class CDVBTeletextSubPageEnumerator
:
    public CUnknown
    , public IEnumTeletextSubPages
{
public :
    CDVBTeletextSubPageEnumerator(int page, CDVBTeletextSubtitles* filter)
    :
        CUnknown(_T("CDVBTeletextSubPageEnumerator"), NULL)
        , m_nPage(page)
        , m_pFilter(filter)
    {
        m_nIndex = 0;
    }

    DECLARE_IUNKNOWN

    CComPtr<CDVBTeletextSubtitles> m_pFilter;
    int m_nPage;
    int m_nIndex;

// 
// CUnknown overrides
//
protected :
	STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);

    // IEnumTeletextSubPages methods
protected :
    STDMETHOD(Next)
    ( 
        /*[in]*/ ULONG cRequest,
        /*[size_is][out][in]*/ int *pSubPage,
        /* [out] */ int* pOccurances,
        /*[out]*/ ULONG *pcReceived
    );

    STDMETHOD(Skip)(/*[in]*/ ULONG cRecords);
    STDMETHOD(Reset)(void);
    STDMETHOD(Clone)(/*[out]*/ IEnumTeletextSubPages** ppIEnumTeletextSubPages);
};

class CDVBTeletextSubtitles
:
	public CSource
	, public IDVBTeletextSubtitles
    , public ISpecifyPropertyPages
    , public CPersistStream
{
private : // construction is through CreateInstance
    // Constructor
    CDVBTeletextSubtitles( LPUNKNOWN punk, HRESULT *phr );

public :
    ~CDVBTeletextSubtitles( );

public :
    DECLARE_IUNKNOWN;

//
// DirectShow filter management
//
// Attributes
protected :
    CCritSec m_csFilter;
	CComPtr<IFilterGraph> m_pFilterGraph;
    CComBSTR m_FilePath;

// Operations
protected :
	STDMETHOD(Run)(REFERENCE_TIME tStart);
	CBasePin* GetPin(int n);
	int GetPinCount();

public :
    static CUnknown * WINAPI CreateInstance(LPUNKNOWN punk, HRESULT *phr);

//
// Input pin management
//
// Attributes
protected :
    CTeletextPIDInputPin* m_pTeletextPIDInput;
    CTeletextOutputPin* m_pTeletextOutput;

public :
	int m_nTeletextPid;

	// Mapping from video PID to teletext PID.
	// If there is only one, we use that one.
	std::map<int, int> m_TeletextPids;
	bool m_ConnectedToInputPID;
	int m_ThreadId;

// Operations
protected :
    HRESULT PrintMpeg2Section(IMpeg2Data* pMpeg2Data, SECTION *pSection, DWORD dwPacketLength);
    HRESULT PrintMpeg2Table(IMpeg2Data* pMpeg2Data, PID pid, TID tid, DWORD dwTimeout);

	static void FindTeletextPidThread(void* pParam);

public :
	void StartFixTeletextInputPinThread(void);

//
// DirectShow video output management
//
// Attributes
protected :
	long m_TransparencyPercent;
    COLORREF m_Colours[Colour_Max];
	CComPtr<IVMRMixerBitmap9> m_pVMRMixerBitmap9;

// Operations
protected :

//
// Full page display management
//
// Attributes
protected :

// Operations
protected :

//
// Subtitle management
//
// Attributes
protected :
	int m_nSubtitlesDecimalPage;
	int m_nSubtitlesDecimalSubPage;
    BOOL m_DisplayHeadingLine;
	int m_nLastLine;
    unsigned __int64 m_FirstEventMilliseconds;
	DWORD m_SubtitleDelayTime;
	DWORD m_SubtitleDelayRange;

// Operations
protected :
	void GetSubPagesAt(__int64 sub_page_time, std::vector<SMagazineSubPage*>& results);
	void GetSubPageInstances(std::vector<SMagazineSubPage*>& results);
    DWORD GetIntervalToNextEvent(void);
    void ClearSubPages(void);

//
// Magazine management
//
// Attributes
public :
	std::map<int, SMagazine> m_Magazines;

// Operations
protected :

//
// Pes packet management
//
// Attributes
protected :
	bool m_PesPacketDirty;
	int m_PesPacketLength;
	unsigned char m_PesPacketBuffer[1265536];

// Operations
protected :
    bool CheckPesPacket(void);
	bool ProcessPesPacket(void);

// ts packet management
// Attributes
protected :
	int m_tsPacketCounter;
	ts_status_t m_tsStatus;

// Operations
protected :
	bool ReadTeletextTransportStreamPacket(unsigned char* ts_buf);

public :
	bool ReadTeletextTransportStreamSample(IMediaSample * pSample);

// 
// CUnknown overrides
//
protected :
	STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);

    STDMETHODIMP GetClassID(OUT CLSID* pCLSID);

protected :
    // ISpecifyPropertyPages methods
    STDMETHODIMP GetPages(CAUUID *pPages);

protected :
    // IDVBTeletextSubtitles methods
public:

	STDMETHOD(set_SubtitlesDecimalPage)(LONG subtitles_page);
	STDMETHOD(get_SubtitlesDecimalPage)(LONG* subtitles_page);
	STDMETHOD(set_SubtitlesDecimalSubPage)(LONG subtitles_subpage);
	STDMETHOD(get_SubtitlesDecimalSubPage)(LONG* subtitles_subpage);
	STDMETHOD(set_SubtitleDelayTime)(/* [in] */ DWORD subtitle_delay_time);
    STDMETHOD(get_SubtitleDelayTime)(/* [out] */ DWORD *subtitle_delay_time);
	STDMETHOD(set_SubtitleDelayRange)(/* [in] */ DWORD subtitle_delay_range);
	STDMETHOD(get_SubtitleDelayRange)(/* [out] */ DWORD *subtitle_delay_range);
	STDMETHOD(set_TeletextPid)(LONG teletext_pid);
	STDMETHOD(get_TeletextPid)(LONG* teletext_pid);
	STDMETHOD(ReadTeletextTransportStreamFile)(BSTR file_path);
	STDMETHOD(get_InputPidMap)(IEnumPIDMap** enum_map);
    STDMETHOD(get_Pages)(IEnumTeletextPages** enum_pages);
    STDMETHOD(get_SubPages)(int page, IEnumTeletextSubPages** enum_subpages);
	STDMETHOD(set_LastLine)(LONG last_line);
	STDMETHOD(get_LastLine)(LONG* last_line);
	STDMETHOD(RefreshDisplay)(void);
	STDMETHOD(ClearDisplay)(void);
	STDMETHOD(set_Colour)(colour_types colour_index, LONG colour);
	STDMETHOD(get_Colour)(colour_types colour_index, LONG* colour);
	STDMETHOD(set_TextMode)(BOOL opaque);
	STDMETHOD(get_TextMode)(BOOL* opaque);
	STDMETHOD(set_TransparencyPercent)(LONG transparency_percent);
	STDMETHOD(get_TransparencyPercent)(LONG* transparency_percent);
	STDMETHOD(set_DisplayHeadingLine)(BOOL display_heading_line);
	STDMETHOD(get_DisplayHeadingLine)(BOOL* display_heading_line);
    STDMETHOD(set_File)(BSTR file_path);
    STDMETHOD(get_File)(BSTR* file_path);
    STDMETHOD(FindTeletextPid)(void);

protected :
    // CPersistStream methods
    
    HRESULT WriteToStream(IStream* stream);
    HRESULT ReadFromStream(IStream* stream);
    int SizeMax(void);
    void LockFilter() { m_csFilter.Lock(); }
    void UnlockFilter() { m_csFilter.Unlock(); }

    friend class CTeletextOutputPin;
public:
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -