Пример #1
0
int
main (int argc, char *argv[])
{
  FILE *file;

  schro_init();

  if (argc < 2) {
    printf("decode stream.drc\n");
    exit(1);
  }

  file = fopen (argv[1], "r");
  if (file == NULL) {
    printf("cannot open %s\n", argv[1]);
    return 1;
  }

  decode (file);
  //parse (file);

  fclose (file);

  return 0;
}
Пример #2
0
int
main (int argc, char *argv[])
{
  //int i;

  schro_init();

  //while(1) check(1000, 128);
  check(100, 128);
#if 0
  for(i=100;i<=1000;i+=100) {
    //check(i, 128);
    check(i, 256);
  }
  check(2000, 256);
  check(3000, 256);
  check(4000, 256);
  check(5000, 256);
  check(100000, 256);
#endif
#if 0
  for(i=0;i<=256;i+=16) {
    check(100, i);
  }
#endif

  return 0;
}
Пример #3
0
static int init_schroedinger(bgav_stream_t * s)
  {
  schroedinger_priv_t * priv;

  schro_init();
  
  priv = calloc(1, sizeof(*priv));
  priv->last_pts = GAVL_TIME_UNDEFINED;
  
  s->decoder_priv = priv;

  priv->dec = schro_decoder_new();

  priv->frame = gavl_video_frame_create(NULL);
  s->vframe = priv->frame;
  
  if(decode_picture(s) != GAVL_SOURCE_OK) /* Get format */
    return 0;

  gavl_metadata_set(&s->m, GAVL_META_FORMAT,
                    "Dirac");

  if(!s->ext_data)
    priv->header_sent = 1;
  
  return 1;
  }
Пример #4
0
int
main (int argc, char *argv[])
{
  int filter;
  int width;
  int height;

  schro_init();

  for(filter=0;filter<=SCHRO_WAVELET_DAUBECHIES_9_7;filter++){
    printf("Filter %d:\n", filter);
    fwd_test(filter, 20, 20);
    inv_test(filter, 20, 20);
  }

  for(width = 2; width <= 40; width+=2) {
    for(height = 2; height <= 40; height+=2) {
      printf("Size %dx%d:\n", width, height);
      for(filter=0;filter<=SCHRO_WAVELET_DAUBECHIES_9_7;filter++){
        printf("  filter %d:\n", filter);
        fwd_random_test(filter, width, height);
        inv_random_test(filter, width, height);
        fwd_random_test_s32(filter, width, height);
        inv_random_test_s32(filter, width, height);
      }
    }
  }

  return fail;
}
Пример #5
0
static gboolean
plugin_init (GstPlugin * plugin)
{
  schro_init();

  GST_DEBUG_CATEGORY_INIT (schro_debug, "schro", 0, "Schroedinger");
  gst_element_register (plugin, "schrotoy", GST_RANK_NONE,
      gst_schrotoy_get_type ());
  gst_element_register (plugin, "schrofilter", GST_RANK_NONE,
      gst_schrofilter_get_type ());
  gst_element_register (plugin, "schrodownsample", GST_RANK_NONE,
      gst_schrodownsample_get_type ());
  gst_element_register (plugin, "schroenc", GST_RANK_PRIMARY,
      gst_schro_enc_get_type ());
  gst_element_register (plugin, "schrodec", GST_RANK_PRIMARY,
      gst_schro_dec_get_type ());
  gst_element_register (plugin, "schroparse", GST_RANK_NONE,
      gst_schro_parse_get_type ());
  gst_element_register (plugin, "framestore", GST_RANK_NONE,
      gst_frame_store_get_type ());
  gst_element_register (plugin, "schroscale", GST_RANK_NONE,
      gst_schro_scale_get_type ());

  return TRUE;
}
Пример #6
0
int
main (int argc, char *argv[])
{
  int x;
  int i;

  schro_init();

  x = 100;
  for(i=0;i<N;i++){
    in_data[i] = rand_u8() < x;
  }

  dumpbits(in_data + 9900, 100);

  //n = encode_arith_dirac (out_data, in_data, N);
  //dumpbits(out_data, n);

  encode_arith_exp (out_data, in_data, N);
  //dumpbits(out_data, n);

  decode_arith_exp (c_data, out_data, N);
  dumpbits(c_data + 9900, 100);

  return 0;
}
Пример #7
0
int
main (int argc, char *argv[])
{
  int ok = 1;
  int i;

  schro_init();

  srand(time(NULL));

  for(i=0;i<100;i++){
    ok &= test1();
  }
  for(i=0;i<100;i++){
    ok &= test2();
  }
  for(i=0;i<100;i++){
    ok &= test3();
  }

  ok &= test4();

  if (ok) exit(0);
  exit(1);
}
Пример #8
0
int
main (int argc, char *argv[])
{
  int i;
  SchroBuffer *buffer = schro_buffer_new_and_alloc (100);
  SchroBits *bits;
  int value;
  int fail = 0;
  int n;

  schro_init();

  printf("unsigned int\n");
  for(i=0;i<21;i++) {
    bits = schro_bits_new();
    schro_bits_encode_init (bits, buffer);
    schro_bits_encode_uint(bits,i);
    schro_bits_flush (bits);
    n = schro_bits_get_offset (bits);
    schro_bits_free (bits);

    bits = schro_bits_new();
    schro_bits_decode_init (bits, buffer);
    printf("%3d:", i);
    dump_bits (bits, n);
    value = schro_bits_decode_uint (bits);
    if (value != i) {
      printf("decode failed (%d != %d)\n", value, i);
      fail = 1;
    }
    schro_bits_free (bits);
  }
  printf("\n");

  printf("signed int\n");
  for(i=-5;i<6;i++) {
    bits = schro_bits_new();
    schro_bits_encode_init (bits, buffer);
    schro_bits_encode_sint(bits,i);
    schro_bits_flush (bits);
    n = schro_bits_get_offset (bits);
    schro_bits_free (bits);

    bits = schro_bits_new();
    schro_bits_decode_init (bits, buffer);
    printf("%3d:", i);
    dump_bits (bits, n);
    value = schro_bits_decode_sint (bits);
    if (value != i) {
      printf("decode failed (%d != %d)\n", value, i);
      fail = 1;
    }
    schro_bits_free (bits);
  }
  printf("\n");

  return fail;
}
Пример #9
0
int
main (int argc, char *argv[])
{
    int i;
    SchroBuffer *buffer = schro_buffer_new_and_alloc (300);
    SchroBits *bits;
    int value;
    int fail = 0;
    int n;

    schro_init();

    srand(time(NULL));

    bits = schro_bits_new();

    printf("unsigned int\n");
    schro_bits_encode_init (bits, buffer);
    for(i=0; i<N; i++) {
        ref[i] = rand() & 0x7;
        schro_bits_encode_uint(bits,ref[i]);
    }
    schro_bits_flush (bits);
    n = schro_bits_get_offset (bits);
    schro_bits_free (bits);

    bits = schro_bits_new();
    schro_bits_decode_init (bits, buffer);
    for(i=0; i<N; i++) {
        value = schro_bits_decode_uint (bits);
        if (value != ref[i]) {
            printf("decode failed (%d != %d) at offset %d\n", value, ref[i], i);
            fail = 1;
        }
    }

    printf("signed int\n");
    schro_bits_encode_init (bits, buffer);
    for(i=0; i<N; i++) {
        ref[i] = (rand() & 0xf) - 8;
        schro_bits_encode_sint (bits,ref[i]);
    }
    schro_bits_flush (bits);
    n = schro_bits_get_offset (bits);
    schro_bits_free (bits);

    bits = schro_bits_new();
    schro_bits_decode_init (bits, buffer);
    for(i=0; i<N; i++) {
        value = schro_bits_decode_sint (bits);
        if (value != ref[i]) {
            printf("decode failed (%d != %d) at offset %d\n", value, ref[i], i);
            fail = 1;
        }
    }

    return fail;
}
Пример #10
0
int
main (int argc, char *argv[])
{
  int i;

  schro_init();

  for(i=-10;i<10;i++){
    printf("%d: %d\n", i, schro_divide(i,3));
  }

  exit(0);
}
Пример #11
0
static gboolean
plugin_init (GstPlugin * plugin)
{
  schro_init ();

  GST_DEBUG_CATEGORY_INIT (schro_debug, "schro", 0, "Schroedinger");
  gst_element_register (plugin, "schrodec", GST_RANK_PRIMARY,
      gst_schro_dec_get_type ());
  gst_element_register (plugin, "schroenc", GST_RANK_PRIMARY,
      gst_schro_enc_get_type ());

  return TRUE;
}
Пример #12
0
int
main (int argc, char *argv[])
{
  int i;

  schro_init();

  for(i=0;i<6;i++){
    test_full_field(720/8, 576/8, matrices[i], matrices[i] + 4, 0, 0);
    test_full_field(720/8, 576/8, matrices[i], matrices[i] + 4, 1, 0);
    test_full_field(720/8, 576/8, matrices[i], matrices[i] + 4, 0, 1);
  }

  return 0;
}
Пример #13
0
int
main (int argc, char *argv[])
{
  int filter;
  int n_levels;

  schro_init();

  filter = 0;
  if (argc > 1) {
    filter = strtol(argv[1], NULL, 0);
  }

  {
    double a[5];
    double b[9];
    int i;
    double min;

    for(n_levels=1;n_levels<=4;n_levels++){
      printf("n_levels=%d:\n", n_levels);
      for(i=0;i<=n_levels;i++){
        a[i] = gain_test (filter, i, n_levels);
      }
      for(i=0;i<=n_levels;i++){
        printf("%d %5.3f\n", i, a[i]);
      }

      b[0] = a[0] * a[0] / (1<<(n_levels*filtershift[filter]));
      for(i=0;i<n_levels;i++){
        b[i*2+1] = a[i+0] * a[i+1] / (1<<((n_levels-i)*filtershift[filter]));
        b[i*2+2] = a[i+1] * a[i+1] / (1<<((n_levels-i)*filtershift[filter]));
      }

      min = b[0];
      for(i=0;i<n_levels*2+1;i++){
        if (b[i] < min) min = b[i];
      }

      for(i=0;i<n_levels*2+1;i++){
        printf("%d %5.3f %5.3f %d\n", i, b[i], b[i]/min, quant_index(b[i]/min));
      }
    }
  }

  return 0;
}
Пример #14
0
int
main (int argc, char *argv[])
{
  int i;
  double x;
  int j,k;

  schro_init();

  for(i=0;i<100;i++){
    x = i*1;
    j = schro_utils_multiplier_to_quant_index (x);
    k = schro_table_quant[j];
    printf("%g %d %d\n", x, j, k);
  }

  exit(0);
}
static av_cold int libschroedinger_decode_init(AVCodecContext *avctx)
{

    SchroDecoderParams *p_schro_params = avctx->priv_data;
    /* First of all, initialize our supporting libraries. */
    schro_init();

    schro_debug_set_level(avctx->debug);
    p_schro_params->decoder = schro_decoder_new();
    schro_decoder_set_skip_ratio(p_schro_params->decoder, 1);

    if (!p_schro_params->decoder)
        return -1;

    /* Initialize the decoded frame queue. */
    ff_schro_queue_init(&p_schro_params->dec_frame_queue);
    return 0;
}
Пример #16
0
int
main (int argc, char *argv[])
{
  schro_init();

  check_output (SCHRO_WAVELET_DAUBECHIES_9_7, 1);
  check_output (SCHRO_WAVELET_DAUBECHIES_9_7, 0);

  check_output (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7, 1);
  check_output (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7, 0);

  check_output (SCHRO_WAVELET_LE_GALL_5_3, 1);
  check_output (SCHRO_WAVELET_LE_GALL_5_3, 0);

  check_output (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7, 1);
  check_output (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7, 0);
  
  check_endpoints (SCHRO_WAVELET_DAUBECHIES_9_7, 1);
  check_endpoints (SCHRO_WAVELET_DAUBECHIES_9_7, 0);

  check_endpoints (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7, 1);
  check_endpoints (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7, 0);

  check_endpoints (SCHRO_WAVELET_LE_GALL_5_3, 1);
  check_endpoints (SCHRO_WAVELET_LE_GALL_5_3, 0);

  check_endpoints (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7, 1);
  check_endpoints (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7, 0);
  

  check_constant (SCHRO_WAVELET_DAUBECHIES_9_7);
  check_constant (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7);
  check_constant (SCHRO_WAVELET_LE_GALL_5_3);
  check_constant (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7);


  check_random (SCHRO_WAVELET_DAUBECHIES_9_7);
  check_random (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7);
  check_random (SCHRO_WAVELET_LE_GALL_5_3);
  check_random (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7);


  return 0;
}
Пример #17
0
int
main (int argc, char *argv[])
{
    int i;
    SchroFrame *frame;
    int width;
    int height;

    width = 1920;
    height = 1088;
    //width = 1280; height = 720;

    orc_init();
    schro_init();

    printf ("size %dx%d\n", width, height);

    frame = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_S16_422,
                                       width, height);

    for(i=0; i<7; i++) {
        printf("wavelet %d\n", i);
        wavelet_speed (frame, i, width, height);
    }

#ifdef HAVE_CUDA
    {
        SchroMemoryDomain *cuda_domain = schro_memory_domain_new_cuda ();

        frame = schro_frame_new_and_alloc (cuda_domain, SCHRO_FRAME_FORMAT_S16_422,
                                           width, height);

        for(i=0; i<7; i++) {
            printf("wavelet %d\n", i);
            wavelet_speed_cuda (frame, i, width, height);
        }
    }
#endif

    return 0;
}
Пример #18
0
int
main (int argc, char *argv[])
{
  int filter;
  int j;
  int n;
  int i;
  SchroEncoder *encoder;
  double min;
  double x;

  schro_init();

  encoder = schro_encoder_new ();

  for(filter=0;filter<8;filter++){
    for(j=0;j<4;j++){
      printf("filter %d n_levels %d\n", filter, j+1);
      n = 3*(j+1)+1;

      min = encoder->subband_weights[filter][j][0];
      for(i=0;i<n;i++){
        if (encoder->subband_weights[filter][j][i] < min) {
          min = encoder->subband_weights[filter][j][i];
        }
      }
      for(i=0;i<n;i++){
        x = encoder->subband_weights[filter][j][i]/min;
        printf("%2d %6.3f %6.3f %d\n", i, encoder->subband_weights[filter][j][i],
            x, gain_to_quant_index(x));
      }
    }
  }

  return 0;
}
Пример #19
0
int
main (int argc, char *argv[])
{
  SchroFrame *dest;
  SchroFrame *ref;
  SchroUpsampledFrame *uref;
  SchroParams params;
  SchroVideoFormat video_format;
  SchroMotionVector *motion_vectors;
  int i;
  int j;
  OilProfile prof;
  double ave, std;

  schro_init();

  video_format.width = 720;
  video_format.height = 480;
  video_format.chroma_format = SCHRO_CHROMA_420;
  schro_video_format_validate (&video_format);

  params.video_format = &video_format;
  params.xbsep_luma = 8;
  params.ybsep_luma = 8;
  params.xblen_luma = 12;
  params.yblen_luma = 12;

  schro_params_calculate_mc_sizes(&params);

  dest = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_S16_420,
      video_format.width, video_format.height);
  schro_frame_clear(dest);

  ref = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_U8_420,
      video_format.width, video_format.height);
  schro_frame_clear(ref);

  uref = schro_upsampled_frame_new (ref);

  schro_upsampled_frame_upsample (uref);

  motion_vectors = malloc(sizeof(SchroMotionVector) *
      params.x_num_blocks * params.y_num_blocks);
  memset (motion_vectors, 0, sizeof(SchroMotionVector) *
      params.x_num_blocks * params.y_num_blocks);
  
  printf("sizeof(SchroMotionVector) = %lu\n",(unsigned long) sizeof(SchroMotionVector));
  printf("num blocks %d x %d\n", params.x_num_blocks, params.y_num_blocks);
  for(i=0;i<params.x_num_blocks*params.y_num_blocks;i++){
    motion_vectors[i].dx[0] = 0;
    motion_vectors[i].dy[0] = 0;
    motion_vectors[i].pred_mode = 1;
    motion_vectors[i].split = 2;
  }

  for(i=0;i<10;i++){
    oil_profile_init (&prof);
    for(j=0;j<10;j++){
      SchroMotion motion;

      motion.src1 = uref;
      motion.src2 = NULL;
      motion.motion_vectors = motion_vectors;
      motion.params = &params;
      oil_profile_start(&prof);
      schro_motion_render (&motion, dest);
      oil_profile_stop(&prof);
    }
    oil_profile_get_ave_std (&prof, &ave, &std);
    printf("cycles %g %g\n", ave, std);
  }



  schro_upsampled_frame_free (uref);
  schro_frame_unref (dest);
  free (motion_vectors);

  return 0;
}
Пример #20
0
static int libschroedinger_encode_init(AVCodecContext *avccontext)
{
    SchroEncoderParams *p_schro_params = avccontext->priv_data;
    SchroVideoFormatEnum preset;

    /* Initialize the libraries that libschroedinger depends on. */
    schro_init();

    /* Create an encoder object. */
    p_schro_params->encoder = schro_encoder_new();

    if (!p_schro_params->encoder) {
        av_log(avccontext, AV_LOG_ERROR,
               "Unrecoverable Error: schro_encoder_new failed. ");
        return -1;
    }

    /* Initialize the format. */
    preset = ff_get_schro_video_format_preset(avccontext);
    p_schro_params->format =
                    schro_encoder_get_video_format(p_schro_params->encoder);
    schro_video_format_set_std_video_format(p_schro_params->format, preset);
    p_schro_params->format->width  = avccontext->width;
    p_schro_params->format->height = avccontext->height;

    if (set_chroma_format(avccontext) == -1)
        return -1;

    if (avccontext->color_primaries == AVCOL_PRI_BT709) {
        p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_HDTV;
    } else if (avccontext->color_primaries == AVCOL_PRI_BT470BG) {
        p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_625;
    } else if (avccontext->color_primaries == AVCOL_PRI_SMPTE170M) {
        p_schro_params->format->colour_primaries = SCHRO_COLOUR_PRIMARY_SDTV_525;
    }

    if (avccontext->colorspace == AVCOL_SPC_BT709) {
        p_schro_params->format->colour_matrix = SCHRO_COLOUR_MATRIX_HDTV;
    } else if (avccontext->colorspace == AVCOL_SPC_BT470BG) {
        p_schro_params->format->colour_matrix = SCHRO_COLOUR_MATRIX_SDTV;
    }

    if (avccontext->color_trc == AVCOL_TRC_BT709) {
        p_schro_params->format->transfer_function = SCHRO_TRANSFER_CHAR_TV_GAMMA;
    }

    if (ff_get_schro_frame_format(p_schro_params->format->chroma_format,
                                  &p_schro_params->frame_format) == -1) {
        av_log(avccontext, AV_LOG_ERROR,
               "This codec currently supports only planar YUV 4:2:0, 4:2:2"
               " and 4:4:4 formats.\n");
        return -1;
    }

    p_schro_params->format->frame_rate_numerator   = avccontext->time_base.den;
    p_schro_params->format->frame_rate_denominator = avccontext->time_base.num;

    p_schro_params->frame_size = avpicture_get_size(avccontext->pix_fmt,
                                                    avccontext->width,
                                                    avccontext->height);

    avccontext->coded_frame = &p_schro_params->picture;

    if (!avccontext->gop_size) {
        schro_encoder_setting_set_double(p_schro_params->encoder,
                                         "gop_structure",
                                         SCHRO_ENCODER_GOP_INTRA_ONLY);

        if (avccontext->coder_type == FF_CODER_TYPE_VLC)
            schro_encoder_setting_set_double(p_schro_params->encoder,
                                             "enable_noarith", 1);
    } else {
        schro_encoder_setting_set_double(p_schro_params->encoder,
                                         "au_distance", avccontext->gop_size);
        avccontext->has_b_frames = 1;
        p_schro_params->dts = -1;
    }

    /* FIXME - Need to handle SCHRO_ENCODER_RATE_CONTROL_LOW_DELAY. */
    if (avccontext->flags & CODEC_FLAG_QSCALE) {
        if (!avccontext->global_quality) {
            /* lossless coding */
            schro_encoder_setting_set_double(p_schro_params->encoder,
                                             "rate_control",
                                             SCHRO_ENCODER_RATE_CONTROL_LOSSLESS);
        } else {
            int quality;
            schro_encoder_setting_set_double(p_schro_params->encoder,
                                             "rate_control",
                                             SCHRO_ENCODER_RATE_CONTROL_CONSTANT_QUALITY);

            quality = avccontext->global_quality / FF_QP2LAMBDA;
            if (quality > 10)
                quality = 10;
            schro_encoder_setting_set_double(p_schro_params->encoder,
                                             "quality", quality);
        }
    } else {
        schro_encoder_setting_set_double(p_schro_params->encoder,
                                         "rate_control",
                                         SCHRO_ENCODER_RATE_CONTROL_CONSTANT_BITRATE);

        schro_encoder_setting_set_double(p_schro_params->encoder,
                                         "bitrate",
                                         avccontext->bit_rate);

    }

    if (avccontext->flags & CODEC_FLAG_INTERLACED_ME)
        /* All material can be coded as interlaced or progressive
           irrespective of the type of source material. */
        schro_encoder_setting_set_double(p_schro_params->encoder,
                                         "interlaced_coding", 1);

    schro_encoder_setting_set_double(p_schro_params->encoder, "open_gop",
                                     !(avccontext->flags & CODEC_FLAG_CLOSED_GOP));

    /* FIXME: Signal range hardcoded to 8-bit data until both libschroedinger
     * and libdirac support other bit-depth data. */
    schro_video_format_set_std_signal_range(p_schro_params->format,
                                            SCHRO_SIGNAL_RANGE_8BIT_VIDEO);

    /* Set the encoder format. */
    schro_encoder_set_video_format(p_schro_params->encoder,
                                   p_schro_params->format);

    /* Set the debug level. */
    schro_debug_set_level(avccontext->debug);

    schro_encoder_start(p_schro_params->encoder);

    /* Initialize the encoded frame queue. */
    ff_schro_queue_init(&p_schro_params->enc_frame_queue);
    return 0;
}
Пример #21
0
int
main (int argc, char *argv[])
{
  SchroFrame *dest;
  SchroFrame *ref;
  SchroFrame *addframe;
  SchroParams params;
  SchroVideoFormat video_format;
  SchroMotionVector *motion_vectors;
  int i;
  int j;
  OrcProfile prof;
  double ave, std;

  schro_init();

  memset (&video_format, 0, sizeof(video_format));
  memset (&params, 0, sizeof(params));

  schro_video_format_set_std_video_format (&video_format,
      SCHRO_VIDEO_FORMAT_CUSTOM);
  video_format.width = 720;
  video_format.height = 480;
  video_format.chroma_format = SCHRO_CHROMA_420;
  schro_video_format_validate (&video_format);

  params.video_format = &video_format;
  params.xbsep_luma = 8;
  params.ybsep_luma = 8;
  params.xblen_luma = 12;
  params.yblen_luma = 12;

  schro_params_calculate_mc_sizes(&params);

  dest = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_S16_420,
      video_format.width, video_format.height);
  schro_frame_clear(dest);

  ref = schro_frame_new_and_alloc_extended (NULL, SCHRO_FRAME_FORMAT_U8_420,
      video_format.width, video_format.height, 32);
  schro_frame_clear(ref);

  addframe = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_S16_420,
      video_format.width, video_format.height);
  schro_frame_clear(addframe);

  schro_upsampled_frame_upsample (ref);

  motion_vectors = malloc(sizeof(SchroMotionVector) *
      params.x_num_blocks * params.y_num_blocks);
  memset (motion_vectors, 0, sizeof(SchroMotionVector) *
      params.x_num_blocks * params.y_num_blocks);
  
  printf("sizeof(SchroMotionVector) = %lu\n",(unsigned long) sizeof(SchroMotionVector));
  printf("num blocks %d x %d\n", params.x_num_blocks, params.y_num_blocks);
  for(i=0;i<params.x_num_blocks*params.y_num_blocks;i++){
    motion_vectors[i].u.vec.dx[0] = 0;
    motion_vectors[i].u.vec.dy[0] = 0;
    motion_vectors[i].pred_mode = 1;
    motion_vectors[i].split = 2;
  }

  for(i=0;i<10;i++){
    orc_profile_init (&prof);
    for(j=0;j<10;j++){
      SchroMotion *motion;
      void *mv_save;

      motion = schro_motion_new (&params, ref, NULL);
      mv_save = motion->motion_vectors;
      motion->motion_vectors = motion_vectors;
      orc_profile_start(&prof);
      schro_motion_render (motion, dest, addframe, FALSE, NULL);
      orc_profile_stop(&prof);
      motion->motion_vectors = mv_save;
      schro_motion_free (motion);
    }
    orc_profile_get_ave_std (&prof, &ave, &std);
    printf("cycles %g %g\n", ave, std);
  }

  schro_frame_unref (ref);
  schro_frame_unref (dest);
  free (motion_vectors);

  return 0;
}
Пример #22
0
static bool
RunTest(int bit_depth)
{
	bool result = true;

	const int seq_len = 5;
	
	const int width = 100;
	const int height = 10;
	
	int luma_min = 16;
	int luma_max = 235;
	int chroma_zero = 128;
	
	schro_init();
	
	// set up encoder
	SchroEncoder *encoder = schro_encoder_new();
	
	schro_encoder_setting_set_double(encoder, "gop_structure", SCHRO_ENCODER_GOP_INTRA_ONLY);
	schro_encoder_setting_set_double(encoder, "rate_control", SCHRO_ENCODER_RATE_CONTROL_LOSSLESS);
	//schro_encoder_setting_set_double(encoder, "force_profile", SCHRO_ENCODER_PROFILE_VC2_SIMPLE);
	//schro_encoder_setting_set_double(encoder, "queue_depth", seq_len);
	//assert(seq_len <= SCHRO_LIMIT_FRAME_QUEUE_LENGTH);
	
	SchroVideoFormat *format = schro_encoder_get_video_format(encoder);
	
	if(format)
	{
		format->width = width;
		format->height = height;
		
		format->clean_width = format->width;
		format->clean_height = format->height;
		format->left_offset = 0;
		format->top_offset = 0;
		
		format->chroma_format = SCHRO_CHROMA_444;
		
		const SchroSignalRange range = (bit_depth == 12 ? SCHRO_SIGNAL_RANGE_12BIT_VIDEO :
										bit_depth == 10 ? SCHRO_SIGNAL_RANGE_10BIT_VIDEO :
										SCHRO_SIGNAL_RANGE_8BIT_VIDEO);
										
		schro_video_format_set_std_signal_range(format, range);
		
		luma_min = format->luma_offset;
		luma_max = format->luma_offset + format->luma_excursion;
		chroma_zero = format->chroma_offset;
		
		format->colour_primaries = SCHRO_COLOUR_PRIMARY_HDTV;
		format->colour_matrix = SCHRO_COLOUR_MATRIX_HDTV;
		format->transfer_function = SCHRO_TRANSFER_CHAR_TV_GAMMA;
		
		format->interlaced = false;
		
		format->frame_rate_numerator = 24;
		format->frame_rate_denominator = 1;
		
		format->aspect_ratio_numerator = 1;
		format->aspect_ratio_denominator = 1;
		
		schro_encoder_set_video_format(encoder, format);
		
		free(format);
	}
	else
		return false;
	
	schro_encoder_start(encoder);
	
	
	// create frame
	SchroFrame *start_frame = schro_frame_new_and_alloc(NULL, SCHRO_FRAME_FORMAT_U8_444, width, height);
	
	FillFrame<unsigned char>(start_frame, 16, 235, 128);
	
	const SchroFrameFormat schro_format = (bit_depth > 8 ? SCHRO_FRAME_FORMAT_S16_444 : SCHRO_FRAME_FORMAT_U8_444);

	SchroFrame *original_frame = schro_frame_new_and_alloc(NULL, schro_format, width, height);
	
	schro_frame_convert(original_frame, start_frame);
	
	
	
	SchroDecoder *decoder = schro_decoder_new();
	
	// push frames to encoder
	for(int t = 0; t < seq_len; t++)
	{
		SchroFrame *new_frame = schro_frame_dup(original_frame);
	
		schro_encoder_push_frame(encoder, new_frame);
	}
	
	
	
	// pull packets out of encoder, pass to decoder
	int packets_out = 0;
	
	while(packets_out < seq_len)
	{
		SchroStateEnum encoder_state = schro_encoder_wait(encoder);
		
		if(encoder_state == SCHRO_STATE_HAVE_BUFFER || encoder_state == SCHRO_STATE_END_OF_STREAM)
		{
			int n_decodable_frames = -1;
		
			SchroBuffer *buffer = schro_encoder_pull(encoder, &n_decodable_frames);
			
			if(buffer)
			{
				const int parse_code = buffer->data[4];
				
				if(SCHRO_PARSE_CODE_IS_SEQ_HEADER(parse_code) ||
					SCHRO_PARSE_CODE_IS_AUXILIARY_DATA(parse_code) ||
					SCHRO_PARSE_CODE_IS_PICTURE(parse_code))
				{
					schro_decoder_push(decoder, buffer);
					
					//schro_buffer_unref(buffer);
					
					if(SCHRO_PARSE_CODE_IS_PICTURE(parse_code))
					{
						packets_out++;
					}
				}
			}
		}
		else
		{
			assert(encoder_state == SCHRO_STATE_NEED_FRAME);
			assert(encoder_state != SCHRO_STATE_AGAIN); // yeah, redundant
		
			schro_encoder_end_of_stream(encoder);
		}
	}
	
	
	
	// pull frames out of decoder
	int frames_out = 0;
	
	while(frames_out < seq_len)
	{
		int decoder_state = schro_decoder_wait(decoder);
		
		if(decoder_state == SCHRO_DECODER_FIRST_ACCESS_UNIT)
		{
			SchroVideoFormat *format = schro_decoder_get_video_format(decoder);
			
			if(format)
			{
				assert(format->width == width);
				assert(format->height == height);
				
				assert(format->chroma_format == SCHRO_CHROMA_444);
				
				assert(format->luma_offset == luma_min);
				assert(format->luma_offset + format->luma_excursion == luma_max);
				assert(format->chroma_offset = chroma_zero);
				
				free(format);
			}
		}
		else if(decoder_state == SCHRO_DECODER_NEED_BITS)
		{
			schro_decoder_push_end_of_stream(decoder);
		}
		else if(decoder_state == SCHRO_DECODER_NEED_FRAME)
		{
			SchroFrame *decoder_frame = schro_frame_new_and_alloc(NULL, schro_format, width, height);
			
			schro_decoder_add_output_picture(decoder, decoder_frame);
		}
		else if(decoder_state == SCHRO_DECODER_OK || decoder_state == SCHRO_DECODER_EOS)
		{
			SchroFrame *decoder_frame = schro_decoder_pull(decoder);
			
			if(decoder_frame)
			{
				frames_out++;
			
				bool match = CompareFrames(decoder_frame, original_frame);
				
				//std::cout << (match ? "Match!" : "No Match!") << "  " << std::endl;
				
				if(!match)
				{
					// output doesn't match input, so print the values of the
					// first line of the first component to see what went in and out
					PrintFirstLine(original_frame);
					std::cout << "==========" << std::endl;
					PrintFirstLine(decoder_frame);
					std::cout << "==========" << std::endl;
				
					result = false;
				}
				
				schro_frame_unref(decoder_frame);
			}
		}
	}

	schro_frame_unref(original_frame);
	schro_frame_unref(start_frame);
	
	schro_decoder_free(decoder);
	schro_encoder_free(encoder);
	
	return result;
}
Пример #23
0
static int libschroedinger_encode_init(AVCodecContext *avccontext)
{
    FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data;
    SchroVideoFormatEnum preset;

    /* Initialize the libraries that libschroedinger depends on. */
    schro_init();

    /* Create an encoder object. */
    p_schro_params->encoder = schro_encoder_new();

    if (!p_schro_params->encoder) {
        av_log(avccontext, AV_LOG_ERROR,
               "Unrecoverable Error: schro_encoder_new failed. ");
        return -1;
    }

    /* Initialize the format. */
    preset = ff_get_schro_video_format_preset(avccontext);
    p_schro_params->format =
                    schro_encoder_get_video_format(p_schro_params->encoder);
    schro_video_format_set_std_video_format(p_schro_params->format, preset);
    p_schro_params->format->width  = avccontext->width;
    p_schro_params->format->height = avccontext->height;

    if (SetSchroChromaFormat(avccontext) == -1)
        return -1;

    if (ff_get_schro_frame_format(p_schro_params->format->chroma_format,
                                  &p_schro_params->frame_format) == -1) {
        av_log(avccontext, AV_LOG_ERROR,
               "This codec currently supports only planar YUV 4:2:0, 4:2:2"
               " and 4:4:4 formats.\n");
        return -1;
    }

    p_schro_params->format->frame_rate_numerator   = avccontext->time_base.den;
    p_schro_params->format->frame_rate_denominator = avccontext->time_base.num;

    p_schro_params->frame_size = avpicture_get_size(avccontext->pix_fmt,
                                                    avccontext->width,
                                                    avccontext->height);

    avccontext->coded_frame = &p_schro_params->picture;

    if (!avccontext->gop_size) {
        schro_encoder_setting_set_double(p_schro_params->encoder,
                                         "gop_structure",
                                         SCHRO_ENCODER_GOP_INTRA_ONLY);

        if (avccontext->coder_type == FF_CODER_TYPE_VLC)
            schro_encoder_setting_set_double(p_schro_params->encoder,
                                             "enable_noarith", 1);
    } else {
        schro_encoder_setting_set_double(p_schro_params->encoder,
                                         "gop_structure",
                                         SCHRO_ENCODER_GOP_BIREF);
        avccontext->has_b_frames = 1;
    }

    /* FIXME - Need to handle SCHRO_ENCODER_RATE_CONTROL_LOW_DELAY. */
    if (avccontext->flags & CODEC_FLAG_QSCALE) {
        if (!avccontext->global_quality) {
            /* lossless coding */
            schro_encoder_setting_set_double(p_schro_params->encoder,
                                             "rate_control",
                                             SCHRO_ENCODER_RATE_CONTROL_LOSSLESS);
        } else {
            int noise_threshold;
            schro_encoder_setting_set_double(p_schro_params->encoder,
                                             "rate_control",
                                             SCHRO_ENCODER_RATE_CONTROL_CONSTANT_NOISE_THRESHOLD);

            noise_threshold = avccontext->global_quality / FF_QP2LAMBDA;
            if (noise_threshold > 100)
                noise_threshold = 100;
            schro_encoder_setting_set_double(p_schro_params->encoder,
                                             "noise_threshold",
                                             noise_threshold);
        }
    } else {
        schro_encoder_setting_set_double(p_schro_params->encoder,
                                         "rate_control",
                                         SCHRO_ENCODER_RATE_CONTROL_CONSTANT_BITRATE);

        schro_encoder_setting_set_double(p_schro_params->encoder,
                                         "bitrate",
                                         avccontext->bit_rate);

    }

    if (avccontext->flags & CODEC_FLAG_INTERLACED_ME)
        /* All material can be coded as interlaced or progressive
           irrespective of the type of source material. */
        schro_encoder_setting_set_double(p_schro_params->encoder,
                                         "interlaced_coding", 1);

    /* FIXME: Signal range hardcoded to 8-bit data until both libschroedinger
     * and libdirac support other bit-depth data. */
    schro_video_format_set_std_signal_range(p_schro_params->format,
                                            SCHRO_SIGNAL_RANGE_8BIT_VIDEO);

    /* Set the encoder format. */
    schro_encoder_set_video_format(p_schro_params->encoder,
                                   p_schro_params->format);

    /* Set the debug level. */
    schro_debug_set_level(avccontext->debug);

    schro_encoder_start(p_schro_params->encoder);

    /* Initialize the encoded frame queue. */
    ff_dirac_schro_queue_init(&p_schro_params->enc_frame_queue);
    return 0;
}
Пример #24
0
int
main (int argc, char *argv[])
{
  SchroEncoder *encoder;
  SchroParams params;
  SchroVideoFormat video_format;
  int filter;
  SchroFrame *frame;
  int transform_depth;
  int i,j;
  int k;

  schro_init();

  encoder = schro_encoder_new ();

  frame = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_S16_444, SIZE, SIZE);

  schro_fft_generate_tables_f32 (costable, sintable, 2*SHIFT);

  filter = 6;
  transform_depth = 4;

  schro_video_format_set_std_video_format (&video_format, 0);
  video_format.width = SIZE;
  video_format.height = SIZE;

  memset (&params, 0, sizeof(params));
  params.video_format = &video_format;
  schro_params_init (&params, 0);
  params.wavelet_filter_index = filter;
  params.transform_depth = transform_depth;
  schro_params_calculate_iwt_sizes (&params);

  for(i=0;i<SIZE*SIZE;i++) power[i] = 0;

  for(k=0;k<N_TRIALS;k++){
    generate_noise (frame, transform_depth,
        encoder->subband_weights[filter][transform_depth-1]);

    schro_frame_inverse_iwt_transform (frame, &params, tmp);

    for(j=0;j<SIZE;j++){
      int16_t *line;
      line = OFFSET(frame->components[0].data,
          frame->components[0].stride * j);
      for(i=0;i<SIZE;i++){
        sr[j*SIZE+i] = line[i];
        si[j*SIZE+i] = 0;
      }
    }

    schro_fft_fwd_f32 (dr, di, sr, si, costable, sintable, 2*SHIFT);

    for(i=0;i<SIZE*SIZE;i++) {
      power[i] += (dr[i]*dr[i]+di[i]*di[i])*(1.0/(SIZE*SIZE));
    }
  }

  //power[0] *= 4.0/SIZE;
  //power[0] = 0;
  for(j=0;j<SIZE/2;j+=CHUNK_SIZE){
    for(i=0;i<SIZE/2;i+=CHUNK_SIZE){
      int ii,jj;
      double sum = 0;
      for(jj=0;jj<CHUNK_SIZE;jj++){
        for(ii=0;ii<CHUNK_SIZE;ii++){
          sum += power[(j+jj)*SIZE+(i+ii)];
        }
      }
      sum /= N_TRIALS*CHUNK_SIZE*CHUNK_SIZE;
      printf("%d %d %g\n", j, i, sqrt(sum)/AMPLITUDE);
    }
    printf("\n");
  }

  return fail;
}
Пример #25
0
int
main (int argc, char *argv[])
{
  SchroFrame *dest;
  SchroFrame *dest_u8;
  SchroFrame *ref;
  SchroUpsampledFrame *uref;
  SchroParams params;
  SchroVideoFormat video_format;
  SchroMotionVector *motion_vectors;
  int i,j;

  schro_init();

  video_format.width = 720;
  video_format.height = 480;
  video_format.chroma_format = SCHRO_CHROMA_420;
  schro_video_format_validate (&video_format);

  params.video_format = &video_format;
  params.xbsep_luma = 8;
  params.ybsep_luma = 8;
  params.xblen_luma = 12;
  params.yblen_luma = 12;

  schro_params_calculate_mc_sizes(&params);

  dest = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_S16_420,
      video_format.width, video_format.height);
  ref = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_U8_420,
      video_format.width, video_format.height);
  dest_u8 = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_U8_420,
      video_format.width, video_format.height);

  schro_frame_clear(dest);
  schro_frame_create_pattern(ref,1);

  motion_vectors = malloc(sizeof(SchroMotionVector) *
      params.x_num_blocks * params.y_num_blocks);
  memset (motion_vectors, 0, sizeof(SchroMotionVector) *
      params.x_num_blocks * params.y_num_blocks);
  
  printf("sizeof(SchroMotionVector) = %lu\n",(unsigned long) sizeof(SchroMotionVector));
  printf("num blocks %d x %d\n", params.x_num_blocks, params.y_num_blocks);
  for(j=0;j<params.y_num_blocks;j++){
    int jj;
    jj = j * params.x_num_blocks;
    for(i=0;i<params.x_num_blocks;i++){
#if 0
      if (i == 0 || i == 2 || i == params.x_num_blocks*2) {
        motion_vectors[jj+i].u.dc[0] = 100;
        motion_vectors[jj+i].u.dc[1] = 100;
        motion_vectors[jj+i].u.dc[2] = 0;
        motion_vectors[jj+i].pred_mode = 0;
      } else {
        motion_vectors[jj+i].u.dc[0] = 0;
        motion_vectors[jj+i].u.dc[1] = 0;
        motion_vectors[jj+i].u.dc[2] = 0;
        motion_vectors[jj+i].pred_mode = 0;
      }
#endif
      motion_vectors[jj+i].dx[0] = 0;
      motion_vectors[jj+i].dy[0] = -8*i;
      motion_vectors[jj+i].pred_mode = 1;
      motion_vectors[jj+i].split = 2;
    }
  }

  uref = schro_upsampled_frame_new (ref);

  {
    SchroMotion motion;

    motion.src1 = uref;
    motion.src2 = NULL;
    motion.motion_vectors = motion_vectors;
    motion.params = &params;
    schro_motion_render (&motion, dest);
  }

  schro_frame_convert (dest_u8, dest);
  schro_frame_dump (dest_u8);
  //schro_frame_compare (ref, dest_u8);

  schro_upsampled_frame_free (uref);
  schro_frame_unref (dest);
  schro_frame_unref (dest_u8);
  free (motion_vectors);

  return 0;
}