Пример #1
0
static event_t *
rtmp_process_event(rtmp_t *r, event_t *e, media_buf_t **mbp)
{
  media_pipe_t *mp = r->mp;

  if(event_is_type(e, EVENT_EXIT) ||
     event_is_type(e, EVENT_PLAY_URL) ||
     event_is_action(e, ACTION_SKIP_FORWARD))
    return e;
  
  if(event_is_action(e, ACTION_SKIP_BACKWARD)) {
    if(mp->mp_seek_base < MP_SKIP_LIMIT) {
      return e;
    }
    video_seek(r, mp, mbp, 0, "direct");
  }
  
  if(event_is_type(e, EVENT_CURRENT_TIME)) {
    event_ts_t *ets = (event_ts_t *)e;
    
    int sec = ets->ts / 1000000;

    if(sec != r->restartpos_last && r->can_seek) {
      r->restartpos_last = sec;
      metadb_set_video_restartpos(r->canonical_url, mp->mp_seek_base / 1000);
    }

  } else if(r->can_seek && event_is_type(e, EVENT_SEEK)) {
    event_ts_t *ets = (event_ts_t *)e;

    video_seek(r, mp, mbp, ets->ts, "direct");

  } else if(event_is_action(e, ACTION_STOP)) {
    mp_set_playstatus_stop(mp);
  } else if(event_is_type(e, EVENT_SELECT_SUBTITLE_TRACK)) {
    event_select_track_t *est = (event_select_track_t *)e;
    prop_set_string(mp->mp_prop_subtitle_track_current, est->id);
    if(!strcmp(est->id, "sub:off")) {
      mp_load_ext_sub(mp, NULL);
      } else {
      mp_load_ext_sub(mp, est->id);
    }

  }
  event_release(e);
  return NULL;
}
Пример #2
0
static event_t *
rtmp_process_event(rtmp_t *r, event_t *e, media_buf_t **mbp)
{
  media_pipe_t *mp = r->mp;

  if(event_is_type(e, EVENT_EXIT) ||
     event_is_type(e, EVENT_PLAY_URL))
    return e;

  if(event_is_action(e, ACTION_PLAYPAUSE) ||
     event_is_action(e, ACTION_PLAY) ||
     event_is_action(e, ACTION_PAUSE)) {
    
    r->hold = action_update_hold_by_event(r->hold, e);
    mp_send_cmd_head(mp, &mp->mp_video, r->hold ? MB_CTRL_PAUSE : MB_CTRL_PLAY);
    mp_send_cmd_head(mp, &mp->mp_audio, r->hold ? MB_CTRL_PAUSE : MB_CTRL_PLAY);
    mp_set_playstatus_by_hold(mp, r->hold, NULL);
    r->lost_focus = 0;
    

  } else if(event_is_type(e, EVENT_MP_NO_LONGER_PRIMARY)) {

    r->hold = 1;
    r->lost_focus = 1;
    mp_send_cmd_head(mp, &mp->mp_video, MB_CTRL_PAUSE);
    mp_send_cmd_head(mp, &mp->mp_audio, MB_CTRL_PAUSE);
    mp_set_playstatus_by_hold(mp, r->hold, e->e_payload);
    
  } else if(event_is_type(e, EVENT_MP_IS_PRIMARY)) {
    
    if(r->lost_focus) {
      r->hold = 0;
      r->lost_focus = 0;
      mp_send_cmd_head(mp, &mp->mp_video, MB_CTRL_PLAY);
      mp_send_cmd_head(mp, &mp->mp_audio, MB_CTRL_PLAY);
      mp_set_playstatus_by_hold(mp, r->hold, NULL);
    }
    
  } else if(event_is_type(e, EVENT_INTERNAL_PAUSE)) {
    
    r->hold = 1;
    r->lost_focus = 0;
    mp_send_cmd_head(mp, &mp->mp_video, MB_CTRL_PAUSE);
    mp_send_cmd_head(mp, &mp->mp_audio, MB_CTRL_PAUSE);
    mp_set_playstatus_by_hold(mp, r->hold, e->e_payload);

  } else if(event_is_type(e, EVENT_CURRENT_PTS)) {
    event_ts_t *ets = (event_ts_t *)e;
    
    r->seekbase = ets->ts;
    
    int sec = r->seekbase / 1000000;

    if(sec != r->restartpos_last && r->can_seek) {
      r->restartpos_last = sec;
      metadb_set_video_restartpos(r->canonical_url, r->seekbase / 1000);
    }

  } else if(r->can_seek && event_is_type(e, EVENT_SEEK)) {
    event_ts_t *ets = (event_ts_t *)e;

    r->epoch++;
      
    r->seekbase = video_seek(r, mp, mbp, ets->ts, 1, "direct");

  } else if(r->can_seek && event_is_action(e, ACTION_SEEK_FAST_BACKWARD)) {

    r->seekbase = video_seek(r, mp, mbp, r->seekbase - 60000000, 1, "-60s");

  } else if(r->can_seek && event_is_action(e, ACTION_SEEK_BACKWARD)) {

    r->seekbase = video_seek(r, mp, mbp, r->seekbase - 15000000, 1, "-15s");

  } else if(r->can_seek && event_is_action(e, ACTION_SEEK_FORWARD)) {

    r->seekbase = video_seek(r, mp, mbp, r->seekbase + 15000000, 1, "+15s");

  } else if(r->can_seek && event_is_action(e, ACTION_SEEK_FAST_FORWARD)) {

    r->seekbase = video_seek(r, mp, mbp, r->seekbase + 60000000, 1, "+60s");

  } else if(event_is_action(e, ACTION_STOP)) {
    mp_set_playstatus_stop(mp);
  } else if(event_is_type(e, EVENT_SELECT_SUBTITLE_TRACK)) {
    event_select_track_t *est = (event_select_track_t *)e;
    prop_set_string(mp->mp_prop_subtitle_track_current, est->id);
    if(!strcmp(est->id, "sub:off")) {
      mp_load_ext_sub(mp, NULL);
      } else {
      mp_load_ext_sub(mp, est->id);
    }

  }
  event_release(e);
  return NULL;
}