高分求解决!!!S3C6410用Qt写硬件编码程序出问题
之前一直在做S3C6410视频编码的工作,在网上找到了一些资料,再通过实验确实成功地实现了编码。可是当我把这个程序写入我自己的Qt线程中时,却出现了我没见过的错误。先把我自己的程序贴上来吧:
我把编码写成了一个线程,编码的初始化工作也在线程内完成。
Encode::Encode()
{
stopEncodeThread=false;
}
void Encode::run()
{
int start;
int ret;
int frame_count=0;
struct v4l2_capability cap;
struct v4l2_format codec_fmt;
int yuv_cnt;
unsigned char g_yuv[YUV_FRAME_BUFFER_SIZE];
unsigned char *encoded_buf;
long encoded_size;
/*Camera codec initialization*/
if((cam_c_fp = cam_c_init()) < 0)
printf("Encode initilization failed\n");
/* Codec set */
/* Get capability*/
ret=ioctl(cam_c_fp , VIDIOC_QUERYCAP, &cap);
if(ret < 0)
{
printf("V4L2 : ioctl on VIDIOC_QUERYCAP failled\n");
}
/* Check the type - preview(OVERLAY)*/
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
{
printf("V4L2 : Can not capture(V4L2_CAP_VIDEO_CAPTURE is false)\n");
}
/* Set format*/
codec_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
codec_fmt.fmt.pix.width = LCD_WIDTH;
codec_fmt.fmt.pix.height = LCD_HEIGHT;
codec_fmt.fmt.pix.pixelformat= V4L2_PIX_FMT_YUV420;
ret=ioctl(cam_c_fp , VIDIOC_S_FMT, &codec_fmt);
if (ret < 0)
{
printf("V4L2 : ioctl on VIDIOC_S_FMT failled\n");
}
pthread_mutex_lock(&mutex);
enc_handle = mfc_encoder_init(LCD_WIDTH, LCD_HEIGHT, 25, 1000, 30);
fflush(stdout);
encoded_fp = fopen("/sdcard/test.h264", "wb");
/* Codec start*/
start = 1;
ret=ioctl(cam_c_fp, VIDIOC_STREAMON, &start);
if (ret < 0)
{
printf("V4L2 : ioctl on VIDIOC_STREAMON failed\n");
}
for(yuv_cnt=0; ; yuv_cnt++)
{
if(stopEncodeThread==true)
break;
if(frame_count==0)
{
frame_count++;
}
/* read from camera device*/
if(read(cam_c_fp, g_yuv, YUV_FRAME_BUFFER_SIZE)<0)
{printf("can't read") ;}
if(frame_count == 1)
{
encoded_buf = mfc_encoder_exe(enc_handle, g_yuv, YUV_FRAME_BUFFER_SIZE, 1, &encoded_size);
frame_count++;
}
else
encoded_buf = mfc_encoder_exe(enc_handle, g_yuv, YUV_FRAME_BUFFER_SIZE, 0, &encoded_size);
fwrite(encoded_buf, 1, encoded_size, encoded_fp); //write to file
}
/* Codec stop*/
start = 0;
ioctl(cam_c_fp, VIDIOC_STREAMOFF, &start);
mfc_encoder_free(enc_handle);
fclose(encoded_fp);
pthread_mutex_unlock(&mutex);
}
另外还有硬件编码的一个API
unsigned char *mfc_encoder_exe(void *handle, unsigned char *yuv_buf, int frame_size, int first_frame, long *size)
{
unsigned char *p_inbuf, *p_outbuf;
int hdr_size;
int ret;
p_inbuf = (unsigned char *)SsbSipH264EncodeGetInBuf(handle, 0);
memcpy(p_inbuf, yuv_buf, frame_size);
ret = SsbSipH264EncodeExe(handle);
if (first_frame) {
SsbSipH264EncodeGetConfig(handle, H264_ENC_GETCONF_HEADER_SIZE, &hdr_size);
printf("Header Size : %d\n", hdr_size);
}
p_outbuf =(unsigned char *) SsbSipH264EncodeGetOutBuf(handle, size);
return p_outbuf;
}
执行过程中我自己设置的出错打印信息一直没有出来,可是却打印出 invalid target size这样的信息,实在是看不明白。
我现在怀疑的是这样一个原因,在上面这个mfc_encode_exe中,p_inbuf = (unsigned char *)SsbSipH264EncodeGetInBuf(handle, 0);这句话里的强制转换是我自己加的,因为C++不能直接强制转换。这个地方是个疑点。因为我之前用g++编译的时候这个录制函数也出了问题。
各位有谁能解决? --------------------编程问答-------------------- 你自己的出错打印信息没有打印,是因为程序程序根本没有执行,target根本不匹配 --------------------编程问答-------------------- 可是我在程序运行中,确实生成了test.h264这个文件,我后来还打印了整个从摄像头读取出的数据,数据确实是有,但是是错误的.我觉得程序还是应该运行了
补充:移动开发 , Qt