From ac382f3adcf64b31e594ec1c0ad427cfc031bf14 Mon Sep 17 00:00:00 2001 From: hta Date: Tue, 6 Dec 2016 23:43:49 -0800 Subject: [PATCH] Make ostream<< for enum class H264PacketizationMode This makes it possible to use << and RTC_CHECK_EQ with this class. BUG=none Review-Url: https://codereview.webrtc.org/2554003002 Cr-Commit-Position: refs/heads/master@{#15456} --- webrtc/modules/include/module_common_types.h | 16 ++++++++++++++++ .../modules/rtp_rtcp/source/rtp_format_h264.cc | 9 +++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/webrtc/modules/include/module_common_types.h b/webrtc/modules/include/module_common_types.h index 3df93b6c89..fa0826a551 100644 --- a/webrtc/modules/include/module_common_types.h +++ b/webrtc/modules/include/module_common_types.h @@ -271,6 +271,22 @@ enum class H264PacketizationMode { SingleNalUnit // Mode 0 - only single NALU allowed }; +// This function is declared inline because it is not clear which +// .cc file it should belong to. +// TODO(hta): Refactor. https://bugs.webrtc.org/6842 +inline std::ostream& operator<<(std::ostream& stream, + H264PacketizationMode mode) { + switch (mode) { + case H264PacketizationMode::NonInterleaved: + stream << "NonInterleaved"; + break; + case H264PacketizationMode::SingleNalUnit: + stream << "SingleNalUnit"; + break; + } + return stream; +} + struct NaluInfo { uint8_t type; int sps_id; diff --git a/webrtc/modules/rtp_rtcp/source/rtp_format_h264.cc b/webrtc/modules/rtp_rtcp/source/rtp_format_h264.cc index 9d71803f3b..e896c65f97 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_format_h264.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_format_h264.cc @@ -245,10 +245,7 @@ void RtpPacketizerH264::PacketizeSingleNalu(size_t fragment_index) { const Fragment* fragment = &input_fragments_[fragment_index]; RTC_CHECK_GE(payload_size_left, fragment->length) << "Payload size left " << payload_size_left << ", fragment length " - << fragment->length << ", packetization mode " - << (packetization_mode_ == H264PacketizationMode::SingleNalUnit - ? "SingleNalUnit" - : "NonInterleaved"); + << fragment->length << ", packetization mode " << packetization_mode_; RTC_CHECK_GT(fragment->length, 0u); packets_.push(PacketUnit(*fragment, true /* first */, true /* last */, false /* aggregated */, fragment->buffer[0])); @@ -272,10 +269,10 @@ bool RtpPacketizerH264::NextPacket(RtpPacketToSend* rtp_packet, packets_.pop(); input_fragments_.pop_front(); } else if (packet.aggregated) { - RTC_CHECK(packetization_mode_ == H264PacketizationMode::NonInterleaved); + RTC_CHECK_EQ(H264PacketizationMode::NonInterleaved, packetization_mode_); NextAggregatePacket(rtp_packet); } else { - RTC_CHECK(packetization_mode_ == H264PacketizationMode::NonInterleaved); + RTC_CHECK_EQ(H264PacketizationMode::NonInterleaved, packetization_mode_); NextFragmentPacket(rtp_packet); } RTC_DCHECK_LE(rtp_packet->payload_size(), max_payload_len_);