initial commit
This commit is contained in:
commit
fcaaeaaf5d
2 changed files with 169 additions and 0 deletions
26
main.py
Normal file
26
main.py
Normal file
|
|
@ -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)
|
||||
143
new.c
Normal file
143
new.c
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdint.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#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 <pthread.h>
|
||||
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<PIXELS;j++){
|
||||
uint64_t pixel = xorshf96() % RANDOMNESS_LEN;
|
||||
uint16_t x = pixel%WIDTH;
|
||||
uint16_t y = pixel/WIDTH;
|
||||
uint16_t draw_x = OFFSET_X+x;
|
||||
uint16_t draw_y = OFFSET_Y+y;
|
||||
buf[i][2+j*7+0] = draw_x & 0xff;
|
||||
buf[i][2+j*7+1] = (draw_x >> 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);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue