Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

627 lines
17 KiB

  1. // $Header: G:/SwDev/WDM/Video/bt848/rcs/Vidch.h 1.14 1998/05/11 23:59:58 tomz Exp $
  2. #ifndef __VXDVIDCH_H
  3. #define __VXDVIDCH_H
  4. extern "C" {
  5. #include "strmini.h"
  6. #include "ksmedia.h"
  7. }
  8. #include "mytypes.h"
  9. #include "pisces.h"
  10. #include "vidchifc.h"
  11. typedef enum { Closed, Open, Created, Started, Paused } StreamState;
  12. typedef enum { Single, Paired } StreamType;
  13. void GetRequestedSize2( const KS_VIDEOINFOHEADER2 &vidHdr, MSize &size );
  14. void GetRequestedSize( const KS_VIDEOINFOHEADER &vidHdr, MSize &size );
  15. extern PHW_STREAM_REQUEST_BLOCK StreamIdxToSrb[];
  16. /* Class: VideoChannel
  17. * Purpose: The base class to be used in the BtPisces capture VxD. Used for
  18. * processing user requests ( comes from the device class, goes to capture
  19. * chip class )
  20. * Attributes:
  21. * Methods
  22. */
  23. class VideoChannel
  24. {
  25. protected:
  26. BtPisces *Digitizer_;
  27. SRBQueue Requests_;
  28. KS_VIDEOINFOHEADER VidHeader_;
  29. KS_VIDEOINFOHEADER2 VidHeader2_;
  30. // this seems to be the most convenient place for the original copy
  31. // other option is to make SetVidHdr() virtual and move this member into
  32. // the PairedChannels
  33. KS_VIDEOINFOHEADER OrigVidHeader_;
  34. KS_VIDEOINFOHEADER2 OrigVidHeader2_;
  35. BOOL m_bIsVideoInfo2;
  36. DWORD FieldType_;
  37. VidBufQueue BufQue_;
  38. VideoChanIface Caller_;
  39. DWORD dwBufferOffset_;
  40. HANDLE hMasterClock;
  41. KSSTATE KSState_;
  42. LONG TimePerFrame_;
  43. VideoStream Stream_;
  44. Field *OurField_;
  45. StreamState State_;
  46. bool NeedNotification_;
  47. virtual void Interrupt( PVOID pTag, bool skipped );
  48. void CheckNotificationNeed();
  49. static void STREAMAPI TimeStamp( PHW_STREAM_REQUEST_BLOCK pSrb );
  50. static void STREAMAPI TimeStampVBI( PHW_STREAM_REQUEST_BLOCK pSrb );
  51. PVOID pStrmEx_;
  52. public:
  53. PHW_STREAM_REQUEST_BLOCK pSRB_;
  54. #ifdef ENABLE_DDRAW_STUFF
  55. // Kernel DDraw interface
  56. BOOL bKernelDirectDrawRegistered;
  57. HANDLE hUserDirectDrawHandle; // DD itself
  58. HANDLE hKernelDirectDrawHandle;
  59. BOOL bPreEventOccurred;
  60. BOOL bPostEventOccurred;
  61. #endif
  62. BOOL IsVideoInfo2() { return m_bIsVideoInfo2; }
  63. PVOID GetStrmEx()
  64. {
  65. DEBUG_ASSERT(pStrmEx_ != 0);
  66. return pStrmEx_;
  67. }
  68. VOID SetStrmEx(PVOID pv)
  69. {
  70. DEBUG_ASSERT(pv != 0);
  71. pStrmEx_ = pv;
  72. }
  73. BOOL bIsVBI();
  74. BOOL bIsVideo();
  75. VOID ResetCounters();
  76. virtual ErrorCode OpenChannel();
  77. virtual ErrorCode CloseChannel();
  78. virtual ErrorCode SetFormat( ColFmt );
  79. ColFmt GetFormat();
  80. virtual ErrorCode SetDigitalWindow( MRect &r );
  81. virtual ErrorCode SetAnalogWindow( MRect &r );
  82. virtual ErrorCode Create();
  83. virtual void Start();
  84. virtual ErrorCode Stop();
  85. virtual ErrorCode Pause();
  86. StreamState GetState();
  87. KSSTATE GetKSState();
  88. void SetKSState( KSSTATE st );
  89. VideoStream GetStreamID();
  90. void SetClockMaster( HANDLE h );
  91. //LONGLONG GetFramesNo();
  92. LONG GetTimePerFrame();
  93. void SetTimePerFrame( LONG time );
  94. void SetInterrupt( bool state );
  95. void SetCallback( ChanIface *cb );
  96. virtual StreamType GetStreamType();
  97. virtual void AddSRB( PHW_STREAM_REQUEST_BLOCK pSrb );
  98. virtual bool RemoveSRB( PHW_STREAM_REQUEST_BLOCK pSrb );
  99. virtual void ChangeNotification( PHW_STREAM_REQUEST_BLOCK pSrb );
  100. virtual void AddBuffer( PVOID );
  101. void SetSRB( PHW_STREAM_REQUEST_BLOCK srb );
  102. PHW_STREAM_REQUEST_BLOCK GetSRB();
  103. void SetVidHdr( const KS_VIDEOINFOHEADER &rVidHdr );
  104. void SetVidHdr2( const KS_VIDEOINFOHEADER2 &rVidHdr );
  105. PKS_VIDEOINFOHEADER GetVidHdr();
  106. KS_VIDEOINFOHEADER2* GetVidHdr2();
  107. void SetBufPitch( DWORD dwP );
  108. void SetDefaultQue()
  109. { Digitizer_->SetBufQuePtr( *OurField_, &BufQue_ ); }
  110. void SetPaired( bool p = false );
  111. void IntNotify( PVOID pTag, bool skipped );
  112. bool IsOpen();
  113. void SetOpen();
  114. void SetClose();
  115. void Init( BtPisces *const pCapChip );
  116. VideoChannel( VideoStream aStrm );
  117. virtual ~VideoChannel();
  118. friend class VideoChanIface;
  119. // placement new
  120. void *operator new( size_t, void *buf ) { return buf; }
  121. void operator delete( void *, size_t ) {}
  122. };
  123. /* Class: PairedVideoChannels
  124. * Purpose: Implements basic functionality of paired video channels
  125. */
  126. template <class ParentChan>
  127. class PairedVideoChannels : public ParentChan
  128. {
  129. typedef ParentChan Parent;
  130. public:
  131. VideoChannel &slave;
  132. PairedVideoChannels( VideoStream st, VideoChannel &chan );
  133. virtual ErrorCode Create();
  134. virtual void Start();
  135. virtual ErrorCode Stop();
  136. virtual ErrorCode Pause();
  137. virtual StreamType GetStreamType();
  138. };
  139. template <class ParentChan>
  140. inline PairedVideoChannels<ParentChan>::PairedVideoChannels( VideoStream st, VideoChannel &chan )
  141. : ParentChan( st ), slave( chan )
  142. {}
  143. /* Class: InterVideoChannel
  144. * Purpose: The base class to be used in the BtPisces capture VxD. Used for
  145. * processing user requests ( comes from the device class, goes to capture
  146. * chip class )
  147. * Attributes:
  148. * Methods
  149. */
  150. class InterVideoChannel : public PairedVideoChannels<VideoChannel>
  151. {
  152. typedef PairedVideoChannels<VideoChannel> Parent;
  153. public:
  154. virtual ErrorCode Create();
  155. virtual void AddSRB( PHW_STREAM_REQUEST_BLOCK pSrb );
  156. InterVideoChannel( VideoStream aStrm, VideoChannel &chan );
  157. virtual void Interrupt( PVOID pTag, bool skipped );
  158. };
  159. inline InterVideoChannel::InterVideoChannel( VideoStream aStrm, VideoChannel &chan )
  160. : Parent( aStrm, chan )
  161. {}
  162. /* Class: AlterVideoChannel
  163. * Purpose: The base class to be used in the BtPisces capture VxD. Used for
  164. * processing user requests ( comes from the device class, goes to capture
  165. * chip class )
  166. * Attributes:
  167. * Methods
  168. */
  169. template <class ParentChan>
  170. class AlterVideoChannel : public PairedVideoChannels<ParentChan>
  171. {
  172. typedef PairedVideoChannels<ParentChan> Parent;
  173. int toggle_;
  174. public:
  175. virtual ErrorCode Create();
  176. virtual void AddSRB( PHW_STREAM_REQUEST_BLOCK pSrb );
  177. virtual bool RemoveSRB( PHW_STREAM_REQUEST_BLOCK pSrb );
  178. AlterVideoChannel( VideoStream aStrm, VideoChannel &chan );
  179. };
  180. /* Class: VBIChannel
  181. * Purpose: Implements functionality for the VBI field
  182. */
  183. class VBIChannel : public VideoChannel
  184. {
  185. typedef VideoChannel Parent;
  186. // Channel Change information
  187. public:
  188. bool Dirty_;
  189. KS_TVTUNER_CHANGE_INFO TVTunerChangeInfo_;
  190. KS_VBIINFOHEADER VBIInfoHeader_;
  191. virtual void Interrupt( PVOID pTag, bool skipped );
  192. virtual void ChangeNotification( PHW_STREAM_REQUEST_BLOCK pSrb );
  193. VBIChannel( VideoStream aStrm );
  194. void SetVBIInfHdr( const KS_VBIINFOHEADER &vbiHdr );
  195. };
  196. /* Class: VBIAlterChannel
  197. * Purpose: Implements alternating VBI fields
  198. */
  199. class VBIAlterChannel : public AlterVideoChannel<VBIChannel>
  200. {
  201. typedef AlterVideoChannel<VBIChannel> Parent;
  202. public:
  203. void SetVidHdr( const KS_DATAFORMAT_VBIINFOHEADER &df );
  204. void SetVidHdr2( const KS_DATAFORMAT_VBIINFOHEADER &df );
  205. VBIAlterChannel( VideoStream aStrm, VBIChannel &chan );
  206. };
  207. inline VBIChannel::VBIChannel( VideoStream aStrm ) : VideoChannel( aStrm ),
  208. Dirty_( false )
  209. {}
  210. inline void DumpVbiInfoHeader( const KS_VBIINFOHEADER &vbiHdr )
  211. {
  212. // typedef struct tagKS_VBIINFOHEADER {
  213. // ULONG StartLine; // inclusive
  214. // ULONG EndLine; // inclusive
  215. // ULONG SamplingFrequency; // Hz.
  216. // ULONG MinLineStartTime; // microSec * 100 from HSync LE
  217. // ULONG MaxLineStartTime; // microSec * 100 from HSync LE
  218. // ULONG ActualLineStartTime; // microSec * 100 from HSync LE
  219. // ULONG ActualLineEndTime; // microSec * 100 from HSync LE
  220. // ULONG VideoStandard; // KS_AnalogVideoStandard*
  221. // ULONG SamplesPerLine;
  222. // ULONG StrideInBytes; // May be > SamplesPerLine
  223. // ULONG BufferSize; // Bytes
  224. // } KS_VBIINFOHEADER, *PKS_VBIINFOHEADER;
  225. DebugOut((0, "KS_VBIINFOHEADER at address %x\n", &vbiHdr));
  226. DUMP(vbiHdr.StartLine);
  227. DUMP(vbiHdr.EndLine);
  228. DUMP(vbiHdr.SamplingFrequency);
  229. DUMP(vbiHdr.MinLineStartTime);
  230. DUMP(vbiHdr.MaxLineStartTime);
  231. DUMP(vbiHdr.ActualLineStartTime);
  232. DUMP(vbiHdr.ActualLineEndTime);
  233. DUMP(vbiHdr.VideoStandard);
  234. DUMP(vbiHdr.SamplesPerLine);
  235. DUMP(vbiHdr.StrideInBytes);
  236. DUMP(vbiHdr.BufferSize);
  237. }
  238. inline void VBIChannel::SetVBIInfHdr( const KS_VBIINFOHEADER &vbiHdr )
  239. {
  240. VBIInfoHeader_ = vbiHdr;
  241. }
  242. inline VBIAlterChannel::VBIAlterChannel( VideoStream aStrm, VBIChannel &chan )
  243. : AlterVideoChannel<VBIChannel>( aStrm, chan )
  244. {}
  245. template <class ParentChan>
  246. inline AlterVideoChannel<ParentChan>::AlterVideoChannel( VideoStream aStrm, VideoChannel &chan )
  247. : Parent( aStrm, chan ), toggle_( 0 )
  248. {}
  249. inline void VideoChannel::SetSRB( PHW_STREAM_REQUEST_BLOCK srb )
  250. {
  251. pSRB_ = srb;
  252. }
  253. /* Method: AlterVideoChannel::AddSRB
  254. * Purpose: This method dispatches the SRB to the next appropriate channel
  255. * Input: pSrb:
  256. */
  257. template <class ParentChan>
  258. void AlterVideoChannel<ParentChan>::AddSRB( PHW_STREAM_REQUEST_BLOCK pSrb )
  259. {
  260. if ( !toggle_ ) {
  261. // first buffer goes to the slave channel as it comes out of the
  262. // decoder first
  263. DebugOut((1, "slave.AddSRB(%x)\n", pSrb));
  264. slave.AddSRB( pSrb );
  265. } else {
  266. DebugOut((1, "parent.AddSRB(%x)\n", pSrb));
  267. Parent::AddSRB( pSrb );
  268. }
  269. toggle_++;
  270. toggle_ %= 2;
  271. }
  272. /* Method: AlterVideoChannel::RemoveSRB
  273. * Purpose: Just calls into each channel in hope one of them will find the SRB
  274. * Input: pSRB
  275. * Output: None
  276. */
  277. template <class ParentChan>
  278. bool AlterVideoChannel<ParentChan>::RemoveSRB( PHW_STREAM_REQUEST_BLOCK pSrb )
  279. {
  280. // one or the other will pick it up
  281. bool b1 = slave.RemoveSRB( pSrb );
  282. bool b2 = Parent::RemoveSRB( pSrb );
  283. if( !b1 && !b2 )
  284. {
  285. DebugOut((1, "AlterVideoChannel<ParentChan>::RemoveSRB - RemoveSRB failed\n"));
  286. }
  287. return ( b1 || b2 );
  288. }
  289. /* Method: AlterVideoChannel::Create
  290. * Purpose: Sets the slave video params and calls into parent to do the work
  291. * Input: pSRB
  292. * Output: None
  293. */
  294. template <class ParentChan>
  295. ErrorCode AlterVideoChannel<ParentChan>::Create()
  296. {
  297. slave.SetVidHdr( VidHeader_ );
  298. return Parent::Create();
  299. }
  300. inline PHW_STREAM_REQUEST_BLOCK VideoChannel::GetSRB()
  301. {
  302. return pSRB_;
  303. }
  304. inline void DumpVideoInfoHeader(const KS_VIDEOINFOHEADER &rVidHdr)
  305. {
  306. DebugOut((0, "-----------------------------------------\n"));
  307. DebugOut((0, "setting KS_VIDEOINFOHEADER\n"));
  308. DebugOut((0, "-----------------------------------------\n"));
  309. DebugOut((0, "rcSource (%d,%d,%d,%d)\n",
  310. rVidHdr.rcSource.left,
  311. rVidHdr.rcSource.top,
  312. rVidHdr.rcSource.right,
  313. rVidHdr.rcSource.bottom));
  314. DebugOut((0, "rcTarget (%d,%d,%d,%d)\n",
  315. rVidHdr.rcTarget.left,
  316. rVidHdr.rcTarget.top,
  317. rVidHdr.rcTarget.right,
  318. rVidHdr.rcTarget.bottom));
  319. DebugOut((0, "dwBitRate (%u)\n", rVidHdr.dwBitRate));
  320. DebugOut((0, "dwBitErrorRate (%u)\n", rVidHdr.dwBitErrorRate));
  321. DebugOut((0, "bmiHeader\n"));
  322. DebugOut((0, " biSize (%d)\n", rVidHdr.bmiHeader.biSize));
  323. DebugOut((0, " biWidth (%d)\n", rVidHdr.bmiHeader.biWidth));
  324. DebugOut((0, " biHeight (%d)\n", rVidHdr.bmiHeader.biHeight));
  325. DebugOut((0, " biPlanes (%d)\n", rVidHdr.bmiHeader.biPlanes));
  326. DebugOut((0, " biBitCount (%d)\n", rVidHdr.bmiHeader.biBitCount));
  327. DebugOut((0, " biCompression (%d)\n", rVidHdr.bmiHeader.biCompression));
  328. DebugOut((0, " biSizeImage (%d)\n", rVidHdr.bmiHeader.biSizeImage));
  329. DebugOut((0, " biXPelsPerMeter (%d)\n", rVidHdr.bmiHeader.biXPelsPerMeter));
  330. DebugOut((0, " biYPelsPerMeter (%d)\n", rVidHdr.bmiHeader.biYPelsPerMeter));
  331. DebugOut((0, " biClrUsed (%d)\n", rVidHdr.bmiHeader.biClrUsed));
  332. DebugOut((0, " biClrImportant (%d)\n", rVidHdr.bmiHeader.biClrImportant));
  333. }
  334. inline void VideoChannel::SetVidHdr( const KS_VIDEOINFOHEADER &rVidHdr )
  335. {
  336. // DumpVideoInfoHeader(rVidHdr);
  337. m_bIsVideoInfo2 = FALSE;
  338. VidHeader_ = rVidHdr;
  339. // save this for paired channels
  340. OrigVidHeader_ = rVidHdr;
  341. }
  342. inline void VideoChannel::SetVidHdr2( const KS_VIDEOINFOHEADER2 &rVidHdr )
  343. {
  344. // DumpVideoInfoHeader(rVidHdr);
  345. m_bIsVideoInfo2 = TRUE;
  346. VidHeader2_ = rVidHdr;
  347. // save this for paired channels
  348. OrigVidHeader2_ = rVidHdr;
  349. }
  350. inline PKS_VIDEOINFOHEADER VideoChannel::GetVidHdr()
  351. {
  352. return &VidHeader_;
  353. }
  354. inline KS_VIDEOINFOHEADER2* VideoChannel::GetVidHdr2()
  355. {
  356. return &VidHeader2_;
  357. }
  358. inline void VideoChannel::SetBufPitch( DWORD dwP )
  359. {
  360. Digitizer_->SetBufPitch( dwP, *OurField_ );
  361. }
  362. inline bool VideoChannel::IsOpen()
  363. {
  364. return State_ >= Open;
  365. }
  366. inline void VideoChannel::SetOpen()
  367. {
  368. State_ = Open;
  369. }
  370. inline void VideoChannel::SetClose()
  371. {
  372. State_ = Closed;
  373. }
  374. inline void VideoChannel::Init( BtPisces *const pCapChip )
  375. {
  376. Digitizer_ = pCapChip;
  377. }
  378. inline StreamState VideoChannel::GetState()
  379. {
  380. return State_;
  381. }
  382. inline VideoStream VideoChannel::GetStreamID()
  383. {
  384. return OurField_->GetStreamID();
  385. }
  386. inline void VideoChannel::SetPaired( bool p )
  387. {
  388. OurField_->SetPaired( p );
  389. }
  390. inline void VideoChannel::SetClockMaster( HANDLE h )
  391. {
  392. DebugOut((1, "SetClockMaster(%x)\n", h ));
  393. hMasterClock = h;
  394. }
  395. inline KSSTATE VideoChannel::GetKSState()
  396. {
  397. return KSState_;
  398. }
  399. inline void VideoChannel::SetKSState( KSSTATE st )
  400. {
  401. KSState_ = st;
  402. }
  403. #if 0
  404. inline LONGLONG VideoChannel::GetFramesNo()
  405. {
  406. LONGLONG PicNumber, DropCnt;
  407. OurField_->GetCounters( PicNumber, DropCnt );
  408. return PicNumber;
  409. }
  410. #endif
  411. inline LONG VideoChannel::GetTimePerFrame()
  412. {
  413. return OurField_->GetStandardTiming();
  414. }
  415. inline void VideoChannel::SetTimePerFrame( LONG time )
  416. {
  417. TimePerFrame_ = time;
  418. OurField_->SetStandardTiming( time );
  419. }
  420. inline void VideoChannel::IntNotify( PVOID pTag, bool skipped )
  421. {
  422. Caller_.Notify( pTag, skipped );
  423. }
  424. inline void VideoChannel::SetInterrupt( bool state )
  425. {
  426. OurField_->Interrupt_ = state;
  427. }
  428. inline void VideoChannel::SetCallback( ChanIface *cb )
  429. {
  430. OurField_->SetCallback( cb );
  431. }
  432. #ifdef _MSC_VER
  433. #pragma warning(disable:4355)
  434. #endif
  435. inline VideoChannel::VideoChannel( VideoStream aStrm ) :
  436. NeedNotification_( false ), BufQue_(), Caller_( this ), Stream_( aStrm ),
  437. OurField_( NULL ), State_( Closed ), pSRB_( NULL ), VidHeader_(), Requests_(),
  438. dwBufferOffset_( 0 ), hMasterClock( NULL ), TimePerFrame_( 333667 )
  439. {
  440. m_bIsVideoInfo2 = FALSE;
  441. #ifdef ENABLE_DDRAW_STUFF
  442. bKernelDirectDrawRegistered = FALSE;
  443. hUserDirectDrawHandle = NULL;
  444. hKernelDirectDrawHandle = NULL;
  445. bPreEventOccurred = FALSE;
  446. bPostEventOccurred = FALSE;
  447. #endif
  448. // VS_Field1 is defined as 0
  449. FieldType_ = aStrm & 0x01 ? KS_VIDEO_FLAG_FIELD2 : KS_VIDEO_FLAG_FIELD1;
  450. }
  451. template <class ParentChan>
  452. StreamType PairedVideoChannels<ParentChan>::GetStreamType()
  453. {
  454. return Paired;
  455. }
  456. /* Method: PairedVideoChannel::Create
  457. * Purpose: Creates both streams
  458. * Input: None
  459. * Output: None
  460. */
  461. template <class ParentChan>
  462. ErrorCode PairedVideoChannels<ParentChan>::Create()
  463. {
  464. if ( slave.Create() == Success ) {
  465. Digitizer_->SetPlanarAdjust( 0 );
  466. return Parent::Create();
  467. }
  468. return Fail;
  469. }
  470. /* Method: PairedVideoChannels::Start
  471. * Purpose: Starts both channels
  472. * Input: None
  473. * Output: None
  474. */
  475. template <class ParentChan>
  476. void PairedVideoChannels<ParentChan>::Start()
  477. {
  478. slave.Start();
  479. Parent::Start();
  480. }
  481. /* Method: PairedVideoChannels::Stop
  482. * Purpose: Stops both channels
  483. * Input: None
  484. * Output: None
  485. */
  486. template <class ParentChan>
  487. ErrorCode PairedVideoChannels<ParentChan>::Stop()
  488. {
  489. slave.Stop();
  490. Parent::Stop();
  491. return Success;
  492. }
  493. /* Method: PairedVideoChannels::Pause
  494. * Purpose: Pauses both channels
  495. * Input: None
  496. * Output: None
  497. */
  498. template <class ParentChan>
  499. ErrorCode PairedVideoChannels<ParentChan>::Pause()
  500. {
  501. if ( bIsVBI() )
  502. {
  503. Digitizer_->PairedPause( (VBIEStartLocation + DistBetweenProgs) );
  504. }
  505. else
  506. {
  507. Digitizer_->PairedPause( (EvenStartLocation + DistBetweenProgs) );
  508. }
  509. State_ = Paused;
  510. return Success;
  511. }
  512. #endif __VXDVIDCH_H