#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PIXELS 120 #define MSGSIZE (2 + 7 * PIXELS) #define WIDTH (640) #define HEIGHT (360) #define OFFSET_X 1200 #define OFFSET_Y 40 //#define DISPLAY_HOST "100.65.0.2" #define DISPLAY_HOST "fcda:f100::d" #define DISPLAY_PORT 5005 #define SIZE WIDTH*HEIGHT*3 #define INPUT_FILE "/tmp/video" #define RANDOMNESS_LEN (WIDTH*HEIGHT) #include struct mmsghdr msg[RANDOMNESS_LEN/PIXELS]; struct iovec iovec[RANDOMNESS_LEN/PIXELS]; uint8_t buf[RANDOMNESS_LEN/PIXELS][MSGSIZE]; uint64_t randomness[RANDOMNESS_LEN]; int randomness_o =0; static unsigned long x=123456789, y=362436069, z=521288629; unsigned long xorshf96(void) { //period 2^96-1 unsigned long t; x ^= x << 16; x ^= x >> 5; x ^= x << 1; t = x; x = y; y = z; z = t ^ x ^ y; return z; } void shuffle(uint64_t *array, size_t n) { if (n > 1) { size_t i; for (i = 0; i < n - 1; i++) { size_t j = i + rand() / (RAND_MAX / (n - i) + 1); unsigned long t = array[j]; array[j] = array[i]; array[i] = t; } } } void *send_thread(void * ifname){ int sockfd; struct sockaddr_in6 addr; sockfd = socket(AF_INET6, SOCK_DGRAM, 0); if (sockfd == -1) { perror("socket()"); exit(EXIT_FAILURE); } struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); snprintf(ifr.ifr_name, sizeof(ifr.ifr_name),(char *) ifname); addr.sin6_family = AF_INET6; addr.sin6_port = htons(DISPLAY_PORT); inet_pton(AF_INET6, DISPLAY_HOST, &addr.sin6_addr); if (connect(sockfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) { perror("connect()"); exit(EXIT_FAILURE); } int from = 0; sleep(1); while(1){ int retval = sendmmsg(sockfd, &msg[from], (RANDOMNESS_LEN/PIXELS)-from, 0); if (retval == -1) { perror("sendmmsg()"); } from += retval; if(from <= (RANDOMNESS_LEN/PIXELS)){ from = 0; } } } int main(int argc, char *argv[]) { printf(argv[1]); x=rand(); y=rand(); z=rand(); for(int i = 0; i < RANDOMNESS_LEN; i++) { randomness[i] = i; } shuffle(randomness,RANDOMNESS_LEN); for(int i = 0; i < RANDOMNESS_LEN/PIXELS; i++){ iovec[i].iov_base = buf[i]; iovec[i].iov_len = MSGSIZE; msg[i].msg_hdr.msg_iov = &iovec[i]; msg[i].msg_hdr.msg_iovlen = 1; buf[i][0] = 0x00; buf[i][1] = 0x01; } int fd = open(INPUT_FILE,O_RDONLY); printf("fd: %d\n", fd); uint8_t * data = mmap(NULL, SIZE, PROT_READ , MAP_SHARED, fd, 0); if (data == MAP_FAILED) { perror("mmap"); } pthread_t th1,th2,th3,th4; pthread_create(&th1, NULL, send_thread, argv[1]); while (1) { for(int i = 0; i < (int)(RANDOMNESS_LEN/PIXELS); i++){ for(int j=0; j> 8) & 0xff; buf[i][2+j*7+2] = draw_y & 0xff; buf[i][2+j*7+3] = (draw_y >> 8) & 0xff; buf[i][2+j*7+4] = *(data+pixel*3+0) & 0xff; buf[i][2+j*7+5] = *(data+pixel*3+1) & 0xff; buf[i][2+j*7+6] = *(data+pixel*3+2) & 0xff; } } } exit(0); }