Esempio n. 1
0
File: cvirtual.c Progetto: tbe/LiVES
// load frame_index from disk
boolean load_frame_index(int fileno) {
  int fd,i;
  int retval;
  char *fname;
  lives_clip_t *sfile=mainw->files[fileno];

  if (sfile==NULL||sfile->frame_index!=NULL) return FALSE;

  if (sfile->frame_index!=NULL) lives_free(sfile->frame_index);
  sfile->frame_index=NULL;

  fname=lives_build_filename(prefs->tmpdir,sfile->handle,"file_index",NULL);

  if (!lives_file_test(fname,LIVES_FILE_TEST_EXISTS)) {
    lives_free(fname);
    return FALSE;
  }


  do {
    retval=0;

    fd=lives_open_buffered_rdonly(fname);

    if (fd<0) {
      retval=do_read_failed_error_s_with_retry(fname,lives_strerror(errno),NULL);
      if (retval==LIVES_RESPONSE_CANCEL) {
        lives_free(fname);
        return FALSE;
      }
    } else {

#ifdef IS_MINGW
      setmode(fd, O_BINARY);
#endif
      create_frame_index(fileno,FALSE,0,sfile->frames);

      mainw->read_failed=FALSE;
      for (i=0; i<sfile->frames; i++) {
        lives_read_le_buffered(fd,&sfile->frame_index[i],4,FALSE);
        if (mainw->read_failed) break;
      }

      lives_close_buffered(fd);

      if (mainw->read_failed) {
        mainw->read_failed=FALSE;
        retval=do_read_failed_error_s_with_retry(fname,NULL,NULL);
      }

    }
  } while (retval==LIVES_RESPONSE_RETRY);

  lives_free(fname);

  return TRUE;
}
Esempio n. 2
0
void load_rfx_preview(lives_rfx_t *rfx) {
  // load a preview of an rfx (rendered effect) in clip editor

  LiVESPixbuf *pixbuf;
  FILE *infofile=NULL;

  int max_frame=0,tot_frames=0;
  int vend=cfile->start;
  int retval;
  int alarm_handle;
  int current_file=mainw->current_file;

  boolean retb;
  boolean timeout;

  weed_timecode_t tc;
  const char *img_ext;

  if (mainw->framedraw_frame==0) mainw->framedraw_frame=1;

  lives_set_cursor_style(LIVES_CURSOR_BUSY,NULL);

  clear_mainw_msg();
  mainw->write_failed=FALSE;


  if (cfile->clip_type==CLIP_TYPE_FILE&&vend<=cfile->end) {
    // pull some frames for 10 seconds
    alarm_handle=lives_alarm_set(LIVES_DEFAULT_TIMEOUT);
    do {
      lives_widget_context_update();
      if (is_virtual_frame(mainw->current_file,vend)) {
        retb=virtual_to_images(mainw->current_file,vend,vend,FALSE,NULL);
        if (!retb) return;
      }
      vend++;
      timeout=lives_alarm_get(alarm_handle);
    } while (vend<=cfile->end&&!timeout&&!mainw->cancelled);
    lives_alarm_clear(alarm_handle);
  }

  if (mainw->cancelled) {
    lives_set_cursor_style(LIVES_CURSOR_NORMAL,NULL);
    return;
  }

  // get message from back end processor
  while (!(infofile=fopen(cfile->info_file,"r"))&&!mainw->cancelled) {
    // wait until we get at least 1 frame
    lives_widget_context_update();
    if (cfile->clip_type==CLIP_TYPE_FILE&&vend<=cfile->end) {
      // if we have a virtual clip (frames inside a video file)
      // pull some more frames to images to get us started
      do {
        retb=FALSE;
        if (is_virtual_frame(mainw->current_file,vend)) {
          retb=virtual_to_images(mainw->current_file,vend,vend,FALSE,NULL);
          if (!retb) {
            fclose(infofile);
            return;
          }
        }
        vend++;
      } while (vend<=cfile->end&&!retb);
    } else {
      // otherwise wait
      lives_usleep(prefs->sleep_time);
    }
  }

  if (mainw->cancelled) {
    if (infofile) fclose(infofile);
    lives_set_cursor_style(LIVES_CURSOR_NORMAL,NULL);
    return;
  }

  do {
    retval=0;
    mainw->read_failed=FALSE;
    lives_fgets(mainw->msg,512,infofile);
    if (mainw->read_failed) retval=do_read_failed_error_s_with_retry(cfile->info_file,NULL,NULL);
  } while (retval==LIVES_RESPONSE_RETRY);

  fclose(infofile);


  if (strncmp(mainw->msg,"completed",9)) {
    if (rfx->num_in_channels>0) {
      max_frame=atoi(mainw->msg);
    } else {
      int numtok=get_token_count(mainw->msg,'|');
      if (numtok>4) {
        char **array=lives_strsplit(mainw->msg,"|",numtok);
        max_frame=atoi(array[0]);
        cfile->hsize=atoi(array[1]);
        cfile->vsize=atoi(array[2]);
        cfile->fps=cfile->pb_fps=strtod(array[3],NULL);
        if (cfile->fps==0) cfile->fps=cfile->pb_fps=prefs->default_fps;
        tot_frames=atoi(array[4]);
        lives_strfreev(array);
      }
    }
  } else {
    max_frame=cfile->end;
  }

  lives_set_cursor_style(LIVES_CURSOR_NORMAL,NULL);

  if (max_frame>0) {
    if (rfx->num_in_channels==0) {
      int maxlen=calc_spin_button_width(1.,(double)tot_frames,0);
      lives_spin_button_set_range(LIVES_SPIN_BUTTON(mainw->framedraw_spinbutton),1,tot_frames);
      lives_entry_set_width_chars(LIVES_ENTRY(mainw->framedraw_spinbutton),maxlen);
      lives_widget_queue_draw(mainw->framedraw_spinbutton);
      lives_widget_queue_draw(mainw->framedraw_scale);
    }

    if (mainw->framedraw_frame>max_frame) {
      lives_spin_button_set_value(LIVES_SPIN_BUTTON(mainw->framedraw_spinbutton),max_frame);
      mainw->current_file=current_file;
      return;
    }
  }

  if (rfx->num_in_channels>0) {
    img_ext=LIVES_FILE_EXT_PRE;
  } else {
    img_ext=get_image_ext_for_type(cfile->img_type);
  }

  tc=((mainw->framedraw_frame-1.))/cfile->fps*U_SECL;
  pixbuf=pull_lives_pixbuf_at_size(mainw->current_file,mainw->framedraw_frame,(char *)img_ext,
                                   tc,(double)cfile->hsize,
                                   (double)cfile->vsize,LIVES_INTERP_BEST);


  load_framedraw_image(pixbuf);
  redraw_framedraw_image();

  mainw->current_file=current_file;
}