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

📄 rtsp_command.c

📁 嵌入式系统中c程序实现了rtsp协议的基本内容
💻 C
📖 第 1 页 / 共 2 页
字号:
  rtsp_client_t *info;

  info = session->parent;
  if (info == NULL) {
   Rtsp_Printf( "Session doesn't point to parent\n");
    return (FALSE);
  }
  
  sptr = info->session_list;
  while (sptr != session && sptr != NULL) sptr = sptr->next;
  if (sptr == NULL) {
   Rtsp_Printf( "session not found in info list\n");
    return (FALSE);
  }
  
  if ((cmd != NULL) &&
      (cmd->session != NULL) &&
      (strcmp(cmd->session, session->session) != 0)) {
   Rtsp_Printf( "Have cmd->session set wrong\n");
    return (FALSE);
  }
  return (TRUE);
}

static int rtsp_send_play_or_pause (const char *command,
				    const char *url,
				    const char *session,
				    rtsp_client_t *info,
				    rtsp_command_t *cmd,
				    rtsp_decode_t **decode_result)
{
  char buffer[2048];
  uint32_t maxlen, buflen;
  int ret;
  rtsp_decode_t *decode;

  *decode_result = NULL;
  if (info->server_socket < 0) {
    return (RTSP_RESPONSE_CLOSED_SOCKET);
  }

  maxlen = sizeof(buffer);
  buflen = snprintf(buffer, maxlen, "%s %s RTSP/1.0\r\n", command, url);

  if (rtsp_build_common(buffer, maxlen, &buflen,
			info, cmd, session) == -1) {
    return (RTSP_RESPONSE_RECV_ERROR);
  }
    
  ret = snprintf(buffer + buflen, maxlen - buflen, "\r\n");
  if (ret == -1) {
    return (RTSP_RESPONSE_RECV_ERROR);
  }
  buflen += ret;

/* Rtsp_Printf( "Sending %s %s\n", command, url);
 Rtsp_Printf( "%s\n",buffer);
*/
  ret = rtsp_send_and_get(info, buffer, buflen);
  decode = info->decode_response;
    
  if (ret == RTSP_RESPONSE_GOOD) {
/*   Rtsp_Printf( "%s returned correctly\n", command);
*/
    *decode_result = info->decode_response;
    info->decode_response = NULL;

    return (RTSP_RESPONSE_GOOD);
  } else {
   Rtsp_Printf( "%s return code %d\n", command, ret);
    if (ret != RTSP_RESPONSE_RECV_ERROR &&
	decode != NULL) {
      *decode_result = info->decode_response;
      info->decode_response = NULL;
     Rtsp_Printf( "Error code %s %s\n",
		 decode->retcode,
		 decode->retresp);
    }
    return (ret);
  }
  
  return (RTSP_RESPONSE_RECV_ERROR);
}

static int rtsp_send_get_or_set_parameter (const char *command,
				    const char *url,
				    const char *session,
				    rtsp_client_t*info,
				    rtsp_command_t *cmd,
				    rtsp_decode_t **decode_result)
{
  char buffer[500];
  uint32_t maxlen, buflen;
  int ret;
  rtsp_decode_t *decode;

  *decode_result = NULL;
  if (info->server_socket < 0) {
    return (RTSP_RESPONSE_CLOSED_SOCKET);
  }

  maxlen = sizeof(buffer);
  buflen = snprintf(buffer, maxlen, "%s %s RTSP/1.0\r\n", command, url);

  if (rtsp_build_common(buffer, maxlen, &buflen,
			info, cmd, session) == -1) {
    return (RTSP_RESPONSE_RECV_ERROR);
  }
    
  ret = snprintf(buffer + buflen, maxlen - buflen, "\r\n");
  if (ret == -1) {
    return (RTSP_RESPONSE_RECV_ERROR);
  }
  buflen += ret;


  ret = rtsp_send_and_get(info, buffer, buflen);
  decode = info->decode_response;
    
  if (ret == RTSP_RESPONSE_GOOD) {
    *decode_result = info->decode_response;
    info->decode_response = NULL;

    return (RTSP_RESPONSE_GOOD);
  } else {
    if (ret != RTSP_RESPONSE_RECV_ERROR &&
	decode != NULL) {
      *decode_result = info->decode_response;
      info->decode_response = NULL;

    }
    return (ret);
  }
  
  return (RTSP_RESPONSE_RECV_ERROR);
}


/*
 * rtsp_send_play - send play command.  It helps if Range is set
 */
int rtsp_send_play (rtsp_session_t *session,
		    rtsp_command_t *cmd,
		    rtsp_decode_t **decode_result)
{
  if (check_session(session, cmd) == FALSE) {
    return (RTSP_RESPONSE_MISSING_OR_BAD_PARAM);
  }

  return (rtsp_send_play_or_pause("PLAY",
				  session->url,
				  session->session,
				  session->parent,
				  cmd,
				  decode_result));
}

/*
 * rtsp_send_pause - send a pause on a particular session
 */
int rtsp_send_pause (rtsp_session_t *session,
		     rtsp_command_t *cmd,
		     rtsp_decode_t **decode_result)
{
  if (check_session(session, cmd) == FALSE) {
    return (RTSP_RESPONSE_MISSING_OR_BAD_PARAM);
  }

  return (rtsp_send_play_or_pause("PAUSE",
				  session->url,
				  session->session,
				  session->parent,
				  cmd,
				  decode_result));
}

int rtsp_send_aggregate_play (rtsp_client_t *info,
			      const char *aggregate_url,
			      rtsp_command_t *cmd,
			      rtsp_decode_t **decode_result)
{
  return (rtsp_send_play_or_pause("PLAY",
				  aggregate_url,
				  info->session,
				  info,
				  cmd,
				  decode_result));
}

int rtsp_send_aggregate_pause (rtsp_client_t *info,
			       const char *aggregate_url,
			       rtsp_command_t *cmd,
			       rtsp_decode_t **decode_result)
{
  return (rtsp_send_play_or_pause("PAUSE",
				  aggregate_url,
				  info->session,
				  info,
				  cmd,
				  decode_result));
}

static int rtsp_send_teardown_common (rtsp_client_t *info,
				      const char *url,
				      const char *session,
				      rtsp_command_t *cmd,
				      rtsp_decode_t **decode_result)
{
  char buffer[2048];
  uint32_t maxlen, buflen;
  int ret;
  rtsp_decode_t *decode;
  
  *decode_result = NULL;
  if (info->server_socket < 0) {
    return (RTSP_RESPONSE_CLOSED_SOCKET);
  }

  maxlen = sizeof(buffer);
  buflen = snprintf(buffer, maxlen, "TEARDOWN %s RTSP/1.0\r\n", url);

  if (rtsp_build_common(buffer, maxlen, &buflen,
			info, cmd, session) == -1) {
    return (RTSP_RESPONSE_RECV_ERROR);
  }
    
  ret = snprintf(buffer + buflen, maxlen - buflen, "\r\n");
  if (ret == -1) {
    return (RTSP_RESPONSE_RECV_ERROR);
  }
  buflen += ret;

/* Rtsp_Printf( "Sending TEARDOWN %s\n", url);
 Rtsp_Printf( "%s\n",buffer);
*/
  ret = rtsp_send_and_get(info, buffer, buflen);
  decode = info->decode_response;
    
  if (ret == RTSP_RESPONSE_GOOD) {
/*   Rtsp_Printf( "TEARDOWN returned correctly\n");
*/
    *decode_result = info->decode_response;
    info->decode_response = NULL;
    return (RTSP_RESPONSE_GOOD);
  } else {
   Rtsp_Printf( "TEARDOWN return code %d\n", ret);
    if (ret != RTSP_RESPONSE_RECV_ERROR &&
	decode != NULL) {
      *decode_result = info->decode_response;
      info->decode_response = NULL;
     Rtsp_Printf( "Error code %s %s\n",
		 decode->retcode,
		 decode->retresp);
    }
    return (ret);
  }
  
  return (RTSP_RESPONSE_RECV_ERROR);
}
/*
 * rtsp_send_teardown.  Sends a teardown for a session.  We might eventually
 * want to provide a teardown for the base url, rather than one for each
 * session
 */
int rtsp_send_teardown (rtsp_session_t *session,
			rtsp_command_t *cmd,
			rtsp_decode_t **decode_result)
{
  int ret;
  rtsp_client_t *info;
  rtsp_session_t *sptr;
  if (check_session(session, cmd) == FALSE) {
    return (RTSP_RESPONSE_MISSING_OR_BAD_PARAM);
  }
  info = session->parent;

  ret = rtsp_send_teardown_common(info,
				  session->url,
				  session->session,
				  cmd,
				  decode_result);
  if (ret == RTSP_RESPONSE_GOOD) {
    if (info->session_list == session) {
      info->session_list = session->next;
    } else {
      sptr = info->session_list;
      while (sptr->next != session) sptr = sptr->next;
      sptr->next = session->next;
    }
    free_session_info(session);
  }
  return (ret);
}

int rtsp_send_aggregate_teardown (rtsp_client_t *info,
				  const char *url,
				  rtsp_command_t *cmd,
				  rtsp_decode_t **decode_result)
{
  int ret;
  rtsp_session_t *p;
  ret = rtsp_send_teardown_common(info,
				  url,
				  info->session,
				  cmd,
				  decode_result);
  if (ret == RTSP_RESPONSE_GOOD) {
    while (info->session_list != NULL) {
      p = info->session_list;
      info->session_list = info->session_list->next;
      free_session_info(p);
    }
  }
  return (ret);
}
  
int rtsp_send_set_parameter (rtsp_client_t *info,
			      const char *aggregate_url,
			      rtsp_command_t *cmd,
			      rtsp_decode_t **decode_result)
{

  return (rtsp_send_get_or_set_parameter("SET_PARAMETER",
				  aggregate_url,
				  info->session,
				  info,
				  cmd,
				  decode_result));
}


int rtsp_send_get_parameter (rtsp_client_t *info,
			      const char *aggregate_url,
			      rtsp_command_t *cmd,
			      rtsp_decode_t **decode_result)
{

  return (rtsp_send_get_or_set_parameter("GET_PARAMETER",
				  aggregate_url,
				  info->session,
				  info,
				  cmd,
				  decode_result));
}
		       

⌨️ 快捷键说明

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