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

OutputPin.h - github.com/mpc-hc/rarfilesource.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 05e39c70f7a43b703b5a31a2f9265a57d2e474de (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
/*
 * Copyright (C) 2008-2012, OctaneSnail <os@v12pwr.com>
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#ifndef OUTPUT_PIN_H
#define OUTPUT_PIN_H

#include "List.h"

class CRARFileSource;
class CRFSFile;
class CRFSFilePart;

class SubRequest : public CRFSNode<SubRequest>
{
public:
	SubRequest (void) : file (INVALID_HANDLE_VALUE), expected (0)
		{ memset (&o, 0, sizeof (OVERLAPPED)); o.hEvent = INVALID_HANDLE_VALUE; }
	~SubRequest (void) { if (o.hEvent != INVALID_HANDLE_VALUE) CloseHandle (o.hEvent); }

	HANDLE file;
	DWORD expected;
	OVERLAPPED o;
};

class ReadRequest : public CRFSNode<ReadRequest>
{
public:
	~ReadRequest (void) { subreqs.Clear (); }

	DWORD_PTR dwUser;
	IMediaSample *pSample;

	DWORD count;
	CRFSList<SubRequest> subreqs;
};

class CRFSOutputPin :
	public CBasePin,
	public IAsyncReader
{
public:
	CRFSOutputPin (CRARFileSource *pFilter, CCritSec *pLock, HRESULT *phr);
	~CRFSOutputPin (void);

	DECLARE_IUNKNOWN;

	// Reveals IAsyncReader
	STDMETHODIMP NonDelegatingQueryInterface (REFIID riid, void **ppv);

	// IPin interface
	STDMETHODIMP Connect (IPin *pReceivePin, const AM_MEDIA_TYPE *pmt);

	// CBasePin
	HRESULT GetMediaType (int iPosition, CMediaType *pMediaType);
	HRESULT CheckMediaType (const CMediaType* pType);
	HRESULT CheckConnect (IPin *pPin);
	HRESULT CompleteConnect (IPin *pReceivePin);
	HRESULT BreakConnect ();

	// IAsyncReader interface
	STDMETHODIMP RequestAllocator (IMemAllocator *pPreferred, ALLOCATOR_PROPERTIES *pProps, IMemAllocator **ppActual);

	STDMETHODIMP Request (IMediaSample* pSample, DWORD_PTR dwUser);
	STDMETHODIMP WaitForNext (DWORD dwTimeout, IMediaSample **ppSample, DWORD_PTR *pdwUser);

	STDMETHODIMP SyncReadAligned (IMediaSample *pSample);
	STDMETHODIMP SyncRead (LONGLONG llPosition, LONG lLength, BYTE *pBuffer);

	STDMETHODIMP Length (LONGLONG *pTotal, LONGLONG *pAvailable);

	STDMETHODIMP BeginFlush (void);
	STDMETHODIMP EndFlush (void);

	void SetFile (CRFSFile *file) { m_file = file; }

private:
	DWORD m_align;
	BOOL m_asked_for_reader;
	CRFSFile *m_file;
	BOOL m_flush;
	HANDLE m_event;

	CRFSList<ReadRequest> m_requests;
	CCritSec m_lock;

	HRESULT ConvertSample (IMediaSample *sample, LONGLONG *pos, DWORD *length, BYTE **buffer);
	HRESULT DoFlush (IMediaSample **ppSample, DWORD_PTR *pdwUser);

	BOOL IsAligned (INT_PTR l) { return !(l & (m_align - 1)); }
};

#endif // OUTPUT_PIN_H