bpm-internal.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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, 0x52, 0x72, 0x4e, 0x2f,
  32. 0xa6, 0x2f, 0xd1, 0x9c, 0xd6, 0x1a, 0x93, 0xb5};
  33. static const uint8_t bpm_sm_uuid[SEI_UUID_SIZE] = {0xca, 0x60, 0xe7, 0x1c, 0x6a, 0x8b, 0x43, 0x88,
  34. 0xa3, 0x77, 0x15, 0x1d, 0xf7, 0xbf, 0x8a, 0xc2};
  35. static const uint8_t bpm_erm_uuid[SEI_UUID_SIZE] = {0xf1, 0xfb, 0xc1, 0xd5, 0x10, 0x1e, 0x4f, 0xb5,
  36. 0xa6, 0x1e, 0xb8, 0xce, 0x3c, 0x07, 0xb8, 0xc0};
  37. // Broadcast Performance Metrics timestamp types
  38. enum bpm_ts_type {
  39. BPM_TS_RFC3339 = 1, // RFC3339 timestamp string
  40. BPM_TS_DURATION, // Duration since epoch in milliseconds (64-bit)
  41. BPM_TS_DELTA // Delta timestamp in nanoseconds (64-bit)
  42. };
  43. // Broadcast Performance Metrics timestamp event tags
  44. enum bpm_ts_event_tag {
  45. BPM_TS_EVENT_CTS = 1, // Composition Time Event
  46. BPM_TS_EVENT_FER, // Frame Encode Request Event
  47. BPM_TS_EVENT_FERC, // Frame Encode Request Complete Event
  48. BPM_TS_EVENT_PIR // Packet Interleave Request Event
  49. };
  50. // Broadcast Performance Session Metrics types
  51. enum bpm_sm_type {
  52. BPM_SM_FRAMES_RENDERED = 1, // Frames rendered by compositor
  53. BPM_SM_FRAMES_LAGGED, // Frames lagged by compositor
  54. BPM_SM_FRAMES_DROPPED, // Frames dropped due to network congestion
  55. BPM_SM_FRAMES_OUTPUT // Total frames output (sum of all video encoder rendition sinks)
  56. };
  57. // Broadcast Performance Encoded Rendition Metrics types
  58. enum bpm_erm_type {
  59. BPM_ERM_FRAMES_INPUT = 1, // Frames input to the encoder rendition
  60. BPM_ERM_FRAMES_SKIPPED, // Frames skippped by the encoder rendition
  61. BPM_ERM_FRAMES_OUTPUT // Frames output (encoded) by the encoder rendition
  62. };
  63. struct metrics_data {
  64. pthread_mutex_t metrics_mutex;
  65. struct counter_data rendition_frames_input;
  66. struct counter_data rendition_frames_output;
  67. struct counter_data rendition_frames_skipped;
  68. struct counter_data session_frames_rendered;
  69. struct counter_data session_frames_output;
  70. struct counter_data session_frames_dropped;
  71. struct counter_data session_frames_lagged;
  72. struct array_output_data sei_payload[BPM_MAX_SEI];
  73. bool sei_rendered[BPM_MAX_SEI];
  74. struct metrics_time cts; // Composition timestamp (i.e. when the frame was created)
  75. struct metrics_time ferts; // Frame encode request timestamp
  76. struct metrics_time fercts; // Frame encode request complete timestamp
  77. struct metrics_time pirts; // Packet Interleave Request timestamp
  78. };
  79. struct output_metrics_link {
  80. obs_output_t *output;
  81. struct metrics_data *metrics_tracks[MAX_OUTPUT_VIDEO_ENCODERS];
  82. };
  83. static pthread_once_t bpm_once = PTHREAD_ONCE_INIT;
  84. static pthread_mutex_t bpm_metrics_mutex;
  85. /* This DARRAY is used for creating an association between the output_t
  86. * and the BPM metrics track data for each output that requires BPM injection.
  87. */
  88. static DARRAY(struct output_metrics_link) bpm_metrics;
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif