Beispiel #1
0
static int
stroke_rect_element(svg_state_t *s, htsmsg_t *attribs)
{
  const char *str_width  = htsmsg_get_str(attribs, "width");
  const char *str_height = htsmsg_get_str(attribs, "height");
  const char *str_x      = htsmsg_get_str(attribs, "x");
  const char *str_y      = htsmsg_get_str(attribs, "y");
  
  if(str_width == NULL || str_height == NULL || str_x == NULL || str_y == NULL)
    return -1;

  float width  = my_str2double(str_width,  NULL);
  float height = my_str2double(str_height, NULL);
  float x      = my_str2double(str_x,      NULL);
  float y      = my_str2double(str_y,      NULL);

  float v[2];

  v[0] = x;
  v[1] = y;
  cmd_move_abs(s, v);
  v[0] += width;
  cmd_lineto_abs(s, v);
  v[1] += height;
  cmd_lineto_abs(s, v);
  v[0] = x;
  cmd_lineto_abs(s, v);
  cmd_close(s);
  return 0;
}
Beispiel #2
0
static ext_subtitles_t *
load_timedtext(const char *url, buf_t *buf)
{
  char errbuf[256];
  htsmsg_field_t *f;
  htsmsg_t *xml = htsmsg_xml_deserialize_buf(buf, errbuf, sizeof(errbuf));

  if(xml == NULL) {
    TRACE(TRACE_INFO, "Subtitles", "Unable to load timed text: %s", errbuf);
    return NULL;
  }

  htsmsg_t *transcript = htsmsg_get_map_multi(xml, "transcript", NULL);

  if(transcript == NULL) {
    htsmsg_release(xml);
    return NULL;
  }

  ext_subtitles_t *es = calloc(1, sizeof(ext_subtitles_t));
  TAILQ_INIT(&es->es_entries);

  HTSMSG_FOREACH(f, transcript) {
    if(f->hmf_type == HMF_STR && f->hmf_childs != NULL) {
      htsmsg_t *n = f->hmf_childs;
      const char *str;
      int64_t start, end;

      if((str = htsmsg_get_str(n, "start")) == NULL)
	continue;
      start = my_str2double(str, NULL) * 1000000.0;

      if((str = htsmsg_get_str(n, "dur")) == NULL)
	continue;
      end = start + my_str2double(str, NULL) * 1000000.0;

      char *txt = strdup(f->hmf_str);
      html_entities_decode(txt);
      es_insert_text(es, txt, start, end, 0);
      free(txt);
    }
  }
  return es;
}
Beispiel #3
0
static int
xmlrpc_parse_value(htsmsg_t *dst, htsmsg_field_t *g, const char *name,
		   char *errbuf, size_t errlen)
{
  const char *cdata;
  htsmsg_t *c;
  htsmsg_t *sub;

  if(!strcmp(g->hmf_name, "struct") &&
     (c = htsmsg_get_map_by_field(g)) != NULL) {

    sub = htsmsg_create_map();
    if(xmlrpc_parse_struct(sub, c, errbuf, errlen)) {
      htsmsg_release(sub);
      return -1;
    }
    htsmsg_add_msg(dst, name, sub);
    return 0;

  } else if(!strcmp(g->hmf_name, "array") &&
	    (c = htsmsg_get_map_by_field(g)) != NULL) {

    sub = htsmsg_create_list();
    if(xmlrpc_parse_array(sub, c, errbuf, errlen)) {
      htsmsg_release(sub);
      return -1;
    }
    htsmsg_add_msg(dst, name, sub);
    return 0;
  }

  cdata = g->hmf_type == HMF_STR ? g->hmf_str : NULL;

  if(!strcmp(g->hmf_name, "string")) {
    if(cdata != NULL)
      htsmsg_add_str(dst, name, cdata);

  } else if(!strcmp(g->hmf_name, "boolean")) {
    if(cdata != NULL)
      htsmsg_add_u32(dst, name, atoi(cdata));

  } else if(!strcmp(g->hmf_name, "double")) {
    if(cdata != NULL)
      htsmsg_add_dbl(dst, name, my_str2double(cdata, NULL));

  } else if(!strcmp(g->hmf_name, "int")) {
    if(cdata != NULL)
      htsmsg_add_s64(dst, name, atoll(cdata));

  } else {
    snprintf(errbuf, errlen, "Unknown field type \"%s\" %s = %s",
             g->hmf_name, name, cdata);
    return -1;
  }
  return 0;
}
Beispiel #4
0
static const char *
json_parse_double(const char *s, double *dp)
{
  const char *ep;
  while(*s > 0 && *s < 33)
    s++;

  double d = my_str2double(s, &ep);

  if(ep == s)
    return NULL;

  *dp = d;
  return ep;
}
Beispiel #5
0
static ext_subtitles_t *
load_sub_variant(const char *url, char *buf, size_t len, AVRational *fr,
                 int mpl)
{
  ext_subtitles_t *es = calloc(1, sizeof(ext_subtitles_t));
  AVRational sub_default = {25, 1};
  AVRational mpl_default = {10, 1};
  AVRational fr0;

  const char left  = "{["[mpl];
  const char right = "}]"[mpl];

  if(fr == NULL || fr->num == 0 || fr->den == 0)
    fr = mpl ? &mpl_default : &sub_default;

  TAILQ_INIT(&es->es_entries);

  int tagflags = TEXT_PARSE_SUB_TAGS;

  if(mpl)
    tagflags |= TEXT_PARSE_SLASH_PREFIX;

  LINEPARSE(s, buf) {
    int start, stop;
    int x = get_sub_mpl_timestamp(s, &start, &stop, left, right);
    if(x <= 0)
      continue;

    s += x;

    if(!mpl && start == 1 && stop == 1) {
      // Set framerate
      fr0.num = my_str2double(s, NULL) * 1000000.0;
      fr0.den = 1000000;
      fr = &fr0;
      continue;
    }

    for(int i = 0, len = strlen(s); i < len; i++) {
      if(s[i] == '|')
        s[i] = '\n';
    }

    es_insert_text(es, s,
                   1000000LL * start * fr->den / fr->num,
                   1000000LL * stop  * fr->den / fr->num,
                   tagflags);
  }
Beispiel #6
0
static int64_t
ttml_time_expression(const char *str)
{
  const char *endp = NULL;
  double t = my_str2double(str, &endp);

  if(!strcmp(endp, "h"))
    return t * 3600 * 1000000;
  if(!strcmp(endp, "m"))
    return t * 60 * 1000000;
  if(!strcmp(endp, "ms"))
    return t * 1000;
  if(!strcmp(endp, "s"))
    return t * 1000000;
  return -1;
}
Beispiel #7
0
static void
svg_parse_transform(svg_state_t *s, const char *t)
{
  float values[6];
  int nargs = 0, i;
  void (*fn)(svg_state_t *s, const float *p);
  while(*t < 33 && *t)
    t++;
  if(!*t)
    return;
  if(!strncmp(t, "matrix", strlen("matrix"))) {
    fn = svg_state_apply_matrix;
    nargs = 6;
    t += strlen("matrix");
  } else if(!strncmp(t, "translate", strlen("translate"))) {
    fn = svg_state_translate;
    nargs = 2;
    t += strlen("translate");
  } else {
    return;
  }

  while(*t < 33 && *t)
    t++;
  if(*t != '(')
    return;
  t++;
  for(i = 0; i < nargs; i++) {
    const char *end;
    values[i] = my_str2double(t, &end);
    if(t == end)
      return;
    t = end;
    while(*t < 33 && *t)
      t++;
    if(*t == ',')
      t++;
  }
  fn(s, values);
}
Beispiel #8
0
static void
stroke_path(svg_state_t *state, const char *str)
{
  float values[6];
  int num_params = 0;
  int cur_param = 0;
  void (*cur_cmd)(svg_state_t *state, const float *params) = NULL; 

  while(*str) {
    if(*str < 33) {
      str++;
      continue;
    }

    if(cur_cmd != NULL) {
      const char *endptr;

      double d = my_str2double(str, &endptr);

      if(endptr != str) {
	values[cur_param] = d;
	cur_param++;
	if(cur_param == num_params) {
	  cur_cmd(state, values);
	  cur_param = 0;
	}

	str = endptr;

	while(*str < 33 && *str)
	  str++;
	if(*str == ',')
	  str++;
	while(*str < 33 && *str)
	  str++;
	continue;
      } 
    }

    while(*str < 33 && *str)
      str++;

    char mode = *str++;
    switch(mode) {
    case 'M':
      cur_cmd = cmd_move_abs;
      num_params = 2;
      break;
    case 'm':
      cur_cmd = cmd_move_rel;
      num_params = 2;
      break;
    case 'c':
      cur_cmd = cmd_curveto_rel;
      num_params = 6;
      break;

    case 'C':
      cur_cmd = cmd_curveto_abs;
      num_params = 6;
      break;

    case 'l':
      cur_cmd = cmd_lineto_rel;
      num_params = 2;
      break;

    case 'L':
      cur_cmd = cmd_lineto_abs;
      num_params = 2;
      break;

    case 'z':
    case 'Z':
      cur_cmd = NULL;
      num_params = 0;
      cmd_close(state);
      break;
    default:
      printf("Cant handle mode %c\n", mode);
      return;
    }
  }
}
Beispiel #9
0
static void
jni_sub_value_cb(void *opaque, prop_event_t event, ...)
{
  JNIEnv *env;
  int r = (*JVM)->GetEnv(JVM, (void **)&env, JNI_VERSION_1_6);

  if(r) {
    TRACE(TRACE_DEBUG, "JNI_PROP", "No environment");
    return;
  }

  const char *str;
  va_list ap;

  jni_subscription_t *js = opaque;
  double dbl;
  int i32;

  va_start(ap, event);

  switch(event) {
  case PROP_SET_CSTRING:
    str = va_arg(ap, const char *);
    if(0)
  case PROP_SET_RSTRING:
      str = rstr_get(va_arg(ap, rstr_t *));

    if(js->js_setstr) {
      jstring jstr = (*env)->NewStringUTF(env, str);
      (*env)->CallVoidMethod(env, js->js_cbif, js->js_setstr, jstr);
    } else if(js->js_setfloat) {
      dbl = my_str2double(str, NULL);
      (*env)->CallVoidMethod(env, js->js_cbif, js->js_setfloat, dbl);
    } else if(js->js_setint) {
      i32 = atoi(str);
      (*env)->CallVoidMethod(env, js->js_cbif, js->js_setint, i32);
    } else {
      TRACE(TRACE_DEBUG, "JNI_PROP", "Appropriate set() not found for string");
    }
    break;

  case PROP_SET_FLOAT:
    dbl = va_arg(ap, double);
    if(js->js_setfloat) {
      (*env)->CallVoidMethod(env, js->js_cbif, js->js_setfloat, dbl);
    } else if(js->js_setint) {
      (*env)->CallVoidMethod(env, js->js_cbif, js->js_setint, (int)dbl);
    } else if(js->js_setstr) {
      char buf[32];
      my_double2str(buf, sizeof(buf), dbl);
      jstring jstr = (*env)->NewStringUTF(env, buf);
      (*env)->CallVoidMethod(env, js->js_cbif, js->js_setstr, jstr);
    } else {
      TRACE(TRACE_DEBUG, "JNI_PROP", "Appropriate set() not found for float");
    }
    break;

  case PROP_SET_INT:
    i32 = va_arg(ap, int);

    if(js->js_setint) {
      (*env)->CallVoidMethod(env, js->js_cbif, js->js_setint, i32);
    } else if(js->js_setfloat) {
      (*env)->CallVoidMethod(env, js->js_cbif, js->js_setfloat, (float)i32);
    } else if(js->js_setstr) {
      char buf[32];
      snprintf(buf, sizeof(buf), "%d", i32);
      jstring jstr = (*env)->NewStringUTF(env, buf);
      (*env)->CallVoidMethod(env, js->js_cbif, js->js_setstr, jstr);
    } else {
      TRACE(TRACE_DEBUG, "JNI_PROP", "Appropriate set() not found for int");
    }
    break;

  case PROP_SET_DIR:
  case PROP_SET_VOID:
    if(js->js_setvoid) {
      (*env)->CallVoidMethod(env, js->js_cbif, js->js_setvoid);
    } if(js->js_setint) {
      (*env)->CallVoidMethod(env, js->js_cbif, js->js_setint, 0);
    } else if(js->js_setfloat) {
      (*env)->CallVoidMethod(env, js->js_cbif, js->js_setfloat, 0);
    } else if(js->js_setstr) {
      jstring jstr = (*env)->NewStringUTF(env, "");
      (*env)->CallVoidMethod(env, js->js_cbif, js->js_setstr, jstr);
    } else {
      TRACE(TRACE_DEBUG, "JNI_PROP", "Appropriate set() not found for void");
    }
    break;

  default:
    TRACE(TRACE_DEBUG, "JNI_PROP", "Not hanlding event %d", event);
    break;
  }

  if((*env)->ExceptionCheck(env)) {
    TRACE(TRACE_DEBUG, "JNI_PROP",
          "Exception raised during prop notify, ignoring");
    (*env)->ExceptionDescribe(env);
  }
  va_end(ap);
}