Example #1
0
   void Scheduler::process_video(AVPacket& pkt, Display::Ptr vid, AVFrame *frame)
   {
      if (!has_video)
         return;

      int finished = 0;

      uint64_t pts = pkt.pts;
      FF::set_global_pts(pkt.pts);

      gfx_lock.lock();
      avcodec_decode_video2(file->video().ctx, frame, &finished, &pkt);
      gfx_lock.unlock();

      if (pkt.dts == (int64_t)AV_NOPTS_VALUE && frame->opaque && *(uint64_t*)frame->opaque != AV_NOPTS_VALUE)
         pts = *(uint64_t*)frame->opaque;
      else if (pkt.dts != (int64_t)AV_NOPTS_VALUE)
         pts = pkt.dts;

      if (finished)
      {
         if (pts != AV_NOPTS_VALUE)
            video_pts = pts * av_q2d(file->video().time_base);
         else
            video_pts += frame_time();

         video_pts += frame->repeat_pict / (2.0 * frame_time());
         vid->frame(frame->data, frame->linesize, file->video().width, file->video().height);
      }
   }
Example #2
0
File: sea.c Project: RicoP/Corange
void sea_update() {

    camera* cam = entity_get("camera");
    light* sun = entity_get("sun");

    wave_time += frame_time();
    static_object* corvette = entity_get("corvette");
    corvette->position.y = (sin(wave_time) + 1) / 2;
    corvette->rotation = v4_quaternion_pitch(sin(wave_time * 1.123) / 50);
    corvette->rotation = v4_quaternion_mul(corvette->rotation, v4_quaternion_yaw(sin(wave_time * 1.254) / 25));
    corvette->rotation = v4_quaternion_mul(corvette->rotation, v4_quaternion_roll(sin(wave_time * 1.355) / 100));

    static_object* center_sphere = entity_get("center_sphere");

    physics_object* balls[100];
    int num_balls;
    entities_get(balls, &num_balls, physics_object);
    for(int i = 0; i < num_balls; i++) {
        physics_object_collide_static(balls[i], center_sphere, frame_time());
        physics_object_collide_static(balls[i], corvette, frame_time());
        physics_object_update(balls[i], frame_time());
    }

    Uint8 keystate = SDL_GetMouseState(NULL, NULL);
    if(keystate & SDL_BUTTON(1)) {
        float a1 = -(float)mouse_x * 0.01;
        float a2 = (float)mouse_y * 0.01;

        cam->position = v3_sub(cam->position, cam->target);
        cam->position = m33_mul_v3(m33_rotation_y( a1 ), cam->position );
        cam->position = v3_add(cam->position, cam->target);

        cam->position = v3_sub(cam->position, cam->target);
        vector3 rotation_axis = v3_normalize(v3_cross( v3_sub(cam->position, v3_zero()) , v3(0,1,0) ));
        cam->position = m33_mul_v3(m33_rotation_axis_angle(rotation_axis, a2 ), cam->position );
        cam->position = v3_add(cam->position, cam->target);

    }

    if(keystate & SDL_BUTTON(3)) {
        sun->position.x += (float)mouse_y / 2;
        sun->position.z -= (float)mouse_x / 2;
    }

    mouse_x = 0;
    mouse_y = 0;

    ui_button* framerate = ui_elem_get("framerate");
    ui_button_set_label(framerate, frame_rate_string());

}
Example #3
0
void character_update(character* c) {
  c->velocity.x = clamp(c->velocity.x, -7.0, 7.0);
  c->position = v2_add(c->position, c->velocity);
  
  if (c->flap_timer > 0.0) {
    c->flap_timer -= frame_time();
  }
}
Example #4
0
void metaballs_update() {

  camera* cam = entity_get("camera");
  light* sun = entity_get("sun");

  Uint8 keystate = SDL_GetMouseState(NULL, NULL);
  if(keystate & SDL_BUTTON(1)){
    float a1 = -(float)mouse_x * frame_time() * 0.25;
    float a2 = (float)mouse_y * frame_time() * 0.25;
    
    cam->position = v3_sub(cam->position, cam->target);
    cam->position = m33_mul_v3(m33_rotation_y( a1 ), cam->position );
    cam->position = v3_add(cam->position, cam->target);
    
    cam->position = v3_sub(cam->position, cam->target);
    vector3 rotation_axis = v3_normalize(v3_cross( v3_sub(cam->position, v3_zero()) , v3(0,1,0) ));
    cam->position = m33_mul_v3(m33_rotation_axis_angle(rotation_axis, a2 ), cam->position );
    cam->position = v3_add(cam->position, cam->target);
  }
  
  if(keystate & SDL_BUTTON(3)){
    sun->position.x += (float)mouse_y / 2;
    sun->position.z -= (float)mouse_x / 2;
  }

  mouse_x = 0;
  mouse_y = 0;

  particles_update(frame_time());
  
  ui_button* framerate = ui_elem_get("framerate");
  ui_button_set_label(framerate, frame_rate_string());
  
#ifdef MARCHING_CUBES
  marching_cubes_metaball_data( particle_positions_memory(), particles_count() );
  marching_cubes_clear();
  marching_cubes_update();
#endif

#ifdef VOLUME_RENDERER
  volume_renderer_metaball_data( particle_positions_memory(), particles_count() );
  volume_renderer_update();
#endif
  
}
Example #5
0
void scotland_update() {
  
  camera* cam = entity_get("camera");
  light* sun = entity_get("sun");
  static_object* skydome = entity_get("skydome");
  landscape* world = entity_get("world");
  
  sun_orbit += frame_time() * 0.01;
  
  sun->position.x = 512 + sin(sun_orbit) * 512;
  sun->position.y = cos(sun_orbit) * 512;
  sun->position.z = 512;
  sun->target = vec3_new(512, 0, 512);
  
  if (w_held || s_held) {
    
    vec3 cam_dir = vec3_normalize(vec3_sub(cam->target, cam->position));
    float speed = 0.5;
    if (!freecam) speed = 0.05;
    if (w_held) {
      cam->position = vec3_add(cam->position, vec3_mul(cam_dir, speed));
    }
    if (s_held) {
      cam->position = vec3_sub(cam->position, vec3_mul(cam_dir, speed));
    }
    
    if (!freecam) {
      float height = terrain_height(asset_hndl_ptr(world->terrain), vec2_new(cam->position.x, cam->position.z));
      cam->position.y = height + 1;
    }
    
    cam->target = vec3_add(cam->position, cam_dir);
  }
  
  Uint8 keystate = SDL_GetMouseState(NULL, NULL);
  if(keystate & SDL_BUTTON(1)){
  
    float a1 = -(float)mouse_x * 0.005;
    float a2 = (float)mouse_y * 0.005;
    
    vec3 cam_dir = vec3_normalize(vec3_sub(cam->target, cam->position));
    
    cam_dir.y += -a2;
    vec3 side_dir = vec3_normalize(vec3_cross(cam_dir, vec3_new(0,1,0)));
    cam_dir = vec3_add(cam_dir, vec3_mul(side_dir, -a1));
    cam_dir = vec3_normalize(cam_dir);
    
    cam->target = vec3_add(cam->position, cam_dir);
  }
  
  mouse_x = 0;
  mouse_y = 0;
  
  ui_button* framerate = ui_elem_get("framerate");
  ui_button_set_label(framerate, frame_rate_string());
}
Example #6
0
void sea_update() {

  camera* cam = entity_get("camera");
  light* sun = entity_get("sun");
  
  wave_time += frame_time();
  static_object* corvette = entity_get("corvette");
  corvette->position.y = (sin(wave_time) + 1) / 2;
  corvette->rotation = quaternion_pitch(sin(wave_time * 1.123) / 50);
  corvette->rotation = quaternion_mul(corvette->rotation, quaternion_yaw(sin(wave_time * 1.254) / 25));
  corvette->rotation = quaternion_mul(corvette->rotation, quaternion_roll(sin(wave_time * 1.355) / 100));
  
  static_object* center_sphere = entity_get("center_sphere");
  
  physics_object* balls[100];
  int num_balls;
  entities_get(balls, &num_balls, physics_object);
  for(int i = 0; i < num_balls; i++) {
    physics_object_collide_static(balls[i], center_sphere, frame_time());
    physics_object_collide_static(balls[i], corvette, frame_time());
    physics_object_update(balls[i], frame_time());
  }
  
  Uint8 keystate = SDL_GetMouseState(NULL, NULL);
  
  if(keystate & SDL_BUTTON(3)){
    sun->position.x += (float)mouse_y / 2;
    sun->position.z -= (float)mouse_x / 2;
  }

  mouse_x = 0;
  mouse_y = 0;
  
  ui_button* framerate = ui_elem_get("framerate");
  ui_button_set_label(framerate, frame_rate_string());
  
}
Example #7
0
void platformer_update() {
  
  character* main_char = entity_get("main_char");
  
  if (left_held) {
    main_char->velocity.x -= 0.1;
    main_char->facing_left = true;
  } else if (right_held) {
    main_char->velocity.x += 0.1;
    main_char->facing_left = false;
  } else {
    main_char->velocity.x *= 0.95;
  }
  
  /* Give the player some gravity speed */
  const float gravity = 0.2;
  main_char->velocity.y += gravity;
  
  /* Update moves position based on velocity */
  character_update(main_char);
  
  /* Two phases of collision detection */
  collision_detection();
  collision_detection_coins();
  
  /* Camera follows main character */
  camera_position = vec2_new(main_char->position.x, -main_char->position.y);
  
  /* Update the framerate text */
  ui_button* framerate = ui_elem_get("framerate");
  ui_button_set_label(framerate, frame_rate_string());
  
  /* Update the time text */
  ui_button* victory = ui_elem_get("victory");
  if (!victory->active) {
    level_time += frame_time();
    ui_button* time = ui_elem_get("time");
    sprintf(time->label->string, "Time %06i", (int)level_time);
      ui_text_draw(time->label);
  }
  
}
Example #8
0
int main(int argc, char **argv) {

#ifdef _WIN32
    FILE* ctt = fopen("CON", "w" );
    FILE* fout = freopen( "CON", "w", stdout );
    FILE* ferr = freopen( "CON", "w", stderr );
#endif

    corange_init("../../assets_core");

    graphics_viewport_set_size(1280, 720);
    graphics_viewport_set_title("Noise");

    folder_load(P("./"));
    file_load(P("$CORANGE/textures/random.dds"));

    glClearColor(1.0, 0.0, 0.0, 1.0);

    ui_button* info_button = ui_elem_new("info_button", ui_button);
    ui_button_move(info_button, vec2_new(10, 10));
    ui_button_resize(info_button, vec2_new(460,25));
    ui_button_set_label(info_button, "Procedural texture from perlin noise and feedback functions");

    ui_button* save_button = ui_elem_new("save_button", ui_button);
    ui_button_move(save_button, vec2_new(480, 10));
    ui_button_resize(save_button, vec2_new(380,25));
    ui_button_set_label(save_button, "Click Here to save tileable perlin noise to file");
    ui_button_set_onclick(save_button, save_noise_to_file);

    ui_button* spinner_box = ui_elem_new("spinner_box", ui_button);
    ui_button_resize(spinner_box, vec2_new(32, 32));
    ui_button_move(spinner_box, vec2_new(870, 7));
    ui_button_set_label(spinner_box, "");

    ui_spinner* save_spinner = ui_elem_new("save_spinner", ui_spinner);
    save_spinner->color = vec4_new(1,1,1,0);
    save_spinner->top_left = vec2_new(874, 11);
    save_spinner->bottom_right = vec2_add(save_spinner->top_left, vec2_new(24,24));

    srand(time(NULL));
    shader_time = (float)rand() / (RAND_MAX / 1000);

    bool running = true;
    while(running) {
        frame_begin();

        SDL_Event event;
        while(SDL_PollEvent(&event)) {

            switch(event.type) {
            case SDL_KEYDOWN:
            case SDL_KEYUP:
                if (event.key.keysym.sym == SDLK_ESCAPE) {
                    running = 0;
                }
                if (event.key.keysym.sym == SDLK_PRINTSCREEN) {
                    graphics_viewport_screenshot();
                }
                break;
            case SDL_QUIT:
                running = 0;
                break;
                break;
            }

            ui_event(event);

        }

        shader_time += frame_time();
        ui_update();

        noise_render();
        ui_render();

        graphics_swap();

        frame_end();

    }

    SDL_WaitThread(save_thread, NULL);

    corange_finish();

    return 0;
}
Example #9
0
void ui_spinner_update(ui_spinner* s) {
  s->rotation += s->speed * frame_time();
}
Example #10
0
   // Video thread
   void Scheduler::video_thread_fn()
   {
      auto vid = GL::shared(file->video().width, file->video().height, file->video().aspect_ratio, file->video().ctx->pix_fmt);
      video = vid;
      auto event = GLEvent::shared();

      if (file->sub().active)
         sub_renderer = ASSRenderer::shared(file->sub().fonts, file->sub().ass_data, file->video().width, file->video().height);

      AVFrame *frame = avcodec_alloc_frame();

      // Add event handler for GL.
      add_event_handler(event);

      while (video_thread_active && vid_pkt_queue.alive())
      {
         event->poll(); 
         avlock.lock();
         if (vid_pkt_queue.size() > 0 && !is_paused)
         {
            auto pkt = vid_pkt_queue.pull();
            avlock.unlock();
            process_video(pkt.get(), vid, frame);

            if (file->sub().active)
               process_subtitle(vid);

            // We have to calculate how long we should wait before swapping frame to screen.
            // We sync everything to audio clock.
            double delta = get_time();

            avlock.lock();
            delta -= audio_pts_ts;
            double sleep_time = video_pts - (audio_pts + delta);
            avlock.unlock();

            // Yes, it can happen! :(
            if (delta < 0.0)
               delta = 0.0;
            //std::cout << "Delta: " << delta << std::endl;

            if (video_pts > (audio_pts + delta) && audio_thread_active)
            {
               double last_frame_delta = get_time();
               last_frame_delta -= video_pts_ts;

               // :(
               if (last_frame_delta < 0.0)
                  last_frame_delta = 0.0;

               // We try to keep the sleep time to a somewhat small value to avoid choppy video in some cases.
               // Max sleep time should be a bit over 1 frame time to allow audio to catch up.
               double max_sleep = 1.2 * frame_time() - last_frame_delta;

               if (max_sleep < 0.0)
                  max_sleep = 0.0;

               if (sleep_time > max_sleep)
               {
                  sleep_time = max_sleep;
               }
               //std::cout << "Sleep for " << sleep_time << std::endl;
               sync_sleep(sleep_time);
            }

            video_pts_ts = get_time();
            vid->flip();
         }
         else
         {
            avlock.unlock();

            if (is_paused)
               sync_sleep(0.01);
            else
            {
               // Having some race conditions... quickfix it for now.
               vid_pkt_queue.wait();
               //sync_sleep(0.01);
               //vid_pkt_queue.signal();
            }
         }
      }
      video_thread_active = false;
      av_free(frame);
   }
Example #11
0
void ui_rectangle_update(ui_rectangle* r) {
    r->time += frame_time();
}
Example #12
0
File: rtv.c Project: myler/unix
int
v4lGrab (struct vdIn *vd, int channel )
{
//    static	int frame = 0;

//    int len;
//    int status;
//    int count = 0;
//    int size;
    int erreur = 0;
    int jpegsize = 0;
    int qualite = 1024;
    struct frame_t *headerframe;
//    double timecourant =0;
//    double temps = 0;
//  timecourant = ms_time();
    if (vd->grabMethod)
    {

        vd->vmmap.height = vd->hdrheight;
        vd->vmmap.width = vd->hdrwidth;
        vd->vmmap.format = vd->formatIn;
//            logger(TLOG_NOTICE, "channel:%d step 1.\n", channel);
        if (ioctl (vd->fd, VIDIOCSYNC,&vd->vmmap.frame) < 0)
        {
            logger(TLOG_ERROR, "rtv cvsync err\n");
            erreur = -1;
        }

        thread_syn_wait(&frame_syn_ctrl[channel][vd->frame_cour].mutex_w,
                        &frame_syn_ctrl[channel][vd->frame_cour].cond_w,
                        &frame_syn_ctrl[channel][vd->frame_cour].flag_w);
        //         logger(TLOG_NOTICE, "channel:%d step 3.\n", channel);
        jpegsize= convertframe(vd->ptframe[vd->frame_cour]+ sizeof(struct frame_t),
                               vd->pFramebuffer + vd->videombuf.offsets[vd->vmmap.frame],
                               vd->hdrwidth,vd->hdrheight,vd->formatIn,qualite);
        vd->ptframesize[vd->frame_cour] = ((jpegsize < 0)?0:jpegsize);

        headerframe=(struct frame_t*)vd->ptframe[vd->frame_cour];
//        snprintf(headerframe->header,5,"%s","SPCA");
//        headerframe->seqtimes = ms_time();
        frame_time(&(headerframe->date), &(headerframe->time));
//        headerframe->deltatimes=(int)(headerframe->seqtimes-timecourant);
        headerframe->w = vd->hdrwidth;
        headerframe->h = vd->hdrheight;
        headerframe->size = (( jpegsize < 0)?0:jpegsize);
        headerframe->format = vd->formatIn;
//        headerframe->nbframe = frame++;
        //       logger(TLOG_NOTICE, "channel:%d step 4.\n", channel);
        thread_syn_flag_clr(&frame_syn_ctrl[channel][vd->frame_cour].mutex_w,
                            &frame_syn_ctrl[channel][vd->frame_cour].cond_w,
                            &frame_syn_ctrl[channel][vd->frame_cour].flag_w);
        thread_syn_flag_set(&frame_syn_ctrl[channel][vd->frame_cour].mutex_r,
                            &frame_syn_ctrl[channel][vd->frame_cour].cond_r,
                            &frame_syn_ctrl[channel][vd->frame_cour].flag_r);
        // logger(TLOG_NOTICE, "compress frame %d times %f\n",frame, headerframe->seqtimes-temps);
//	pthread_mutex_unlock (&vd->grabmutex);
        /************************************/
        //        logger(TLOG_NOTICE, "channel:%d step 5.\n", channel);
        if ((ioctl (vd->fd, VIDIOCMCAPTURE, &(vd->vmmap))) < 0)
        {
            logger(TLOG_ERROR, "rtv cmcapture err\n");
            erreur = -1;
        }
        vd->vmmap.frame = (vd->vmmap.frame + 1) % vd->videombuf.frames;
        vd->frame_cour = (vd->frame_cour +1) % OUTFRMNUMB;
        //         logger(TLOG_NOTICE, "channel:%d step 6.\n", channel);
        //logger(TLOG_NOTICE, "frame nb %d\n",vd->vmmap.frame);

    }
#if 0
    else
    {
        /* read method */
        size = vd->framesizeIn;
        len = read (vd->fd, vd->pFramebuffer, size);
        if (len <= 0 )
        {
            printf ("v4l read error\n");
            printf ("len %d asked %d \n", len, size);
            return 0;
        }
        /* Is there someone using the frame */
        while ((vd->framelock[vd->frame_cour] != 0)&& vd->signalquit)
            usleep(1000);
        pthread_mutex_lock (&vd->grabmutex);
        /*
         memcpy (vd->ptframe[vd->frame_cour]+ sizeof(struct frame_t), vd->pFramebuffer, vd->framesizeIn);
         jpegsize =jpeg_compress(vd->ptframe[vd->frame_cour]+ sizeof(struct frame_t),len,
         vd->pFramebuffer, vd->hdrwidth, vd->hdrheight, qualite);
         */
        temps = ms_time();
        jpegsize= convertframe(vd->ptframe[vd->frame_cour]+ sizeof(struct frame_t),
                               vd->pFramebuffer ,
                               vd->hdrwidth,vd->hdrheight,vd->formatIn,qualite);
        headerframe=(struct frame_t*)vd->ptframe[vd->frame_cour];
        snprintf(headerframe->header,5,"%s","SPCA");
        headerframe->seqtimes = ms_time();
        headerframe->deltatimes=(int)(headerframe->seqtimes-timecourant);
        headerframe->w = vd->hdrwidth;
        headerframe->h = vd->hdrheight;
        headerframe->size = (( jpegsize < 0)?0:jpegsize);;
        headerframe->format = vd->formatIn;
        headerframe->nbframe = frame++;
        //  printf("compress frame %d times %f\n",frame, headerframe->seqtimes-temps);
        vd->frame_cour = (vd->frame_cour +1) % OUTFRMNUMB;
        pthread_mutex_unlock (&vd->grabmutex);
        /************************************/

    }
#endif

    return erreur;
}