Beispiel #1
0
void weed_layer_set_from_yuv4m(weed_plant_t *layer, lives_clip_t *sfile) {
  lives_yuv4m_t *yuv4mpeg=(lives_yuv4m_t *)(sfile->ext_src);

  y4data thread_data;

  int error;

  pthread_t y4thread;

  int alarm_handle;

  if (!yuv4mpeg->ready) lives_yuv_stream_start_read(sfile);

  weed_set_int_value(layer,"width",sfile->hsize);
  weed_set_int_value(layer,"height",sfile->vsize);
  weed_set_int_value(layer,"current_palette",WEED_PALETTE_YUV420P);
  weed_set_int_value(layer,"YUV_subspace",WEED_YUV_SUBSPACE_YCBCR);

  create_empty_pixel_data(layer,TRUE,TRUE);

  if (!yuv4mpeg->ready) {
    return;
  }

  yuv4mpeg->pixel_data=weed_get_voidptr_array(layer,"pixel_data",&error);

  // create a thread to open the stream header

  thread_data.yuv4mpeg=yuv4mpeg;
  pthread_create(&y4thread,NULL,y4frame_thread,&thread_data);

  alarm_handle=lives_alarm_set(YUV4_F_TIME);

  while (!lives_alarm_get(alarm_handle)&&!pthread_kill(y4thread,0)) {
    // wait for thread to complete or timeout
    lives_usleep(prefs->sleep_time);
  }

  if (lives_alarm_get(alarm_handle)) {
    // timeout - kill thread and wait for it to terminate
    // timeout - kill thread and wait for it to terminate
    pthread_cancel(y4thread);
    d_print(_("Unable to read the incoming video frame\n"));
  }

  pthread_join(y4thread,NULL);
  lives_alarm_clear(alarm_handle);

  lives_free(yuv4mpeg->pixel_data);
  yuv4mpeg->pixel_data=NULL;

  weed_set_int_value(layer,"YUV_sampling",WEED_YUV_SAMPLING_MPEG);

  return;
}
Beispiel #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;
}
Beispiel #3
0
static boolean lives_yuv_stream_start_read(lives_clip_t *sfile) {
  double ofps=sfile->fps;

  lives_yuv4m_t *yuv4mpeg=(lives_yuv4m_t *)sfile->ext_src;

  pthread_t y4thread;

  char *filename=yuv4mpeg->filename,*tmp;

  int alarm_handle=0;

  int ohsize=sfile->hsize;
  int ovsize=sfile->vsize;

  y4data thread_data;

  register int i;


  if (filename==NULL) return FALSE;

  if (yuv4mpeg->fd==-1) {
    // create a thread to open the fifo

    thread_data.filename=filename;

    pthread_create(&y4thread,NULL,y4open_thread,(void *)&thread_data);

    alarm_handle=lives_alarm_set(YUV4_O_TIME);

    d_print("");
    d_print(_("Waiting for yuv4mpeg frames..."));

    while (!lives_alarm_get(alarm_handle)&&!pthread_kill(y4thread,0)) {
      // wait for thread to complete or timeout
      lives_usleep(prefs->sleep_time);
      lives_widget_context_update();
    }

    if (lives_alarm_get(alarm_handle)) {
      // timeout - kill thread and wait for it to terminate
      pthread_cancel(y4thread);
      pthread_join(y4thread,NULL);
      lives_alarm_clear(alarm_handle);

      d_print_failed();
      d_print(_("Unable to open the incoming video stream\n"));

      yuv4mpeg->fd=thread_data.fd;

      if (yuv4mpeg->fd>=0) {
        close(yuv4mpeg->fd);
        yuv4mpeg->fd=-1;
      }

      return FALSE;
    }

    pthread_join(y4thread,NULL);
    lives_alarm_clear(alarm_handle);

    yuv4mpeg->fd=thread_data.fd;

    if (yuv4mpeg->fd<0) {
      return FALSE;
    }
  }

  // create a thread to open the stream header
  thread_data.yuv4mpeg=yuv4mpeg;
  pthread_create(&y4thread,NULL,y4header_thread,&thread_data);
  alarm_handle=lives_alarm_set(YUV4_H_TIME);

  while (!lives_alarm_get(alarm_handle)&&!pthread_kill(y4thread,0)) {
    // wait for thread to complete or timeout
    lives_usleep(prefs->sleep_time);
    lives_widget_context_update();
  }

  if (lives_alarm_get(alarm_handle)) {
    // timeout - kill thread and wait for it to terminate
    pthread_cancel(y4thread);
    pthread_join(y4thread,NULL);
    lives_alarm_clear(alarm_handle);
    d_print(_("Unable to read the stream header\n"));
    return FALSE;
  }

  pthread_join(y4thread,NULL);
  lives_alarm_clear(alarm_handle);

  i=thread_data.i;

  if (i != Y4M_OK) {
    char *tmp;
    d_print((tmp=lives_strdup_printf("yuv4mpeg: %s\n", y4m_strerr(i))));
    lives_free(tmp);
    return FALSE;
  }

  d_print(_("got header\n"));

  sfile->hsize = yuv4mpeg->hsize = y4m_si_get_width(&(yuv4mpeg->streaminfo));
  sfile->vsize = yuv4mpeg->vsize = y4m_si_get_height(&(yuv4mpeg->streaminfo));

  sfile->fps=cfile->pb_fps=lives_strtod(lives_strdup_printf("%.8f",Y4M_RATIO_DBL
                                        (y4m_si_get_framerate(&(yuv4mpeg->streaminfo)))),NULL);

  if (!(sfile->hsize*sfile->vsize)) {
    do_error_dialog(lives_strdup_printf(_("Video dimensions: %d x %d are invalid. Stream cannot be opened"),
                                        sfile->hsize,sfile->vsize));
    return FALSE;
  }

  if (sfile->hsize!=ohsize||sfile->vsize!=ovsize||sfile->fps!=ofps) {
    set_main_title(sfile->file_name,0);
  }

  d_print((tmp=lives_strdup_printf(_("Reset clip values for %s: size=%dx%d fps=%.3f\n"),yuv4mpeg->name,
                                   cfile->hsize,yuv4mpeg->vsize,cfile->bpp,cfile->fps)));
  lives_free(tmp);

  yuv4mpeg->ready=TRUE;

  return TRUE;
}