#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] = %
没有合适的资源?快使用搜索试试~ 我知道了~
v4l2视频采集与传输
共35个文件
c:8个
o:8个
h:8个
5星 · 超过95%的资源 需积分: 50 130 下载量 82 浏览量
2013-05-12
19:34:21
上传
评论
收藏 55KB RAR 举报
温馨提示
视频采集与传输,利用v4l2采集视频,H264编解码视频,UDP视频传输
资源推荐
资源详情
资源评论
收起资源包目录
video_watch.rar (35个子文件)
video_watch
h264_recv
recv_nalu.o 3KB
h264_recv 13KB
h264_play.c 3KB
main.c 1002B
h264_play.o 4KB
h264_play.h 198B
play 13KB
make 74B
Makefile 356B
main.o 2KB
recv_nalu.c 3KB
recv_nalu.h 242B
h264_send
capture.cpp 6KB
capture.h 954B
capture 7KB
capture.o 5KB
main.c 4KB
send_nalu 4KB
send_nalu.o 5KB
SsbSipH264Encode.c 10KB
LogMsg.o 2KB
capture.c 5KB
send_nalu.h 2KB
MfcDrvParams.h 4KB
LogMsg.h 390B
LogMsg.c 1KB
SsbSipH264Encode.o 6KB
h264_send 23KB
MfcDriver.h 2KB
make 165B
h264.h.bak 2KB
Makefile 315B
send_nalu.c 7KB
main.o 5KB
SsbSipH264Encode.h 2KB
共 35 条
- 1
fankun23
- 粉丝: 1
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 2023-04-06-项目笔记 - 第一百十五阶段 - 4.4.2.113全局变量的作用域-113 -2024.04.26
- 2023-04-06-项目笔记 - 第一百十五阶段 - 4.4.2.113全局变量的作用域-113 -2024.04.26
- htmlzwbjq_downyi.com.zip
- 无头单向非循环链表的实现(Test.c)
- 无头单向非循环链表的实现(SList.c)
- 浏览器重定向插件更新文件
- SSA-BP麻雀算法优化BP神经网络多特征分类预测(Matlab实现完整源码和数据)
- 粒子群算法优化BP神经网络PSO-BP的MATLAB代码(数值预测)
- 基于Springboot的一起看书平台.zip
- 无头单向非循环链表的实现(SList.h)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页