⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 player_media.cpp

📁 完整的RTP RTSP代码库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  if (p == NULL) {    p = check_for_video_codec(stream_type, 			      compressor, 			      sdp_media, 			      type, 			      profile, 			      user_data, 			      userdata_size, 			      &config);    if (p == NULL) return -1;  }   m_plugin = p;  m_video_info = video;  m_plugin_data = (p->vc_create)(stream_type,				 compressor, 				 type,				 profile, sdp_media,				 video,				 user_data,				 userdata_size,				 get_video_vft(),				 m_videoSync);  if (m_plugin_data == NULL)     return -1;  if (user_data != NULL)     set_user_data(user_data, userdata_size);  return 0;}void CPlayerMedia::set_plugin_data (const codec_plugin_t *p, 				    codec_data_t *d, 				    video_vft_t *v, 				    audio_vft_t *a){  m_plugin = p;  m_plugin_data = d;  d->ifptr = m_sync;  if (is_audio() == false) {    //d->ifptr = m_videoSync;    d->v.video_vft = v;  } else {    //d->ifptr = m_audioSync;    d->v.audio_vft = a;  }    }int CPlayerMedia::get_plugin_status (char *buffer, uint32_t buflen){  if (m_plugin == NULL) return -1;  if (m_plugin->c_print_status == NULL) return -1;  return ((m_plugin->c_print_status)(m_plugin_data, buffer, buflen));}int CPlayerMedia::create_audio_plugin (const codec_plugin_t *p,				       const char *stream_type,				       const char *compressor, 				       int type, 				       int profile,				       format_list_t *sdp_media,				       audio_info_t *audio,				       const uint8_t *user_data,				       uint32_t userdata_size){  if (p == NULL) {    p = check_for_audio_codec(stream_type, compressor, sdp_media, 			      type, profile, user_data, userdata_size, 			      &config);    if (p == NULL) return -1;  }  m_audio_info = audio;  m_plugin = p;  m_plugin_data = (p->ac_create)(stream_type,				 compressor,				 type, 				 profile, 				 sdp_media,				 audio,				 user_data,				 userdata_size,				 get_audio_vft(),				 m_sync);  if (m_plugin_data == NULL) return -1;  if (user_data != NULL)    set_user_data(user_data, userdata_size);  return 0;}int CPlayerMedia::create_text_plugin (const codec_plugin_t *p,				      const char *stream_type,				      const char *compressor, 				      format_list_t *sdp_media,				      const uint8_t *user_data,				      uint32_t userdata_size){  if (p == NULL) {    p = check_for_text_codec(stream_type, compressor, sdp_media, 			     user_data, userdata_size, 			     &config);    if (p == NULL) return -1;  }  m_plugin = p;  m_plugin_data = (p->tc_create)(stream_type,				 compressor,				 sdp_media,				 user_data,				 userdata_size,				 get_text_vft(),				 m_sync);  if (m_plugin_data == NULL) return -1;  if (user_data != NULL)    set_user_data(user_data, userdata_size);  return 0;}/* * CPlayerMedia::do_play - get play command */int CPlayerMedia::do_play (double start_time_offset){  if (m_streaming) {    m_paused = false;    if (m_stream_ondemand != 0) {      /*       * We're streaming - send the RTSP play command       */      if (m_parent->session_control_is_aggregate() == 0) {	char buffer[80];	rtsp_command_t cmd;	rtsp_decode_t *decode;	range_desc_t *range;	memset(&cmd, 0, sizeof(rtsp_command_t));	// only do range if we're not paused	range = get_range_from_media(m_media_info);	if (range != NULL) {	  if (start_time_offset < range->range_start || 	      start_time_offset > range->range_end) 	    start_time_offset = range->range_start;	  // need to check for smpte	  sprintf(buffer, "npt=%g-%g", start_time_offset, range->range_end);	  cmd.range = buffer;	}	if (rtsp_send_play(m_rtsp_session, &cmd, &decode) != 0) {	  media_message(LOG_ERR, "RTSP play command failed");	  m_parent->set_message("RTSP Play Error %s-%s", 				decode->retcode,				decode->retresp != NULL ? 				decode->retresp : "");	  free_decode_response(decode);	  return (-1);	}	/*	 * process the return information	 */	int ret = process_rtsp_rtpinfo(decode->rtp_info, m_parent, this);	if (ret < 0) {	  media_message(LOG_ERR, "rtsp rtpinfo failed");	  free_decode_response(decode);	  m_parent->set_message("RTSP aggregate RtpInfo response failure");	  return (-1);	}	free_decode_response(decode);      }      if (m_source_addr == NULL) {	// get the ip address of the server from the rtsp stack	m_source_addr = rtsp_get_server_ip_address_string(m_rtsp_session);	media_message(LOG_INFO, "Setting source address from rtsp - %s", 		      m_source_addr);      }      // ASDF - probably need to do some stuff here for no rtpinfo...      /*       * set the various play times, and send a message to the recv task       * that it needs to start       */      m_play_start_time = start_time_offset;    }    if (m_byte_stream != NULL) {      m_byte_stream->play((uint64_t)(start_time_offset * 1000.0));    }    if (m_rtp_use_rtsp) {      rtsp_thread_perform_callback(m_parent->get_rtsp_client(),				   c_rtp_start, 				   this);    }   } else {    /*     * File (or other) playback.     */    if (m_paused == false || start_time_offset == 0.0) {      m_byte_stream->reset();    }    m_byte_stream->play((uint64_t)(start_time_offset * 1000.0));    m_play_start_time = start_time_offset;    m_paused = false;    start_decoding();  }  return (0);}/* * CPlayerMedia::do_pause - stop what we're doing */int CPlayerMedia::do_pause (void){  if (m_streaming) {    if (m_stream_ondemand != 0) {      /*     * streaming - send RTSP pause     */      if (m_parent->session_control_is_aggregate() == 0) {	rtsp_command_t cmd;	rtsp_decode_t *decode;	memset(&cmd, 0, sizeof(rtsp_command_t));	if (rtsp_send_pause(m_rtsp_session, &cmd, &decode) != 0) {	  media_message(LOG_ERR, "RTSP play command failed");	  free_decode_response(decode);	  return (-1);	}	free_decode_response(decode);      }    }    if (m_recv_thread != NULL) {      m_rtp_msg_queue.send_message(MSG_PAUSE_SESSION);    }  }  if (m_byte_stream != NULL)     m_byte_stream->pause();  /*   * Pause the various threads   */  m_decode_msg_queue.send_message(MSG_PAUSE_SESSION, 				  m_decode_thread_sem);  m_paused = true;  return (0);}double CPlayerMedia::get_max_playtime (void) {  if (m_byte_stream) {    return (m_byte_stream->get_max_playtime());  }  return (0.0);}/*************************************************************************** * Transport and RTP-Info RTSP header line parsing. ***************************************************************************/#define TTYPE(a,b) {a, sizeof(a), b}static char *rtpinfo_parse_ssrc (char *transport, CPlayerMedia *m, int &end){  uint32_t ssrc;  if (*transport != '=') {    return (NULL);  }  transport++;  ADV_SPACE(transport);  transport = convert_hex(transport, &ssrc);  ADV_SPACE(transport);  if (*transport != '\0') {    if (*transport == ',') {      end = 1;    } else if (*transport != ';') {      return (NULL);    }    transport++;  }  m->set_rtp_ssrc(ssrc);  return (transport);}static char *rtpinfo_parse_seq (char *rtpinfo, CPlayerMedia *m, int &endofurl){  uint32_t seq;  if (*rtpinfo != '=') {    return (NULL);  }  rtpinfo++;  ADV_SPACE(rtpinfo);  rtpinfo = convert_number(rtpinfo, &seq);  ADV_SPACE(rtpinfo);  if (*rtpinfo != '\0') {    if (*rtpinfo == ',') {      endofurl = 1;    } else if (*rtpinfo != ';') {      return (NULL);    }    rtpinfo++;  }  m->set_rtp_base_seq(seq);  return (rtpinfo);}static char *rtpinfo_parse_rtptime (char *rtpinfo, 				    CPlayerMedia *m, 				    int &endofurl){  uint32_t rtptime;  int neg = 0;  if (*rtpinfo != '=') {    return (NULL);  }  rtpinfo++;  ADV_SPACE(rtpinfo);  if (*rtpinfo == '-') {    neg = 1;    rtpinfo++;    ADV_SPACE(rtpinfo);  }  rtpinfo = convert_number(rtpinfo, &rtptime);  ADV_SPACE(rtpinfo);  if (*rtpinfo != '\0') {    if (*rtpinfo == ',') {      endofurl = 1;    } else if (*rtpinfo != ';') {      return (NULL);    }    rtpinfo++;  }  if (neg != 0) {    player_error_message("Warning - negative time returned in rtpinfo");    rtptime = 0 - rtptime;  }  m->set_rtp_base_ts(rtptime);  return (rtpinfo);}int CPlayerMedia::process_rtsp_transport (char *transport){  rtsp_transport_parse_t parse;  memset(&parse, 0, sizeof(parse));  parse.client_port = get_our_port();  parse.interleave_port = get_rtp_media_number() * 2;  parse.use_interleaved = m_rtp_use_rtsp;  int ret = ::process_rtsp_transport(&parse, transport, m_media_info->proto);  if (ret >= 0) {    set_server_port(parse.server_port);    if (parse.have_ssrc != 0) {      set_rtp_ssrc(parse.ssrc);    }  }  return ret;}static struct {  const char *name;  uint32_t namelen;  char *(*routine)(char *transport, CPlayerMedia *, int &end_for_url);} rtpinfo_types[] = {  TTYPE("seq", rtpinfo_parse_seq),  TTYPE("rtptime", rtpinfo_parse_rtptime),  TTYPE("ssrc", rtpinfo_parse_ssrc),  {NULL, 0, NULL},};int process_rtsp_rtpinfo (char *rtpinfo, 			  CPlayerSession *session,			  CPlayerMedia *media){  int ix;  CPlayerMedia *newmedia;  if (rtpinfo == NULL)     return (0);  do {    int no_mimes = 0;    ADV_SPACE(rtpinfo);    if (strncasecmp(rtpinfo, "url", strlen("url")) != 0) {      media_message(LOG_ERR, "Url not found");      return (-1);    }    rtpinfo += strlen("url");    ADV_SPACE(rtpinfo);    if (*rtpinfo != '=') {      media_message(LOG_ERR, "Can't find = after url");      return (-1);    }    rtpinfo++;    ADV_SPACE(rtpinfo);    char *url = rtpinfo;    while (*rtpinfo != '\0' && *rtpinfo != ';' && *rtpinfo != ',') {      rtpinfo++;    }    if (*rtpinfo == '\0') {      no_mimes = 1;    } else {      if (*rtpinfo == ',') {	no_mimes = 1;      }      *rtpinfo++ = '\0';    }    char *temp = url;    newmedia = session->rtsp_url_to_media(url);    if (newmedia == NULL) {      media_message(LOG_ERR, "Can't find media from %s", url);      return -1;    } else if (media != NULL && media != newmedia) {      media_message(LOG_ERR, "Url in rtpinfo does not match media %s", url);      return -1;    }    if (temp != url)       free(url);    if (no_mimes == 0) {    int endofurl = 0;    do {      ADV_SPACE(rtpinfo);      for (ix = 0; rtpinfo_types[ix].name != NULL; ix++) {	if (strncasecmp(rtpinfo,			rtpinfo_types[ix].name, 			rtpinfo_types[ix].namelen - 1) == 0) {	  rtpinfo += rtpinfo_types[ix].namelen - 1;	  ADV_SPACE(rtpinfo);	  rtpinfo = (rtpinfo_types[ix].routine)(rtpinfo, newmedia, endofurl);	  break;	}      }      if (rtpinfo_types[ix].name == NULL) {#if 1	media_message(LOG_INFO, "Unknown mime-type in RtpInfo - skipping %s", 			     rtpinfo);#endif	while (*rtpinfo != ';' && *rtpinfo != '\0') rtpinfo++;	if (*rtpinfo != '\0') rtpinfo++;      }    } while (endofurl == 0 && rtpinfo != NULL && *rtpinfo != '\0');    }     newmedia = NULL;  } while (rtpinfo != NULL && *rtpinfo != '\0');  if (rtpinfo == NULL) {    return (-1);  }  return (1);}void CPlayerMedia::display_status (void) {  if (m_rtp_byte_stream != NULL) {    m_rtp_byte_stream->display_status();  }  if (m_sync != NULL) {    m_sync->display_status();  }  media_message(LOG_DEBUG, "%s decode waiting %d", m_is_audio ? "audio" : "video", 		m_decode_thread_waiting);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -