コード例 #1
0
ファイル: vtx.c プロジェクト: FauxFaux/deadbeef
static DB_playItem_t *
vtx_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) {
    // read information from the track
    // load/process cuesheet if exists
    // insert track into playlist
    // return track pointer on success
    // return NULL on failure

    trace ("vtx_insert %s\n");
    // load header
    DB_FILE *fp = deadbeef->fopen (fname);
    if (!fp) {
        trace ("vtx: failed to open file\n");
        return NULL;
    }
    char buf[0x4000];
    size_t sz;
    sz = deadbeef->fread (buf, 1, sizeof (buf), fp);
    deadbeef->fclose (fp);
    if (sz <= 0) {
        trace ("vtx: failed to read header data from file\n");
        return NULL;
    }
    ayemu_vtx_t *hdr = ayemu_vtx_header (buf, sz);
    if (!hdr) {
        trace ("vtx: failed to read header\n");
        return NULL;
    }
    trace ("vtx: datasize: %d\n", hdr->regdata_size);

    DB_playItem_t *it = deadbeef->pl_item_alloc_init (fname, plugin.plugin.id);
    deadbeef->pl_add_meta (it, ":FILETYPE", "VTX");

    int numframes = hdr->regdata_size / AY_FRAME_SIZE;
//    int totalsamples = numframes * hdr->playerFreq;
    trace ("vtx: numframes=%d, playerFreq=%d\n", numframes, hdr->playerFreq);
    deadbeef->plt_set_item_duration (plt, it, (float)numframes / hdr->playerFreq);

    // add metadata
    deadbeef->pl_add_meta (it, "title", hdr->title);
    deadbeef->pl_add_meta (it, "artist", hdr->author);
    deadbeef->pl_add_meta (it, "album", hdr->from);

    ayemu_vtx_free (hdr);
    after = deadbeef->plt_insert_item (plt, after, it);
    deadbeef->pl_item_unref (it);
    return after;
}
コード例 #2
0
ファイル: vtxfile.c プロジェクト: eblanca/deadbeef-0.7.2
ayemu_vtx_t * ayemu_vtx_header_from_file(const char *filename)
{
  ayemu_vtx_t *ret;
  size_t size;
#ifdef __MINGW32__
  SYSTEM_INFO si;
  GetSystemInfo(&si);
  const size_t page_size = (size_t) si.dwPageSize;
#else
  const size_t page_size = (size_t) sysconf (_SC_PAGESIZE);
#endif
  int fd;
  struct stat st;

  // printf("Page size is %d\n", page_size);

  if (stat(filename, &st) != 0) {
    fprintf(stderr, "Can't stat file %s: %s\n", filename, strerror(errno));
    return NULL;
  }
  size = st.st_size;

  fd = open(filename, O_RDONLY, 0);
  if (fd == 0) {
    fprintf(stderr, "Can't open file %s: %s\n", filename, strerror(errno));
    return NULL;
  }

  size_t data_len = (size / page_size + 1) * page_size;

  char *data = mmap(NULL, data_len, PROT_READ, MAP_PRIVATE, fd, 0);
  if (data == (void*)(-1)) {
    fprintf(stderr, "Can't mmap file %s: %s\n", filename, strerror(errno));
    return NULL;
  }

  ret = ayemu_vtx_header(data, size);

  if (munmap(data, data_len) != 0) {
    fprintf(stderr, "Can't munmmap file %s: %s\n", filename, strerror(errno));
  }

  return ret;
}