From e69a1a93427f44f7c3deb734c4c492ccd4fb63aa Mon Sep 17 00:00:00 2001 From: magjed Date: Fri, 25 Nov 2016 10:06:31 -0800 Subject: [PATCH] Reland of Add H264 profile to webrtc::VideoCodecH264 and webrtc::VideoPayload (patchset #1 id:1 of https://codereview.webrtc.org/2529143002/ ) Reason for revert: Include fix; set profile information in CreatePayloadType for video. Original issue's description: > Revert of Add H264 profile to webrtc::VideoCodecH264 and webrtc::VideoPayload (patchset #1 id:40001 of https://codereview.webrtc.org/2525693003/ ) > > Reason for revert: > The CL doesn't actually set profile information in VideoPayload. > > Original issue's description: > > Add H264 profile to webrtc::VideoCodecH264 and webrtc::VideoPayload > > > > It's necessary to check H264 profile information as well as payload name > > in PayloadIsCompatible in RTPPayloadRegistry. > > > > BUG=webrtc:6743 > > > > Committed: https://crrev.com/bdbc4b7ef578ba1d61ceec351bc47c33da115329 > > Cr-Commit-Position: refs/heads/master@{#15248} > > TBR=mflodman@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=webrtc:6743 > > Committed: https://crrev.com/d7e6ccbc53fc24acdcc7507a6f3a155626473d54 > Cr-Commit-Position: refs/heads/master@{#15251} TBR=mflodman@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:6743 Review-Url: https://codereview.webrtc.org/2529153002 Cr-Commit-Position: refs/heads/master@{#15252} --- webrtc/common_types.h | 14 ++++++++++++++ webrtc/common_video/h264/profile_level_id.h | 9 +-------- webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h | 5 ++++- .../rtp_rtcp/source/rtp_payload_registry.cc | 11 ++++++++++- webrtc/modules/video_coding/codec_database.cc | 1 + webrtc/video/video_receive_stream.cc | 3 +++ 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/webrtc/common_types.h b/webrtc/common_types.h index 4128f13ffa..3a0d6d8cc5 100644 --- a/webrtc/common_types.h +++ b/webrtc/common_types.h @@ -548,6 +548,19 @@ struct VideoCodecVP9 { bool flexibleMode; }; +// TODO(magjed): Move this and other H264 related classes out to their own file. +namespace H264 { + +enum Profile { + kProfileConstrainedBaseline, + kProfileBaseline, + kProfileMain, + kProfileConstrainedHigh, + kProfileHigh, +}; + +} // namespace H264 + // H264 specific. struct VideoCodecH264 { bool frameDroppingOn; @@ -557,6 +570,7 @@ struct VideoCodecH264 { size_t spsLen; const uint8_t* ppsData; size_t ppsLen; + H264::Profile profile; }; // Video codec types diff --git a/webrtc/common_video/h264/profile_level_id.h b/webrtc/common_video/h264/profile_level_id.h index bb1c435926..20147bb66e 100644 --- a/webrtc/common_video/h264/profile_level_id.h +++ b/webrtc/common_video/h264/profile_level_id.h @@ -15,6 +15,7 @@ #include #include "webrtc/base/optional.h" +#include "webrtc/common_types.h" namespace webrtc { namespace H264 { @@ -22,14 +23,6 @@ namespace H264 { // Map containting SDP codec parameters. typedef std::map CodecParameterMap; -enum Profile { - kProfileConstrainedBaseline, - kProfileBaseline, - kProfileMain, - kProfileConstrainedHigh, - kProfileHigh, -}; - // All values are equal to ten times the level number, except level 1b which is // special. enum Level { diff --git a/webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h b/webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h index bd3aae72b5..9ba9b51bbb 100644 --- a/webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h +++ b/webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h @@ -15,6 +15,7 @@ #include #include +#include "webrtc/common_types.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/system_wrappers/include/clock.h" #include "webrtc/typedefs.h" @@ -44,7 +45,9 @@ struct AudioPayload { }; struct VideoPayload { - RtpVideoCodecTypes videoCodecType; + RtpVideoCodecTypes videoCodecType; + // The H264 profile only matters if videoCodecType == kRtpVideoH264. + H264::Profile h264_profile; }; union PayloadUnion { diff --git a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc index 7d4afc6e36..d99e22110a 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc @@ -37,7 +37,14 @@ bool PayloadIsCompatible(const RtpUtility::Payload& payload, bool PayloadIsCompatible(const RtpUtility::Payload& payload, const VideoCodec& video_codec) { - return !payload.audio && _stricmp(payload.name, video_codec.plName) == 0; + if (payload.audio || _stricmp(payload.name, video_codec.plName) != 0) + return false; + // For H264, profiles must match as well. + if (video_codec.codecType == kVideoCodecH264) { + return video_codec.H264().profile == + payload.typeSpecific.Video.h264_profile; + } + return true; } RtpUtility::Payload CreatePayloadType(const CodecInst& audio_codec) { @@ -74,6 +81,8 @@ RtpUtility::Payload CreatePayloadType(const VideoCodec& video_codec) { strncpy(payload.name, video_codec.plName, RTP_PAYLOAD_NAME_SIZE - 1); payload.typeSpecific.Video.videoCodecType = ConvertToRtpVideoCodecType(video_codec.codecType); + if (video_codec.codecType == kVideoCodecH264) + payload.typeSpecific.Video.h264_profile = video_codec.H264().profile; payload.audio = false; return payload; } diff --git a/webrtc/modules/video_coding/codec_database.cc b/webrtc/modules/video_coding/codec_database.cc index 9d8c8f3489..ff7077e569 100644 --- a/webrtc/modules/video_coding/codec_database.cc +++ b/webrtc/modules/video_coding/codec_database.cc @@ -68,6 +68,7 @@ VideoCodecH264 VideoEncoder::GetDefaultH264Settings() { h264_settings.spsLen = 0; h264_settings.ppsData = nullptr; h264_settings.ppsLen = 0; + h264_settings.profile = H264::kProfileConstrainedBaseline; return h264_settings; } diff --git a/webrtc/video/video_receive_stream.cc b/webrtc/video/video_receive_stream.cc index cc14525654..5fd79a7744 100644 --- a/webrtc/video/video_receive_stream.cc +++ b/webrtc/video/video_receive_stream.cc @@ -19,6 +19,7 @@ #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" #include "webrtc/base/optional.h" +#include "webrtc/common_video/h264/profile_level_id.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/congestion_controller/include/congestion_controller.h" #include "webrtc/modules/utility/include/process_thread.h" @@ -169,6 +170,8 @@ VideoCodec CreateDecoderVideoCodec(const VideoReceiveStream::Decoder& decoder) { *(codec.VP9()) = VideoEncoder::GetDefaultVp9Settings(); } else if (codec.codecType == kVideoCodecH264) { *(codec.H264()) = VideoEncoder::GetDefaultH264Settings(); + codec.H264()->profile = + H264::ParseSdpProfileLevelId(decoder.codec_params)->profile; } codec.width = 320;