您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

10 个月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "hls-parser.h"
  2. #include "hls-string.h"
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <assert.h>
  6. #include <errno.h>
  7. // Typically, closed-caption [CEA608] media is carried in the video stream.
  8. // Therefore, an EXT-X-MEDIA tag with TYPE of CLOSED-CAPTIONS does not specify
  9. // a Rendition; the closed-caption media is present in the Media Segments of every video Rendition.
  10. int hls_master_rendition(const struct hls_master_t* master, int variant, int type, const char* name)
  11. {
  12. size_t i;
  13. int is_default;
  14. int autoselect;
  15. struct hls_media_t* m;
  16. struct hls_variant_t* v;
  17. const char* groups[4];
  18. const char* renditions[] = { "AUDIO", "VIDEO", "SUBTITLES", "CLOSED-CAPTIONS", };
  19. if (variant < 0 || variant >= (int)master->variant_count
  20. || type < HLS_MEDIA_AUDIO || type > HLS_MEDIA_CLOSED_CAPTIONS)
  21. return -ENOENT;
  22. type -= HLS_MEDIA_AUDIO;
  23. v = &master->variants[variant];
  24. groups[0] = v->audio ? v->audio : "";
  25. groups[1] = v->video ? v->video : "";
  26. groups[2] = v->subtitle ? v->subtitle : "";
  27. groups[3] = v->closed_captions ? v->closed_captions : "";
  28. if (!*groups[type])
  29. return -1; // don't have alternative renditions
  30. is_default = -1;
  31. autoselect = -1;
  32. for (i = 0; i < master->media_count; i++)
  33. {
  34. m = &master->medias[i];
  35. if (0 != strcasecmp(renditions[type], m->type))
  36. continue;
  37. if (!m->group_id || 0 != strcmp(groups[type], m->group_id))
  38. continue;
  39. if (name)
  40. {
  41. if(m->name && 0 == strcmp(name, m->name))
  42. return (int)i;
  43. }
  44. else
  45. {
  46. if (m->is_default)
  47. is_default = (int)i;
  48. else if(m->autoselect)
  49. autoselect = (int)i;
  50. }
  51. }
  52. return is_default > 0 ? is_default : (autoselect ? autoselect : -1);
  53. }
  54. int hls_master_best_variant(const struct hls_master_t* master)
  55. {
  56. int best;
  57. size_t i;
  58. struct hls_variant_t* v;
  59. best = -1;
  60. for (i = 0; i < master->variant_count; i++)
  61. {
  62. v = &master->variants[i];
  63. if (-1 == best || v->bandwidth > master->variants[best].bandwidth)
  64. best = (int)i;
  65. }
  66. return best;
  67. }