Ejemplo n.º 1
0
void
schro_async_free (SchroAsync *async)
{
  int i;
  HANDLE *handles;

  EnterCriticalSection (&async->mutex);
  async->stop = TRUE;
  LeaveCriticalSection (&async->mutex);

  for(i=0;i<async->n_threads;i++){
    SetEvent (async->threads[i].event);
  }

  handles = schro_malloc (sizeof(HANDLE) * async->n_threads);
  for(i=0;i<async->n_threads;i++){
    handles[i] = async->threads[i].thread;
  }
  WaitForMultipleObjects (async->n_threads, handles, TRUE,
      INFINITE);
  schro_free (handles);

  for(i=0;i<async->n_threads;i++){
    CloseHandle (async->threads[i].event);
    CloseHandle (async->threads[i].thread);
  }
  CloseHandle (async->app_event);
  DeleteCriticalSection (&async->mutex);
  schro_free(async->threads);
  schro_free(async);
}
Ejemplo n.º 2
0
void
schro_fft_fwd_f32 (float *d_real, float *d_imag, const float *s_real,
    const float *s_imag, const float *costable, const float *sintable,
    int shift)
{
  int i;
  int n = 1 << shift;
  float *tmp;
  float *tmp1_1, *tmp1_2, *tmp2_1, *tmp2_2;

  tmp = schro_malloc (4 * sizeof (float) * n);
  tmp1_1 = tmp;
  tmp1_2 = tmp + n;
  tmp2_1 = tmp + 2 * n;
  tmp2_2 = tmp + 3 * n;

  i = 0;
  fft_stage (tmp1_1, tmp1_2, s_real, s_imag, costable, sintable, i, shift);
  for (i = 1; i < shift - 2; i += 2) {
    fft_stage (tmp2_1, tmp2_2, tmp1_1, tmp1_2, costable, sintable, i, shift);
    fft_stage (tmp1_1, tmp1_2, tmp2_1, tmp2_2, costable, sintable, i + 1,
        shift);
  }
  if (i < shift - 1) {
    fft_stage (tmp2_1, tmp2_2, tmp1_1, tmp1_2, costable, sintable, i, shift);
    fft_stage (d_real, d_imag, tmp2_1, tmp2_2, costable, sintable, i + 1,
        shift);
  } else {
    fft_stage (d_real, d_imag, tmp1_1, tmp1_2, costable, sintable, i, shift);
  }

  schro_free (tmp);
}
Ejemplo n.º 3
0
SchroMutex *
schro_mutex_new (void)
{
  SchroMutex *mutex;
  pthread_mutexattr_t mutexattr;

  mutex = schro_malloc (sizeof (SchroMutex));
  pthread_mutexattr_init (&mutexattr);
  pthread_mutex_init (&mutex->mutex, &mutexattr);
  pthread_mutexattr_destroy (&mutexattr);

  return mutex;
}
Ejemplo n.º 4
0
SchroMotion *
schro_motion_new (SchroParams *params, SchroUpsampledFrame *ref1,
    SchroUpsampledFrame *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);

  motion->tmpdata = schro_malloc (64*64*3);

  return motion;
}
Ejemplo n.º 5
0
static void
schro_lowdelay_init (SchroLowDelay *lowdelay, SchroFrame *frame,
    SchroParams *params)
{
  int i;
  int size;

  lowdelay->params = params;
  for(i=0;i<1+3*params->transform_depth;i++){
    int position = schro_subband_get_position(i);

    schro_subband_get_frame_data (lowdelay->luma_subbands + i,
        frame, 0, position, params);
    schro_subband_get_frame_data (lowdelay->chroma1_subbands + i,
        frame, 1, position, params);
    schro_subband_get_frame_data (lowdelay->chroma2_subbands + i,
        frame, 2, position, params);
  }

  size = 1000;
  lowdelay->saved_dc_values = schro_malloc (sizeof(int16_t) * size);
}
Ejemplo n.º 6
0
void
schro_encoder_calculate_subband_weights (SchroEncoder *encoder,
    double (*perceptual_weight)(double))
{
  int wavelet;
  int n_levels;
  double *matrix;
  int n;
  int i,j;
  double column[SCHRO_LIMIT_SUBBANDS];
  double *weight;

  matrix = schro_malloc (sizeof(double)*SCHRO_LIMIT_SUBBANDS*SCHRO_LIMIT_SUBBANDS);
  weight = schro_malloc (sizeof(double)*CURVE_SIZE*CURVE_SIZE);

  for(j=0;j<CURVE_SIZE;j++){
    for(i=0;i<CURVE_SIZE;i++){
      double fv = j*encoder->cycles_per_degree_vert*(1.0/CURVE_SIZE);
      double fh = i*encoder->cycles_per_degree_horiz*(1.0/CURVE_SIZE);

      weight[j*CURVE_SIZE+i] = perceptual_weight (sqrt(fv*fv+fh*fh));
    }
  }

  for(wavelet=0;wavelet<SCHRO_N_WAVELETS;wavelet++) {
    for(n_levels=1;n_levels<=4;n_levels++){
      const float *h_curve[SCHRO_LIMIT_SUBBANDS];
      const float *v_curve[SCHRO_LIMIT_SUBBANDS];
      int hi[SCHRO_LIMIT_SUBBANDS];
      int vi[SCHRO_LIMIT_SUBBANDS];

      n = 3*n_levels+1;

      for(i=0;i<n;i++){
        int position = schro_subband_get_position(i);
        int n_transforms;

        n_transforms = n_levels - SCHRO_SUBBAND_SHIFT(position);
        if (position&1) {
          hi[i] = (n_transforms-1)*2;
        } else {
          hi[i] = (n_transforms-1)*2+1;
        }
        if (position&2) {
          vi[i] = (n_transforms-1)*2;
        } else {
          vi[i] = (n_transforms-1)*2+1;
        }
        h_curve[i] = schro_tables_wavelet_noise_curve[wavelet][hi[i]];
        v_curve[i] = schro_tables_wavelet_noise_curve[wavelet][vi[i]];
      }

      if (0) {
        for(i=0;i<n;i++){
          column[i] = weighted_sum(h_curve[i], v_curve[i], weight);
          matrix[i*n+i] = dot_product (h_curve[i], v_curve[i],
              h_curve[i], v_curve[i], weight);
          for(j=i+1;j<n;j++) {
            matrix[i*n+j] = dot_product (h_curve[i], v_curve[i],
                h_curve[j], v_curve[j], weight);
            matrix[j*n+i] = matrix[i*n+j];
          }
        }

        solve (matrix, column, n);

        for(i=0;i<n;i++){
          if (column[i] < 0) {
            SCHRO_ERROR("BROKEN wavelet %d n_levels %d", wavelet, n_levels);
            break;
          }
        }

        SCHRO_DEBUG("wavelet %d n_levels %d", wavelet, n_levels);
        for(i=0;i<n;i++){
          SCHRO_DEBUG("%g", 1.0/sqrt(column[i]));
          encoder->subband_weights[wavelet][n_levels-1][i] = sqrt(column[i]);
        }
      } else {
        for(i=0;i<n;i++){
          int position = schro_subband_get_position(i);
          int n_transforms;
          double size;

          n_transforms = n_levels - SCHRO_SUBBAND_SHIFT(position);
          size = (1.0/CURVE_SIZE)*(1<<n_transforms);
          encoder->subband_weights[wavelet][n_levels-1][i] = 1.0/(size *
            sqrt(weighted_sum(h_curve[i], v_curve[i], weight)));
        }
      }
    }
  }

#if 0
  for(wavelet=0;wavelet<8;wavelet++) {
    for(n_levels=1;n_levels<=4;n_levels++){
      double alpha, beta, shift;
      double gain;

      alpha = schro_tables_wavelet_gain[wavelet][0];
      beta = schro_tables_wavelet_gain[wavelet][1];
      shift = (1<<filtershift[wavelet]);

      n = 3*n_levels+1;

      gain = shift;
      for(i=n_levels-1;i>=0;i--){
        encoder->subband_weights[wavelet][n_levels-1][1+3*i+0] =
          sqrt(alpha*beta)*gain;
        encoder->subband_weights[wavelet][n_levels-1][1+3*i+1] =
          sqrt(alpha*beta)*gain;
        encoder->subband_weights[wavelet][n_levels-1][1+3*i+2] =
          sqrt(beta*beta)*gain;
        gain *= alpha;
        gain *= shift;
      }
      encoder->subband_weights[wavelet][n_levels-1][0] = gain / shift;
      if (wavelet == 3 && n_levels == 3) {
        for(i=0;i<10;i++){
          SCHRO_ERROR("%g",
              encoder->subband_weights[wavelet][n_levels-1][i]);
        }
      }
    }
  }
#endif

  schro_free(weight);
  schro_free(matrix);
}