⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fmfcdecfilter.cpp

📁 SAMSUNG S3C6410 CPU BSP for winmobile6
💻 CPP
📖 第 1 页 / 共 2 页
字号:

		/////////////////////////////////////
		///   4. Get stream information   ///
		/////////////////////////////////////
		SsbSipMPEG4DecodeGetConfig(decode_ctx, MPEG4_DEC_GETCONF_STREAMINFO, &stream_info);
		m_Width  = stream_info.width;
		m_Height = stream_info.height;

		m_MP4IsFirstTransform = FALSE;
	}
	else {
		////////////////////////////////////////////////
		// 2. Data copy								  //
		////////////////////////////////////////////////
		pStrmBuf = (BYTE*) SsbSipMPEG4DecodeGetInBuf(decode_ctx, dwBytesToRead);
		memcpy(pStrmBuf, pDataIn, dwBytesToRead);
	}

	////////////////////////////////////////////////
	// 3. Decode Frames							  //
	////////////////////////////////////////////////
	if (SsbSipH264DecodeExe(decode_ctx, dwBytesToRead) != SSBSIP_MPEG4_DEC_RET_OK) {
		RETAILMSG(1,(L"H.264 Decoder Configuration Failed.\n"));
		return 0;
	}


	/////////////////////////////////////
	///   4. Get YUV data   ///
	/////////////////////////////////////
	m_pFrmBuf = (BYTE*) SsbSipMPEG4DecodeGetOutBuf(decode_ctx, &m_FrmSize);

	return S_OK;
}


//
// H264Transform
//
HRESULT CMFCDecFilter::H264Decode(IMediaSample* pSample)
{
	BYTE						*pDataIn;
	HRESULT						hr;
	unsigned int					dwBytesToRead;
	BYTE						*pStrmBuf;
	SSBSIP_H264_STREAM_INFO    	stream_info;


	hr = pSample->GetPointer(&pDataIn);
	if (FAILED(hr))
		return hr;

	dwBytesToRead = pSample->GetActualDataLength();

	////////////////////////////////////////////////
	// 1. Decoder init							  //
	////////////////////////////////////////////////
	if(m_H264IsFirstTransform) {

		decode_ctx = SsbSipH264DecodeInit();
		if (decode_ctx == NULL) {
			RETAILMSG(1,(L"[MFC Filter] SsbSipH264DecodeInit Failed.\n"));
			return 0;

		}

		////////////////////////////////////////////////
		// 2. Data copy								  //
		////////////////////////////////////////////////
		pStrmBuf = (BYTE*) SsbSipH264DecodeGetInBuf(decode_ctx, dwBytesToRead);
		memcpy(pStrmBuf, pDataIn, dwBytesToRead);
		pStrmBuf += dwBytesToRead;
		pStrmBuf[0] = 0x00;
		pStrmBuf[1] = 0x00;
		pStrmBuf[2] = 0x00;
		pStrmBuf[3] = 0x01;

		////////////////////////////////////////////////
		// 3. Decoder Init							  //
		////////////////////////////////////////////////
		if (SsbSipH264DecodeExe(decode_ctx, dwBytesToRead) != SSBSIP_H264_DEC_RET_OK) {
			RETAILMSG(1,(L"H.264 Decoder Configuration Failed.\n"));
			return 0;
		}

		/////////////////////////////////////
		///   4. Get stream information   ///
		/////////////////////////////////////
		SsbSipH264DecodeGetConfig(decode_ctx, H264_DEC_GETCONF_STREAMINFO, &stream_info);
		m_Width  = stream_info.width;
		m_Height = stream_info.height;
	
		m_H264IsFirstTransform = FALSE;
	}
	else {
		////////////////////////////////////////////////
		// 2. Data copy								  //
		////////////////////////////////////////////////
		pStrmBuf = (BYTE*) SsbSipH264DecodeGetInBuf(decode_ctx, dwBytesToRead);
		memcpy(pStrmBuf, pDataIn, dwBytesToRead);
		pStrmBuf += dwBytesToRead;
		pStrmBuf[0] = 0x00;
		pStrmBuf[1] = 0x00;
		pStrmBuf[2] = 0x00;
		pStrmBuf[3] = 0x01;
	}

	////////////////////////////////////////////////
	// 3. Decode Frames							  //
	////////////////////////////////////////////////
	if (SsbSipH264DecodeExe(decode_ctx, dwBytesToRead) != SSBSIP_H264_DEC_RET_OK) {
		RETAILMSG(1,(L"H.264 Decoder Configuration Failed.\n"));
		return 0;
	}

	/////////////////////////////////////
	///   5. Get YUV data   ///
	/////////////////////////////////////
	m_pFrmBuf = (BYTE*) SsbSipH264DecodeGetOutBuf(decode_ctx, &m_FrmSize);

	return S_OK;
}


//
// H264Transform
//
HRESULT CMFCDecFilter::VC1Decode(IMediaSample* pSample)
{
	BYTE						*pDataIn;
	HRESULT						hr;
	unsigned int					dwBytesToRead;
	BYTE						*pStrmBuf;
	SSBSIP_H264_STREAM_INFO    	stream_info;


	hr = pSample->GetPointer(&pDataIn);
	if (FAILED(hr))
		return hr;

	dwBytesToRead = pSample->GetActualDataLength();

	////////////////////////////////////////////////
	// 1. Decoder init							  //
	////////////////////////////////////////////////
	if(m_VC1IsFirstTransform) {

		decode_ctx = SsbSipVC1DecodeInit();
		if (decode_ctx == NULL) {
			RETAILMSG(1,(L"[MFC Filter] SsbSipH264DecodeInit Failed.\n"));
			return 0;

		}

		////////////////////////////////////////////////
		// 2. Data copy								  //
		////////////////////////////////////////////////
		pStrmBuf = (BYTE*) SsbSipVC1DecodeGetInBuf(decode_ctx, dwBytesToRead);
		memcpy(pStrmBuf, pDataIn, dwBytesToRead);
		pStrmBuf += dwBytesToRead;
		pStrmBuf[0] = 0x00;
		pStrmBuf[1] = 0x00;
		pStrmBuf[2] = 0x00;
		pStrmBuf[3] = 0x01;

		////////////////////////////////////////////////
		// 3. Decoder Init							  //
		////////////////////////////////////////////////
		if (SsbSipVC1DecodeExe(decode_ctx, dwBytesToRead) != SSBSIP_H264_DEC_RET_OK) {
			RETAILMSG(1,(L"H.264 Decoder Configuration Failed.\n"));
			return 0;
		}


		/////////////////////////////////////
		///   4. Get stream information   ///
		/////////////////////////////////////
		SsbSipVC1DecodeGetConfig(decode_ctx, H264_DEC_GETCONF_STREAMINFO, &stream_info);
		m_Width = stream_info.width;
		m_Height = stream_info.height;

		m_VC1IsFirstTransform = FALSE;
	}
	else {
		////////////////////////////////////////////////
		// 2. Data copy								  //
		////////////////////////////////////////////////
		pStrmBuf = (BYTE*) SsbSipVC1DecodeGetInBuf(decode_ctx, dwBytesToRead);
		memcpy(pStrmBuf, pDataIn, dwBytesToRead);
		pStrmBuf += dwBytesToRead;
		pStrmBuf[0] = 0x00;
		pStrmBuf[1] = 0x00;
		pStrmBuf[2] = 0x00;
		pStrmBuf[3] = 0x01;
	}

	////////////////////////////////////////////////
	// 3. Decode Frames							  //
	////////////////////////////////////////////////
	if (SsbSipVC1DecodeExe(decode_ctx, dwBytesToRead) != SSBSIP_H264_DEC_RET_OK) {
		RETAILMSG(1,(L"H.264 Decoder Configuration Failed.\n"));
		return 0;
	}

	/////////////////////////////////////
	///   5. Get YUV data   ///
	/////////////////////////////////////
	m_pFrmBuf = (BYTE*) SsbSipVC1DecodeGetOutBuf(decode_ctx, &m_FrmSize);
	
	return S_OK;
}

// WMV9 Transform
//
HRESULT CMFCDecFilter::WMV9Decode(IMediaSample* pSample)
{
	
	BYTE						*pDataIn;
	HRESULT						hr;
	unsigned char       				*sourcebuff;
	unsigned int					dwBytesToRead, index=0;
	BYTE						*pStrmBuf;

	SSBSIP_H264_STREAM_INFO    stream_info;
		

	hr = pSample->GetPointer(&pDataIn);
	if (FAILED(hr))
		return hr;


	dwBytesToRead = pSample->GetActualDataLength();

	////////////////////////////////////////////////
	// 1. Decoder init							  //
	////////////////////////////////////////////////
	if(m_WMV9sFirstTransform) {
		decode_ctx = SsbSipVC1DecodeInit();
		if (decode_ctx == NULL) {
			RETAILMSG(0,(L"[MFC Filter] wmvDecodeInit Failed.\n"));
			return 0;

		}
		
		////////////////////////////////////////////////
		// 2. Data copy								  //
		////////////////////////////////////////////////
		pStrmBuf = (BYTE*) SsbSipVC1DecodeGetInBuf(decode_ctx, dwBytesToRead);

		
		index =0;
		
		//indefnite stream
		pStrmBuf[index]   = 0xFF;
		pStrmBuf[index+1] = 0xFF ;
		pStrmBuf[index+2] = 0xFF ;
		pStrmBuf[index+3] = 0xc5;
		index+=4;

		pStrmBuf[index]   = 0x04;
		pStrmBuf[index+1] = 0x00;
		pStrmBuf[index+2] = 0x00;
		pStrmBuf[index+3] = 0x00;
		index+=4;
		
		//struct_c

		pStrmBuf[index]   = m_Wmvdata & 0xFF ;
		pStrmBuf[index+1] = (m_Wmvdata >>8)& 0xFF ;
		pStrmBuf[index+2] = (m_Wmvdata>>16) & 0xFF;
		pStrmBuf[index+3] = (m_Wmvdata>>24) & 0xFF;
		index+=4;
		
		//struct_a_vert
		
		pStrmBuf[index]	  = m_Height & 0xFF ;
		pStrmBuf[index+1] = (m_Height>>8) & 0xFF ;
		pStrmBuf[index+2] = (m_Height>>16) & 0xFF;
		pStrmBuf[index+3] = (m_Height>>24) & 0xFF;
		index+=4;
		
		//struct_a_horz
		
		pStrmBuf[index]   = m_Width & 0xFF ;
		pStrmBuf[index+1] = (m_Width>>8) & 0xFF ;
		pStrmBuf[index+2] = (m_Width>>16) & 0xFF;
		pStrmBuf[index+3] = (m_Width>>24) & 0xFF;
		index+=4;
		
		//const_0C
		pStrmBuf[index]   = 0x0C;
		pStrmBuf[index+1] = 0x00;
		pStrmBuf[index+2] = 0x00;
		pStrmBuf[index+3] = 0x00;
		index+=4;
		
		//struct_b_1
		pStrmBuf[index]   = 0x00;
		pStrmBuf[index+1] = 0x00;
		pStrmBuf[index+2] = 0x00;
		pStrmBuf[index+3] = 0x00;
		index+=4;
		
		//struct_b_2
		pStrmBuf[index]   = 0x00;
		pStrmBuf[index+1] = 0x00;
		pStrmBuf[index+2] = 0x00;
		pStrmBuf[index+3] = 0x00;
		index+=4;
		
		//struct_b_3
		pStrmBuf[index]   = 0x00;
		pStrmBuf[index+1] = 0x00;
		pStrmBuf[index+2] = 0x00;
		pStrmBuf[index+3] = 0x00;
		index+=4;
		
		//pStrmBuf +=index;
		
		//frame data
		//index;
		pStrmBuf[index]   = dwBytesToRead & 0xFF;
		pStrmBuf[index+1] = (dwBytesToRead>>8) & 0xFF;
		pStrmBuf[index+2] = (dwBytesToRead>>16) & 0xFF;
		pStrmBuf[index+3] = 0x80;
		index+=4;

		pStrmBuf[index]   = 0x00;
		pStrmBuf[index+1] = 0x00;
		pStrmBuf[index+2] = 0x00;
		pStrmBuf[index+3] = 0x00;
		index+=4;
		

		pStrmBuf +=index;

		memcpy(pStrmBuf, pDataIn, dwBytesToRead);
		pStrmBuf += dwBytesToRead;


		
		////////////////////////////////////////////////
		// 3. Decoder Init							  //
		////////////////////////////////////////////////
		if (SsbSipVC1DecodeExe(decode_ctx, dwBytesToRead) != SSBSIP_H264_DEC_RET_OK) {
			RETAILMSG(1,(L"WMV9 Decoder decoding 1 Failed.\n"));
			return 0;
		}

		/////////////////////////////////////
		///   4. Get stream information   ///
		/////////////////////////////////////
		SsbSipVC1DecodeGetConfig(decode_ctx, H264_DEC_GETCONF_STREAMINFO, &stream_info);
		m_Width = stream_info.width;
		m_Height = stream_info.height;
		
		m_WMV9sFirstTransform = FALSE;
	}
	else {
		////////////////////////////////////////////////
		// 2. Data copy								  //
		////////////////////////////////////////////////
		

		pStrmBuf = (BYTE*) SsbSipVC1DecodeGetInBuf(decode_ctx, dwBytesToRead);

		pStrmBuf[index]   = dwBytesToRead & 0xFF;
		pStrmBuf[index+1] = (dwBytesToRead>>8) & 0xFF;
		pStrmBuf[index+2] = (dwBytesToRead>>16) & 0xFF;
		pStrmBuf[index+3] = 0x00;
		index+=4;

		pStrmBuf[index]   = 0x00;
		pStrmBuf[index+1] = 0x00;
		pStrmBuf[index+2] = 0x00;
		pStrmBuf[index+3] = 0x00;
		index+=4;

		pStrmBuf +=8;
		memcpy(pStrmBuf, pDataIn, dwBytesToRead);
	
		pStrmBuf += dwBytesToRead;
	}

	////////////////////////////////////////////////
	// 3. Decode Frames							  //
	////////////////////////////////////////////////
	if (SsbSipVC1DecodeExe(decode_ctx, dwBytesToRead) != SSBSIP_H264_DEC_RET_OK) {
		RETAILMSG(1,(L"WMV9 Decoder decoding  Failed.\n"));
		return 0;
	}

	/////////////////////////////////////
	///   5. Get YUV data   ///
	/////////////////////////////////////
	m_pFrmBuf = (BYTE*) SsbSipVC1DecodeGetOutBuf(decode_ctx, &m_FrmSize);
	
	return S_OK;
}




HRESULT CMFCDecFilter::Receive(IMediaSample* pSample)
{
	HRESULT				hr;

	switch (m_StrmType) {
		case RAW_STRM_TYPE_M4V:
			hr = MP4Decode(pSample);
			break;

		case RAW_STRM_TYPE_H264RAW:
			hr = H264Decode(pSample);
			break;

		case RAW_STRM_TYPE_RCV:
			hr = VC1Decode(pSample);
			break;
			
		case VIDEO_STRM_TYPE_WMV9:
			hr = WMV9Decode(pSample);
			break;

		default:
			RETAILMSG(1, (L"[MFC Filter]unsupported file type\n"));
			return E_FAIL;
	}

	if (FAILED(hr))
		return hr;

	return CTransformFilter::Receive(pSample);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -