예제 #1
0
void get_delimited_text()
{
  char *filename;
  int lineno;
  int got_location = get_location(&filename, &lineno);
  int start = get_char();
  while (start == ' ' || start == '\t' || start == '\n')
    start = get_char();
  token_buffer.clear();
  if (start == EOF) {
    if (got_location)
      error_with_file_and_line(filename, lineno,
			       "end of input while defining macro");
    else
      error("end of input while defining macro");
    return;
  }
  for (;;) {
    int c = get_char();
    if (c == EOF) {
      if (got_location)
	error_with_file_and_line(filename, lineno,
				 "end of input while defining macro");
      else
	error("end of input while defining macro");
      add_context(start + token_buffer);
      return;
    }
    if (c == start)
      break;
    token_buffer += char(c);
  }
  add_context(start + token_buffer + start);
}
예제 #2
0
static void put_samplerate_context(gavl_audio_converter_t* cnv,
                                   gavl_audio_format_t * tmp_format,
                                   int out_samplerate)
  {
  gavl_audio_convert_context_t * ctx;

  /* Sampleformat conversion with GAVL_INTERLEAVE_2 is not supported */
  if(cnv->current_format->interleave_mode == GAVL_INTERLEAVE_2)
    {
    tmp_format->interleave_mode = GAVL_INTERLEAVE_NONE;
    ctx = gavl_interleave_context_create(&cnv->opt,
                                         cnv->current_format,
                                         tmp_format);
    add_context(cnv, ctx);
    }
  
  if(cnv->current_format->sample_format < GAVL_SAMPLE_FLOAT)
    {
    tmp_format->sample_format = GAVL_SAMPLE_FLOAT;
    ctx = gavl_sampleformat_context_create(&cnv->opt,
                                           cnv->current_format,
                                           tmp_format);
    add_context(cnv, ctx);
    }
  
  tmp_format->samplerate = out_samplerate;
  ctx = gavl_samplerate_context_create(&cnv->opt,
                                       cnv->current_format,
                                       tmp_format);
  add_context(cnv, ctx);
  }
예제 #3
0
int gavl_audio_converter_init_resample(gavl_audio_converter_t * cnv,
                                   const gavl_audio_format_t * format)
  {
  gavl_audio_format_t tmp_format;
  gavl_audio_convert_context_t * ctx;
  
  gavl_audio_format_copy(&cnv->input_format, format);
  gavl_audio_format_copy(&cnv->output_format, format);
  gavl_audio_format_copy(&tmp_format, format);

  adjust_format(&cnv->input_format);
  adjust_format(&cnv->output_format);

  // Delete previous conversions 
  audio_converter_cleanup(cnv);

  cnv->current_format = &cnv->input_format;

  put_samplerate_context(cnv, &tmp_format, cnv->output_format.samplerate);

  /* put_samplerate will automatically convert sample format and interleave format 
	* we need to check to see if it did or not and add contexts to convert back */
  if(cnv->current_format->sample_format != cnv->output_format.sample_format)
    {
    if(cnv->current_format->interleave_mode == GAVL_INTERLEAVE_2)
      {
      tmp_format.interleave_mode = GAVL_INTERLEAVE_NONE;
      ctx = gavl_interleave_context_create(&cnv->opt,
                                           cnv->current_format,
                                           &tmp_format);
      add_context(cnv, ctx);
      }

    tmp_format.sample_format = cnv->output_format.sample_format;
    ctx = gavl_sampleformat_context_create(&cnv->opt,
                                           cnv->current_format,
                                           &tmp_format);
    add_context(cnv, ctx);
    }

  /* Final interleaving */

  if(cnv->current_format->interleave_mode != cnv->output_format.interleave_mode)
    {
    tmp_format.interleave_mode = cnv->output_format.interleave_mode;
    ctx = gavl_interleave_context_create(&cnv->opt,
                                         cnv->current_format,
                                         &tmp_format);
    add_context(cnv, ctx);
    }

  cnv->input_format.samples_per_frame = 0;

  return cnv->num_conversions;
  }
예제 #4
0
static int add_context_csp(gavl_video_converter_t * cnv,
                     const gavl_video_format_t * input_format,
                     const gavl_video_format_t * output_format)
  {
  gavl_video_convert_context_t * ctx;
  ctx = add_context(cnv, input_format, output_format);

  ctx->func = gavl_find_pixelformat_converter(&cnv->options,
                                             input_format->pixelformat,
                                             output_format->pixelformat,
                                             input_format->frame_width,
                                             input_format->frame_height);

  if(!ctx->func)
    {
#if 0
    fprintf(stderr, "Found no conversion from %s to %s\n",
            gavl_pixelformat_to_string(input_format->pixelformat),
            gavl_pixelformat_to_string(output_format->pixelformat));
#endif
    return 0;
    }
#if 0
  fprintf(stderr, "Doing pixelformat conversion from %s to %s\n",
          gavl_pixelformat_to_string(input_format->pixelformat),
          gavl_pixelformat_to_string(output_format->pixelformat));
  
#endif
  return 1;
  }
예제 #5
0
static int add_context_deinterlace(gavl_video_converter_t * cnv,
                                    const gavl_video_format_t * in_format,
                                    const gavl_video_format_t * out_format)
  {
  gavl_video_options_t * deinterlacer_options;
  gavl_video_convert_context_t * ctx;
  ctx = add_context(cnv, in_format, out_format);

  ctx->deinterlacer = gavl_video_deinterlacer_create();
  deinterlacer_options = gavl_video_deinterlacer_get_options(ctx->deinterlacer);
  gavl_video_options_copy(deinterlacer_options, &cnv->options);
  
  if(!gavl_video_deinterlacer_init(ctx->deinterlacer,
                                   in_format))
    return 0;
  
  ctx->func = deinterlace_func;
  return 1;
  }
예제 #6
0
struct cloud_helper_context* cloud_helper_init(struct nodeID *local,
                                               const char *config)
{
  struct cloud_helper_context *ctx;
  struct tag *cfg_tags;
  const char *provider;

  cfg_tags = grapes_config_parse(config);
  provider = grapes_config_value_str(cfg_tags, "provider");

  if (!provider) return NULL;

  ctx = malloc(sizeof(struct cloud_helper_context));
  if (!ctx) return NULL;
  memset(ctx, 0, sizeof(struct cloud_helper_context));
#ifdef DELEGATE
  if (strcmp(provider, "delegate") == 0){
    ctx->ch = &delegate;
  }
#endif
  if (!ctx->ch) {
    free(ctx);

    return NULL;
  }

 ctx->ch_context = ctx->ch->cloud_helper_init(local, config);
 if(!ctx->ch_context){
   free(ctx);
   return NULL;
 }

 if (add_context(local, ctx) != 0){
   //TODO: a better deallocation process is needed
   free(ctx->ch_context);
   free(ctx);
   return NULL;
 }

 return ctx;
}
예제 #7
0
static int add_context_scale(gavl_video_converter_t * cnv,
                             const gavl_video_format_t * input_format,
                             const gavl_video_format_t * output_format)
  {
  gavl_video_options_t * scaler_options;
  
  gavl_video_convert_context_t * ctx;
  ctx = add_context(cnv, input_format, output_format);

  ctx->scaler = gavl_video_scaler_create();

  scaler_options = gavl_video_scaler_get_options(ctx->scaler);

  gavl_video_options_copy(scaler_options, &cnv->options);
#if 0
  fprintf(stderr, "gavl_video_scaler_init:\n");
  fprintf(stderr, "src_format:\n");
  gavl_video_format_dump(input_format);
  fprintf(stderr, "dst_format:\n");
  gavl_video_format_dump(output_format);

  fprintf(stderr, "src_rectangle: ");
  gavl_rectangle_f_dump(&cnv->options.src_rect);
  fprintf(stderr, "\n");

  fprintf(stderr, "dst_rectangle: ");
  gavl_rectangle_i_dump(&cnv->options.dst_rect);
  fprintf(stderr, "\n");
#endif
  
  if(!gavl_video_scaler_init(ctx->scaler,
                             input_format,
                             output_format))
    {
    //    fprintf(stderr, "Initializing scaler failed\n");
    return 0;
    }
  ctx->func = scale_func;
  return 1;
  }
예제 #8
0
int gavl_audio_converter_reinit(gavl_audio_converter_t* cnv)
  {
  int do_mix, do_resample;
  int i;
  gavl_audio_convert_context_t * ctx;

  gavl_audio_format_t * input_format, * output_format;
  
  gavl_audio_format_t tmp_format;

  input_format = &cnv->input_format;
  output_format = &cnv->output_format;
  
#if 0
  fprintf(stderr, "Initializing audio converter, quality: %d, Flags: 0x%08x\n",
          cnv->opt.quality, cnv->opt.accel_flags);
#endif
  
  /* Delete previous conversions */
  audio_converter_cleanup(cnv);

  /* Copy formats and options */
  
  memset(&tmp_format, 0, sizeof(tmp_format));
  gavl_audio_format_copy(&tmp_format, &cnv->input_format);
  
  cnv->current_format = &cnv->input_format;
    
  /* Check if we must mix */

  do_mix = 0;
  
  if((input_format->num_channels != output_format->num_channels) ||
     (gavl_front_channels(input_format) != gavl_front_channels(output_format)) ||
     (gavl_rear_channels(input_format) != gavl_rear_channels(output_format)) ||
     (gavl_side_channels(input_format) != gavl_side_channels(output_format)))
    {
    do_mix = 1;
    }
  if(!do_mix)
    {
    i = (input_format->num_channels < output_format->num_channels) ?
      input_format->num_channels : output_format->num_channels;
    
    while(i--)
      {
      if(input_format->channel_locations[i] != output_format->channel_locations[i])
        {
        do_mix = 1;
        break;
        }
      }
    }

  /* Check if we must resample */

  do_resample = (input_format->samplerate != output_format->samplerate) ? 1 : 0;

  /* Check for resampling. We take care, that we do resampling for the least possible channels */

  if(do_resample &&
     (!do_mix ||
      (do_mix && (input_format->num_channels <= output_format->num_channels))))
    put_samplerate_context(cnv, &tmp_format, output_format->samplerate);
  
  /* Check for mixing */
    
  if(do_mix)
    {
    if(cnv->current_format->interleave_mode != GAVL_INTERLEAVE_NONE)
      {
      tmp_format.interleave_mode = GAVL_INTERLEAVE_NONE;
      ctx = gavl_interleave_context_create(&cnv->opt,
                                           cnv->current_format,
                                           &tmp_format);
      add_context(cnv, ctx);
      }
    
    if((cnv->current_format->sample_format < GAVL_SAMPLE_FLOAT) &&
       ((cnv->opt.quality > 3) ||
        (cnv->output_format.sample_format == GAVL_SAMPLE_FLOAT)))
      {
      tmp_format.sample_format = GAVL_SAMPLE_FLOAT;
      ctx = gavl_sampleformat_context_create(&cnv->opt,
                                             cnv->current_format,
                                             &tmp_format);
      add_context(cnv, ctx);
      }
    else if((cnv->current_format->sample_format < GAVL_SAMPLE_DOUBLE) &&
       ((cnv->opt.quality > 4) ||
        (cnv->output_format.sample_format == GAVL_SAMPLE_DOUBLE)))
      {
      tmp_format.sample_format = GAVL_SAMPLE_DOUBLE;
      ctx = gavl_sampleformat_context_create(&cnv->opt,
                                             cnv->current_format,
                                             &tmp_format);
      add_context(cnv, ctx);
      }

    else if(gavl_bytes_per_sample(cnv->current_format->sample_format) <
            gavl_bytes_per_sample(cnv->output_format.sample_format))
      {
      tmp_format.sample_format = cnv->output_format.sample_format;
      ctx = gavl_sampleformat_context_create(&cnv->opt,
                                             cnv->current_format,
                                             &tmp_format);
      add_context(cnv, ctx);
      }

    tmp_format.num_channels = cnv->output_format.num_channels;
    memcpy(tmp_format.channel_locations, cnv->output_format.channel_locations,
           GAVL_MAX_CHANNELS * sizeof(tmp_format.channel_locations[0]));

    ctx = gavl_mix_context_create(&cnv->opt, cnv->current_format,
                                  &tmp_format);
    add_context(cnv, ctx);
    }

  if(do_resample && do_mix && (input_format->num_channels > output_format->num_channels))
    {
    put_samplerate_context(cnv, &tmp_format, output_format->samplerate);
    }
  
  /* Check, if we must change the sample format */
  
  if(cnv->current_format->sample_format != cnv->output_format.sample_format)
    {
    if(cnv->current_format->interleave_mode == GAVL_INTERLEAVE_2)
      {
      tmp_format.interleave_mode = GAVL_INTERLEAVE_NONE;
      ctx = gavl_interleave_context_create(&cnv->opt,
                                           cnv->current_format,
                                           &tmp_format);
      add_context(cnv, ctx);
      }

    tmp_format.sample_format = cnv->output_format.sample_format;
    ctx = gavl_sampleformat_context_create(&cnv->opt,
                                           cnv->current_format,
                                           &tmp_format);
    add_context(cnv, ctx);
    
    }
     
  /* Final interleaving */

  if(cnv->current_format->interleave_mode != cnv->output_format.interleave_mode)
    {
    tmp_format.interleave_mode = cnv->output_format.interleave_mode;
    ctx = gavl_interleave_context_create(&cnv->opt,
                                         cnv->current_format,
                                         &tmp_format);
    add_context(cnv, ctx);
    }

  //  fprintf(stderr, "Audio converter initialized, %d conversions\n", cnv->num_conversions);
  
  //  gavl_audio_format_dump(&cnv->input_format);

  //  gavl_audio_format_dump(&cnv->output_format);
  //  gavl_audio_format_dump(cnv->current_format);

  /* Set samples_per_frame of the first context
     to zero to enable automatic allocation later on */
  
  cnv->input_format.samples_per_frame = 0;
  return cnv->num_conversions;
  }
예제 #9
0
int get_token(int lookup_flag = 0)
{
  for (;;) {
    int c = get_char();
    while (c == ' ' || c == '\n')
      c = get_char();
    switch (c) {
    case EOF:
      {
	add_context("end of input");
      }
      return 0;
    case '"':
      {
	int quoted = 0;
	token_buffer.clear();
	for (;;) {
	  c = get_char();
	  if (c == EOF) {
	    lex_error("missing \"");
	    break;
	  }
	  else if (c == '\n') {
	    lex_error("newline before end of quoted text");
	    break;
	  }
	  else if (c == '"') {
	    if (!quoted)
	      break;
	    token_buffer[token_buffer.length() - 1] = '"';
	    quoted = 0;
	  }
	  else {
	    token_buffer += c;
	    quoted = quoted ? 0 : c == '\\';
	  }
	}
      }
      add_quoted_context(token_buffer);
      return QUOTED_TEXT;
    case '{':
    case '}':
    case '^':
    case '~':
    case '\t':
      add_context(c);
      return c;
    default:
      {
	int break_flag = 0;
	int quoted = 0;
	token_buffer.clear();
	if (c == '\\')
	  quoted = 1;
	else
	  token_buffer += c;
	int done = 0;
	while (!done) {
	  c = peek_char();
	  if (!quoted && lookup_flag != 0 && c == '(') {
	    token_buffer += '\0';
	    definition *def = macro_table.lookup(token_buffer.contents());
	    if (def && def->is_macro && !def->is_simple) {
	      (void)get_char();	// skip initial '('
	      interpolate_macro_with_args(def->contents);
	      break_flag = 1;
	      break;
	    }
	    token_buffer.set_length(token_buffer.length() - 1);
	  }
	  if (quoted) {
	    quoted = 0;
	    switch (c) {
	    case EOF:
	      lex_error("`\\' ignored at end of equation");
	      done = 1;
	      break;
	    case '\n':
	      lex_error("`\\' ignored because followed by newline");
	      done = 1;
	      break;
	    case '\t':
	      lex_error("`\\' ignored because followed by tab");
	      done = 1;
	      break;
	    case '"':
	      (void)get_char();
	      token_buffer += '"';
	      break;
	    default:
	      (void)get_char();
	      token_buffer += '\\';
	      token_buffer += c;
	      break;
	    }
	  }
	  else {
	    switch (c) {
	    case EOF:
	    case '{':
	    case '}':
	    case '^':
	    case '~':
	    case '"':
	    case ' ':
	    case '\t':
	    case '\n':
	      done = 1;
	      break;
	    case '\\':
	      (void)get_char();
	      quoted = 1;
	      break;
	    default:
	      (void)get_char();
	      token_buffer += char(c);
	      break;
	    }
	  }
	}
	if (break_flag || token_buffer.length() == 0)
	  break;
	if (lookup_flag != 0) {
	  token_buffer += '\0';
	  definition *def = macro_table.lookup(token_buffer.contents());
	  token_buffer.set_length(token_buffer.length() - 1);
	  if (def) {
	    if (def->is_macro) {
	      current_input = new macro_input(def->contents, current_input);
	      break;
	    }
	    else if (lookup_flag == 1) {
	      add_context(token_buffer);
	      return def->tok;
	    }
	  }
	}
	add_context(token_buffer);
	return TEXT;
      }
    }
  }
}