Commit e90652cf authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Commit Bot

[RTCInsertableStreams] Wire RTCEncodedAudioFrame

This CL wires RTCEncodedAudioFrame to the underlying WebRTC frame.
Tests coming up in follow-up CLs that implement the rest of the
Insertable Streams API.

Bug: 1052765
Change-Id: I833139ad89166673ce48af027879f2755206b5eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2130551
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarMarina Ciocea <marinaciocea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755537}
parent 56471bb2
...@@ -6,14 +6,37 @@ ...@@ -6,14 +6,37 @@
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h" #include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/webrtc/api/frame_transformer_interface.h"
namespace blink { namespace blink {
RTCEncodedAudioFrame::RTCEncodedAudioFrame(
std::unique_ptr<webrtc::TransformableFrameInterface> webrtc_frame)
: webrtc_frame_(std::move(webrtc_frame)) {}
RTCEncodedAudioFrame::RTCEncodedAudioFrame(
std::unique_ptr<webrtc::TransformableAudioFrameInterface>
webrtc_audio_frame) {
if (webrtc_audio_frame) {
wtf_size_t num_csrcs = webrtc_audio_frame->GetHeader().numCSRCs;
contributing_sources_.ReserveInitialCapacity(num_csrcs);
for (wtf_size_t i = 0; i < num_csrcs; i++) {
contributing_sources_.push_back(
webrtc_audio_frame->GetHeader().arrOfCSRCs[i]);
}
}
webrtc_frame_ = std::move(webrtc_audio_frame);
}
uint64_t RTCEncodedAudioFrame::timestamp() const { uint64_t RTCEncodedAudioFrame::timestamp() const {
return 0; return webrtc_frame_ ? webrtc_frame_->GetTimestamp() : 0;
} }
DOMArrayBuffer* RTCEncodedAudioFrame::data() const { DOMArrayBuffer* RTCEncodedAudioFrame::data() const {
if (webrtc_frame_ && !frame_data_) {
frame_data_ = DOMArrayBuffer::Create(webrtc_frame_->GetData().data(),
webrtc_frame_->GetData().size());
}
return frame_data_; return frame_data_;
} }
...@@ -26,11 +49,11 @@ void RTCEncodedAudioFrame::setData(DOMArrayBuffer* data) { ...@@ -26,11 +49,11 @@ void RTCEncodedAudioFrame::setData(DOMArrayBuffer* data) {
} }
uint32_t RTCEncodedAudioFrame::synchronizationSource() const { uint32_t RTCEncodedAudioFrame::synchronizationSource() const {
return 0; return webrtc_frame_ ? webrtc_frame_->GetSsrc() : 0;
} }
Vector<uint32_t> RTCEncodedAudioFrame::contributingSources() const { Vector<uint32_t> RTCEncodedAudioFrame::contributingSources() const {
return Vector<uint32_t>(); return webrtc_frame_ ? contributing_sources_ : Vector<uint32_t>();
} }
String RTCEncodedAudioFrame::toString() const { String RTCEncodedAudioFrame::toString() const {
...@@ -43,6 +66,17 @@ String RTCEncodedAudioFrame::toString() const { ...@@ -43,6 +66,17 @@ String RTCEncodedAudioFrame::toString() const {
return sb.ToString(); return sb.ToString();
} }
std::unique_ptr<webrtc::TransformableFrameInterface>
RTCEncodedAudioFrame::PassDelegate() {
// Sync the delegate data with |frame_data_| if necessary.
if (webrtc_frame_ && frame_data_) {
webrtc_frame_->SetData(rtc::ArrayView<const uint8_t>(
static_cast<const uint8_t*>(frame_data_->Data()),
frame_data_->ByteLengthAsSizeT()));
}
return std::move(webrtc_frame_);
}
void RTCEncodedAudioFrame::Trace(Visitor* visitor) { void RTCEncodedAudioFrame::Trace(Visitor* visitor) {
ScriptWrappable::Trace(visitor); ScriptWrappable::Trace(visitor);
visitor->Trace(frame_data_); visitor->Trace(frame_data_);
......
...@@ -7,18 +7,28 @@ ...@@ -7,18 +7,28 @@
#include <stdint.h> #include <stdint.h>
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace webrtc {
class TransformableAudioFrameInterface;
class TransformableFrameInterface;
} // namespace webrtc
namespace blink { namespace blink {
class DOMArrayBuffer; class DOMArrayBuffer;
class RTCEncodedAudioFrame final : public ScriptWrappable { class MODULES_EXPORT RTCEncodedAudioFrame final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
RTCEncodedAudioFrame() = default; explicit RTCEncodedAudioFrame(
std::unique_ptr<webrtc::TransformableFrameInterface> webrtc_frame);
explicit RTCEncodedAudioFrame(
std::unique_ptr<webrtc::TransformableAudioFrameInterface> webrtc_frame);
// rtc_encoded_audio_frame.idl implementation. // rtc_encoded_audio_frame.idl implementation.
uint64_t timestamp() const; uint64_t timestamp() const;
...@@ -29,10 +39,17 @@ class RTCEncodedAudioFrame final : public ScriptWrappable { ...@@ -29,10 +39,17 @@ class RTCEncodedAudioFrame final : public ScriptWrappable {
Vector<uint32_t> contributingSources() const; Vector<uint32_t> contributingSources() const;
String toString() const; String toString() const;
// Returns and transfers ownership of the internal WebRTC frame
// backing this RTCEncodedVideoFrame, leaving the RTCEncodedVideoFrame
// without a delegate WebRTC frame.
std::unique_ptr<webrtc::TransformableFrameInterface> PassDelegate();
void Trace(Visitor*) override; void Trace(Visitor*) override;
private: private:
mutable Member<DOMArrayBuffer> frame_data_; mutable Member<DOMArrayBuffer> frame_data_;
Vector<uint32_t> contributing_sources_;
std::unique_ptr<webrtc::TransformableFrameInterface> webrtc_frame_;
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment