From fcaaeaaf5df11fd37eec85410eb4571637d96a7a Mon Sep 17 00:00:00 2001 From: Alexander Jacobsen Date: Fri, 17 Jul 2026 16:30:22 +0200 Subject: [PATCH] initial commit --- main.py | 26 +++++++++++ new.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 main.py create mode 100644 new.c diff --git a/main.py b/main.py new file mode 100644 index 0000000..5182284 --- /dev/null +++ b/main.py @@ -0,0 +1,26 @@ +import ffmpeg +import os +in_filename = "/home/albmj/media/Cowboy_Bebop.mkv" +width=640 +height=360 +process1 = ( + ffmpeg + .input(in_filename,re=None,stream_loop="-1") + .filter('scale', width, height) + .filter('subtitles', in_filename, force_style='Fontsize=120', si='2') + .output('pipe:', format='rawvideo', pix_fmt='rgb24') + .run_async(pipe_stdout=True,quiet=False) +) +fd = os.open("/tmp/video",os.O_RDWR|os.O_CREAT) +os.lseek(fd,0,os.SEEK_SET) +#fd = os.memfd_create('test_file') +print(f'{width}x{height}x3={width*height*3}') +print(f'/tmp/video') +while True: + in_bytes = process1.stdout.read(width * height * 3) + if len(in_bytes) != width*height*3: + print("wrong size") + print(len(in_bytes)) + exit(1) + os.write(fd, in_bytes) + os.lseek(fd, 0, os.SEEK_SET) diff --git a/new.c b/new.c new file mode 100644 index 0000000..1ec68f6 --- /dev/null +++ b/new.c @@ -0,0 +1,143 @@ +#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); +} +