1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2006-2012 |
---|
3 | // Created by Roman Ryltsov roman@alax.info |
---|
4 | // |
---|
5 | // A permission to use the source code is granted as long as reference to |
---|
6 | // source website http://alax.info is retained. |
---|
7 | |
---|
8 | #pragma once |
---|
9 | |
---|
10 | //////////////////////////////////////////////////////////// |
---|
11 | // CAbstractHandler |
---|
12 | |
---|
13 | class __declspec(uuid("344FF979-AC10-4346-B14E-EC81966076FF")) CAbstractHandler : |
---|
14 | public IUnknown |
---|
15 | { |
---|
16 | public: |
---|
17 | // CAbstractHandler |
---|
18 | virtual VOID Initialize(const CMediaType& pMediaType) = 0; |
---|
19 | virtual VOID HandleSample(const CMediaSampleProperties& Properties) = 0; |
---|
20 | }; |
---|
21 | |
---|
22 | //////////////////////////////////////////////////////////// |
---|
23 | // CHdycInterlacingHandler |
---|
24 | |
---|
25 | class ATL_NO_VTABLE CHdycInterlacingHandler : |
---|
26 | public CComObjectRootEx<CComMultiThreadModelNoCS>, |
---|
27 | public CAbstractHandler |
---|
28 | { |
---|
29 | public: |
---|
30 | |
---|
31 | BEGIN_COM_MAP(CHdycInterlacingHandler) |
---|
32 | COM_INTERFACE_ENTRY(CAbstractHandler) |
---|
33 | END_COM_MAP() |
---|
34 | |
---|
35 | private: |
---|
36 | mutable CRoCriticalSection m_DataCriticalSection; |
---|
37 | CVideoInfoHeader m_VideoInfoHeader; |
---|
38 | CSize m_Extent; |
---|
39 | BOOL m_bInitialized; |
---|
40 | CObjectPtr<CDormantMediaSample> m_pPreviousMediaSample; |
---|
41 | |
---|
42 | public: |
---|
43 | // CHdycInterlacingHandler |
---|
44 | |
---|
45 | // CAbstractHandler |
---|
46 | VOID Initialize(const CMediaType& pMediaType) |
---|
47 | { |
---|
48 | CRoCriticalSectionLock DataLock(m_DataCriticalSection); |
---|
49 | m_bInitialized = FALSE; |
---|
50 | m_VideoInfoHeader = pMediaType.GetCompatibleVideoInfoHeader(); |
---|
51 | if(!(m_VideoInfoHeader.GetBitmapInfoHeader().biCompression == FOURCC_UYVY || m_VideoInfoHeader.GetBitmapInfoHeader().biCompression == FOURCC_HDYC)) |
---|
52 | return; |
---|
53 | m_Extent = m_VideoInfoHeader.GetExtent(); |
---|
54 | _A(!m_pPreviousMediaSample); |
---|
55 | m_bInitialized = TRUE; |
---|
56 | } |
---|
57 | VOID HandleSample(const CMediaSampleProperties& Properties) |
---|
58 | { |
---|
59 | CRoCriticalSectionLock DataLock(m_DataCriticalSection); |
---|
60 | if(!m_bInitialized) |
---|
61 | return; |
---|
62 | _A(m_VideoInfoHeader.GetBitmapInfoHeader().biSize); |
---|
63 | _A(m_Extent.cx > 0 && m_Extent.cy > 0); |
---|
64 | if(m_pPreviousMediaSample) |
---|
65 | { |
---|
66 | const CMediaSampleProperties PreviousProperties(m_pPreviousMediaSample); |
---|
67 | SSIZE_T nFirstRowOffset, nNextRowOffset; |
---|
68 | m_VideoInfoHeader.GetData(nFirstRowOffset, nNextRowOffset); |
---|
69 | _A(nNextRowOffset > 0); |
---|
70 | const BYTE* pnDataA = PreviousProperties.pbBuffer + nFirstRowOffset; |
---|
71 | const BYTE* pnDataB = Properties.pbBuffer + nFirstRowOffset; |
---|
72 | INT pnCompareResults[2] = { 0, 0 }; |
---|
73 | for(LONG nY = 0; nY < m_Extent.cy; nY++) |
---|
74 | { |
---|
75 | const INT nCompareResult = memcmp(pnDataA, pnDataB, nNextRowOffset); |
---|
76 | if(nCompareResult == 0) |
---|
77 | pnCompareResults[nY % 2]++; |
---|
78 | #pragma region Per-Pixel |
---|
79 | //CString s; |
---|
80 | //static const SSIZE_T g_nFactor = 8; |
---|
81 | //for(LONG nX = 0; nX < m_Extent.cx / g_nFactor + 1; nX++) |
---|
82 | // s.AppendChar('-'); |
---|
83 | //static const UINT32 g_nMask = 0x00FF00FF; |
---|
84 | //for(LONG nX = 0; nX < m_Extent.cx / 2; nX++) |
---|
85 | // if((*((const UINT32*) pnDataA + (nX / 2)) & g_nMask) != (*((const UINT32*) pnDataB + (nX / 2)) & g_nMask)) |
---|
86 | // s.SetAt(nX / (g_nFactor / 2), 'X'); |
---|
87 | //_tprintf(_T("%s\n"), s); |
---|
88 | #pragma endregion |
---|
89 | pnDataA += nNextRowOffset; |
---|
90 | pnDataB += nNextRowOffset; |
---|
91 | } |
---|
92 | _tprintf(_T("Match to Previous Sample: Even Lines %d, Odd Lines %d\n"), pnCompareResults[0], pnCompareResults[1]); |
---|
93 | } |
---|
94 | m_pPreviousMediaSample.Release(); |
---|
95 | m_pPreviousMediaSample.Construct(); |
---|
96 | m_pPreviousMediaSample->SetProperties(Properties); |
---|
97 | } |
---|
98 | }; |
---|