Skip to content

Commit

Permalink
Implement PayloadUnion as variant instead of pair of optionals
Browse files Browse the repository at this point in the history
Bug: None
Change-Id: I2e54f5a0561804bc59c4d4c8e35ccdaa9536b8e4
Reviewed-on: https://webrtc-review.googlesource.com/85366
Reviewed-by: Karl Wiberg <[email protected]>
Commit-Queue: Danil Chapovalov <[email protected]>
Cr-Commit-Position: refs/heads/master@{#23745}
  • Loading branch information
DanilChapovalov authored and Commit Bot committed Jun 26, 2018
1 parent 72f52a1 commit fb8e7ef
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -745,4 +745,5 @@ include_rules = [

# Abseil whitelist.
"+absl/types/optional.h",
"+absl/types/variant.h",
]
1 change: 1 addition & 0 deletions modules/rtp_rtcp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ rtc_source_set("rtp_rtcp_format") {
"../../rtc_base:rtc_base_approved",
"../../system_wrappers",
"//third_party/abseil-cpp/absl/types:optional",
"//third_party/abseil-cpp/absl/types:variant",
]
}

Expand Down
6 changes: 2 additions & 4 deletions modules/rtp_rtcp/include/rtp_rtcp_defines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ void StreamId::Set(const char* data, size_t size) {
// and thus assume trivial destructibility.
static_assert(std::is_trivially_destructible<StreamId>::value, "");

PayloadUnion::PayloadUnion(const AudioPayload& payload)
: audio_payload_(payload) {}
PayloadUnion::PayloadUnion(const VideoPayload& payload)
: video_payload_(payload) {}
PayloadUnion::PayloadUnion(const AudioPayload& payload) : payload_(payload) {}
PayloadUnion::PayloadUnion(const VideoPayload& payload) : payload_(payload) {}
PayloadUnion::PayloadUnion(const PayloadUnion&) = default;
PayloadUnion::PayloadUnion(PayloadUnion&&) = default;
PayloadUnion::~PayloadUnion() = default;
Expand Down
28 changes: 12 additions & 16 deletions modules/rtp_rtcp/include/rtp_rtcp_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <list>
#include <vector>

#include "absl/types/variant.h"
#include "api/audio_codecs/audio_format.h"
#include "api/rtp_headers.h"
#include "common_types.h" // NOLINT(build/include)
Expand Down Expand Up @@ -71,28 +72,23 @@ class PayloadUnion {
PayloadUnion& operator=(const PayloadUnion&);
PayloadUnion& operator=(PayloadUnion&&);

bool is_audio() const { return audio_payload_.has_value(); }
bool is_video() const { return video_payload_.has_value(); }
const AudioPayload& audio_payload() const {
RTC_DCHECK(audio_payload_);
return *audio_payload_;
bool is_audio() const {
return absl::holds_alternative<AudioPayload>(payload_);
}
const VideoPayload& video_payload() const {
RTC_DCHECK(video_payload_);
return *video_payload_;
bool is_video() const {
return absl::holds_alternative<VideoPayload>(payload_);
}
AudioPayload& audio_payload() {
RTC_DCHECK(audio_payload_);
return *audio_payload_;
const AudioPayload& audio_payload() const {
return absl::get<AudioPayload>(payload_);
}
VideoPayload& video_payload() {
RTC_DCHECK(video_payload_);
return *video_payload_;
const VideoPayload& video_payload() const {
return absl::get<VideoPayload>(payload_);
}
AudioPayload& audio_payload() { return absl::get<AudioPayload>(payload_); }
VideoPayload& video_payload() { return absl::get<VideoPayload>(payload_); }

private:
absl::optional<AudioPayload> audio_payload_;
absl::optional<VideoPayload> video_payload_;
absl::variant<AudioPayload, VideoPayload> payload_;
};

enum RTPAliveType { kRtpDead = 0, kRtpNoRtp = 1, kRtpAlive = 2 };
Expand Down

0 comments on commit fb8e7ef

Please sign in to comment.