SchroMotionEst * schro_motionest_new (SchroEncoderFrame *frame) { SchroParams *params = &frame->params; SchroMotionEst *me; int n; me = schro_malloc0 (sizeof(SchroMotionEst)); me->encoder_frame = frame; me->params = &frame->params; me->src0 = frame->ref_frame[0]->reconstructed_frame; me->downsampled_src0[0] = frame->ref_frame[0]->filtered_frame; me->downsampled_src0[1] = frame->ref_frame[0]->downsampled_frames[0]; me->downsampled_src0[2] = frame->ref_frame[0]->downsampled_frames[1]; me->downsampled_src0[3] = frame->ref_frame[0]->downsampled_frames[2]; me->downsampled_src0[4] = frame->ref_frame[0]->downsampled_frames[3]; if (me->params->num_refs > 1) { me->src1 = frame->ref_frame[1]->reconstructed_frame; me->downsampled_src1[0] = frame->ref_frame[1]->filtered_frame; me->downsampled_src1[1] = frame->ref_frame[1]->downsampled_frames[0]; me->downsampled_src1[2] = frame->ref_frame[1]->downsampled_frames[1]; me->downsampled_src1[3] = frame->ref_frame[1]->downsampled_frames[2]; me->downsampled_src1[4] = frame->ref_frame[1]->downsampled_frames[3]; } n = params->x_num_blocks * params->y_num_blocks / 16; me->sblocks = schro_malloc0(sizeof(SchroBlock)*n); return me; }
SchroMotion * schro_motion_new (SchroParams * params, SchroFrame * ref1, SchroFrame * ref2) { SchroMotion *motion; motion = schro_malloc0 (sizeof (SchroMotion)); motion->params = params; motion->src1 = ref1; motion->src2 = ref2; motion->motion_vectors = schro_malloc0 (sizeof (SchroMotionVector) * params->x_num_blocks * params->y_num_blocks); return motion; }
SchroArith * schro_arith_new (void) { SchroArith *arith; arith = schro_malloc0 (sizeof(*arith)); return arith; }
SchroMemoryDomain * schro_memory_domain_new (void) { SchroMemoryDomain *domain; domain = schro_malloc0 (sizeof (SchroMemoryDomain)); domain->mutex = schro_mutex_new (); return domain; }
SchroAsync * schro_async_new (int n_threads, SchroAsyncScheduleFunc schedule, SchroAsyncCompleteFunc complete, void *closure) { SchroAsync *async; pthread_attr_t attr; pthread_mutexattr_t mutexattr; pthread_condattr_t condattr; int i; if (n_threads == 0) { char *s; s = getenv ("SCHRO_THREADS"); if (s && s[0]) { char *end; int n; n = strtoul (s, &end, 0); if (end[0] == 0) { n_threads = n; } } if (n_threads == 0) { #if defined(_WIN32) const char *s = getenv ("NUMBER_OF_PROCESSORS"); if (s) { n_threads = atoi (s); } #elif defined(__APPLE__) { int mib[] = { CTL_HW, HW_NCPU }; size_t dataSize = sizeof (int); if (sysctl (mib, 2, &n_threads, &dataSize, NULL, 0)) { n_threads = 0; } } #else n_threads = sysconf (_SC_NPROCESSORS_CONF); #endif } if (n_threads == 0) { n_threads = 1; } } async = schro_malloc0 (sizeof (SchroAsync)); SCHRO_DEBUG ("%d", n_threads); async->n_threads = n_threads; async->threads = schro_malloc0 (sizeof (SchroThread) * (n_threads + 1)); async->stop = RUNNING; async->schedule = schedule; async->schedule_closure = closure; async->complete = complete; pthread_mutexattr_init (&mutexattr); pthread_mutex_init (&async->mutex, &mutexattr); pthread_condattr_init (&condattr); pthread_cond_init (&async->app_cond, &condattr); pthread_cond_init (&async->thread_cond, &condattr); if (!domain_key_inited) { pthread_key_create (&domain_key, NULL); domain_key_inited = TRUE; } pthread_attr_init (&attr); pthread_mutex_lock (&async->mutex); for (i = 0; i < n_threads; i++) { SchroThread *thread = async->threads + i; thread->async = async; thread->index = i; thread->exec_domain = SCHRO_EXEC_DOMAIN_CPU; pthread_create (&async->threads[i].pthread, &attr, schro_thread_main, async->threads + i); pthread_mutex_lock (&async->mutex); } pthread_mutex_unlock (&async->mutex); pthread_attr_destroy (&attr); pthread_mutexattr_destroy (&mutexattr); pthread_condattr_destroy (&condattr); return async; }
SchroOpenGL * schro_opengl_new (void) { return schro_malloc0 (sizeof(SchroOpenGL)); }
SchroAsync * schro_async_new(int n_threads, SchroAsyncScheduleFunc schedule, SchroAsyncCompleteFunc complete, void *closure) { SchroAsync *async; int i; if (n_threads == 0) { char *s; s = getenv ("SCHRO_THREADS"); if (s && s[0]) { char *end; int n; n = strtoul (s, &end, 0); if (end[0] == 0) { n_threads = n; } } if (n_threads == 0) { const char *s = getenv("NUMBER_OF_PROCESSORS"); if (s) { n_threads = atoi(s); } } if (n_threads == 0) { n_threads = 1; } } async = schro_malloc0 (sizeof(SchroAsync)); SCHRO_DEBUG("%d", n_threads); async->n_threads = n_threads; async->threads = schro_malloc0 (sizeof(SchroThread) * (n_threads + 1)); async->schedule = schedule; async->schedule_closure = closure; async->complete = complete; InitializeCriticalSection (&async->mutex); async->app_event = CreateEvent (0, FALSE, FALSE, NULL); EnterCriticalSection (&async->mutex); for(i=0;i<n_threads;i++){ SchroThread *thread = async->threads + i; unsigned int ignore; thread->event = CreateEvent (0, FALSE, FALSE, NULL); thread->async = async; thread->index = i; thread->exec_domain = SCHRO_EXEC_DOMAIN_CPU; async->threads[i].thread = (HANDLE) _beginthreadex (NULL, STACK_SIZE, schro_thread_main, async->threads + i, 0, &ignore); EnterCriticalSection (&async->mutex); } LeaveCriticalSection (&async->mutex); return async; }