Convert PayloadUnion from a union to a class, step 1

I need to replace the audio part of PayloadUnion with SdpAudioFormat,
but that's a non-trivially-deletable class and those just don't work
well in unions, especially unions that don't have a discriminator that
says which member is currently active.

This CL converts the union to a class, adds a discriminator, and
provides accessor functions. CL #2 in the series will change all
outsiders to use the accessors instead of the public member variables
directly, and CL #3 will remove the public member variables. (It needs
to be done in separate steps like this because PayloadUnion is
unfortunately part of the API, and just changing it all in one go
would break users.)

BUG=webrtc:8159

Change-Id: I38c44bbb21a2d38600cff59bf37d8d47dfdbce21
Reviewed-on: https://webrtc-review.googlesource.com/4340
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20025}
This commit is contained in:
Karl Wiberg
2017-09-28 19:54:38 +02:00
committed by Commit Bot
parent 27bafec7c1
commit 83d3ec177c
9 changed files with 70 additions and 46 deletions

View File

@ -51,9 +51,39 @@ struct VideoPayload {
H264::Profile h264_profile;
};
union PayloadUnion {
AudioPayload Audio;
VideoPayload Video;
class PayloadUnion {
public:
explicit PayloadUnion(const AudioPayload& payload)
: Audio(payload), is_audio_(true) {}
explicit PayloadUnion(const VideoPayload& payload)
: Video(payload), is_audio_(false) {}
bool is_audio() const { return is_audio_; }
bool is_video() const { return !is_audio_; }
const AudioPayload& audio_payload() const {
RTC_DCHECK(is_audio_);
return Audio;
}
const VideoPayload& video_payload() const {
RTC_DCHECK(!is_audio_);
return Video;
}
AudioPayload& audio_payload() {
RTC_DCHECK(is_audio_);
return Audio;
}
VideoPayload& video_payload() {
RTC_DCHECK(!is_audio_);
return Video;
}
public:
// These two are public for backwards compatibilty. They'll go private soon.
AudioPayload Audio;
VideoPayload Video;
private:
bool is_audio_;
};
enum RTPAliveType { kRtpDead = 0, kRtpNoRtp = 1, kRtpAlive = 2 };