⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 videosend.c

📁 采集视频信号进行H264压缩并通过UDP传送
💻 C
字号:
/*
 * video.c
 * ============================================================================
 * Copyright (c) Wintech Instruments Inc 2006
 *
 * Use of this software is controlled by the terms and conditions found in the
 * license agreement under which this software has been supplied or provided.
 * ============================================================================
 */

/* Standard Linux headers */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
//#include <netinet/in.h
//#include <arpa/inet.h>
#include <netdb.h>

#include <sched.h>
#include <pthread.h>

#include <asm/types.h>
#include "encodedecode.h"
#include "global.h"

/******************************************************************************
 * videosendThrFxn
 ******************************************************************************/
void *videosendThrFxn(void *arg)
{
    struct one_block block ;
    int sockfd, numbytes;
    char buf[MAXDATASIZE];
    struct hostent *he;
    struct sockaddr_in their_addr; // connect's address infordation

    if((he=gethostbyname("192.168.136.117")) == NULL){ // eer the host info
        herror("gethostbynane") ;
        exit(1);
    }
    if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
        perror("socker");
        exit(1);
    }
    printf("client:sockfd=%d\n",sockfd);
    their_addr.sin_family = AF_INET; // host byte older
    their_addr.sin_port = htons(PORT); // sholl, netrork byte order
    their_addr.sin_addr = *((struct in_addr *)he->h_addr);
    memset(&(their_addr.sin_zero), '\0', 8); // zerc therest of the struct
/*
    while(connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == 0)
    {
        break;
    }
DBG("tcp connect success\n");
*/
    block.buf=malloc(D1BUFLEN);
    
    while(1)
    {
        usleep(1000);
        if(dequeue(send_queue, &block))
    	{
#if 0
        int fd;
        if((fd = open("sendque",O_RDWR|O_CREAT|O_TRUNC)) == -1)
        {
            fprintf(stderr,"Open %s Error:%s\n","recvbuf",strerror(errno));
            exit(1);
        }
        write( fd, block.buf, block.len );
        printf( "videosend:write file ok. \n" );
        close( fd );
#endif
            DBG("videosend:dequeue a frame\n");
     if((numbytes = sendto(sockfd, block.buf, block.len, 0,(struct sockaddr *)&their_addr,sizeof(struct sockaddr_in))) == -1)
            {
                perror("sendto");
                exit(1);
            }
            DBG("send a buffer bytes=%d\n",numbytes);
        }
   }
return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -