Works on windows

This commit is contained in:
Joose Sainio 2024-01-26 15:13:42 +02:00
parent 3b8be5b8c1
commit c0a0f69b00
6 changed files with 85 additions and 11 deletions

View file

@ -71,7 +71,7 @@ if(NOT EXISTS "${PROJECT_SOURCE_DIR}/greatest/greatest.h")
endif()
find_package(ZeroMQ REQUIRED)
find_package(ZeroMQ REQUIRED SHARED)
# Grab <year>-<month>-<day> timestamp for debug purposes
string(TIMESTAMP CMAKE_BUILD_DATE %Y-%m-%d)
@ -144,6 +144,7 @@ endif()
target_include_directories(uvg266 PUBLIC src)
target_include_directories(uvg266 PUBLIC src/extras)
target_include_directories(uvg266 PUBLIC src/strategies)
target_include_directories(uvg266 PUBLIC "G:/Local/sainio/Documents/libzmq/out/install/include")
file(GLOB LIB_SOURCES_STRATEGIES_AVX2 RELATIVE ${PROJECT_SOURCE_DIR} "src/strategies/avx2/*.c")
file(GLOB LIB_SOURCES_STRATEGIES_SSE41 RELATIVE ${PROJECT_SOURCE_DIR} "src/strategies/sse41/*.c")
@ -165,7 +166,7 @@ endif()
add_executable(uvg266-bin ${CLI_SOURCES})
target_link_libraries(uvg266-bin PUBLIC uvg266 zmq)
target_link_libraries(uvg266-bin PUBLIC uvg266 "G:/Local/sainio/Documents/libzmq/out/install/lib/libzmq-mt-4_3_6.lib")
set_target_properties(uvg266-bin PROPERTIES OUTPUT_NAME uvg266)
set_target_properties(uvg266-bin PROPERTIES RUNTIME_OUTPUT_NAME uvg266)

View file

@ -270,7 +270,12 @@ static void* input_read_thread(void* in_args)
frame_in->interlacing = args->encoder->cfg.source_scan_type;
}
#if defined(__GNUC__) && !defined(__MINGW32__)
usleep(33000);
#else
Sleep(33);
#endif
// Wait until main thread is ready to receive the next frame.
if (uvg_sem_trywait(args->available_input_slots) == 0) {
args->img_in = frame_in;

View file

@ -34,7 +34,6 @@
#include <limits.h>
#include <string.h>
#include <unistd.h>
#include "cabac.h"
#include "cu.h"
@ -58,6 +57,27 @@
#include "uvg266.h"
#include "videoframe.h"
#if defined(__GNUC__) && !defined(__MINGW32__)
#include <unistd.h>
#else
#include <windows.h>
void usleep(__int64 usec)
{
HANDLE timer;
LARGE_INTEGER ft;
ft.QuadPart = -(
10 *
usec); // Convert to 100 nanosecond interval, negative value indicates relative time
timer = CreateWaitableTimer(NULL, TRUE, NULL);
SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
WaitForSingleObject(timer, INFINITE);
CloseHandle(timer);
}
#endif
#define IN_FRAME(x, y, width, height, block_width, block_height) \
((x) >= 0 && (y) >= 0 \
&& (x) + (block_width) <= (width) \
@ -1639,13 +1659,26 @@ static double search_cu(
if (cur_cu->type != CU_NOTSET) {
uint8_t type = 0;
uint8_t buffer[8192];
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
uint64_t timestamp = ts.tv_sec * 1000000000 + ts.tv_nsec;
UVG_CLOCK_T time;
UVG_GET_TIME(&time);
uint64_t time_high = time.dwHighDateTime & 0x000fffff;
time_high <<= 32;
uint64_t time_low = time.dwLowDateTime;
uint64_t timestamp = time_high | time_low;
timestamp *= 100;
// printf("%llu\n", timestamp);
uint64_t bytes = 0;
memcpy(buffer, &type, 1); bytes++;
memcpy(buffer + bytes, &timestamp, 8); bytes+=8;
memcpy(buffer + bytes, &state->frame->num, 1); bytes++;
if (cu_height == 64 && cu_width == 64) {
printf("%llu\n", timestamp);
printf("%llx\n", timestamp);
for (int i = 0; i < bytes; i++) {
printf("%2x", buffer[i]);
}
printf("\n");
}
memcpy(buffer + bytes, &cu_loc->x, 2); bytes+=2;
memcpy(buffer + bytes, &cu_loc->y, 2); bytes+=2;
memcpy(buffer + bytes, &cu_loc->width, 1); bytes++;
@ -1659,6 +1692,13 @@ static double search_cu(
memcpy(buffer + bytes, &cur_cu->intra.isp_mode, 1); bytes++;
memcpy(buffer + bytes, &cur_cu->lfnst_idx, 1); bytes++;
memcpy(buffer + bytes, &cur_cu->tr_idx, 1); bytes++;
if (cu_height == 64 && cu_width == 64) {
for (int i = 0; i < bytes; i++) {
printf("%2x", buffer[i]);
}
printf("\n");
}
uvg_pixels_blit(&lcu->rec.y[x_local + y_local * LCU_WIDTH], buffer + bytes, cu_width, cu_height, LCU_WIDTH, cu_width);
bytes += cu_loc->width*cu_loc->height;
@ -1668,11 +1708,18 @@ static double search_cu(
bytes += cu_loc->width*cu_loc->height / 4;
zmq_send(state->send_socket, buffer, bytes, 0);
if(state->frame->cfg->speed > 1) {
if (state->frame->cfg->speed > 1) {
#if defined(__GNUC__) && !defined(__MINGW32__)
struct timespec sleep_time;
sleep_time.tv_sec = 0;
sleep_time.tv_nsec = UVG_CLOCK_T_DIFF(start_time, end_time) * 1e9 * (state->frame->cfg->speed - 1);
nanosleep(&sleep_time, NULL);
#else
usleep(
UVG_CLOCK_T_DIFF(start_time, end_time) * 1e6 *
(state->frame->cfg->speed - 1));
#endif
}
}
@ -2004,10 +2051,15 @@ static double search_cu(
if (cost <= best_split_cost) {
uint8_t type = 1;
uint8_t buffer[8192];
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
uint64_t timestamp = ts.tv_sec * 1000000000 + ts.tv_nsec;
uint8_t buffer[8192];
UVG_CLOCK_T time;
UVG_GET_TIME(&time);
uint64_t time_high = time.dwHighDateTime & 0x000fffff;
time_high <<= 32;
uint64_t time_low = time.dwLowDateTime;
uint64_t timestamp = time_high | time_low;
timestamp *= 100;
//printf("%llu\n", timestamp);
uint64_t bytes = 0;
memcpy(buffer, &type, 1); bytes++;
memcpy(buffer + bytes, &timestamp, 8); bytes+=8;

View file

@ -76,6 +76,7 @@
#define UVG_GET_TIME(clock_t) { GetSystemTimeAsFileTime(clock_t); }
// _FILETIME has 32bit low and high part of 64bit 100ns resolution timestamp (since 12:00 AM January 1, 1601)
#define UVG_CLOCK_T_AS_DOUBLE(ts) ((double)(((uint64_t)(ts).dwHighDateTime)<<32 | (uint64_t)(ts).dwLowDateTime) / 1e7)
#define UVG_CLOCK_T_AS_UINT64_T(ts) (((uint64_t)(ts).dwHighDateTime)<<32 | (((uint64_t)(ts).dwLowDateTime) * 100))
#define UVG_CLOCK_T_DIFF(start, stop) ((double)((((uint64_t)(stop).dwHighDateTime)<<32 | (uint64_t)(stop).dwLowDateTime) - \
(((uint64_t)(start).dwHighDateTime)<<32 | (uint64_t)(start).dwLowDateTime)) / 1e7)

View file

@ -27,6 +27,7 @@ int sem_destroy(sem_t* sem);
int sem_init(sem_t* sem, int /*pshared*/, unsigned int value);
int sem_post(sem_t* sem);
int sem_wait(sem_t* sem);
int sem_trywait(sem_t* sem);
#ifdef __cplusplus
}

View file

@ -40,6 +40,15 @@ public:
}
}
int trywait()
{
std::unique_lock<std::mutex> lck(mtx_);
if (val_ > 0) {
--val_;
return 0;
}
return -1;
}
private:
@ -70,3 +79,8 @@ int sem_wait(sem_t* sem) {
static_cast<Semaphore*>(*sem)->wait();
return 0;
}
int sem_trywait(sem_t* sem)
{
return static_cast<Semaphore*>(*sem)->trywait();
}