Пример #1
0
static event_t *
be_gmeplayer_play(const char *url0, media_pipe_t *mp, 
		  char *errbuf, size_t errlen, int hold)
{
  event_t *e;
  char *url, *p;
  int track;
  void *fh;

  url0 += strlen("gmeplayer:");

  url = mystrdupa(url0);
  p = strrchr(url, '/');
  if(p == NULL) {
    snprintf(errbuf, errlen, "Invalid filename");
    return NULL;
  }

  *p++= 0;
  track = atoi(p) - 1;

  if((fh = fa_open(url, errbuf, errlen)) == NULL)
    return NULL;

  e = fa_gme_playfile_internal(mp, fh, errbuf, errlen, hold, track);
  fa_close(fh);
  return e;

}
Пример #2
0
void
load_syms(void)
{
  char sympath[256];
  char errbuf[256];

  snprintf(sympath, sizeof(sympath), "%s/showtime.syms", showtime_dataroot());

  my_trace("sympath: %s\n", sympath);

  fa_handle_t *fh = fa_open(sympath, errbuf, sizeof(errbuf));

  if(fh == NULL) {
    my_trace("Unable to open symbol file %s -- %s",
	  sympath, errbuf);
    return;
  }

  int size = fa_fsize(fh);
  char *buf = halloc(size + 1);

  int r = fa_read(fh, buf, size);
  if(r != size) {
    my_trace("Unable to read %d bytes", size);
    hfree(buf, size+1);
  } else {
    buf[size] = 0;
    my_trace("Loaded symbol table %d bytes to %p",
	  size, buf);
    symbuf = buf;
  }
  fa_close(fh);
}
Пример #3
0
static int
sidfile_scandir(fa_dir_t *fd, const char *url, char *errbuf, size_t errlen)
{
  void *fh = NULL;
  char *p, *fpath = mystrdupa(url);
  char buf[128];
  char name[32];
  char turl[URL_MAX];
  int tracks, i;
  fa_dir_entry_t *fde;
  rstr_t *album, *artist;
 

  if((p = strrchr(fpath, '/')) == NULL) {
    snprintf(errbuf, errlen, "Invalid filename");
    return -1;
  }

  *p = 0;
  if((fh = fa_open(fpath, errbuf, errlen)) == NULL)
    return -1;

  if(fa_read(fh, buf, 128) != 128) {
    snprintf(errbuf, errlen, "Unable to read file");
    fa_close(fh);
    return -1;
  }

  album = rstr_alloc(utf8_from_bytes((char *)buf + 0x16, 32, NULL));
  artist = rstr_alloc(utf8_from_bytes((char *)buf + 0x36, 32, NULL));

  tracks = buf[0xf];
  for(i = 0; i < tracks; i++) {

    snprintf(name, sizeof(name), "Track %02d", i + 1);
    snprintf(turl, sizeof(turl), "sidplayer:%s/%d", fpath, i + 1);
    fde = fa_dir_add(fd, turl, name, CONTENT_AUDIO);

    fde->fde_probestatus = FDE_PROBE_DEEP;

    fde->fde_metadata = prop_create_root("metadata");
    prop_set_string(prop_create(fde->fde_metadata, "title"), name);
    prop_set_rstring(prop_create(fde->fde_metadata, "album"), album);
    prop_set_rstring(prop_create(fde->fde_metadata, "artist"), artist);
  }

  rstr_release(album);
  rstr_release(artist);

  fa_close(fh);
  return 0;
}
Пример #4
0
AVIOContext *
fa_libav_open(const char *url, int buf_size, char *errbuf, size_t errlen)
{
  fa_handle_t *fh;

  if((fh = fa_open(url, errbuf, errlen)) == NULL)
    return NULL;

  if(buf_size == 0)
    buf_size = 32768;
  void *buf = malloc(buf_size);
  return avio_alloc_context(buf, buf_size, 0, fh, fa_libav_read, NULL, 
			    fa_libav_seek);
}
Пример #5
0
static image_t *
thumb_from_attachment(const char *url, int64_t offset, int size,
                      char *errbuf, size_t errlen, const char *cacheid,
                      time_t mtime)
{
  fa_handle_t *fh = fa_open(url, errbuf, errlen);
  if(fh == NULL)
    return NULL;

  fh = fa_slice_open(fh, offset, size);
  buf_t *buf = fa_load_and_close(fh);
  if(buf == NULL) {
    snprintf(errbuf, errlen, "Load error");
    return NULL;
  }
  image_t *img = fa_imageloader_buf(buf, errbuf, errlen);

  if(img != NULL) {
    blobcache_put(cacheid, "videothumb", buf, INT32_MAX, NULL, mtime, 0);
  }

  buf_release(buf);
  return img;
}
Пример #6
0
static void *
dvd_fa_open(const char *url)
{
  return fa_open(url, NULL, 0);
}
Пример #7
0
static int
gmefile_scandir(fa_dir_t *fd, const char *url, char *errbuf, size_t errlen)
{
  void *fh = NULL;
  char *p, *fpath = mystrdupa(url);
  char name[32];
  char turl[URL_MAX];
  int tracks, i, size;
  fa_dir_entry_t *fde;
  const char *title;
  char *buf;
  Music_Emu *emu;
  gme_info_t *info;
  gme_err_t err;
  size_t r;
  if((p = strrchr(fpath, '/')) == NULL) {
    snprintf(errbuf, errlen, "Invalid filename");
    return -1;
  }

  *p = 0;
  if((fh = fa_open(fpath, errbuf, errlen)) == NULL)
    return -1;

  size = fa_fsize(fh);

  buf = malloc(size);
  r = fa_read(fh, buf, size);
  fa_close(fh);
  if(r != size) {
    snprintf(errbuf, errlen, "Unable to read file");
    free(buf);
    return -1;
  }

  err = gme_open_data(buf, size, &emu, gme_info_only);
  free(buf);
  if(err != NULL)
    return 0;

  tracks = gme_track_count(emu);
  
  for(i = 0; i < tracks; i++) {

    snprintf(turl, sizeof(turl), "gmeplayer:%s/%d", fpath, i + 1);

    err = gme_track_info(emu, &info, i);

    if(err == NULL && info->song[0]) {
      title = info->song;
    } else {
      snprintf(name, sizeof(name), "Track %02d", i + 1);
      title = name;
    }

      
    fde = fa_dir_add(fd, turl, title, CONTENT_AUDIO);

    fde->fde_probestatus = FDE_PROBE_DEEP;

    fde->fde_metadata = prop_create_root("metadata");
    prop_set_string(prop_create(fde->fde_metadata, "title"), title);

    if(err == NULL) {
      if(info->game[0])
	prop_set_string(prop_create(fde->fde_metadata, "album"), info->game);
      if(info->author[0])
	prop_set_string(prop_create(fde->fde_metadata, "artist"), info->author);

      prop_set_float(prop_create(fde->fde_metadata, "duration"), 
		     info->play_length / 1000.0);

      gme_free_info(info);
    }
  }

  gme_delete(emu);
  return 0;
}