mjpg-streamer服务器移植

“MJPG-streamer”,是用户从webcam摄像头采集图像,并以流的形式通过基于IP的网络传输到浏览器图Firefox,Cambozola,VlC播放器,Windows的移动设备或者其他用户浏览器的移动设备,她可以利用某系webcam的硬件压缩功能来降低服务器CPU的开销,她为嵌入式设备和一些常规的服务器提供了一个轻量级且更少CPU消耗的方案。

在UBuntu上编译安装MJPG-streamer后,以input_uvc和output_http的方式作为输入和输出,并在Android上使用HttpClient以get方式(action=stream)连接MJPG-streamer服务器,发现,HttpClient无法获取的视频流,查看服务器源代码httpd.c时发现,MJPG-streamer一直将数据流写入response,从而导致httpclient取不出来,于是对MJPG-streamer httpd.c中的void send_stream(int fd, int input_number)函数作了一下修改,重新编译安装,发现,通知是android一次连接取一帧数据,不断循环的独缺,结果成功获取数据了,画面也能显示了。
后来发现若以action=snapshot方式连接时,就能直接得到一帧数据,不用修改void send_stream(int fd, int input_number)函数,哈哈!白忙活一趟。
使用action=snapshot方式连接时服务器调用void send_snapshot(int fd, int input_number)函数,该函数只发送一帧数据并断开了TCP连接,同时该函数有一个缺陷,即发送的http头中,没有Content-Length,从而导致httpclient不能获取内容长度,于是再次修改void send_snapshot(int fd, int input_number)的代码,在http头中加入Content-Length:
/* write the response */
sprintf(buffer, “HTTP/1.0 200 OK\r\n” \
STD_HEADER \
“Content-type: image/jpeg\r\n” \
“Content-Length: %d\r\n” \
“X-Timestamp: %d.%06d\r\n” \
“\r\n”,frame_size, (int) timestamp.tv_sec, (int) timestamp.tv_usec);

再次编译,完美运行!

猜你喜欢

转载自blog.csdn.net/wenshifang/article/details/68490018
今日推荐