diff options
author | Moonchild <moonchild@palemoon.org> | 2021-03-03 18:48:48 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2021-03-04 00:03:46 +0000 |
commit | 44d2b4a86e3d862eb1b68db3d9a29b9dbf3da746 (patch) | |
tree | 9d9cc4d21c93ae3e1a88ab5c160c3be5f6af0ca9 /media/libaom/src/aom_util | |
parent | 353943d1a48086a39ff5f4365b22f8f058d5f66e (diff) | |
download | aura-central-44d2b4a86e3d862eb1b68db3d9a29b9dbf3da746.tar.gz |
Issue mcp-graveyard/UXP%1737 - Import libaom 2.0.2 source
Diffstat (limited to 'media/libaom/src/aom_util')
-rw-r--r-- | media/libaom/src/aom_util/aom_thread.c | 28 | ||||
-rw-r--r-- | media/libaom/src/aom_util/aom_thread.h | 92 | ||||
-rw-r--r-- | media/libaom/src/aom_util/aom_util.cmake | 3 | ||||
-rw-r--r-- | media/libaom/src/aom_util/debug_util.c | 12 | ||||
-rw-r--r-- | media/libaom/src/aom_util/debug_util.h | 8 |
5 files changed, 56 insertions, 87 deletions
diff --git a/media/libaom/src/aom_util/aom_thread.c b/media/libaom/src/aom_util/aom_thread.c index cae9f5e25..a749a2240 100644 --- a/media/libaom/src/aom_util/aom_thread.c +++ b/media/libaom/src/aom_util/aom_thread.c @@ -14,6 +14,12 @@ // Original source: // https://chromium.googlesource.com/webm/libwebp +// Enable GNU extensions in glibc so that we can call pthread_setname_np(). +// This must be before any #include statements. +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + #include <assert.h> #include <string.h> // for memset() @@ -34,6 +40,28 @@ static void execute(AVxWorker *const worker); // Forward declaration. static THREADFN thread_loop(void *ptr) { AVxWorker *const worker = (AVxWorker *)ptr; +#ifdef __APPLE__ + if (worker->thread_name != NULL) { + // Apple's version of pthread_setname_np takes one argument and operates on + // the current thread only. The maximum size of the thread_name buffer was + // noted in the Chromium source code and was confirmed by experiments. If + // thread_name is too long, pthread_setname_np returns -1 with errno + // ENAMETOOLONG (63). + char thread_name[64]; + strncpy(thread_name, worker->thread_name, sizeof(thread_name) - 1); + thread_name[sizeof(thread_name) - 1] = '\0'; + pthread_setname_np(thread_name); + } +#elif defined(__GLIBC__) || defined(__BIONIC__) + if (worker->thread_name != NULL) { + // Linux and Android require names (with nul) fit in 16 chars, otherwise + // pthread_setname_np() returns ERANGE (34). + char thread_name[16]; + strncpy(thread_name, worker->thread_name, sizeof(thread_name) - 1); + thread_name[sizeof(thread_name) - 1] = '\0'; + pthread_setname_np(pthread_self(), thread_name); + } +#endif int done = 0; while (!done) { pthread_mutex_lock(&worker->impl_->mutex_); diff --git a/media/libaom/src/aom_util/aom_thread.h b/media/libaom/src/aom_util/aom_thread.h index f14c1ac18..8d0431258 100644 --- a/media/libaom/src/aom_util/aom_thread.h +++ b/media/libaom/src/aom_util/aom_thread.h @@ -23,9 +23,7 @@ extern "C" { #endif -// Set maximum decode threads to be 8 due to the limit of frame buffers -// and not enough semaphores in the emulation layer on windows. -#define MAX_DECODE_THREADS 8 +#define MAX_NUM_THREADS 64 #if CONFIG_MULTITHREAD @@ -36,16 +34,10 @@ extern "C" { typedef HANDLE pthread_t; typedef CRITICAL_SECTION pthread_mutex_t; -#if _WIN32_WINNT >= 0x0600 // Windows Vista / Server 2008 or greater -#define USE_WINDOWS_CONDITION_VARIABLE +#if _WIN32_WINNT < 0x0600 +#error _WIN32_WINNT must target Windows Vista / Server 2008 or newer. +#endif typedef CONDITION_VARIABLE pthread_cond_t; -#else -typedef struct { - HANDLE waiting_sem_; - HANDLE received_sem_; - HANDLE signal_event_; -} pthread_cond_t; -#endif // _WIN32_WINNT >= 0x600 #ifndef WINAPI_FAMILY_PARTITION #define WINAPI_PARTITION_DESKTOP 1 @@ -63,11 +55,6 @@ typedef struct { #define THREADFN unsigned int __stdcall #define THREAD_RETURN(val) (unsigned int)((DWORD_PTR)val) -#if _WIN32_WINNT >= 0x0501 // Windows XP or greater -#define WaitForSingleObject(obj, timeout) \ - WaitForSingleObjectEx(obj, timeout, FALSE /*bAlertable*/) -#endif - static INLINE int pthread_create(pthread_t *const thread, const void *attr, unsigned int(__stdcall *start)(void *), void *arg) { @@ -90,7 +77,8 @@ static INLINE int pthread_create(pthread_t *const thread, const void *attr, static INLINE int pthread_join(pthread_t thread, void **value_ptr) { (void)value_ptr; - return (WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0 || + return (WaitForSingleObjectEx(thread, INFINITE, FALSE /*bAlertable*/) != + WAIT_OBJECT_0 || CloseHandle(thread) == 0); } @@ -98,11 +86,7 @@ static INLINE int pthread_join(pthread_t thread, void **value_ptr) { static INLINE int pthread_mutex_init(pthread_mutex_t *const mutex, void *mutexattr) { (void)mutexattr; -#if _WIN32_WINNT >= 0x0600 // Windows Vista / Server 2008 or greater InitializeCriticalSectionEx(mutex, 0 /*dwSpinCount*/, 0 /*Flags*/); -#else - InitializeCriticalSection(mutex); -#endif return 0; } @@ -127,85 +111,31 @@ static INLINE int pthread_mutex_destroy(pthread_mutex_t *const mutex) { // Condition static INLINE int pthread_cond_destroy(pthread_cond_t *const condition) { - int ok = 1; -#ifdef USE_WINDOWS_CONDITION_VARIABLE (void)condition; -#else - ok &= (CloseHandle(condition->waiting_sem_) != 0); - ok &= (CloseHandle(condition->received_sem_) != 0); - ok &= (CloseHandle(condition->signal_event_) != 0); -#endif - return !ok; + return 0; } static INLINE int pthread_cond_init(pthread_cond_t *const condition, void *cond_attr) { (void)cond_attr; -#ifdef USE_WINDOWS_CONDITION_VARIABLE InitializeConditionVariable(condition); -#else - condition->waiting_sem_ = CreateSemaphore(NULL, 0, MAX_DECODE_THREADS, NULL); - condition->received_sem_ = CreateSemaphore(NULL, 0, MAX_DECODE_THREADS, NULL); - condition->signal_event_ = CreateEvent(NULL, FALSE, FALSE, NULL); - if (condition->waiting_sem_ == NULL || condition->received_sem_ == NULL || - condition->signal_event_ == NULL) { - pthread_cond_destroy(condition); - return 1; - } -#endif return 0; } static INLINE int pthread_cond_signal(pthread_cond_t *const condition) { - int ok = 1; -#ifdef USE_WINDOWS_CONDITION_VARIABLE WakeConditionVariable(condition); -#else - if (WaitForSingleObject(condition->waiting_sem_, 0) == WAIT_OBJECT_0) { - // a thread is waiting in pthread_cond_wait: allow it to be notified - ok = SetEvent(condition->signal_event_); - // wait until the event is consumed so the signaler cannot consume - // the event via its own pthread_cond_wait. - ok &= (WaitForSingleObject(condition->received_sem_, INFINITE) != - WAIT_OBJECT_0); - } -#endif - return !ok; + return 0; } static INLINE int pthread_cond_broadcast(pthread_cond_t *const condition) { - int ok = 1; -#ifdef USE_WINDOWS_CONDITION_VARIABLE WakeAllConditionVariable(condition); -#else - while (WaitForSingleObject(condition->waiting_sem_, 0) == WAIT_OBJECT_0) { - // a thread is waiting in pthread_cond_wait: allow it to be notified - ok &= SetEvent(condition->signal_event_); - // wait until the event is consumed so the signaler cannot consume - // the event via its own pthread_cond_wait. - ok &= (WaitForSingleObject(condition->received_sem_, INFINITE) != - WAIT_OBJECT_0); - } -#endif - return !ok; + return 0; } static INLINE int pthread_cond_wait(pthread_cond_t *const condition, pthread_mutex_t *const mutex) { int ok; -#ifdef USE_WINDOWS_CONDITION_VARIABLE ok = SleepConditionVariableCS(condition, mutex, INFINITE); -#else - // note that there is a consumer available so the signal isn't dropped in - // pthread_cond_signal - if (!ReleaseSemaphore(condition->waiting_sem_, 1, NULL)) return 1; - // now unlock the mutex so pthread_cond_signal may be issued - pthread_mutex_unlock(mutex); - ok = (WaitForSingleObject(condition->signal_event_, INFINITE) == - WAIT_OBJECT_0); - ok &= ReleaseSemaphore(condition->received_sem_, 1, NULL); - pthread_mutex_lock(mutex); -#endif return !ok; } #elif defined(__OS2__) @@ -380,6 +310,10 @@ typedef struct AVxWorkerImpl AVxWorkerImpl; typedef struct { AVxWorkerImpl *impl_; AVxWorkerStatus status_; + // Thread name for the debugger. If not NULL, must point to a string that + // outlives the worker thread. For portability, use a name <= 15 characters + // long (not including the terminating NUL character). + const char *thread_name; AVxWorkerHook hook; // hook to call void *data1; // first argument passed to 'hook' void *data2; // second argument passed to 'hook' diff --git a/media/libaom/src/aom_util/aom_util.cmake b/media/libaom/src/aom_util/aom_util.cmake index d4f3bce74..1a1bfe1e6 100644 --- a/media/libaom/src/aom_util/aom_util.cmake +++ b/media/libaom/src/aom_util/aom_util.cmake @@ -25,4 +25,7 @@ function(setup_aom_util_targets) add_library(aom_util OBJECT ${AOM_UTIL_SOURCES}) set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_util PARENT_SCOPE) target_sources(aom PRIVATE $<TARGET_OBJECTS:aom_util>) + if(BUILD_SHARED_LIBS) + target_sources(aom_static PRIVATE $<TARGET_OBJECTS:aom_util>) + endif() endfunction() diff --git a/media/libaom/src/aom_util/debug_util.c b/media/libaom/src/aom_util/debug_util.c index 468c47ed1..5762e693b 100644 --- a/media/libaom/src/aom_util/debug_util.c +++ b/media/libaom/src/aom_util/debug_util.c @@ -18,13 +18,17 @@ static int frame_idx_w = 0; static int frame_idx_r = 0; -void bitstream_queue_set_frame_write(int frame_idx) { frame_idx_w = frame_idx; } +void aom_bitstream_queue_set_frame_write(int frame_idx) { + frame_idx_w = frame_idx; +} -int bitstream_queue_get_frame_write(void) { return frame_idx_w; } +int aom_bitstream_queue_get_frame_writee(void) { return frame_idx_w; } -void bitstream_queue_set_frame_read(int frame_idx) { frame_idx_r = frame_idx; } +void aom_bitstream_queue_set_frame_read(int frame_idx) { + frame_idx_r = frame_idx; +} -int bitstream_queue_get_frame_read(void) { return frame_idx_r; } +int aom_bitstream_queue_get_frame_read(void) { return frame_idx_r; } #if CONFIG_BITSTREAM_DEBUG #define QUEUE_MAX_SIZE 2000000 diff --git a/media/libaom/src/aom_util/debug_util.h b/media/libaom/src/aom_util/debug_util.h index 127a8b468..23cad2a5b 100644 --- a/media/libaom/src/aom_util/debug_util.h +++ b/media/libaom/src/aom_util/debug_util.h @@ -20,10 +20,10 @@ extern "C" { #endif -void bitstream_queue_set_frame_write(int frame_idx); -int bitstream_queue_get_frame_write(void); -void bitstream_queue_set_frame_read(int frame_idx); -int bitstream_queue_get_frame_read(void); +void aom_bitstream_queue_set_frame_write(int frame_idx); +int aom_bitstream_queue_get_frame_writee(void); +void aom_bitstream_queue_set_frame_read(int frame_idx); +int aom_bitstream_queue_get_frame_read(void); #if CONFIG_BITSTREAM_DEBUG /* This is a debug tool used to detect bitstream error. On encoder side, it |