]> git.vomp.tv Git - vompclient.git/blob - dssourcepin.cc
*** empty log message ***
[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)\r
41 {\r
42         HRESULT hr;\r
43         ASSERT(pmt);\r
44         pmt->InitMediaType();\r
45         if (isaudiopin){\r
46                 if (iPosition==0) {\r
47                         pmt->SetType(&MEDIATYPE_Audio);\r
48                         MPEG1WAVEFORMAT wfe;\r
49                         ZeroMemory(&wfe,sizeof(wfe));\r
50                         wfe.wfx.cbSize=22;\r
51                         wfe.wfx.nSamplesPerSec=48000;\r
52                         wfe.wfx.nChannels=2;\r
53                         wfe.wfx.nAvgBytesPerSec=32000;\r
54                         wfe.wfx.nBlockAlign=768;\r
55                         wfe.wfx.wFormatTag=WAVE_FORMAT_MPEG;\r
56                         wfe.fwHeadLayer=2;\r
57                         wfe.dwHeadBitrate=256000;\r
58                         wfe.fwHeadMode=ACM_MPEG_STEREO;\r
59                         wfe.fwHeadModeExt=1;\r
60                         wfe.wHeadEmphasis=1;\r
61                         wfe.fwHeadFlags=ACM_MPEG_ID_MPEG1 |ACM_MPEG_ORIGINALHOME | ACM_MPEG_PROTECTIONBIT;\r
62                         pmt->SetSubtype(&MEDIASUBTYPE_MPEG2_AUDIO);\r
63                         pmt->SetFormatType(&FORMAT_WaveFormatEx);\r
64                         pmt->SetFormat((BYTE*)&wfe,sizeof(wfe));\r
65                         pmt->SetSampleSize(0);\r
66                         hr=S_OK;\r
67 \r
68                 \r
69         } else  {\r
70                         hr=VFW_S_NO_MORE_ITEMS ;\r
71                 }\r
72         } else {\r
73                 if (iPosition == 0) {\r
74                         pmt->SetType(&MEDIATYPE_Video);\r
75                         hr=S_OK;\r
76                         pmt->SetSubtype(&MEDIASUBTYPE_MPEG2_VIDEO);\r
77             pmt->SetFormatType(&FORMAT_MPEG2Video);\r
78 \r
79             MPEG2VIDEOINFO hdr;\r
80             ZeroMemory(&hdr,sizeof(hdr));\r
81             hdr.dwProfile=AM_MPEG2Profile_Main;\r
82             hdr.dwLevel=AM_MPEG2Level_Main;\r
83             hdr.hdr.bmiHeader.biSize = sizeof(hdr.hdr.bmiHeader);\r
84             hdr.hdr.bmiHeader.biWidth = 720;\r
85             hdr.hdr.bmiHeader.biHeight = 568;\r
86             pmt->SetFormat((BYTE*)&hdr,sizeof(hdr));\r
87                 } else {\r
88                         hr=VFW_S_NO_MORE_ITEMS;\r
89                 }\r
90         }\r
91         return hr ;\r
92 }\r
93 \r
94 // No description\r
95 HRESULT DsSourcePin::CheckMediaType(const CMediaType *pmt)\r
96 {\r
97     HRESULT res;\r
98     ASSERT (pmt);\r
99     if (isaudiopin) {\r
100         bool subtype=false;\r
101 #if 0 /* For future demands ac3 */\r
102                 subtype=pmt->subtype==(MEDIASUBTYPE_DOLBY_AC3);\r
103 #endif\r
104                 subtype=(pmt->subtype==(MEDIASUBTYPE_MPEG2_AUDIO));\r
105         if (pmt->majortype==MEDIATYPE_Audio && subtype) {\r
106                         res = S_OK ;\r
107         } else {\r
108             res = S_FALSE ;\r
109         }    \r
110     } else {\r
111         if (pmt->majortype==MEDIATYPE_Video &&\r
112                   pmt-> subtype==MEDIASUBTYPE_MPEG2_VIDEO) {\r
113                         res = S_OK ;\r
114         } else {\r
115             res = S_FALSE ;\r
116         }  \r
117     }\r
118     return res;\r
119 }\r
120 \r
121 HRESULT DsSourcePin::DecideBufferSize(IMemAllocator *pa,ALLOCATOR_PROPERTIES *all_pp){\r
122         HRESULT hr;\r
123     CAutoLock al(m_pFilter->GetLock());\r
124     CheckPointer(pa, E_POINTER);\r
125     CheckPointer(all_pp, E_POINTER);\r
126         if (isaudiopin) {\r
127                 if (all_pp->cBuffers*all_pp->cbBuffer < 300*64*1024)\r
128                 {\r
129                         //all_pp->cBuffers = 300;//old\r
130                         all_pp->cBuffers = 10;\r
131                         all_pp->cbBuffer = 64*1024;\r
132                 }\r
133         } else {\r
134                 if (all_pp->cBuffers*all_pp->cbBuffer < 300*64*1024)\r
135                 {\r
136                         //all_pp->cBuffers = 300;//old\r
137                         all_pp->cBuffers = 30;\r
138                         all_pp->cbBuffer = 64*1024;\r
139                 }\r
140         }\r
141 \r
142     ALLOCATOR_PROPERTIES all_pp_cur;\r
143     hr =pa->SetProperties(all_pp,&all_pp_cur);\r
144     if (FAILED(hr)) \r
145     {\r
146         return hr;\r
147     }\r
148     if (all_pp_cur.cbBuffer*all_pp_cur.cBuffers < all_pp->cBuffers*all_pp->cbBuffer) \r
149     {\r
150         return E_FAIL;\r
151     }\r
152 \r
153     return S_OK;\r
154 }\r