Add FPS and byte count telemetry measurement for sources. (#125)

* Add FPS and byte count telemetry measurement for sources.

* Add new error code for telemetry not enabled.
This commit is contained in:
Peter Johnson
2018-03-04 21:01:55 -08:00
committed by GitHub
parent 698feff2ff
commit 040731447f
18 changed files with 414 additions and 5 deletions

View File

@@ -54,7 +54,8 @@ enum CS_StatusValue {
CS_READ_FAILED = -2004,
CS_SOURCE_IS_DISCONNECTED = -2005,
CS_EMPTY_VALUE = -2006,
CS_BAD_URL = -2007
CS_BAD_URL = -2007,
CS_TELEMETRY_NOT_ENABLED = -2008
};
//
@@ -148,7 +149,16 @@ enum CS_EventKind {
CS_SINK_DESTROYED = 0x0800,
CS_SINK_ENABLED = 0x1000,
CS_SINK_DISABLED = 0x2000,
CS_NETWORK_INTERFACES_CHANGED = 0x4000
CS_NETWORK_INTERFACES_CHANGED = 0x4000,
CS_TELEMETRY_UPDATED = 0x8000
};
//
// Telemetry kinds
//
enum CS_TelemetryKind {
CS_SOURCE_BYTES_RECEIVED = 1,
CS_SOURCE_FRAMES_RECEIVED = 2
};
//
@@ -338,6 +348,16 @@ void CS_RemoveListener(CS_Listener handle, CS_Status* status);
int CS_NotifierDestroyed(void);
//
// Telemetry Functions
//
void CS_SetTelemetryPeriod(double seconds);
double CS_GetTelemetryElapsedTime();
int64_t CS_GetTelemetryValue(CS_Handle handle, CS_TelemetryKind kind,
CS_Status* status);
double CS_GetTelemetryAverageValue(CS_Handle handle, CS_TelemetryKind kind,
CS_Status* status);
//
// Logging Functions
//

View File

@@ -84,7 +84,8 @@ struct RawEvent {
kSinkDestroyed = CS_SINK_DESTROYED,
kSinkEnabled = CS_SINK_ENABLED,
kSinkDisabled = CS_SINK_DISABLED,
kNetworkInterfacesChanged = CS_NETWORK_INTERFACES_CHANGED
kNetworkInterfacesChanged = CS_NETWORK_INTERFACES_CHANGED,
kTelemetryUpdated = CS_TELEMETRY_UPDATED
};
RawEvent() = default;
@@ -306,6 +307,16 @@ void RemoveListener(CS_Listener handle, CS_Status* status);
bool NotifierDestroyed();
//
// Telemetry Functions
//
void SetTelemetryPeriod(double seconds);
double GetTelemetryElapsedTime();
int64_t GetTelemetryValue(CS_Handle handle, CS_TelemetryKind kind,
CS_Status* status);
double GetTelemetryAverageValue(CS_Handle handle, CS_TelemetryKind kind,
CS_Status* status);
//
// Logging Functions
//

View File

@@ -170,6 +170,16 @@ class VideoSource {
/// @return True if set successfully
bool SetFPS(int fps);
/// Get the actual FPS.
/// SetTelemetryPeriod() must be called for this to be valid.
/// @return Actual FPS averaged over the telemetry period.
double GetActualFPS() const;
/// Get the data rate (in bytes per second).
/// SetTelemetryPeriod() must be called for this to be valid.
/// @return Data rate averaged over the telemetry period.
double GetActualDataRate() const;
/// Enumerate all known video modes for this source.
std::vector<VideoMode> EnumerateVideoModes() const;

View File

@@ -158,6 +158,18 @@ inline bool VideoSource::SetFPS(int fps) {
return SetSourceFPS(m_handle, fps, &m_status);
}
inline double VideoSource::GetActualFPS() const {
m_status = 0;
return cs::GetTelemetryAverageValue(m_handle, CS_SOURCE_FRAMES_RECEIVED,
&m_status);
}
inline double VideoSource::GetActualDataRate() const {
m_status = 0;
return cs::GetTelemetryAverageValue(m_handle, CS_SOURCE_BYTES_RECEIVED,
&m_status);
}
inline std::vector<VideoMode> VideoSource::EnumerateVideoModes() const {
CS_Status status = 0;
return EnumerateSourceVideoModes(m_handle, &status);