Make all encodedaudioframes inherit from TransformableAudioFrameI'face

Make outgoing encoded audio frames inherit from the same Audio interface
that incoming frames inherit from, to align them and make it possible to
eg clone frames regardless of their direction.

Also begin removing GetHeader() from the Audio interface, replacing it
with getters for the specific values we actually need to propagate in
the API: sequence number and CSRCs. This makes it much easier to treat
incoming and outgoing frames the same, even if they don't have full
RtpHeaders prepared at the point of the transform.

Bug: chromium:1453226
Change-Id: Ib5b39b30dea8a378b3b26efb1589dfd64741d201
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/308141
Commit-Queue: Tony Herre <herre@google.com>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Palak Agarwal <agpalak@google.com>
Cr-Commit-Position: refs/heads/main@{#40309}
This commit is contained in:
Tony Herre 2023-06-19 15:13:08 +00:00 committed by WebRTC LUCI CQ
parent bb917acb10
commit 097a4decc2
7 changed files with 46 additions and 5 deletions

View file

@ -25,7 +25,7 @@ std::unique_ptr<TransformableVideoFrameInterface> CreateVideoReceiverFrame() {
return nullptr;
}
std::unique_ptr<TransformableFrameInterface> CloneAudioFrame(
std::unique_ptr<TransformableAudioFrameInterface> CloneAudioFrame(
TransformableAudioFrameInterface* original) {
// At the moment, only making sender frames is supported.
return CloneSenderAudioFrame(original);

View file

@ -32,7 +32,7 @@ std::unique_ptr<TransformableVideoFrameInterface> CreateVideoSenderFrame();
std::unique_ptr<TransformableVideoFrameInterface> CreateVideoReceiverFrame();
// Creates a new frame with the same metadata as the original.
// The original can be a sender or receiver frame.
RTC_EXPORT std::unique_ptr<TransformableFrameInterface> CloneAudioFrame(
RTC_EXPORT std::unique_ptr<TransformableAudioFrameInterface> CloneAudioFrame(
TransformableAudioFrameInterface* original);
RTC_EXPORT std::unique_ptr<TransformableVideoFrameInterface> CloneVideoFrame(
TransformableVideoFrameInterface* original);

View file

@ -72,9 +72,17 @@ class TransformableAudioFrameInterface : public TransformableFrameInterface {
// Exposes the frame header, enabling the interface clients to use the
// information in the header as needed, for example to compile the list of
// csrcs.
// TODO(crbug.com/1453226): Deprecate and remove once callers have migrated to
// the getters for specific fields.
virtual const RTPHeader& GetHeader() const = 0;
virtual rtc::ArrayView<const uint32_t> GetContributingSources() const = 0;
// TODO(crbug.com/1453226): Change this to pure virtual after it
// is implemented everywhere.
virtual const absl::optional<uint16_t> SequenceNumber() const {
return absl::nullopt;
}
};
// Objects implement this interface to be notified with the transformed frame.

View file

@ -29,6 +29,14 @@ class MockTransformableAudioFrame : public TransformableAudioFrameInterface {
GetContributingSources,
(),
(const override));
MOCK_METHOD(const absl::optional<uint16_t>,
SequenceNumber,
(),
(const, override));
MOCK_METHOD(TransformableFrameInterface::Direction,
GetDirection,
(),
(const, override));
};
} // namespace webrtc

View file

@ -46,6 +46,10 @@ class TransformableIncomingAudioFrame
}
Direction GetDirection() const override { return Direction::kReceiver; }
const absl::optional<uint16_t> SequenceNumber() const override {
return header_.sequenceNumber;
}
private:
rtc::Buffer payload_;
RTPHeader header_;

View file

@ -15,7 +15,8 @@
namespace webrtc {
namespace {
class TransformableOutgoingAudioFrame : public TransformableFrameInterface {
class TransformableOutgoingAudioFrame
: public TransformableAudioFrameInterface {
public:
TransformableOutgoingAudioFrame(AudioFrameType frame_type,
uint8_t payload_type,
@ -50,6 +51,22 @@ class TransformableOutgoingAudioFrame : public TransformableFrameInterface {
}
Direction GetDirection() const override { return Direction::kSender; }
// TODO(crbug.com/1453226): Remove once GetHeader() is removed from
// TransformableAudioFrameInterface.
const RTPHeader& GetHeader() const override { return empty_header_; }
rtc::ArrayView<const uint32_t> GetContributingSources() const override {
return {};
}
const absl::optional<uint16_t> SequenceNumber() const override {
return absl::nullopt;
}
void SetRTPTimestamp(uint32_t timestamp) override {
rtp_timestamp_ = timestamp - rtp_start_timestamp_;
}
private:
AudioFrameType frame_type_;
uint8_t payload_type_;
@ -58,6 +75,10 @@ class TransformableOutgoingAudioFrame : public TransformableFrameInterface {
rtc::Buffer payload_;
int64_t absolute_capture_timestamp_ms_;
uint32_t ssrc_;
// TODO(crbug.com/1453226): Remove once GetHeader() is removed from
// TransformableAudioFrameInterface.
RTPHeader empty_header_;
};
} // namespace
@ -127,7 +148,7 @@ void ChannelSendFrameTransformerDelegate::SendFrame(
transformed_frame->GetAbsoluteCaptureTimestampMs());
}
std::unique_ptr<TransformableFrameInterface> CloneSenderAudioFrame(
std::unique_ptr<TransformableAudioFrameInterface> CloneSenderAudioFrame(
TransformableAudioFrameInterface* original) {
AudioFrameType audio_frame_type =
original->GetHeader().extension.voiceActivity

View file

@ -78,7 +78,7 @@ class ChannelSendFrameTransformerDelegate : public TransformedFrameCallback {
rtc::TaskQueue* encoder_queue_ RTC_GUARDED_BY(send_lock_);
};
std::unique_ptr<TransformableFrameInterface> CloneSenderAudioFrame(
std::unique_ptr<TransformableAudioFrameInterface> CloneSenderAudioFrame(
TransformableAudioFrameInterface* original);
} // namespace webrtc