SsbSipH264Encode.c ( File view )

  • By rarshion 2014-11-04
  • View(s):131
  • Download(s):3
  • Point(s): 2
			#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
#include <errno.h>
#include <sys/time.h>

#include "MfcDriver.h"
#include "MfcDrvParams.h"

#include "SsbSipH264Encode.h"
//#include "LogMsg.h"


#define _MFCLIB_H264_ENC_MAGIC_NUMBER		0x92242002

typedef struct
{

	int   	magic;
	int  	hOpen;
	int     fInit;
	int     enc_strm_size;
	int		enc_hdr_size;
	
	unsigned int  	width, height;
	unsigned int  	framerate, bitrate;
	unsigned int  	gop_num;
	unsigned char	*mapped_addr;

} _MFCLIB_H264_ENC;


typedef struct {

	int width;
	int height;
	int frameRateRes;
	int frameRateDiv;
	int gopNum;
	int bitrate;

} enc_info_t;


void *SsbSipH264EncodeInit(unsigned int uiWidth,     unsigned int uiHeight,
                           unsigned int uiFramerate, unsigned int uiBitrate_kbps,
                           unsigned int uiGOPNum)
{

	_MFCLIB_H264_ENC	*pCTX;
	int					hOpen;
	unsigned char		*addr;


	//////////////////////////////
	/////     CreateFile     /////
	//////////////////////////////
	hOpen = open(MFC_DEV_NAME, O_RDWR|O_NDELAY);
	if (hOpen < 0) {

		//LOG_MSG(LOG_ERROR, "SsbSipH264EncodeInit", "MFC Open failure.\n");
		return NULL;
	
}

	//////////////////////////////////////////
	//	Mapping the MFC Input/Output Buffer	//
	//////////////////////////////////////////
	// mapping shared in/out buffer between application and MFC device driver
	addr = (unsigned char *) mmap(0, BUF_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, hOpen, 0);
	if (addr == NULL) {

		//LOG_MSG(LOG_ERROR, "SsbSipH264EncodeInit", "MFC Mmap failure.\n");
		return NULL;
	
}

	pCTX = (_MFCLIB_H264_ENC *) malloc(sizeof(_MFCLIB_H264_ENC));
	if (pCTX == NULL) {

		//LOG_MSG(LOG_ERROR, "SsbSipH264EncodeInit", "malloc failed.\n");
		close(hOpen);
		return NULL;
	
}
	memset(pCTX, 0, sizeof(_MFCLIB_H264_ENC));

	pCTX->magic = _MFCLIB_H264_ENC_MAGIC_NUMBER;
	pCTX->hOpen = hOpen;
	pCTX->fInit = 0;
	pCTX->mapped_addr	= addr;

	pCTX->width     = uiWidth;
	pCTX->height    = uiHeight;
	pCTX->framerate = uiFramerate;
	pCTX->bitrate   = uiBitrate_kbps;
	pCTX->gop_num   = uiGOPNum;

	pCTX->enc_strm_size = 0;

	return (void *) pCTX;

}


int SsbSipH264EncodeExe(void *openHandle)
{

	_MFCLIB_H264_ENC	*pCTX;
	int					r;
	MFC_ARGS			mfc_args;


	////////////////////////////////
	//  Input Parameter Checking  //
	////////////////////////////////
	if (openHandle == NULL) {

		//LOG_MSG(LOG_ERROR, "SsbSipH264EncodeExe", "openHandle is NULL\n");
		return SSBSIP_H264_ENC_RET_ERR_INVALID_HANDLE;
	
}

	pCTX  = (_MFCLIB_H264_ENC *) openHandle;

	if (!pCTX->fInit) {

		mfc_args.enc_init.in_width		= pCTX->width;
		mfc_args.enc_init.in_height		= pCTX->height;
		mfc_args.enc_init.in_bitrate	= pCTX->bitrate;
		mfc_args.enc_init.in_gopNum		= pCTX->gop_num;
		mfc_args.enc_init.in_frameRateRes	= pCTX->framerate;
		mfc_args.enc_init.in_frameRateDiv	= 0;


		////////////////////////////////////////////////
		/////          (DeviceIoControl)           /////
		/////       IOCTL_MFC_H264_DEC_INIT        /////
		////////////////////////////////////////////////
		r = ioctl(pCTX->hOpen, IOCTL_MFC_H264_ENC_INIT, &mfc_args); 
		if ((r < 0) || (mfc_args.enc_init.ret_code < 0)) {

			//LOG_MSG(LOG_ERROR, "SsbSipH264EncodeInit", "IOCTL_MFC_H264_ENC_INIT failed.\n");
			return SSBSIP_H264_ENC_RET_ERR_ENCODE_FAIL;
		
}

		pCTX->fInit = 1;

		return SSBSIP_H264_ENC_RET_OK;
	
}
	


	/////////////////////////////////////////////////
	/////           (DeviceIoControl)           /////
	/////       IOCTL_MFC_MPEG4_DEC_EXE         /////
	/////////////////////////////////////////////////
	r = ioctl(pCTX->hOpen, IOCTL_MFC_H264_ENC_EXE, &mfc_args);
	if ((r < 0) || (mfc_args.enc_exe.ret_code < 0)) {

		return SSBSIP_H264_ENC_RET_ERR_ENCODE_FAIL;
	
}

	// Encoded stream size is saved. (This value is returned in SsbSipH264EncodeGetOutBuf)
	pCTX->enc_strm_size = mfc_args.enc_exe.out_encoded_size;

	if(mfc_args.enc_exe.out_header_size > 0) {

		pCTX->enc_hdr_size = mfc_args.enc_exe.out_header_size;
		//LOG_MSG(LOG_TRACE, "SsbSipH264EncodeExe", "HEADER SIZE = %d\n", pCTX->enc_hdr_size);
	
}
	

	return SSBSIP_H264_ENC_RET_OK;

}


int SsbSipH264EncodeDeInit(void *openHandle)
{

	_MFCLIB_H264_ENC  *pCTX;


	////////////////////////////////
	//  Input Parameter Checking  //
	////////////////////////////////
	if (openHandle == NULL) {

		//LOG_MSG(LOG_ERROR, "SsbSipH264EncodeDeInit", "openHandle is NULL\n");
		return SSBSIP_H264_ENC_RET_ERR_INVALID_HANDLE;
	
}

	pCTX  = (_MFCLIB_H264_ENC *) openHandle;


	munmap(pCTX->mapped_addr, BUF_SIZE);
	close(pCTX->hOpen);


	return SSBSIP_H264_ENC_RET_OK;

}


void *SsbSipH264EncodeGetInBuf(void *openHandle, long size)
{

	_MFCLIB_H264_ENC	*pCTX;
	int					r;
	MFC_ARGS			mfc_args;
	

	////////////////////////////////
	//  Input Parameter Checking  //
	////////////////////////////////
	if (openHandle == NULL) {

		//LOG_MSG(LOG_ERROR, "SsbSipH264EncodeGetInBuf", "openHandle is NULL\n");
		return NULL;
	
}
	if ((size < 0) || (size > 0x100000)) {

		//LOG_MSG(LOG_ERROR, "SsbSipH264EncodeGetInBuf", "size is invalid. (size=%d)\n", size);
		return NULL;
	
}

	pCTX  = (_MFCLIB_H264_ENC *) openHandle;


	/////////////////////////////////////////////////
	/////           (DeviceIoControl)           /////
	/////     IOCTL_MFC_GET_INPUT_BUF_ADDR      /////
	/////////////////////////////////////////////////
	mfc_args.get_buf_addr.in_usr_data = (int)pCTX->mapped_addr;
	r = ioctl(pCTX->hOpen, IOCTL_MFC_GET_FRAM_BUF_ADDR, &mfc_args);
	if ((r < 0) || (mfc_args.get_buf_addr.ret_code < 0)) {

		//LOG_MSG(LOG_ERROR, "SsbSipH264EncodeGetInBuf", "Failed in get FRAM_BUF address\n");
		return NULL;
	
}

	return (void *)mfc_args.get_buf_addr.out_buf_addr;

}


void *SsbSipH264EncodeGetOutBuf(void *openHandle, long *size)
{

	_MFCLIB_H264_ENC	*pCTX;
	int					r;
	MFC_ARGS			mfc_args;


	////////////////////////////////
	//  Input Parameter Checking  //
	////////////////////////////////
	if (openHandle == NULL) {

		//LOG_MSG(LOG_ERROR, "SsbSipH264EncodeGetOutBuf", "openHandle is NULL\n");
		return NULL;
	
}
	if (size == NULL) {

		//LOG_MSG(LOG_ERROR, "SsbSipH264EncodeGetOutBuf", "size is NULL.\n");
		return NULL;
	
}

	pCTX  = (_MFCLIB_H264_ENC *) openHandle;

	/////////////////////////////////////////////////
	/////           (DeviceIoControl)           /////
	/////      IOCTL_MFC_GET_STRM_BUF_ADDR      /////
	/////////////////////////////////////////////////
	mfc_args.get_buf_addr.in_usr_data = (int)pCTX->mapped_addr;
	r = ioctl(pCTX->hOpen, IOCTL_MFC_GET_LINE_BUF_ADDR, &mfc_args);
	if ((r < 0) |
...
...
(Please download the complete source code to view)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 2

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
arm_capture.o7.44 kB23-09-14|11:04
arm_capture_init.o6.25 kB23-09-14|11:04
arm_capture_uinit.o2.11 kB23-09-14|11:04
arm_capvideo.o18.83 kB23-09-14|11:04
arm_capvideo_init.o6.44 kB23-09-14|11:04
arm_capvideo_uinit.o2.16 kB23-09-14|11:04
arm_Client.o102.76 kB03-11-14|23:23
arm_ClientPort99.95 kB03-11-14|23:23
arm_Common.o2.89 kB23-09-14|11:04
arm_Connector.o37.29 kB23-09-14|11:04
arm_control146.15 kB04-11-14|12:37
arm_Father9.37 kB23-09-14|08:26
arm_Functions.o2.02 kB23-09-14|11:04
arm_Lock.o1.60 kB23-09-14|11:04
arm_Logger.o7.59 kB23-09-14|11:04
arm_Mutex.o6.47 kB23-09-14|11:04
arm_Sem.o4.98 kB23-09-14|11:04
arm_ShareBuff.o21.13 kB23-09-14|11:04
arm_ShareMemory.o7.59 kB23-09-14|11:04
arm_ShmIPS.o12.88 kB23-09-14|11:04
arm_Socket.o1.16 kB23-09-14|11:04
arm_SocketOps.o5.43 kB23-09-14|11:04
arm_SocketStream.o6.77 kB23-09-14|11:04
arm_SsbSipH264Encode.o4.00 kB23-09-14|11:04
arm_TcpClient.o50.54 kB23-09-14|11:04
arm_Thread.o5.96 kB23-09-14|11:04
arm_Transform.o11.05 kB23-09-14|11:04
arm_Video.o22.58 kB23-09-14|11:04
capture.cpp4.76 kB12-12-13|15:12
capture.cpp~4.76 kB23-11-13|09:17
capture.h1,009.00 B23-11-13|09:17
capture.o5.05 kB23-09-14|11:03
capture_init.cpp9.78 kB12-12-13|14:49
capture_init.cpp~9.78 kB12-12-13|14:49
capture_init.o6.09 kB23-09-14|11:03
capture_uinit.cpp1.32 kB23-11-13|09:17
capture_uinit.o1.78 kB23-09-14|11:03
capvideo.cpp8.17 kB07-01-14|19:34
capvideo.cpp~8.15 kB23-11-13|09:17
capvideo.h527.00 B23-11-13|09:17
capvideo.o12.45 kB23-09-14|11:03
capvideo_init.cpp8.04 kB23-11-13|09:17
capvideo_init.o6.01 kB23-09-14|11:03
capvideo_uinit.cpp1.69 kB23-11-13|09:17
capvideo_uinit.o1.82 kB23-09-14|11:03
Client.cpp6.93 kB03-11-14|23:19
Client.cpp~6.91 kB30-03-14|18:48
Client.hpp1.03 kB23-11-13|09:17
Client.o66.13 kB03-11-14|23:23
Client11_19.pro1.27 kB23-11-13|09:17
ClientPort87.28 kB03-11-14|23:23
Common.cpp358.00 B23-11-13|09:17
Common.hpp308.00 B23-11-13|09:17
Common.o2.57 kB23-09-14|11:03
Connector.cpp2.37 kB23-09-14|10:28
Connector.cpp~2.37 kB16-03-14|20:18
Connector.hpp715.00 B16-03-14|21:59
Connector.hpp~715.00 B23-11-13|09:17
Connector.o24.09 kB23-09-14|11:03
control128.54 kB04-11-14|12:37
Control.cpp11.11 kB04-11-14|12:29
Control.cpp~10.58 kB07-04-14|21:25
DeviceControl.cpp0.00 B23-09-14|11:09
DeviceControl.hpp171.00 B23-09-14|11:09
Father12.37 kB23-09-14|08:25
Father.cpp1.89 kB21-02-14|15:48
Father.cpp~1.89 kB23-11-13|09:17
Functions.cpp852.00 B23-11-13|09:17
Functions.hpp317.00 B23-11-13|09:17
Functions.o1.48 kB23-09-14|11:03
IIPS.hpp328.00 B23-11-13|09:17
IMutex.hpp194.00 B23-11-13|09:17
IPC.hpp824.00 B23-11-13|09:17
Lock.cpp168.00 B23-11-13|09:17
Lock.hpp453.00 B23-11-13|09:17
Lock.o1.21 kB23-09-14|11:03
Logger.cpp1.95 kB23-11-13|09:17
Logger.hpp1.40 kB23-11-13|09:17
Logger.o6.40 kB23-09-14|11:03
LogMsg.c1.22 kB23-11-13|09:17
LogMsg.h370.00 B23-11-13|09:17
main.cpp1.24 kB23-11-13|09:17
makefile4.00 kB09-04-14|22:33
makefile~4.00 kB23-11-13|09:17
MfcDriver.h1.71 kB23-11-13|09:17
MfcDrvParams.h4.41 kB23-11-13|09:17
Mutex.cpp543.00 B23-11-13|09:17
Mutex.hpp284.00 B23-11-13|09:17
Mutex.o5.23 kB23-09-14|11:03
Sem.cpp1.01 kB23-11-13|09:17
Sem.hpp504.00 B23-11-13|09:17
Sem.o4.15 kB23-09-14|11:03
ShareBuff.cpp621.00 B23-11-13|09:17
ShareBuff.hpp301.00 B23-11-13|09:17
ShareBuff.o12.41 kB23-09-14|11:03
ShareMemory.cpp1.31 kB23-11-13|09:17
ShareMemory.hpp706.00 B28-03-14|21:41
ShareMemory.hpp~705.00 B28-03-14|21:25
ShareMemory.o6.66 kB23-09-14|11:03
ShmIPS.cpp797.00 B23-11-13|09:17
ShmIPS.hpp771.00 B23-11-13|09:17
ShmIPS.o9.46 kB23-09-14|11:03
Socket.cpp252.00 B23-11-13|09:17
Socket.hpp304.00 B23-11-13|09:17
Socket.o1.02 kB23-09-14|11:03
SocketOps.cpp2.25 kB23-11-13|09:17
SocketOps.hpp566.00 B23-11-13|09:17
SocketOps.o4.96 kB23-09-14|11:03
SocketStream.cpp2.03 kB23-11-13|09:17
SocketStream.hpp685.00 B23-11-13|09:17
SocketStream.o5.71 kB23-09-14|11:03
SsbSipH264Encode.c9.73 kB23-11-13|09:17
SsbSipH264Encode.h1.85 kB23-11-13|09:17
SsbSipH264Encode.o2.63 kB23-09-14|11:03
struct.hpp1.44 kB23-09-14|10:46
TcpClient.cpp1.22 kB23-11-13|09:17
TcpClient.hpp588.00 B23-11-13|09:17
TcpClient.o31.48 kB23-09-14|11:03
Thread.cpp1.56 kB23-11-13|09:17
Thread.hpp1.07 kB23-11-13|09:17
Thread.o5.08 kB23-09-14|11:03
ThreadAttr.cpp1.71 kB23-11-13|09:17
ThreadAttr.hpp651.00 B23-11-13|09:17
Transform.cpp1.26 kB23-11-13|09:17
Transform.hpp547.00 B23-11-13|09:17
Transform.o7.17 kB23-09-14|11:03
Uncopyable.hpp238.00 B28-03-14|21:30
Uncopyable.hpp~239.00 B28-03-14|21:30
Video.cpp1.05 kB23-11-13|09:17
Video.hpp536.00 B23-11-13|09:17
Video.o13.39 kB23-09-14|11:03
Client2013-12-150.00 B04-11-14|22:07
...
Sponsored links

SsbSipH264Encode.c (337.95 kB)

Need 2 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D