Ejemplo n.º 1
0
int			main(int argc, char *argv[])
{
	t_all		*all;

	all = ft_malloc(sizeof(t_all));
	frac_init(all, argc, argv);
	mlx_hook(all->env.win, 6, (1L << 6), mouse_move, all);
	mlx_key_hook(all->env.win, key_hook, all);
	mlx_mouse_hook(all->env.win, mouse_hook, all);
	mlx_loop_hook(all->env.mlx, loop_hook, all);
	mlx_expose_hook(all->env.win, expose_hook, all);
	mlx_loop(all->env.mlx);
	return (0);
}
Ejemplo n.º 2
0
int main(int argc, char *argv[]) {
  frac_init();

  Frac* frac = frac_make(2, 6);
  frac_println(stdout, frac);

  Frac* frac2 = frac_multiply(frac_alloc(), frac, frac);
  frac_println(stdout, frac2);

  Frac* frac3 = frac_add(frac_alloc(), frac2, frac);
  frac_println(stdout, frac3);

  Frac* frac4 = frac_divide(frac_alloc(), frac3, frac);
  frac_println(stdout, frac4);

  frac_free(frac4);
  frac_free(frac3);
  frac_free(frac2);
  frac_free(frac);

  // compute a summation approximation of e^x
  int x = 2;
  Frac* e = frac_make(0, 1);
  for(int k = 0; k < 17; k++) {
    Frac* term = frac_make(ipow(x, k), factorial(k));
    frac_add(e, e, term);
    frac_free(term);
  }
  frac_print(stdout, e);
  printf(" ~= %lf\n", frac_approx(e));


  // allocate and free a "large" number of fractions but never with
  // many alive at once. A pool of only 2 fractions should be
  // sufficient to satisfy this test.
  for(int ii = 0; ii < 10000; ++ii) {
    Frac* aFrac = frac_make(1,2);
    frac_free(aFrac);
  }

  // then make sure nothing obviously broke
  frac_println(stdout, e);
  frac_free(e);

  return 0;
}
Ejemplo n.º 3
0
int MP4Parser::init()
{
  bzero(&m_track, sizeof(m_track));
  Track *trak = &m_track[VIDEO];
  if (init_tracks_from_box(m_box, trak) < 0) {
    LOGE("Init mp4's tracks failed");
    return -1;
  }

  // Make sure the video and audio tracks are valid
  if (m_parsed_track < NB_TRACK || // Only one track in file, not support
      !m_track[AUDIO].track_ID || !m_track[VIDEO].track_ID || // Missing audio or video track
      !m_track[AUDIO].mp4a || !m_track[VIDEO].avc1) { // Either video track's codec isn't h264 or
    // audio track's codec isn't mp4a
    LOGE("Invalid audio(%u:%p) track or video(%u:%p) track",
         m_track[AUDIO].track_ID, m_track[AUDIO].mp4a,
         m_track[VIDEO].track_ID, m_track[VIDEO].avc1);
    return -1;
  }

  bzero(&m_status, sizeof(m_status));
  ReadStatus *rstatus;

  // Compute the shift timebase for tracks
  // NOTE: We manage only one case : when video does not start at 
  // 0, we delay all others tracks by the amount indicated
  trak = &m_track[VIDEO];
  rstatus = &m_status[VIDEO];
  if (trak->elst && trak->elst->entry_count == 1) {
    // Only support 1 entry in "elst" box
    int64_t media_time =
      trak->elst->ver==1 ? trak->elst->elst_entry[0].media_time.i64 :
      trak->elst->elst_entry[0].media_time.i32;
    if (media_time > 0) { // Only delay audio tracks
      // Update audio track's shift timebase
      m_status[AUDIO].shift_time = media_time*1000/trak->timescale;
    }
  }
  frac_init(&rstatus->dts, 0, 0, trak->timescale);

  trak = &m_track[AUDIO];
  rstatus = &m_status[AUDIO];
  uint8_t samplerate_idx = str_to_samplerate_idx(
      STR(sprintf_("%d", trak->mp4a->samplerate>>16)));
  if (trak->esds->to_confirm) {
    // Confirm the asc which is generated by hand
    generate_asc(trak->esds->asc,
                 0x02/*LC fixed*/, samplerate_idx, trak->mp4a->channelcount);

    trak->esds->to_confirm = false;
  } else {
    if (samplerate_idx != trak->esds->samplerate_idx ||
        trak->mp4a->channelcount != trak->esds->channel) {
#ifdef XDEBUG
      LOGD("|esds|:idx=%u, channel=%u != |mp4a|:idx=%u, channel=%u",
           trak->esds->samplerate_idx, trak->esds->channel,
           samplerate_idx, trak->mp4a->channelcount);
#endif
#if 0
      // |mp4a| wins
      generate_asc(trak->esds->asc,
          trak->esds->audio_object_type,
          samplerate_idx, trak->mp4a->channelcount);
#else
      // Use the asc in |esds| by default
      LOGW("AudioSpecificConfig in |esds| is different from |mp4a|");
#endif
    }
  }
  frac_init(&rstatus->dts, 0, 0, trak->timescale);
  // Only audio has shift_time
  if (rstatus->shift_time > 0)
    rstatus->dts.val += rstatus->shift_time;
  return 0;
}