#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) || (mfc_args.get_buf_addr.ret_code < 0)) {
LOG_MSG(LOG_ERROR, "SsbSipH264EncodeGetOutBuf", "Failed in get LINE_BUF address.\n");
return NULL;
}
*size = pCTX->enc_strm_size;
return (void *)mfc_args.get_buf_addr.out_buf_addr;
}
int SsbSipH264EncodeSetConfig(void *openHandle, H264_ENC_CONF conf_type, void *value)
{
_MFCLIB_H264_ENC *pCTX;
MFC_ARGS mfc_args;
int r;
unsigned int num_slices[2];
////////////////////////////////
// Input Parameter Checking //
////////////////////////////////
if (openHandle == NULL) {
LOG_MSG(LOG_ERROR, "SsbSipH264EncodeSetConfig", "openHandle is NULL\n");
return SSBSIP_H264_ENC_RET_ERR_INVALID_HANDLE;
}
if (value == NULL) {
LOG_MSG(LOG_ERROR, "SsbSipH264EncodeSetConfig", "value is NULL\n");
return SSBSIP_H264_ENC_RET_ERR_INVALID_PARAM;
}
pCTX = (_MFCLIB_H264_ENC *) openHandle;
switch (conf_type) {
case H264_ENC_SETCONF_NUM_SLICES:
num_slices[0] = ((unsigned int *)value)[0];
num_slices[1] = ((unsigned int *)value)[1];
printf("num slices[0] = %d\n", num_slices[0]);
printf("num slices[1] = %
没有合适的资源?快使用搜索试试~ 我知道了~
ffmpeg+x264软编码 tiny6410硬编码 jrtplib 发送
共30个文件
h:15个
makefile:6个
c:4个
5星 · 超过95%的资源 需积分: 50 252 下载量 104 浏览量
2013-03-02
13:29:23
上传
评论 8
收藏 33KB ZIP 举报
温馨提示
ffmpeg+x264软编码 tiny6410硬编码 jrtplib 发送
资源推荐
资源详情
资源评论
收起资源包目录
h264+rtp.zip (30个子文件)
h264+rtp
capture
v4l2capture.h 897B
v4l2capture.cpp 5KB
Makefile 238B
build-sh 76B
encode
Makefile 415B
captureAndcompress.cpp 9KB
captureAndcompress.h 546B
main.cpp 122B
rtpsend
rtpsend.h 548B
rtpsend.cpp 5KB
Makefile 290B
Makefile 1KB
hardencode
Common
lcd.h 1KB
performance.c 400B
post.h 3KB
MfcDrvParams.h 4KB
LogMsg.h 390B
LogMsg.c 1KB
videodev2_s3c.h 2KB
MfcDriver.h 2KB
Makefile 585B
mfc.h 2KB
performance.h 293B
videodev2.h 29KB
mfcapi.c 2KB
SsbSipH264Encode.c 10KB
mfcapi.h 471B
s3c_pp.h 3KB
Makefile 713B
SsbSipH264Encode.h 2KB
共 30 条
- 1
wisha1989
- 粉丝: 10
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页