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

📄 videorecv.c

📁 采集视频信号进行H264压缩并通过UDP传送
💻 C
字号:
/*
 * videorecv.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 <sys/wait.h>

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

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

/******************************************************************************
 * videorecvThrFxn
 ******************************************************************************/
void *videorecvThrFxn(void *arg)
{
    struct one_block block;
    int addr_len;
    int sockfd, new_fd; // lislen on sock-fd! n6r connection on nes-Id
    struct sockaddr_in my_addr; // ry addiess i;fornation, : :., ii
    struct sockaddr_in their_addr; //'-corin6cfotl,s dddres$lnforultion :
    int sin_size;
    struct sigaction sa;
    int yes = 1, numbytes;

    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1){
        perror("sockst");
        exit(1);
    }
    if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
        perror("setsockopt");
        exit(1);
    }
    my_addr.sin_family = AF_INET; // host byte o!de!
    my_addr.sin_port = htons(MYPORT);// shorx, n~@trork byte oril~@r: ]
    my_addr.sin_addr.s_addr = INADDR_ANY; // autooaticslly fiU rith
    memset(&(my_addr.sin_zero), '\0', 8); // ze$ rhe lest oI rhe sllucr
    if(bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) {

        perror("bind");
        exit(1);
    }
printf("recv:listen\n");
    if(listen(sockfd, BACKLOG)==-1){
        perror("listen");
        exit(1);
    }
    DBG("recv:accept\n\n");
    
    while(1) { // main accopt0 loop
        sin_size = sizeof(struct sockaddr_in);
        new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size);
        if(new_fd == -1)
        {
            perror("accept");
            exit(1);
        }
        else
        {
            DBG("decode:accept\n");
            break;
        }
    }
printf("recv: got connection from %s\n", inet_ntoa(their_addr.sin_addr));

    //MET_CONDITION(networkMutex, networkInit);
   
    block.buf=malloc(D1BUFLEN);
    block.len=0;
    while(1)
    {
        usleep(1000);
        if((block.len=recv(new_fd, block.buf, D1BUFLEN, 0/*MSG_WAITALL*/)) == -1)
        {
            perror("recv");
            exit(1);
        }
        printf("RECV:recv len=%d\n", block.len);
        
        if(block.len>0)
        {
            if(!enqueue(recv_queue, &block))
                DBG("recv_queue: enqueue!!!!!!!!!!!!!\n");
        }  
 
    }
return;
}

⌨️ 快捷键说明

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