可以實現在web上查看攝像頭采集的圖像
0.png (11.69 KB, 下載次數: 13)
下載附件
2019-4-11 17:09 上傳
單片機源程序如下:
- #include<stdio.h>
- #include"srv.h"
- #include"cam.h"
- #include"web.h"
- pthread_mutex_t cam_mutex;
- pthread_mutex_t sync_mutex;
- pthread_t cam_tid;
- pthread_t web_tid;
- int sync_flag = 2;
- int main(int argc,char *argv[])
- {
- int ret;
- pthread_mutex_init(&cam_mutex,NULL);
- pthread_mutex_init(&sync_mutex,NULL);
- #if 1
- ret = pthread_create(&cam_tid,NULL,thread_cam,NULL);
- if(ret)
- {
- errno = ret;
- perror("create camera thread ");
- exit(EXIT_FAILURE);
- }else
- printf("create camera thread success\n");
- ret = pthread_detach(cam_tid);
- if(ret)
- {
- errno = ret;
- perror("detach camera thread ");
- exit(EXIT_FAILURE);
- }else
- printf("detach camera thread success\n");
- #endif
- #if 0
- ret = pthread_create(&zgb_tid,NULL,thread_zgb,NULL);
- if(ret)
- {
- errno = ret;
- perror("create zigbee thread ");
- exit(EXIT_FAILURE);
- }else
- printf("create zigbee thread success\n");
- ret = pthread_detach(zgb_tid);
- if(ret)
- {
- errno = ret;
- perror("detach zigbee thread\n");
- exit(EXIT_FAILURE);
- }else
- printf("detach zigbee thread success\n");
- #endif
- #if 0
- while(1)
- {
- pthread_mutex_lock(&sync_mutex);
- if(0 == sync_flag)
- {
- pthread_mutex_unlock(&sync_mutex);
- pthread_mutex_destroy(&sync_mutex);
- break;
- }else{
- pthread_mutex_unlock(&sync_mutex);
- sleep(1);
- }
- }
- #endif
- #if 1
- ret = pthread_create(&web_tid,NULL,thread_web,NULL);
- if(ret)
- {
- errno = ret;
- perror("create web server thread\n");
- exit(EXIT_FAILURE);
- }else
- printf("create web server thread success\n");
- ret = pthread_detach(web_tid);
- if(ret)
- {
- errno = ret;
- perror("detach web server thread\n");
- exit(EXIT_FAILURE);
- }else
- printf("detach web server thread success\n");
- #endif
- int listenfd = init_socket(8880,argv[1]);
- while(1)
- {
- int connectfd = accept(listenfd,NULL,NULL);
- printf("%d\n",connectfd);
- if(-1 == connectfd)
- {
- perror("accept ");
- exit(EXIT_FAILURE);
- }
- pthread_t srv_tid;
- ret = pthread_create(&srv_tid,NULL,thread_srv,&connectfd);
- if(ret)
- {
- errno = ret;
- perror("create server thread\n");
- exit(EXIT_FAILURE);
- }else
- printf("create server thread success\n");
- ret = pthread_detach(srv_tid);
- if(ret)
- {
- errno = ret;
- perror("detach server thread\n");
- exit(EXIT_FAILURE);
- }else
- printf("detach server thread success\n");
- }
-
- pthread_mutex_destroy(&cam_mutex);
- sercache_destroy(jpegn) ;
- sercache_destroy(head);
- return 0;
- }
復制代碼
所有資料51hei提供下載:
video monitor.7z
(373.5 KB, 下載次數: 33)
2019-4-11 17:10 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|