bpm-internal.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef BPM_INTERNAL_H
  2. #define BPM_INTERNAL_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "bpm.h"
  7. #include "caption/mpeg.h"
  8. #include "obs-av1.h"
  9. #include "util/array-serializer.h"
  10. #include "util/platform.h"
  11. #include "util/threading.h"
  12. struct counter_data {
  13. uint32_t diff;
  14. uint32_t ref;
  15. uint32_t curr;
  16. };
  17. #define RFC3339_MAX_LENGTH (64)
  18. struct metrics_time {
  19. struct timespec tspec;
  20. char rfc3339_str[RFC3339_MAX_LENGTH];
  21. bool valid;
  22. };
  23. // Broadcast Performance Metrics SEI types
  24. enum bpm_sei_types {
  25. BPM_TS_SEI = 0, // BPM Timestamp SEI
  26. BPM_SM_SEI, // BPM Session Metrics SEI
  27. BPM_ERM_SEI, // BPM Encoded Rendition Metrics SEI
  28. BPM_MAX_SEI
  29. };
  30. #define SEI_UUID_SIZE 16
  31. static const uint8_t bpm_ts_uuid[SEI_UUID_SIZE] = {0x0a, 0xec, 0xff, 0xe7,
  32. 0x52, 0x72, 0x4e, 0x2f,
  33. 0xa6, 0x2f, 0xd1, 0x9c,
  34. 0xd6, 0x1a, 0x93, 0xb5};
  35. static const uint8_t bpm_sm_uuid[SEI_UUID_SIZE] = {0xca, 0x60, 0xe7, 0x1c,
  36. 0x6a, 0x8b, 0x43, 0x88,
  37. 0xa3, 0x77, 0x15, 0x1d,
  38. 0xf7, 0xbf, 0x8a, 0xc2};
  39. static const uint8_t bpm_erm_uuid[SEI_UUID_SIZE] = {0xf1, 0xfb, 0xc1, 0xd5,
  40. 0x10, 0x1e, 0x4f, 0xb5,
  41. 0xa6, 0x1e, 0xb8, 0xce,
  42. 0x3c, 0x07, 0xb8, 0xc0};
  43. // Broadcast Performance Metrics timestamp types
  44. enum bpm_ts_type {
  45. BPM_TS_RFC3339 = 1, // RFC3339 timestamp string
  46. BPM_TS_DURATION, // Duration since epoch in milliseconds (64-bit)
  47. BPM_TS_DELTA // Delta timestamp in nanoseconds (64-bit)
  48. };
  49. // Broadcast Performance Metrics timestamp event tags
  50. enum bpm_ts_event_tag {
  51. BPM_TS_EVENT_CTS = 1, // Composition Time Event
  52. BPM_TS_EVENT_FER, // Frame Encode Request Event
  53. BPM_TS_EVENT_FERC, // Frame Encode Request Complete Event
  54. BPM_TS_EVENT_PIR // Packet Interleave Request Event
  55. };
  56. // Broadcast Performance Session Metrics types
  57. enum bpm_sm_type {
  58. BPM_SM_FRAMES_RENDERED = 1, // Frames rendered by compositor
  59. BPM_SM_FRAMES_LAGGED, // Frames lagged by compositor
  60. BPM_SM_FRAMES_DROPPED, // Frames dropped due to network congestion
  61. BPM_SM_FRAMES_OUTPUT // Total frames output (sum of all video encoder rendition sinks)
  62. };
  63. // Broadcast Performance Encoded Rendition Metrics types
  64. enum bpm_erm_type {
  65. BPM_ERM_FRAMES_INPUT = 1, // Frames input to the encoder rendition
  66. BPM_ERM_FRAMES_SKIPPED, // Frames skippped by the encoder rendition
  67. BPM_ERM_FRAMES_OUTPUT // Frames output (encoded) by the encoder rendition
  68. };
  69. struct metrics_data {
  70. pthread_mutex_t metrics_mutex;
  71. struct counter_data rendition_frames_input;
  72. struct counter_data rendition_frames_output;
  73. struct counter_data rendition_frames_skipped;
  74. struct counter_data session_frames_rendered;
  75. struct counter_data session_frames_output;
  76. struct counter_data session_frames_dropped;
  77. struct counter_data session_frames_lagged;
  78. struct array_output_data sei_payload[BPM_MAX_SEI];
  79. bool sei_rendered[BPM_MAX_SEI];
  80. struct metrics_time
  81. cts; // Composition timestamp (i.e. when the frame was created)
  82. struct metrics_time ferts; // Frame encode request timestamp
  83. struct metrics_time fercts; // Frame encode request complete timestamp
  84. struct metrics_time pirts; // Packet Interleave Request timestamp
  85. };
  86. struct output_metrics_link {
  87. obs_output_t *output;
  88. struct metrics_data *metrics_tracks[MAX_OUTPUT_VIDEO_ENCODERS];
  89. };
  90. static pthread_mutex_t bpm_metrics_mutex;
  91. /* This DARRAY is used for creating an association between the output_t
  92. * and the BPM metrics track data for each output that requires BPM injection.
  93. */
  94. static DARRAY(struct output_metrics_link) bpm_metrics;
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif