Compare commits

...

2 Commits

Author SHA1 Message Date
Scott Graham
4dae3ca262 fix warnings for building on win32
Change-Id: If6e11ba3d681e831d7d98662c0abdd2ac16b3811
2012-07-23 14:23:44 -07:00
John Koleszar
1a23086bc6 Remove threading dependencies with --disable-multithread
Avoid a pthreads dependency via pthread_once() when compiled with
--disable-multithread.

In addition, this synchronization is disabled for Win32 as well, even
though we can be sure that the required primatives exist, so that the
requirements on the application when built with --disable-multithread
are consistent across platforms.

Users using libvpx built with --disable-multithread in a multithreaded
context should provide their own synchronization. Updated the
documentation to vpx_codec_enc_init_ver() and vpx_codec_dec_init_ver()
to note this requirement. Moved the RTCD initialization call to match
this description, as previously it didn't happen until the first
frame.

Change-Id: Id576f6bce2758362188278d3085051c218a56d4a
2012-07-23 14:23:43 -07:00
17 changed files with 100 additions and 84 deletions

View File

@@ -211,6 +211,8 @@ common_top() {
$(process_forward_decls)
$(declare_function_pointers c $ALL_ARCHS)
void ${symbol:-rtcd}(void);
EOF
}
@@ -231,11 +233,10 @@ x86() {
cat <<EOF
$(common_top)
void ${symbol:-rtcd}(void);
#ifdef RTCD_C
#include "vpx_ports/x86.h"
void ${symbol:-rtcd}(void)
static void setup_rtcd_internal(void)
{
int flags = x86_simd_caps();
@@ -261,11 +262,9 @@ arm() {
$(common_top)
#include "vpx_config.h"
void ${symbol:-rtcd}(void);
#ifdef RTCD_C
#include "vpx_ports/arm.h"
void ${symbol:-rtcd}(void)
static void setup_rtcd_internal(void)
{
int flags = arm_cpu_caps();
@@ -285,10 +284,8 @@ unoptimized() {
$(common_top)
#include "vpx_config.h"
void ${symbol:-rtcd}(void);
#ifdef RTCD_C
void ${symbol:-rtcd}(void)
static void setup_rtcd_internal(void)
{
$(set_function_pointers c)
}

View File

@@ -83,57 +83,6 @@ static int get_cpu_count()
#endif
#if HAVE_PTHREAD_H
#include <pthread.h>
static void once(void (*func)(void))
{
static pthread_once_t lock = PTHREAD_ONCE_INIT;
pthread_once(&lock, func);
}
#elif defined(_WIN32)
static void once(void (*func)(void))
{
/* Using a static initializer here rather than InitializeCriticalSection()
* since there's no race-free context in which to execute it. Protecting
* it with an atomic op like InterlockedCompareExchangePointer introduces
* an x86 dependency, and InitOnceExecuteOnce requires Vista.
*/
static CRITICAL_SECTION lock = {(void *)-1, -1, 0, 0, 0, 0};
static int done;
EnterCriticalSection(&lock);
if (!done)
{
func();
done = 1;
}
LeaveCriticalSection(&lock);
}
#else
/* No-op version that performs no synchronization. vpx_rtcd() is idempotent,
* so as long as your platform provides atomic loads/stores of pointers
* no synchronization is strictly necessary.
*/
static void once(void (*func)(void))
{
static int done;
if(!done)
{
func();
done = 1;
}
}
#endif
void vp8_machine_specific_config(VP8_COMMON *ctx)
{
#if CONFIG_MULTITHREAD
@@ -145,6 +94,4 @@ void vp8_machine_specific_config(VP8_COMMON *ctx)
#elif ARCH_X86 || ARCH_X86_64
ctx->cpu_caps = x86_simd_caps();
#endif
once(vpx_rtcd);
}

View File

@@ -106,7 +106,7 @@ extern "C"
int Width; // width of data passed to the compressor
int Height; // height of data passed to the compressor
struct vpx_rational timebase;
int target_bandwidth; // bandwidth to be used in kilobits per second
unsigned int target_bandwidth; // bandwidth to be used in kilobits per second
int noise_sensitivity; // parameter used for applying pre processing blur: recommendation 0
int Sharpness; // parameter used for sharpening output: recommendation 0:

View File

@@ -10,3 +10,60 @@
#include "vpx_config.h"
#define RTCD_C
#include "vpx_rtcd.h"
#if CONFIG_MULTITHREAD && HAVE_PTHREAD_H
#include <pthread.h>
static void once(void (*func)(void))
{
static pthread_once_t lock = PTHREAD_ONCE_INIT;
pthread_once(&lock, func);
}
#elif CONFIG_MULTITHREAD && defined(_WIN32)
#include <windows.h>
static void once(void (*func)(void))
{
/* Using a static initializer here rather than InitializeCriticalSection()
* since there's no race-free context in which to execute it. Protecting
* it with an atomic op like InterlockedCompareExchangePointer introduces
* an x86 dependency, and InitOnceExecuteOnce requires Vista.
*/
static CRITICAL_SECTION lock = {(void *)-1, -1, 0, 0, 0, 0};
static int done;
EnterCriticalSection(&lock);
if (!done)
{
func();
done = 1;
}
LeaveCriticalSection(&lock);
}
#else
/* No-op version that performs no synchronization. vpx_rtcd() is idempotent,
* so as long as your platform provides atomic loads/stores of pointers
* no synchronization is strictly necessary.
*/
static void once(void (*func)(void))
{
static int done;
if(!done)
{
func();
done = 1;
}
}
#endif
void vpx_rtcd()
{
once(setup_rtcd_internal);
}

View File

@@ -549,8 +549,8 @@ static void setup_token_decoder(VP8D_COMP *pbi,
{
vp8_reader *bool_decoder = &pbi->bc2;
unsigned int partition_idx;
int fragment_idx;
int num_token_partitions;
unsigned int fragment_idx;
unsigned int num_token_partitions;
const unsigned char *first_fragment_end = pbi->fragments[0] +
pbi->fragment_sizes[0];
@@ -1132,7 +1132,7 @@ int vp8_decode_frame(VP8D_COMP *pbi)
#if CONFIG_MULTITHREAD
if (pbi->b_multithreaded_rd && pc->multi_token_partition != ONE_PARTITION)
{
int i;
unsigned int i;
vp8mt_decode_mb_rows(pbi, xd);
vp8_yv12_extend_frame_borders(&pc->yv12_fb[pc->new_fb_idx]); /*cm->frame_to_show);*/
for (i = 0; i < pbi->decoding_thread_count; ++i)

View File

@@ -300,7 +300,7 @@ int vp8dx_receive_compressed_data(VP8D_COMP *pbi, unsigned long size, const unsi
if (pbi->num_fragments == 0)
{
/* New frame, reset fragment pointers and sizes */
vpx_memset(pbi->fragments, 0, sizeof(pbi->fragments));
vpx_memset((void*)pbi->fragments, 0, sizeof(pbi->fragments));
vpx_memset(pbi->fragment_sizes, 0, sizeof(pbi->fragment_sizes));
}
if (pbi->input_fragments && !(source == NULL && size == 0))

View File

@@ -62,7 +62,7 @@ typedef struct VP8D_COMP
volatile int b_multithreaded_rd;
int max_threads;
int current_mb_col_main;
int decoding_thread_count;
unsigned int decoding_thread_count;
int allocated_decoding_thread_count;
int mt_baseline_filter_level[MAX_MB_SEGMENTS];

View File

@@ -667,7 +667,7 @@ static THREAD_FUNCTION thread_decoding_proc(void *p_data)
void vp8_decoder_create_threads(VP8D_COMP *pbi)
{
int core_count = 0;
int ithread;
unsigned int ithread;
pbi->b_multithreaded_rd = 0;
pbi->allocated_decoding_thread_count = 0;
@@ -881,7 +881,8 @@ void vp8_decoder_remove_threads(VP8D_COMP *pbi)
void vp8mt_decode_mb_rows( VP8D_COMP *pbi, MACROBLOCKD *xd)
{
VP8_COMMON *pc = &pbi->common;
int i;
unsigned int i;
int j;
int filter_level = pc->filter_level;
@@ -892,19 +893,19 @@ void vp8mt_decode_mb_rows( VP8D_COMP *pbi, MACROBLOCKD *xd)
vpx_memset(pbi->mt_uabove_row[0] + (VP8BORDERINPIXELS>>1)-1, 127, (pc->yv12_fb[pc->lst_fb_idx].y_width>>1) +5);
vpx_memset(pbi->mt_vabove_row[0] + (VP8BORDERINPIXELS>>1)-1, 127, (pc->yv12_fb[pc->lst_fb_idx].y_width>>1) +5);
for (i=1; i<pc->mb_rows; i++)
for (j=1; j<pc->mb_rows; j++)
{
vpx_memset(pbi->mt_yabove_row[i] + VP8BORDERINPIXELS-1, (unsigned char)129, 1);
vpx_memset(pbi->mt_uabove_row[i] + (VP8BORDERINPIXELS>>1)-1, (unsigned char)129, 1);
vpx_memset(pbi->mt_vabove_row[i] + (VP8BORDERINPIXELS>>1)-1, (unsigned char)129, 1);
vpx_memset(pbi->mt_yabove_row[j] + VP8BORDERINPIXELS-1, (unsigned char)129, 1);
vpx_memset(pbi->mt_uabove_row[j] + (VP8BORDERINPIXELS>>1)-1, (unsigned char)129, 1);
vpx_memset(pbi->mt_vabove_row[j] + (VP8BORDERINPIXELS>>1)-1, (unsigned char)129, 1);
}
/* Set left_col to 129 initially */
for (i=0; i<pc->mb_rows; i++)
for (j=0; j<pc->mb_rows; j++)
{
vpx_memset(pbi->mt_yleft_col[i], (unsigned char)129, 16);
vpx_memset(pbi->mt_uleft_col[i], (unsigned char)129, 8);
vpx_memset(pbi->mt_vleft_col[i], (unsigned char)129, 8);
vpx_memset(pbi->mt_yleft_col[j], (unsigned char)129, 16);
vpx_memset(pbi->mt_uleft_col[j], (unsigned char)129, 8);
vpx_memset(pbi->mt_vleft_col[j], (unsigned char)129, 8);
}
/* Initialize the loop filter for this frame. */

View File

@@ -107,7 +107,7 @@ typedef struct macroblock
int skip;
int encode_breakout;
unsigned int encode_breakout;
//char * gf_active_ptr;
signed char *gf_active_ptr;

View File

@@ -4909,7 +4909,7 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
if (cpi->oxcf.number_of_layers > 1)
{
int i;
unsigned int i;
// Update frame rates for each layer
for (i=0; i<cpi->oxcf.number_of_layers; i++)

View File

@@ -458,7 +458,7 @@ static void check_for_encode_breakout(unsigned int sse, MACROBLOCK* x)
if (sse < x->encode_breakout)
{
// Check u and v to make sure skip is ok
int sse2 = 0;
unsigned int sse2 = 0;
sse2 = VP8_UVSSE(x);

View File

@@ -357,7 +357,7 @@ static void calc_iframe_target_size(VP8_COMP *cpi)
{
// boost defaults to half second
int kf_boost;
int target;
unsigned int target;
// Clear down mmx registers to allow floating point in what follows
vp8_clear_system_state(); //__asm emms;

View File

@@ -1766,7 +1766,7 @@ static int evaluate_inter_mode_rd(int mdcounts[4],
{
unsigned int sse;
unsigned int var;
int threshold = (xd->block[0].dequant[1]
unsigned int threshold = (xd->block[0].dequant[1]
* xd->block[0].dequant[1] >>4);
if(threshold < x->encode_breakout)
@@ -1785,7 +1785,7 @@ static int evaluate_inter_mode_rd(int mdcounts[4],
(sse /2 > var && sse-var < 64))
{
// Check u and v to make sure skip is ok
int sse2= VP8_UVSSE(x);
unsigned int sse2 = VP8_UVSSE(x);
if (sse2 * 2 < threshold)
{
x->skip = 1;

View File

@@ -9,6 +9,7 @@
*/
#include "vpx_rtcd.h"
#include "vpx/vpx_codec.h"
#include "vpx/internal/vpx_codec_internal.h"
#include "vpx_version.h"
@@ -227,7 +228,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
if (cfg->ts_number_layers > 1)
{
int i;
unsigned int i;
RANGE_CHECK_HI(cfg, ts_periodicity, 16);
for (i=1; i<cfg->ts_number_layers; i++)
@@ -568,6 +569,8 @@ static vpx_codec_err_t vp8e_init(vpx_codec_ctx_t *ctx,
struct VP8_COMP *optr;
vpx_rtcd();
if (!ctx->priv)
{
priv = calloc(1, sizeof(struct vpx_codec_alg_priv));

View File

@@ -11,6 +11,7 @@
#include <stdlib.h>
#include <string.h>
#include "vpx_rtcd.h"
#include "vpx/vpx_decoder.h"
#include "vpx/vp8dx.h"
#include "vpx/internal/vpx_codec_internal.h"
@@ -187,6 +188,8 @@ static vpx_codec_err_t vp8_init(vpx_codec_ctx_t *ctx,
vpx_codec_err_t res = VPX_CODEC_OK;
(void) data;
vpx_rtcd();
/* This function only allocates space for the vpx_codec_alg_priv_t
* structure. More memory may be required at the time the stream
* information becomes known.

View File

@@ -113,6 +113,10 @@ extern "C" {
* function directly, to ensure that the ABI version number parameter
* is properly initialized.
*
* If the library was configured with --disable-multithread, this call
* is not thread safe and should be guarded with a lock if being used
* in a multithreaded context.
*
* In XMA mode (activated by setting VPX_CODEC_USE_XMA in the flags
* parameter), the storage pointed to by the cfg parameter must be
* kept readable and stable until all memory maps have been set.

View File

@@ -655,6 +655,10 @@ extern "C" {
* function directly, to ensure that the ABI version number parameter
* is properly initialized.
*
* If the library was configured with --disable-multithread, this call
* is not thread safe and should be guarded with a lock if being used
* in a multithreaded context.
*
* In XMA mode (activated by setting VPX_CODEC_USE_XMA in the flags
* parameter), the storage pointed to by the cfg parameter must be
* kept readable and stable until all memory maps have been set.