📄 player_session.cpp
字号:
free_decode_response(decode); m_streaming = true; m_streaming_ondemand = (get_range_from_sdp(m_sdp_info) != NULL); return (0);}int CPlayerSession::create_streaming_ondemand_other(rtsp_client_t *rtsp_client, const char *control_url, int have_end_time, uint64_t end_time, int dont_send_start_play, int seekable){ session_set_seekable(seekable); m_streaming = true; m_streaming_ondemand = 1; m_rtsp_client = rtsp_client; m_set_end_time = have_end_time; m_end_time = end_time; m_dont_send_first_rtsp_play = dont_send_start_play; m_session_control_url = control_url; streaming_media_set_up(); return 0;}/* * play_all_media - get all media to play */int CPlayerSession::play_all_media (int start_from_begin, double start_time){ int ret; CPlayerMedia *p; if (m_set_end_time == 0) { range_desc_t *range; if (m_sdp_info && m_sdp_info->session_range.have_range != FALSE) { range = &m_sdp_info->session_range; } else { range = NULL; p = m_my_media; while (range == NULL && p != NULL) { media_desc_t *media; media = p->get_sdp_media_desc(); if (media && media->media_range.have_range) { range = &media->media_range; } p = p->get_next(); } } if (range != NULL) { m_end_time = (uint64_t)(range->range_end * 1000.0); m_set_end_time = 1; } } p = m_my_media; m_session_state = SESSION_BUFFERING; if (m_paused && start_time == 0.0 && start_from_begin == FALSE) { /* * we were paused. Continue. */ m_play_start_time = m_current_time; start_time = UINT64_TO_DOUBLE(m_current_time); start_time /= 1000.0; player_debug_message("Restarting at " U64 ", %g", m_current_time, start_time); } else { /* * We might have been paused, but we're told to seek */ // Indicate what time we're starting at for sync task. m_play_start_time = (uint64_t)(start_time * 1000.0); } m_paused = false; send_sync_thread_a_message(MSG_START_SESSION); // If we're doing aggregate rtsp, send the play command... if (session_control_is_aggregate() && m_dont_send_first_rtsp_play == 0) { char buffer[80]; rtsp_command_t cmd; rtsp_decode_t *decode; memset(&cmd, 0, sizeof(rtsp_command_t)); if (m_set_end_time != 0) { uint64_t stime = (uint64_t)(start_time * 1000.0); sprintf(buffer, "npt="U64"."U64"-"U64"."U64, stime / 1000, stime % 1000, m_end_time / 1000, m_end_time % 1000); cmd.range = buffer; } if (rtsp_send_aggregate_play(m_rtsp_client, m_session_control_url, &cmd, &decode) != 0) { set_message("RTSP Aggregate Play Error %s-%s", decode->retcode, decode->retresp != NULL ? decode->retresp : ""); player_debug_message("RTSP aggregate play command failed"); free_decode_response(decode); return (-1); } if (decode->rtp_info == NULL) { player_error_message("No rtp info field"); } else { player_debug_message("rtp info is \'%s\'", decode->rtp_info); } int ret = process_rtsp_rtpinfo(decode->rtp_info, this, NULL); free_decode_response(decode); if (ret < 0) { set_message("RTSP aggregate RtpInfo response failure"); player_debug_message("rtsp aggregate rtpinfo failed"); return (-1); } } m_dont_send_first_rtsp_play = 0; while (p != NULL) { ret = p->do_play(start_time); if (ret != 0) return (ret); p = p->get_next(); } return (0);}/* * pause_all_media - do a spin loop until the sync thread indicates it's * paused. */int CPlayerSession::pause_all_media (void) { int ret; CPlayerMedia *p; m_session_state = SESSION_PAUSED; if (session_control_is_aggregate()) { rtsp_command_t cmd; rtsp_decode_t *decode; memset(&cmd, 0, sizeof(rtsp_command_t)); if (rtsp_send_aggregate_pause(m_rtsp_client, m_session_control_url, &cmd, &decode) != 0) { player_debug_message("RTSP aggregate pause command failed"); free_decode_response(decode); return (-1); } free_decode_response(decode); } p = m_my_media; while (p != NULL) { ret = p->do_pause(); if (ret != 0) return (ret); p = p->get_next(); } m_sync_pause_done = 0; send_sync_thread_a_message(MSG_PAUSE_SESSION);#ifndef NEED_SDL_VIDEO_IN_MAIN_THREAD do {#endif SDL_Delay(100);#ifndef NEED_SDL_VIDEO_IN_MAIN_THREAD } while (m_sync_pause_done == 0);#endif m_paused = true; return (0);}void CPlayerSession::add_media (CPlayerMedia *m) { CPlayerMedia *p; if (m_my_media == NULL) { m_my_media = m; } else { p = m_my_media; while (p->get_next() != NULL) { if (p == m) return; p = p->get_next(); } p->set_next(m); } // set the sync values if (m->is_audio()) { // add audio sync m_audio_count++; m_audio_sync = m->get_audio_sync(); if (m_audio_sync == NULL) { player_error_message("add audio media and sync is NULL"); } } else { CTimedSync *ts; ts = m->get_timed_sync(); if (m->get_sync_type() == VIDEO_SYNC) { m_video_count++; if (m_video_list == NULL) { m_video_list = m->get_video_sync(); } else { CVideoSync *vs = m->get_video_sync(); vs->SetNextVideo(m_video_list); m_video_list = vs; } } else { m_text_count++; } ts->SetNext(m_timed_sync_list); m_timed_sync_list = ts; if (ts == NULL) { player_error_message("add timed media and sync is NULL"); } }}bool CPlayerSession::session_has_audio (void){ return m_audio_count > 0;}bool CPlayerSession::session_has_video (void){ return m_video_count > 0;}void CPlayerSession::set_audio_volume (int volume){ m_audio_volume = volume; if (m_audio_sync) { m_audio_sync->set_volume(m_audio_volume); }}void CPlayerSession::set_screen_location (int x, int y){ m_screen_pos_x = x; m_screen_pos_y = y;}void CPlayerSession::set_screen_size (int scaletimes2, bool fullscreen, int pixel_width, int pixel_height, int max_width, int max_height){ m_screen_scale = scaletimes2; m_fullscreen = fullscreen; m_pixel_width = pixel_width; m_pixel_height = pixel_height; m_max_width = max_width; m_max_height = max_height; // Note - wmay - used to set the video sync directly here - now // we wait until we're initing or get resize message in sync thread. send_sync_thread_a_message(MSG_SYNC_RESIZE_SCREEN);}double CPlayerSession::get_max_time (void){ CPlayerMedia *p; double max = 0.0; p = m_my_media; while (p != NULL) { double temp = p->get_max_playtime(); if (temp > max) max = temp; p = p->get_next(); } if (max == 0.0 && m_set_end_time) { max = (double)#ifdef _WIN32 (int64_t)#endif m_end_time; max /= 1000.0; } return (max);}/* * Matches a url with the corresponding media. * Return the media, or NULL if no match. */CPlayerMedia *CPlayerSession::rtsp_url_to_media (const char *url){ CPlayerMedia *p = m_my_media; while (p != NULL) { rtsp_session_t *session = p->get_rtsp_session(); if (rtsp_is_url_my_stream(session, url, m_content_base, m_session_name) == 1) return p; p = p->get_next(); } return (NULL);}int CPlayerSession::set_session_desc (int line, const char *desc){ if (line >= SESSION_DESC_COUNT) { return -1; } if (m_session_desc[line] != NULL) free((void *)m_session_desc[line]); m_session_desc[line] = strdup(desc); if (m_session_desc[line] == NULL) return -1; return (0);}const char *CPlayerSession::get_session_desc (int line){ return m_session_desc[line];}/* * audio_is_ready - when the audio indicates that it's ready, it will * send a latency number, and a play time */void CPlayerSession::audio_is_ready (uint64_t latency, uint64_t time){ m_start = get_time_of_day(); sync_message(LOG_DEBUG, "Aisready "U64, m_start); m_start -= time; m_latency = latency; sync_message(LOG_DEBUG, "Audio is ready "U64" - latency "U64, time, latency); sync_message(LOG_DEBUG, "m_start is "X64, m_start); m_waiting_for_audio = 0; SDL_SemPost(m_sync_sem);}void CPlayerSession::adjust_start_time (int64_t time){ m_start -= time;#if 0 sync_message(LOG_INFO, "Adjusting start time "D64 " to " U64, time, get_current_time());#endif SDL_SemPost(m_sync_sem);}/* * get_current_time. Gets the time of day, subtracts off the start time * to get the current play time. */uint64_t CPlayerSession::get_current_time (void){ uint64_t current_time; if (m_waiting_for_audio != 0) { return 0; } current_time = get_time_of_day(); //if (current_time < m_start) return 0; m_current_time = current_time - m_start; if (m_current_time >= m_latency) m_current_time -= m_latency; return(m_current_time);}void CPlayerSession::synchronize_rtp_bytestreams (rtcp_sync_t *sync){ if (sync != NULL) { m_audio_rtcp_sync = *sync; m_have_audio_rtcp_sync = true; } else { if (!m_have_audio_rtcp_sync) return; } CPlayerMedia *mptr = m_my_media; while (mptr != NULL) { if (mptr->is_audio() == false) { mptr->synchronize_rtp_bytestreams(&m_audio_rtcp_sync); } mptr = mptr->get_next(); }}void *CPlayerSession::grab_video_persistence (void){ if (m_video_list == NULL) { m_grabbed_video_persistence = true; return m_video_persistence; } return m_video_list->grab_video_persistence();}void CPlayerSession::set_cursor (bool on){ CVideoSync *vs = m_video_list; while (vs != NULL) { vs->set_cursor(on); vs = vs->GetNextVideo(); }}/* end file player_session.cpp */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -