]> git.vomp.tv Git - vompclient.git/blob - dssourcepin.cc
Completion of move recording code. Fixes for dir counts, other bugs.
[vompclient.git] / dssourcepin.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20 #include "dssourcepin.h"
21 #include "dssourcefilter.h"
22 #include <Dvdmedia.h>
23 #include <mmreg.h>
24
25 DsSourcePin::DsSourcePin(DsSourceFilter *pFilter,
26                                                  CCritSec *pLock,HRESULT *phr,LPCWSTR pName,bool audio):
27 CBaseOutputPin(NAME("dssourcepin"),pFilter,pLock,phr,pName)
28 {
29         isaudiopin=audio;
30         m_pFilter=pFilter;
31
32 }
33
34 DsSourcePin::~DsSourcePin()
35 {
36         
37
38 }
39
40 HRESULT DsSourcePin::GetMediaType(int iPosition, CMediaType *pmt)
41 {
42         HRESULT hr;
43         ASSERT(pmt);
44         pmt->InitMediaType();
45         if (isaudiopin){
46                 if (iPosition==0) {
47                         pmt->SetType(&MEDIATYPE_Audio);
48                         MPEG1WAVEFORMAT wfe;
49                         ZeroMemory(&wfe,sizeof(wfe));
50                         wfe.wfx.cbSize=22;
51                         wfe.wfx.nSamplesPerSec=48000;
52                         wfe.wfx.nChannels=2;
53                         wfe.wfx.nAvgBytesPerSec=32000;
54                         wfe.wfx.nBlockAlign=768;
55                         wfe.wfx.wFormatTag=WAVE_FORMAT_MPEG;
56                         wfe.fwHeadLayer=2;
57                         wfe.dwHeadBitrate=256000;
58                         wfe.fwHeadMode=ACM_MPEG_STEREO;
59                         wfe.fwHeadModeExt=1;
60                         wfe.wHeadEmphasis=1;
61                         wfe.fwHeadFlags=ACM_MPEG_ID_MPEG1 |ACM_MPEG_ORIGINALHOME | ACM_MPEG_PROTECTIONBIT;
62                         pmt->SetSubtype(&MEDIASUBTYPE_MPEG2_AUDIO);
63                         pmt->SetFormatType(&FORMAT_WaveFormatEx);
64                         pmt->SetFormat((BYTE*)&wfe,sizeof(wfe));
65                         pmt->SetSampleSize(0);
66                         hr=S_OK;
67
68                 
69         } else  {
70                         hr=VFW_S_NO_MORE_ITEMS ;
71                 }
72         } else {
73                 if (iPosition == 0) {
74                         pmt->SetType(&MEDIATYPE_Video);
75                         hr=S_OK;
76                         pmt->SetSubtype(&MEDIASUBTYPE_MPEG2_VIDEO);
77             pmt->SetFormatType(&FORMAT_MPEG2Video);
78
79             MPEG2VIDEOINFO hdr;
80             ZeroMemory(&hdr,sizeof(hdr));
81             hdr.dwProfile=AM_MPEG2Profile_Main;
82             hdr.dwLevel=AM_MPEG2Level_Main;
83             hdr.hdr.bmiHeader.biSize = sizeof(hdr.hdr.bmiHeader);
84             hdr.hdr.bmiHeader.biWidth = 720;
85             hdr.hdr.bmiHeader.biHeight = 568;
86             pmt->SetFormat((BYTE*)&hdr,sizeof(hdr));
87                 } else {
88                         hr=VFW_S_NO_MORE_ITEMS;
89                 }
90         }
91         return hr ;
92 }
93
94 // No description
95 HRESULT DsSourcePin::CheckMediaType(const CMediaType *pmt)
96 {
97     HRESULT res;
98     ASSERT (pmt);
99     if (isaudiopin) {
100         bool subtype=false;
101 #if 0 /* For future demands ac3 */
102                 subtype=pmt->subtype==(MEDIASUBTYPE_DOLBY_AC3);
103 #endif
104                 subtype=(pmt->subtype==(MEDIASUBTYPE_MPEG2_AUDIO));
105         if (pmt->majortype==MEDIATYPE_Audio && subtype) {
106                         res = S_OK ;
107         } else {
108             res = S_FALSE ;
109         }    
110     } else {
111         if (pmt->majortype==MEDIATYPE_Video &&
112                   pmt-> subtype==MEDIASUBTYPE_MPEG2_VIDEO) {
113                         res = S_OK ;
114         } else {
115             res = S_FALSE ;
116         }  
117     }
118     return res;
119 }
120
121 HRESULT DsSourcePin::DecideBufferSize(IMemAllocator *pa,ALLOCATOR_PROPERTIES *all_pp){
122         HRESULT hr;
123     CAutoLock al(m_pFilter->GetLock());
124     CheckPointer(pa, E_POINTER);
125     CheckPointer(all_pp, E_POINTER);
126         if (isaudiopin) {
127                 if (all_pp->cBuffers*all_pp->cbBuffer < 300*64*1024)
128                 {
129                         all_pp->cBuffers = 300;
130                         all_pp->cbBuffer = 64*1024;
131                 }
132         } else {
133                 if (all_pp->cBuffers*all_pp->cbBuffer < 300*64*1024)
134                 {
135                         all_pp->cBuffers = 300;
136                         all_pp->cbBuffer = 64*1024;
137                 }
138         }
139
140     ALLOCATOR_PROPERTIES all_pp_cur;
141     hr =pa->SetProperties(all_pp,&all_pp_cur);
142     if (FAILED(hr)) 
143     {
144         return hr;
145     }
146     if (all_pp_cur.cbBuffer*all_pp_cur.cBuffers < all_pp->cBuffers*all_pp->cbBuffer) 
147     {
148         return E_FAIL;
149     }
150
151     return S_OK;
152 }