Add setTimestamp() method on RTCEncodedVideoFrames behind flag
Video counterpart to crrev.com/c/4601477.
Bug: webrtc:14709
Change-Id: Ia9b61c893595249358383ead7d4c2971b52c03b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4654707
Auto-Submit: Tony Herre <toprice@chromium.org>
Reviewed-by: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: Palak Agarwal <agpalak@chromium.org>
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Commit-Queue: Tony Herre <toprice@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1164638}
diff --git a/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame.cc b/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame.cc
index aee347f..0b3f58b9 100644
--- a/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame.cc
+++ b/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame.cc
@@ -236,6 +236,11 @@
return delegate_->Timestamp();
}
+void RTCEncodedVideoFrame::setTimestamp(uint32_t timestamp,
+ ExceptionState& exception_state) {
+ delegate_->SetTimestamp(timestamp, exception_state);
+}
+
DOMArrayBuffer* RTCEncodedVideoFrame::data() const {
if (!frame_data_)
frame_data_ = delegate_->CreateDataBuffer();
diff --git a/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame.h b/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame.h
index c6d7cbc8..4b49882 100644
--- a/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame.h
+++ b/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame.h
@@ -39,6 +39,7 @@
String type() const;
// Returns the RTP Packet Timestamp for this frame.
uint32_t timestamp() const;
+ void setTimestamp(uint32_t timestamp, ExceptionState& exception_state);
DOMArrayBuffer* data() const;
RTCEncodedVideoFrameMetadata* getMetadata() const;
void setMetadata(RTCEncodedVideoFrameMetadata* metadata,
diff --git a/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame.idl b/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame.idl
index a224e72..2d91436 100644
--- a/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame.idl
+++ b/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame.idl
@@ -20,6 +20,8 @@
RTCEncodedVideoFrameMetadata getMetadata();
[RuntimeEnabled=RTCEncodedVideoFrameAdditionalMetadata, RaisesException]
void setMetadata(RTCEncodedVideoFrameMetadata metadata);
+ [RuntimeEnabled=RTCEncodedVideoFrameAdditionalMetadata, RaisesException] void
+ setTimestamp(unsigned long timestamp);
[RuntimeEnabled=RTCEncodedVideoFrameClone, RaisesException] RTCEncodedVideoFrame clone();
stringifier;
};
diff --git a/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame_delegate.cc b/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame_delegate.cc
index 915560c5..8724cd1 100644
--- a/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame_delegate.cc
+++ b/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame_delegate.cc
@@ -7,6 +7,8 @@
#include <utility>
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
+#include "third_party/blink/renderer/platform/bindings/exception_code.h"
+#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/webrtc/api/frame_transformer_factory.h"
#include "third_party/webrtc/api/frame_transformer_interface.h"
@@ -31,6 +33,18 @@
return webrtc_frame_ ? webrtc_frame_->GetTimestamp() : 0;
}
+void RTCEncodedVideoFrameDelegate::SetTimestamp(
+ uint32_t timestamp,
+ ExceptionState& exception_state) {
+ base::AutoLock lock(lock_);
+ if (webrtc_frame_) {
+ webrtc_frame_->SetRTPTimestamp(timestamp);
+ } else {
+ exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
+ "Video frame is empty.");
+ }
+}
+
absl::optional<webrtc::Timestamp>
RTCEncodedVideoFrameDelegate::CaptureTimeIdentifier() const {
base::AutoLock lock(lock_);
diff --git a/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame_delegate.h b/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame_delegate.h
index 45f30db8..41f3406 100644
--- a/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame_delegate.h
+++ b/third_party/blink/renderer/modules/peerconnection/rtc_encoded_video_frame_delegate.h
@@ -20,6 +20,7 @@
namespace blink {
class DOMArrayBuffer;
+class ExceptionState;
// This class wraps a WebRTC video frame and allows making shallow
// copies. Its purpose is to support making RTCEncodedVideoFrames
@@ -32,6 +33,7 @@
String Type() const;
uint32_t Timestamp() const;
+ void SetTimestamp(uint32_t timestamp, ExceptionState& exception_state);
absl::optional<webrtc::Timestamp> CaptureTimeIdentifier() const;
DOMArrayBuffer* CreateDataBuffer() const;
void SetData(const DOMArrayBuffer* data);
diff --git a/third_party/blink/web_tests/webexposed/global-interface-listing-dedicated-worker-expected.txt b/third_party/blink/web_tests/webexposed/global-interface-listing-dedicated-worker-expected.txt
index a623ebe..0a8e0dd 100644
--- a/third_party/blink/web_tests/webexposed/global-interface-listing-dedicated-worker-expected.txt
+++ b/third_party/blink/web_tests/webexposed/global-interface-listing-dedicated-worker-expected.txt
@@ -1661,6 +1661,7 @@
[Worker] method constructor
[Worker] method getMetadata
[Worker] method setMetadata
+[Worker] method setTimestamp
[Worker] method toString
[Worker] setter data
[Worker] interface ReadableByteStreamController
diff --git a/third_party/blink/web_tests/webexposed/global-interface-listing-expected.txt b/third_party/blink/web_tests/webexposed/global-interface-listing-expected.txt
index 83ffa2b..127aad8 100644
--- a/third_party/blink/web_tests/webexposed/global-interface-listing-expected.txt
+++ b/third_party/blink/web_tests/webexposed/global-interface-listing-expected.txt
@@ -7352,6 +7352,7 @@
method constructor
method getMetadata
method setMetadata
+ method setTimestamp
method toString
setter data
interface RTCError : DOMException