Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

c - UDP restreaming using socket resulting in NULL packets

I am implementing a UDP video redirection feature. Ideally incoming video packets should be processed and redirected to a specified output interface (eth0 or eth1). Here's how it's implemented:

  1. User selects the interface from a webui. The interface gets passed to the backend

  2. Video packets are processed using OpenCaster suite (here)..the following libraries are being used in order to process the packets: tsfixcc, tsdiscont, tsvbr2cbr,tstimedwrite, tspcrrestamp and tsudpsend.

  3. I modified tsudpsend as follows to support binding the socket to a specific interface and there is no compilation error and I think it's working fine.

int main (int argc, char *argv[]) {
    char *opt;
    opt = argv[5];
    sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    if(sockfd < 0) {
        perror("socket(): error ");
        return 0;
    }

    struct ifreq ifr;
    memset(&ifr, 0, sizeof(ifr));
    strcpy(ifr.ifr_name, opt);
    if (ioctl(sockfd, SIOCGIFINDEX, &ifr)<0){
        fprintf(stderr,"ioctl(): error ");
    }

    if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, opt, strlen(opt))>0){
        fprintf(stderr,"setsock(): error ");
    }

    fprintf(stderr, "The bind is done on interface %s 
", opt);
    fprintf(stderr, "opt length is %zu 
", strlen(opt));
    if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) < 0) {
        fprintf(stderr,"Server-setsockopt() error for SO_BINDTODEVICE");
        close(sockfd);
        return 1;
    }

    return 0;
}

The problem: when I do a packet capture on the selected interface (eth0 or eth1), the processed packets are NULL packets not video data packets as follows

1054354 1127.215289 192.168.78.196 -> 239.1.1.1    MPEG TS 1358 NULL packet
1054355 1127.216366 192.168.78.196 -> 239.1.1.1    MPEG TS 1358 NULL packet
1054356 1127.217405 192.168.78.196 -> 239.1.1.1    MPEG TS 1358 NULL packet
1054357 1127.218462 192.168.78.196 -> 239.1.1.1    MPEG TS 1358 NULL packet
1054358 1127.219549 192.168.78.196 -> 239.1.1.1    MPEG TS 1358 NULL packet

Any suggestions or ideas on why this is happening ? Any advice please?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...