欢迎来到天天文库
浏览记录
ID:39465465
大小:86.00 KB
页数:11页
时间:2019-07-04
《linux下视频采集服务器(UDP传输、多线程模式)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、linux下多线程网络编程,实现arm9视频采集和网络发送jpeg数据,使用udp协议,自己写的,搞了好几天!linux下的多线程比较复杂易出错。linuxnetworkunderthemulti-threadedprogramming,videocaptureandrealizeARM9sendjpegdatanetwork,usingudpprotocol,wroteitmyself,engagedinforseveraldays!linuxunderthemorecomplicatedmulti-threaded,error-prone.1.//多线程成功实例 2.#include
2、trings.h> 3.#include 4.#include 5.#include 6.#include 7.#include 8.#include 9.#include 10.#include 11.#include 12.#include 13.#include 14.#include 3、h> 15.#include 16.#include 17.#include 18.#include 19.#include 20.#include 21.#include 22.#include 23.#include 24.#include 25.#include 26.#include 274、.#include 28.#include 29.#include 30. 31.#define BUFSIZE 6 32.#define DATA 32*1024 33.#define PORT 5000 34.#define RTP_HDR_SZ 12 35.#define VIDEO_PALETTE_JPEG 21 36. 37.unsigned char buf[BUFSIZE+2][DATA]; 38.int head,tail; 1. 2.sem_t writen; 5、3.sem_t readn; 4. 5.struct ARG{int sockfd; 6. int sin_size; 7. struct sockaddr_in client; 8.}; 9. 10.struct FDG{ 11.int video_fd; 12.}; 13. 14.typedef unsigned char u_int8; 15.typedef unsigned short u_int16; 16. 17.int get_jpegsize (unsigned char *buf, int insize); 18.double tdbl(struct time6、val *a); 19.pthread_mutex_t buffer_mutex=PTHREAD_MUTEX_INITIALIZER; 20. 21.static void *producer(void *fdg) 22.{ 23. struct FDG *vd; 24. int video_fd; 25. 26. if(sizeof(fdg)!=sizeof(struct FDG)) 27. { 28. perror("producer arg error"); 29. exit(1); 30. } 31. else 32. { 33. vd=(7、struct FDG *)fdg; 34. video_fd=vd->video_fd; 35. free(fdg); 36. fdg=NULL; 37. } 38. 39. 40. for( ; ; ) 41. { 42. sem_wait(&writen);//减少可读的资源数 43. pthread_mutex_lock(&buffe
3、h> 15.#include 16.#include 17.#include 18.#include 19.#include 20.#include 21.#include 22.#include 23.#include 24.#include 25.#include 26.#include 27
4、.#include 28.#include 29.#include 30. 31.#define BUFSIZE 6 32.#define DATA 32*1024 33.#define PORT 5000 34.#define RTP_HDR_SZ 12 35.#define VIDEO_PALETTE_JPEG 21 36. 37.unsigned char buf[BUFSIZE+2][DATA]; 38.int head,tail; 1. 2.sem_t writen;
5、3.sem_t readn; 4. 5.struct ARG{int sockfd; 6. int sin_size; 7. struct sockaddr_in client; 8.}; 9. 10.struct FDG{ 11.int video_fd; 12.}; 13. 14.typedef unsigned char u_int8; 15.typedef unsigned short u_int16; 16. 17.int get_jpegsize (unsigned char *buf, int insize); 18.double tdbl(struct time
6、val *a); 19.pthread_mutex_t buffer_mutex=PTHREAD_MUTEX_INITIALIZER; 20. 21.static void *producer(void *fdg) 22.{ 23. struct FDG *vd; 24. int video_fd; 25. 26. if(sizeof(fdg)!=sizeof(struct FDG)) 27. { 28. perror("producer arg error"); 29. exit(1); 30. } 31. else 32. { 33. vd=(
7、struct FDG *)fdg; 34. video_fd=vd->video_fd; 35. free(fdg); 36. fdg=NULL; 37. } 38. 39. 40. for( ; ; ) 41. { 42. sem_wait(&writen);//减少可读的资源数 43. pthread_mutex_lock(&buffe
此文档下载收益归作者所有