webrtc/api/video_codecs/test/sdp_video_format_unittest.cc
Johannes Kron 20ee02c49f Add codec comparison function to SdpVideoFormat
SdpVideoFormat is used to configure video encoder and decoders.
This CL adds support for comparing two SdpVideoFormat objects
to determine if they specify the same video codec.

This functionality previously only existed in media/base/codec.h
which made the code sensitive to circular dependencies. Once
downstream projects stop using cricket::IsSameCodec, this code
can be removed.

Bug: chromium:1187565
Change-Id: I242069aa6af07917637384c80ee4820887defc7d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213427
Commit-Queue: Johannes Kron <kron@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33794}
2021-04-21 07:21:41 +00:00

74 lines
3.1 KiB
C++

/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "api/video_codecs/sdp_video_format.h"
#include <stdint.h>
#include "test/gtest.h"
namespace webrtc {
typedef SdpVideoFormat Sdp;
typedef SdpVideoFormat::Parameters Params;
TEST(SdpVideoFormatTest, SameCodecNameNoParameters) {
EXPECT_TRUE(Sdp("H264").IsSameCodec(Sdp("h264")));
EXPECT_TRUE(Sdp("VP8").IsSameCodec(Sdp("vp8")));
EXPECT_TRUE(Sdp("Vp9").IsSameCodec(Sdp("vp9")));
EXPECT_TRUE(Sdp("AV1").IsSameCodec(Sdp("Av1")));
}
TEST(SdpVideoFormatTest, DifferentCodecNameNoParameters) {
EXPECT_FALSE(Sdp("H264").IsSameCodec(Sdp("VP8")));
EXPECT_FALSE(Sdp("VP8").IsSameCodec(Sdp("VP9")));
EXPECT_FALSE(Sdp("AV1").IsSameCodec(Sdp("")));
}
TEST(SdpVideoFormatTest, SameCodecNameSameParameters) {
EXPECT_TRUE(Sdp("VP9").IsSameCodec(Sdp("VP9", Params{{"profile-id", "0"}})));
EXPECT_TRUE(Sdp("VP9", Params{{"profile-id", "0"}})
.IsSameCodec(Sdp("VP9", Params{{"profile-id", "0"}})));
EXPECT_TRUE(Sdp("VP9", Params{{"profile-id", "2"}})
.IsSameCodec(Sdp("VP9", Params{{"profile-id", "2"}})));
EXPECT_TRUE(
Sdp("H264", Params{{"profile-level-id", "42e01f"}})
.IsSameCodec(Sdp("H264", Params{{"profile-level-id", "42e01f"}})));
EXPECT_TRUE(
Sdp("H264", Params{{"profile-level-id", "640c34"}})
.IsSameCodec(Sdp("H264", Params{{"profile-level-id", "640c34"}})));
}
TEST(SdpVideoFormatTest, SameCodecNameDifferentParameters) {
EXPECT_FALSE(Sdp("VP9").IsSameCodec(Sdp("VP9", Params{{"profile-id", "2"}})));
EXPECT_FALSE(Sdp("VP9", Params{{"profile-id", "0"}})
.IsSameCodec(Sdp("VP9", Params{{"profile-id", "1"}})));
EXPECT_FALSE(Sdp("VP9", Params{{"profile-id", "2"}})
.IsSameCodec(Sdp("VP9", Params{{"profile-id", "0"}})));
EXPECT_FALSE(
Sdp("H264", Params{{"profile-level-id", "42e01f"}})
.IsSameCodec(Sdp("H264", Params{{"profile-level-id", "640c34"}})));
EXPECT_FALSE(
Sdp("H264", Params{{"profile-level-id", "640c34"}})
.IsSameCodec(Sdp("H264", Params{{"profile-level-id", "42f00b"}})));
}
TEST(SdpVideoFormatTest, DifferentCodecNameSameParameters) {
EXPECT_FALSE(Sdp("VP9", Params{{"profile-id", "0"}})
.IsSameCodec(Sdp("H264", Params{{"profile-id", "0"}})));
EXPECT_FALSE(Sdp("VP9", Params{{"profile-id", "2"}})
.IsSameCodec(Sdp("VP8", Params{{"profile-id", "2"}})));
EXPECT_FALSE(
Sdp("H264", Params{{"profile-level-id", "42e01f"}})
.IsSameCodec(Sdp("VP9", Params{{"profile-level-id", "42e01f"}})));
EXPECT_FALSE(
Sdp("H264", Params{{"profile-level-id", "640c34"}})
.IsSameCodec(Sdp("VP8", Params{{"profile-level-id", "640c34"}})));
}
} // namespace webrtc