初级会员
- 积分
- 80
- 金钱
- 80
- 注册时间
- 2017-6-13
- 在线时间
- 10 小时
|
楼主 |
发表于 2017-6-15 10:13:33
|
显示全部楼层
今天试着先搞MJPEG,发现新问题,没有摄像头数据时,程序本来只发送2个字节的header数据,但是在bushound里面发现传输的是64个字节。
然后捕获按键操作来模拟一帧摄像头数据,结果发现传输的大小还是不一样,差的太多了,本来模拟的是102400字节,结果只发送了很少,搞不懂啊,求指教啊。以下是发送时的代码以及bushound数据。
static uint8_t usbd_video_DataIn (void *pdev, uint8_t epnum)
{
static uint16_t packets_cnt = 0xffff;
static uint8_t header[2] = {2,0};//length + data
static uint32_t picture_pos;
static uint16_t packets_in_frame = 1;
static uint16_t last_packet_size = 0;
static uint8_t tx_enable_flag = 0;//
static uint8_t packet[VIDEO_PACKET_SIZE];
uint16_t i;
if (epnum != (UVC_DATA_EP & 0x7F))
{
return USBD_OK;
}
DCD_EP_Flush(pdev,USB_ENDPOINT_IN(UVC_DATA_EP));//very important
if (tx_enable_flag) packets_cnt++;
if (tx_enable_flag == 0)//if previous transmission ended
{
if (jpeg_encode_done)//if frame endoding ended
{
tx_enable_flag = 1;
//start of new UVC frame
packets_cnt = 0;
header[1] ^= 0x01;//toggle bit0 every new frame
header[1] &= ~(0x02); //EOF
picture_pos = 0;
packets_in_frame = (last_jpeg_frame_size/ (VIDEO_PACKET_SIZE -2))+1;//
last_packet_size = (last_jpeg_frame_size - ((packets_in_frame-1) * (VIDEO_PACKET_SIZE-2)) + 2);//
//printf("framesize=%d,framecnt=%d.\r\n", last_jpeg_frame_size, ov_frame);
}
}
packet[0] = header[0];
packet[1] = header[1];
//fill payload buffer
for (i=2;i<VIDEO_PACKET_SIZE;i++)
{
packet[i] = dcmi_data_bufR[picture_pos];
//packet[i] = packets_cnt;
picture_pos++;
}
if (play_status == 2)
{
if (packets_cnt < (packets_in_frame - 1))
{
DCD_EP_Tx (pdev,USB_ENDPOINT_IN(UVC_DATA_EP), (uint8_t*)packet, (uint32_t)VIDEO_PACKET_SIZE);
}
else if (tx_enable_flag == 1)//only if transmisson enabled
{
//last packet in UVC frame
packet[1] |= 0x02; //EOF
DCD_EP_Tx (pdev,USB_ENDPOINT_IN(UVC_DATA_EP), (uint8_t*)packet, (uint32_t)last_packet_size);
tx_enable_flag = 0;//stop TX data
jpeg_encode_done = 0;
}
else
{
header[0]=2;header[1]=0;
DCD_EP_Tx (pdev,USB_ENDPOINT_IN(UVC_DATA_EP), (uint8_t*)header, 2);//header only
picture_pos = 0;
}
}
else
{
packets_cnt = 0xffff;
picture_pos = 0;
}
return USBD_OK;
} |
|