Skip to content

Commit 149f942

Browse files
committed
Add NTP time ms to OnVideoFrameReceived.
1 parent 7f1ef54 commit 149f942

File tree

11 files changed

+63
-36
lines changed

11 files changed

+63
-36
lines changed

examples/cpp-camera-stream-client/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ int main(int argc, char* argv[])
240240
cout << "\tid=" << client.id() << ", name=" << client.name() << endl;
241241
});
242242
client.setOnVideoFrameReceived(
243-
[](const Client& client, const cv::Mat& bgrImg, uint64_t timestampUs)
243+
[](const Client& client, const cv::Mat& bgrImg, uint64_t timestampUs, uint64_t ntpTimeMs)
244244
{
245245
// This callback is called from a WebRTC processing thread.
246246
cv::imshow(client.id(), bgrImg);

examples/cpp-video-stream-client/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ class SinAudioSource : public AudioSource
118118

119119
auto start = chrono::steady_clock::now();
120120
this_thread::sleep_for(SinAudioSourceFrameDuration - SinAudioSourceSleepBuffer);
121-
while ((chrono::steady_clock::now() - start) < SinAudioSourceFrameDuration);
121+
while ((chrono::steady_clock::now() - start) < SinAudioSourceFrameDuration)
122+
;
122123
}
123124
}
124125
};
@@ -232,7 +233,7 @@ int main(int argc, char* argv[])
232233
cout << "\tid=" << client.id() << ", name=" << client.name() << endl;
233234
});
234235
client.setOnVideoFrameReceived(
235-
[](const Client& client, const cv::Mat& bgrImg, uint64_t timestampUs)
236+
[](const Client& client, const cv::Mat& bgrImg, uint64_t timestampUs, uint64_t ntpTimeMs)
236237
{
237238
// This callback is called from a WebRTC processing thread.
238239
cout << "OnVideoFrameReceived:" << endl;

examples/python-stream-client/python_stream_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def on_remove_remote_stream(client):
6767
client.id, client.name, client.data))
6868

6969

70-
def on_video_frame_received(client, image, timestampUs):
70+
def on_video_frame_received(client, image, timestamp_us, ntp_time_us):
7171
# This callback is called from a WebRTC processing thread.
7272
cv2.imshow(client.id, image)
7373
cv2.waitKey(1)

opentera-webrtc-native-client/OpenteraWebrtcNativeClient/include/OpenteraWebrtcNativeClient/Handlers/StreamPeerConnectionHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace opentera
1212
{
13-
using VideoFrameReceivedCallback = std::function<void(const Client&, const cv::Mat&, uint64_t)>;
13+
using VideoFrameReceivedCallback = std::function<void(const Client&, const cv::Mat&, uint64_t, uint64_t)>;
1414
using EncodedVideoFrameReceivedCallback = std::function<void(
1515
const Client& client,
1616
const uint8_t* data,

opentera-webrtc-native-client/OpenteraWebrtcNativeClient/include/OpenteraWebrtcNativeClient/Sinks/VideoSink.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace opentera
1010
{
1111

12-
using VideoSinkCallback = std::function<void(const cv::Mat&, uint64_t)>;
12+
using VideoSinkCallback = std::function<void(const cv::Mat&, uint64_t, uint64_t)>;
1313

1414
/**
1515
* @brief Class that sinks frame from a webrtc stream
@@ -32,7 +32,10 @@ namespace opentera
3232
* @brief get frame requirements for this sink
3333
* @return frame requirements for this sink
3434
*/
35-
inline rtc::VideoSinkWants VideoSink::wants() const { return m_wants; }
35+
inline rtc::VideoSinkWants VideoSink::wants() const
36+
{
37+
return m_wants;
38+
}
3639

3740
}
3841

opentera-webrtc-native-client/OpenteraWebrtcNativeClient/include/OpenteraWebrtcNativeClient/StreamClient.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,18 @@ namespace opentera
9696
/**
9797
* @brief Mutes the local audio.
9898
*/
99-
inline void StreamClient::muteLocalAudio() { setLocalAudioMuted(true); }
99+
inline void StreamClient::muteLocalAudio()
100+
{
101+
setLocalAudioMuted(true);
102+
}
100103

101104
/**
102105
* @brief Unmutes the local audio.
103106
*/
104-
inline void StreamClient::unmuteLocalAudio() { setLocalAudioMuted(false); }
107+
inline void StreamClient::unmuteLocalAudio()
108+
{
109+
setLocalAudioMuted(false);
110+
}
105111

106112
/**
107113
* @brief Indicates if the remote audio is muted.
@@ -115,12 +121,18 @@ namespace opentera
115121
/**
116122
* @brief Mutes the remote audio.
117123
*/
118-
inline void StreamClient::muteRemoteAudio() { setRemoteAudioMuted(true); }
124+
inline void StreamClient::muteRemoteAudio()
125+
{
126+
setRemoteAudioMuted(true);
127+
}
119128

120129
/**
121130
* @brief Unmutes the remote audio.
122131
*/
123-
inline void StreamClient::unmuteRemoteAudio() { setRemoteAudioMuted(false); }
132+
inline void StreamClient::unmuteRemoteAudio()
133+
{
134+
setRemoteAudioMuted(false);
135+
}
124136

125137
/**
126138
* @brief Indicates if the local video is muted.
@@ -134,12 +146,18 @@ namespace opentera
134146
/**
135147
* @brief Mutes the local video.
136148
*/
137-
inline void StreamClient::muteLocalVideo() { setLocalVideoMuted(true); }
149+
inline void StreamClient::muteLocalVideo()
150+
{
151+
setLocalVideoMuted(true);
152+
}
138153

139154
/**
140155
* @brief Unmutes the local video.
141156
*/
142-
inline void StreamClient::unmuteLocalVideo() { setLocalVideoMuted(false); }
157+
inline void StreamClient::unmuteLocalVideo()
158+
{
159+
setLocalVideoMuted(false);
160+
}
143161

144162
/**
145163
* @brief Sets the callback that is called when a stream is added.
@@ -185,6 +203,7 @@ namespace opentera
185203
* - client: The client of the stream frame
186204
* - bgrImg: The BGR frame image
187205
* - timestampUs The timestamp in microseconds
206+
* - ntpTimeMs The ntp time in milliseconds
188207
* @endparblock
189208
*
190209
* @param callback The callback

opentera-webrtc-native-client/OpenteraWebrtcNativeClient/python/src/StreamClientPython.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace py = pybind11;
1212

1313
void setOnVideoFrameReceived(
1414
StreamClient& self,
15-
const function<void(const Client&, const py::array_t<uint8_t>&, uint64_t)>& pythonCallback)
15+
const function<void(const Client&, const py::array_t<uint8_t>&, uint64_t, uint64_t)>& pythonCallback)
1616
{
17-
auto callback = [=](const Client& client, const cv::Mat& bgrImg, uint64_t timestampUs)
17+
auto callback = [=](const Client& client, const cv::Mat& bgrImg, uint64_t timestampUs, uint64_t ntpTimeMs)
1818
{
1919
size_t height = bgrImg.rows;
2020
size_t width = bgrImg.cols;
@@ -32,7 +32,7 @@ void setOnVideoFrameReceived(
3232

3333
py::gil_scoped_acquire acquire;
3434
py::array_t<uint8_t> numpyBgrImg(bufferInfo);
35-
pythonCallback(client, numpyBgrImg, timestampUs);
35+
pythonCallback(client, numpyBgrImg, timestampUs, ntpTimeMs);
3636
};
3737

3838
self.setOnVideoFrameReceived(callback);
@@ -315,6 +315,7 @@ void opentera::initStreamClientPython(pybind11::module& m)
315315
" - client: The client of the stream frame\n"
316316
" - bgr_img: The BGR frame image (numpy.array[uint8])\n"
317317
" - timestamp_us The timestamp in microseconds\n"
318+
" - ntp_time_ms The ntp time in milliseconds\n"
318319
"\n"
319320
":param callback: The callback")
320321
.def_property(

opentera-webrtc-native-client/OpenteraWebrtcNativeClient/python/test/stream_client_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ def on_add_remote_stream2(client):
7474
def on_remove_remote_stream(client):
7575
self.add_failure('on_remove_remote_stream')
7676

77-
def on_video_frame_received1(client, frame, timestamp):
77+
def on_video_frame_received1(client, frame, timestamp_us, ntp_time_us):
7878
self._mean_color_1 = np.mean(frame, axis=(0, 1))
7979
on_video_frame_awaiter1.done()
8080

81-
def on_video_frame_received2(client, frame, timestamp):
81+
def on_video_frame_received2(client, frame, timestamp_us, ntp_time_us):
8282
self._mean_color_2 = np.mean(frame, axis=(0, 1))
8383
on_video_frame_awaiter2.done()
8484

opentera-webrtc-native-client/OpenteraWebrtcNativeClient/src/Handlers/StreamPeerConnectionHandler.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ StreamPeerConnectionHandler::StreamPeerConnectionHandler(
4444
{
4545
if (onVideoFrameReceived)
4646
{
47-
m_videoSink = make_unique<VideoSink>([=](const cv::Mat& bgrImg, uint64_t timestampUs)
48-
{ onVideoFrameReceived(m_peerClient, bgrImg, timestampUs); });
47+
m_videoSink = make_unique<VideoSink>([=](const cv::Mat& bgrImg, uint64_t timestampUs, uint64_t ntpTimeMs)
48+
{ onVideoFrameReceived(m_peerClient, bgrImg, timestampUs, ntpTimeMs); });
4949
}
5050

5151
if (onEncodedVideoFrameReceived)
@@ -57,7 +57,8 @@ StreamPeerConnectionHandler::StreamPeerConnectionHandler(
5757
bool isKeyFrame,
5858
uint32_t width,
5959
uint32_t height,
60-
uint64_t timestampUs) {
60+
uint64_t timestampUs)
61+
{
6162
onEncodedVideoFrameReceived(
6263
m_peerClient,
6364
data,
@@ -77,7 +78,8 @@ StreamPeerConnectionHandler::StreamPeerConnectionHandler(
7778
int bitsPerSample,
7879
int sampleRate,
7980
size_t numberOfChannels,
80-
size_t numberOfFrames) {
81+
size_t numberOfFrames)
82+
{
8183
onAudioFrameReceived(
8284
m_peerClient,
8385
audioData,

opentera-webrtc-native-client/OpenteraWebrtcNativeClient/src/Sinks/VideoSink.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void VideoSink::OnFrame(const webrtc::VideoFrame& frame)
6161
switch (frame.rotation())
6262
{
6363
case webrtc::kVideoRotation_0:
64-
m_onFrameReceived(m_bgrImg, frame.timestamp_us());
64+
m_onFrameReceived(m_bgrImg, frame.timestamp_us(), frame.ntp_time_ms());
6565
return;
6666
case webrtc::kVideoRotation_90:
6767
cv::rotate(m_bgrImg, m_bgrRotatedImg, cv::ROTATE_90_CLOCKWISE);
@@ -73,5 +73,5 @@ void VideoSink::OnFrame(const webrtc::VideoFrame& frame)
7373
cv::rotate(m_bgrImg, m_bgrRotatedImg, cv::ROTATE_90_COUNTERCLOCKWISE);
7474
break;
7575
}
76-
m_onFrameReceived(m_bgrRotatedImg, frame.timestamp_us());
76+
m_onFrameReceived(m_bgrRotatedImg, frame.timestamp_us(), frame.ntp_time_ms());
7777
}

0 commit comments

Comments
 (0)