www.pudn.com > mediator15src.zip > StateManager.h


/* 
 * StateManager.h 
 * Copyright (C) 2002 Arno Hornberger  
 * Original Version Copyright (C) Alberto Vigata - January 2000 - ultraflask@yahoo.com 
 * 
 * This file is part of MPEG Mediator, a free MPEG stream converter. 
 * 
 * MPEG Mediator 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. 
 * 
 * MPEG Mediator 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, write to the Free Software 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */ 
 
#include "stdafx.h" 
#include  
#include  
 
#ifndef STATEMANAGER_H 
#define STATEMANAGER_H 
 
#define AVI_BLOCK_MARK 0xED0C700C 
// #define MAX_BLOCK_SIZE 4096 
 
// This class manages, the storage 
// of the state of the different codecs 
 
class CStateManager 
{ 
	public: 
		struct TStateHeader 
		{ 
			DWORD Mark;        
			int   blockSize; 
			DWORD fccHandler;   // video fccHandler 
			long  lQuality; 
			long  lKeyRate; 
			long	lDataRate; 
			HIC   hic;          // Hic of the opened compression driver 
 
			HACMDRIVERID hadid; // ID of the audio driver to be used. hadid only has  
                        // validity at runtime and must be checked before using it. 
			bool  HQAudioCompression; 
			int   wfxSize;      // 0 for no wfx. wfx Follows 
		}; 
 
		CStateManager() 
		{ 
			m_pBuf = NULL; 
			Reset(); 
		}; 
 
		~CStateManager() 
		{ 
			if (m_pBuf) 
				delete []m_pBuf; 
		}; 
		// Gets from a memory block all the states 
		bool GetFromMemoryBlock(PBYTE block); 
		// Writes to a memory block all the states 
		bool SetToMemoryBlock(PBYTE block); 
		// Guess if we have a state 
//		bool StateIsValid(){ return m_pBuf ? true : false; }; 
		// Gets the state with fccHandler. Returns false if not found 
		bool GetState(DWORD fccHandler, PBYTE *pBlock, int *blockSize); 
		// Set the state 
		bool SetState(DWORD fccHandler, PBYTE block, int blockSize); 
//		void InvalidState(){ if (m_pBuf) delete []m_pBuf; m_pBuf = 0; }; 
 
		bool SetWfx(WAVEFORMATEX *wfx, int wfxSize); 
		int GetWfxSize() { return ((TStateHeader *)m_pBuf)->wfxSize; }; 
		DWORD GetFccHandler() { return ((TStateHeader *)m_pBuf)->fccHandler; }; 
		int GetBlockSize() { return ((TStateHeader *)m_pBuf)->blockSize; }; 
		HACMDRIVERID GetAcmDriverID() { return ((TStateHeader *)m_pBuf)->hadid; }; 
		HIC GetHic() { return ((TStateHeader *)m_pBuf)->hic; } 
 
		int GetHeaderSize() { return sizeof(TStateHeader); }; 
		void SetBlockSize(int size) { ((TStateHeader *)m_pBuf)->blockSize = size; }; 
		void SetWfxSize(int size) { ((TStateHeader *)m_pBuf)->wfxSize = size; }; 
		void SetFccHandler(DWORD fccHandler) { ((TStateHeader *)m_pBuf)->fccHandler = fccHandler; }; 
 
		long GetQuality() { return ((TStateHeader *)m_pBuf)->lQuality; }; 
		long GetKeyRate() { return ((TStateHeader *)m_pBuf)->lKeyRate; }; 
		long GetDataRate() { return ((TStateHeader *)m_pBuf)->lDataRate; }; 
		 
		void SetQuality(long lQuality) { ((TStateHeader *)m_pBuf)->lQuality = lQuality; }; 
		void SetKeyRate(long lKeyRate) { ((TStateHeader *)m_pBuf)->lKeyRate = lKeyRate; }; 
		void SetDataRate(long lDataRate) { ((TStateHeader *)m_pBuf)->lDataRate = lDataRate; }; 
		 
		void SetAcmDriverID(HACMDRIVERID hadid) { ((TStateHeader *)m_pBuf)->hadid = hadid; }; 
		void SetHic(HIC hic) { ((TStateHeader *)m_pBuf)->hic = hic; } 
		bool IsHQAudio() { return ((TStateHeader *)m_pBuf)->HQAudioCompression; } 
		void SetHQAudio(bool bIsHq) { ((TStateHeader *)m_pBuf)->HQAudioCompression = bIsHq; } 
		void Reset(); 
 
		WAVEFORMATEX *GetWfx() 
		{ 
			if (GetWfxSize()) 
				return (WAVEFORMATEX *)(m_pBuf + sizeof TStateHeader);  
			else 
				return NULL; 
		}; 
 
	private: 
		bool GetStatePos(DWORD fccHandler, int *pos); 
 
		PBYTE m_pBuf; 
}; 
 
#endif