Пример #1
0
void
schro_encoder_frame_downsample (SchroEncoderFrame *frame)
{
  int i;

  SCHRO_DEBUG("downsampling frame %d", frame->frame_number);

  for(i=0;i<5;i++){
    frame->downsampled_frames[i] =
      schro_frame_new_and_alloc (NULL, frame->filtered_frame->format,
          ROUND_UP_SHIFT(frame->filtered_frame->width, i+1),
          ROUND_UP_SHIFT(frame->filtered_frame->height, i+1));
  }

  schro_frame_downsample (frame->downsampled_frames[0],
      frame->filtered_frame);
  schro_frame_downsample (frame->downsampled_frames[1],
      frame->downsampled_frames[0]);
  schro_frame_downsample (frame->downsampled_frames[2],
      frame->downsampled_frames[1]);
  schro_frame_downsample (frame->downsampled_frames[3],
      frame->downsampled_frames[2]);
  schro_frame_downsample (frame->downsampled_frames[4],
      frame->downsampled_frames[3]);
}
Пример #2
0
void
inv_test (int filter, int width, int height)
{
  int i;
  SchroFrame *test;
  SchroFrame *orig;
  SchroFrame *ref;
  SchroFrameData *fd_test;
  SchroFrameData *fd_orig;
  SchroFrameData *fd_ref;
  char name[TEST_PATTERN_NAME_SIZE] = { 0 };

  orig = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_S16_444,
      width, height);
  fd_orig = orig->components + 0;
  test = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_S16_444,
      width, height);
  fd_test = test->components + 0;
  ref = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_S16_444,
      width, height);
  fd_ref = ref->components + 0;

  for(i=0;i<test_pattern_get_n_generators();i++){
    test_pattern_generate (fd_orig, name, i);
    printf("  reverse test \"%s\":\n", name);
    fflush(stdout);

    iwt_ref(fd_orig,filter);
    schro_frame_convert (test, orig);
    schro_frame_convert (ref, orig);
    iiwt_ref(fd_ref,filter);
    iiwt_test(fd_test,filter);
    if (!frame_data_compare(fd_test, fd_ref)) { 
      printf("  failed\n");
      if (verbose) frame_data_dump_full (fd_test, fd_ref, fd_orig);
      fail = TRUE;
    }
  }
  schro_frame_unref (orig);
  schro_frame_unref (test);
  schro_frame_unref (ref);
}
Пример #3
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;
}
Пример #4
0
void
fwd_random_test_s32 (int filter, int width, int height)
{
  SchroFrame *test;
  SchroFrame *orig;
  SchroFrame *ref;
  SchroFrameData *fd_orig;
  SchroFrameData *fd_test;
  SchroFrameData *fd_ref;
  char name[TEST_PATTERN_NAME_SIZE] = { 0 };

  orig = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_S16_444,
      width, height);
  fd_orig = orig->components + 0;
  test = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_S32_444,
      width, height);
  fd_test = test->components + 0;
  ref = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_S16_444,
      width, height);
  fd_ref = ref->components + 0;

  test_pattern_generate (fd_orig, name, 0);
  printf("  forward test 32-bit \"%s\":\n", name);
  fflush(stdout);

  schro_frame_convert (ref, orig);
  schro_frame_convert (test, orig);
  iwt_ref(fd_ref,filter);
  iwt_test(fd_test,filter);
  if (!frame_data_compare(fd_test, fd_ref)) { 
    printf("  failed\n");
    if (verbose) frame_data_dump_full (fd_test, fd_ref, fd_orig);
    fail = TRUE;
  }
  
  schro_frame_unref (orig);
  schro_frame_unref (test);
  schro_frame_unref (ref);
}
Пример #5
0
SchroFrame *
schro_opengl_frame_new (SchroOpenGL *opengl,
    SchroMemoryDomain *opengl_domain, SchroFrameFormat format, int width,
    int height)
{
  SchroFrame *opengl_frame;

  SCHRO_ASSERT (opengl_domain->flags & SCHRO_MEMORY_DOMAIN_OPENGL);

  opengl_frame = schro_frame_new_and_alloc (opengl_domain, format, width,
      height);

  schro_opengl_frame_setup (opengl, opengl_frame);

  return opengl_frame;
}
Пример #6
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;
}
Пример #7
0
void
decode (FILE *file)
{
  SchroDecoder *decoder;
  SchroBuffer *buffer;
  SchroVideoFormat *format = NULL;
  SchroFrame *frame;
  int picture_number;
  int go;
  int it;
  int eos = FALSE;
  void *packet;
  int size;
  int ret;
  int parse_code;

  decoder = schro_decoder_new();
  schro_decoder_set_picture_order (decoder, SCHRO_DECODER_PICTURE_ORDER_CODED);

  while(!eos) {
    ret = parse_packet (file, &packet, &size);
    if (!ret) {
      exit(1);
    }

    if (size == 0) {
      schro_decoder_push_end_of_stream (decoder);
    } else {
      parse_code = ((uint8_t *)packet)[4];

      buffer = schro_buffer_new_with_data (packet, size);
      buffer->free = buffer_free;
      buffer->priv = packet;

      printf("pushing 0x%02x size %d\n", parse_code, size);

      if (SCHRO_PARSE_CODE_IS_PICTURE (parse_code)) {
        frame = schro_frame_new_and_alloc (NULL,
            schro_params_get_frame_format(8, format->chroma_format),
            format->width, format->height);
        schro_decoder_add_output_picture (decoder, frame);
      }

      it = schro_decoder_push (decoder, buffer);
      if (it == SCHRO_DECODER_FIRST_ACCESS_UNIT) {
        format = schro_decoder_get_video_format (decoder);
      }

      if (!SCHRO_PARSE_CODE_IS_PICTURE (parse_code)) {
        continue;
      }
    }

    go = 1;
    while (go) {
      it = schro_decoder_wait (decoder);

      switch (it) {
        case SCHRO_DECODER_NEED_BITS:
          go = 0;
          break;
        case SCHRO_DECODER_NEED_FRAME:
          frame = schro_frame_new_and_alloc (NULL,
              schro_params_get_frame_format(8, format->chroma_format),
              format->width, format->height);
          schro_decoder_add_output_picture (decoder, frame);
          break;
        case SCHRO_DECODER_OK:
          picture_number = schro_decoder_get_picture_number (decoder);
          frame = schro_decoder_pull (decoder);
          printf("got frame %p, picture number %d\n", frame,
              picture_number);

          if (frame) {
            schro_frame_unref (frame);
          }
          go = 0;
          break;
        case SCHRO_DECODER_EOS:
          printf("got eos\n");
          eos = TRUE;
          go = 0;
          break;
        case SCHRO_DECODER_STALLED:
          printf("stall\n");
          go = 0;
          break;
        case SCHRO_DECODER_ERROR:
          exit(0);
          break;
      }
    }
  }

  printf("freeing decoder\n");
  schro_decoder_free (decoder);
  free(format);
}
Пример #8
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;
}
Пример #9
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;
}
Пример #10
0
static int libschroedinger_decode_frame(AVCodecContext *avccontext,
                                        void *data, int *data_size,
                                        const uint8_t *buf, int buf_size)
{

    FfmpegSchroDecoderParams *p_schro_params = avccontext->priv_data;
    SchroDecoder *decoder = p_schro_params->decoder;
    SchroVideoFormat *format;
    AVPicture *picture = data;
    SchroBuffer *enc_buf;
    SchroFrame* frame;
    int state;
    int go = 1;
    int outer = 1;
    FfmpegSchroParseUnitContext parse_ctx;

    *data_size = 0;

    FfmpegSchroParseContextInit (&parse_ctx, buf, buf_size);
    if (buf_size == 0) {
        if (!p_schro_params->eos_signalled) {
            state = schro_decoder_push_end_of_stream(decoder);
            p_schro_params->eos_signalled = 1;
        }
    }

    /* Loop through all the individual parse units in the input buffer */
    do {
        if ((enc_buf = FfmpegFindNextSchroParseUnit(&parse_ctx))) {
            /* Push buffer into decoder. */
            if (SCHRO_PARSE_CODE_IS_PICTURE(enc_buf->data[4]) &&
                SCHRO_PARSE_CODE_NUM_REFS(enc_buf->data[4]) > 0)
                avccontext->has_b_frames = 1;
            state = schro_decoder_push (decoder, enc_buf);
            if (state == SCHRO_DECODER_FIRST_ACCESS_UNIT)
                  libschroedinger_handle_first_access_unit(avccontext);
            go = 1;
        }
        else
            outer = 0;
    format = p_schro_params->format;

    while (go) {
        /* Parse data and process result. */
        state = schro_decoder_wait (decoder);
        switch (state)
        {
        case SCHRO_DECODER_FIRST_ACCESS_UNIT:
            libschroedinger_handle_first_access_unit (avccontext);
            break;

        case SCHRO_DECODER_NEED_BITS:
            /* Need more input data - stop iterating over what we have. */
            go = 0;
            break;

        case SCHRO_DECODER_NEED_FRAME:
            /* Decoder needs a frame - create one and push it in. */

            frame = schro_frame_new_and_alloc(NULL,
                                              p_schro_params->frame_format,
                                              format->width,
                                              format->height);
            schro_decoder_add_output_picture (decoder, frame);
            break;

        case SCHRO_DECODER_OK:
            /* Pull a frame out of the decoder. */
            frame = schro_decoder_pull (decoder);

            if (frame) {
                ff_dirac_schro_queue_push_back(
                                             &p_schro_params->dec_frame_queue,
                                             frame);
            }
            break;
        case SCHRO_DECODER_EOS:
            go = 0;
            p_schro_params->eos_pulled = 1;
            schro_decoder_reset (decoder);
            outer = 0;
            break;

        case SCHRO_DECODER_ERROR:
            return -1;
            break;
        }
    }
    } while(outer);

    /* Grab next frame to be returned from the top of the queue. */
    frame = ff_dirac_schro_queue_pop(&p_schro_params->dec_frame_queue);

    if (frame != NULL) {
        memcpy (p_schro_params->dec_pic.data[0],
                frame->components[0].data,
                frame->components[0].length);

        memcpy (p_schro_params->dec_pic.data[1],
                frame->components[1].data,
                frame->components[1].length);

        memcpy (p_schro_params->dec_pic.data[2],
                frame->components[2].data,
                frame->components[2].length);

        /* Fill picture with current buffer data from Schroedinger. */
        avpicture_fill(picture, p_schro_params->dec_pic.data[0],
                       avccontext->pix_fmt,
                       avccontext->width, avccontext->height);

        *data_size = sizeof(AVPicture);

        /* Now free the frame resources. */
        libschroedinger_decode_frame_free (frame);
    }
    return buf_size;
}
Пример #11
0
static gavl_source_status_t decode_picture(bgav_stream_t * s)
  {
  int state;
  SchroBuffer * buf = NULL;
  SchroFrame * frame = NULL;
  schroedinger_priv_t* priv;
  gavl_source_status_t st;
  priv = s->decoder_priv;

  while(1)
    {
    state = schro_decoder_wait(priv->dec);
    
    switch (state)
      {
      case SCHRO_DECODER_FIRST_ACCESS_UNIT:
        //        fprintf(stderr, "State: SCHRO_DECODER_FIRST_ACCESS_UNIT\n");

        get_format(s);
        
        // libschroedinger_handle_first_access_unit (avccontext);
        break;

      case SCHRO_DECODER_NEED_BITS:
        /* Need more input data - stop iterating over what we have. */
        //        fprintf(stderr, "State: SCHRO_DECODER_NEED_BITS\n");

        st = get_data(s, &buf);
#if 1
        if(st == GAVL_SOURCE_OK)
          {
          state = schro_decoder_push(priv->dec, buf);
          if(state == SCHRO_DECODER_FIRST_ACCESS_UNIT)
            {
            //            fprintf(stderr, "State: SCHRO_DECODER_FIRST_ACCESS_UNIT\n");
            get_format(s);
            }
          }
#endif
        break;

      case SCHRO_DECODER_NEED_FRAME:
        /* Decoder needs a frame - create one and push it in. */
        //        fprintf(stderr, "State: SCHRO_DECODER_NEED_FRAME\n");
        frame = schro_frame_new_and_alloc(NULL,
                                          priv->frame_format,
                                          s->data.video.format.frame_width,
                                          s->data.video.format.frame_height);
        schro_decoder_add_output_picture (priv->dec, frame);
        //     fprintf(stderr, "Need frame %p\n", frame);
        break;

      case SCHRO_DECODER_OK:

        // pic_num = schro_decoder_get_picture_number(priv->dec);

        /* Pull a frame out of the decoder. */
        //        fprintf(stderr, "State: SCHRO_DECODER_OK %d\n",
        //                schro_decoder_get_picture_number(priv->dec));
        
        // if(codec->dec_delay)
        //          {
        priv->dec_frame = schro_decoder_pull(priv->dec);
        //        fprintf(stderr, "Got frame %p\n", priv->dec_frame);
        
        return GAVL_SOURCE_OK;
          //          }
        break;
      case SCHRO_DECODER_EOS:
        //        fprintf(stderr, "State: SCHRO_DECODER_EOS\n");
        // p_schro_params->eos_pulled = 1;
        //        schro_decoder_reset (decoder);
        //        outer = 0;
        return GAVL_SOURCE_EOF;
        break;
      case SCHRO_DECODER_ERROR:
        //        fprintf(stderr, "State: SCHRO_DECODER_ERROR\n");
        return GAVL_SOURCE_EOF;
        break;
      }
    }
  return GAVL_SOURCE_EOF;
  }
Пример #12
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;
}
Пример #13
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;
}
Пример #14
0
void
decode (FILE *file)
{
  SchroDecoder *decoder;
  SchroBuffer *buffer;
  SchroVideoFormat *format = NULL;
  SchroFrame *frame;
  int go;
  int it;
  int eos = FALSE;
  void *packet;
  int size;
  int ret;

  decoder = schro_decoder_new();

  while(!eos) {
    ret = parse_packet (file, &packet, &size);
    if (!ret) {
      exit(1);
    }

    if (size == 0) {
      schro_decoder_push_end_of_stream (decoder);
    } else {
      buffer = schro_buffer_new_with_data (packet, size);
      buffer->free = buffer_free;
      buffer->priv = packet;

      it = schro_decoder_push (decoder, buffer);
      if (it == SCHRO_DECODER_FIRST_ACCESS_UNIT) {
        format = schro_decoder_get_video_format (decoder);
      }
    }

    go = 1;
    while (go) {
      it = schro_decoder_wait (decoder);

      switch (it) {
        case SCHRO_DECODER_NEED_BITS:
          go = 0;
          break;
        case SCHRO_DECODER_NEED_FRAME:
          frame = schro_frame_new_and_alloc (NULL,
              schro_params_get_frame_format(8, format->chroma_format),
              format->width, format->height);
          schro_decoder_add_output_picture (decoder, frame);
          break;
        case SCHRO_DECODER_OK:
          frame = schro_decoder_pull (decoder);
          //printf("got frame %p\n", frame);

          if (frame) {
            //printf("picture number %d\n",
            //    schro_decoder_get_picture_number (decoder) - 1);

            schro_frame_unref (frame);
          }
          break;
        case SCHRO_DECODER_EOS:
          printf("got eos\n");
          eos = TRUE;
          go = 0;
          break;
        case SCHRO_DECODER_ERROR:
          exit(0);
          break;
      }
    }
  }

  printf("freeing decoder\n");
  schro_decoder_free (decoder);
  free(format);
}