You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
923B

  1. #pragma once
  2. #include "uri-parse.h"
  3. #include <vector>
  4. #include <string>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <assert.h>
  8. struct RTMPUrl
  9. {
  10. int port;
  11. std::string host;
  12. std::string app;
  13. std::string stream;
  14. std::string tcurl;
  15. RTMPUrl(const std::string& url) : port(0), tcurl(url)
  16. {
  17. Parse(url.c_str());
  18. }
  19. bool Valid() const
  20. {
  21. return host.size() && app.size() && stream.size() && port;
  22. }
  23. private:
  24. int Parse(const char* rtmp)
  25. {
  26. uri_t* uri = uri_parse(rtmp, strlen(rtmp));
  27. if (NULL == uri)
  28. return -1;
  29. host = uri->host;
  30. port = uri->port ? uri->port : 1935; // rtmp default port
  31. const char* p1 = strchr(rtmp + ((uri->scheme&&*uri->scheme) ? (strlen(uri->scheme) + 3) : 1), '/');
  32. if (!p1) return -1;
  33. const char* p2 = strchr(p1 + 1, '/');
  34. if (!p2) return -1;
  35. app.assign(p1 + 1, p2 - p1 - 1);
  36. stream.assign(p2 + 1);
  37. tcurl.assign(rtmp, p2);
  38. uri_free(uri);
  39. return 0;
  40. }
  41. };