diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index d0f4ce803c..39b9180869 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -138,6 +138,8 @@ rtc_library("rtp_rtcp") { "source/absolute_capture_time_receiver.h", "source/absolute_capture_time_sender.cc", "source/absolute_capture_time_sender.h", + "source/create_video_rtp_depacketizer.cc", + "source/create_video_rtp_depacketizer.h", "source/dtmf_queue.cc", "source/dtmf_queue.h", "source/fec_private_tables_bursty.cc", @@ -211,6 +213,8 @@ rtc_library("rtp_rtcp") { "source/ulpfec_receiver_impl.cc", "source/ulpfec_receiver_impl.h", "source/video_rtp_depacketizer.h", + "source/video_rtp_depacketizer_raw.cc", + "source/video_rtp_depacketizer_raw.h", ] if (rtc_enable_bwe_test_logging) { @@ -273,6 +277,7 @@ rtc_library("rtp_rtcp") { "../video_coding:codec_globals_headers", "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/container:inlined_vector", + "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:variant", @@ -474,6 +479,7 @@ if (rtc_include_tests) { "source/ulpfec_generator_unittest.cc", "source/ulpfec_header_reader_writer_unittest.cc", "source/ulpfec_receiver_unittest.cc", + "source/video_rtp_depacketizer_raw_unittest.cc", ] deps = [ ":fec_test_helper", diff --git a/modules/rtp_rtcp/source/create_video_rtp_depacketizer.cc b/modules/rtp_rtcp/source/create_video_rtp_depacketizer.cc new file mode 100644 index 0000000000..8946ec0180 --- /dev/null +++ b/modules/rtp_rtcp/source/create_video_rtp_depacketizer.cc @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2019 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 "modules/rtp_rtcp/source/create_video_rtp_depacketizer.h" + +#include + +#include "absl/memory/memory.h" +#include "absl/types/optional.h" +#include "modules/rtp_rtcp/source/rtp_format.h" +#include "modules/rtp_rtcp/source/video_rtp_depacketizer.h" +#include "rtc_base/checks.h" +#include "rtc_base/copy_on_write_buffer.h" + +namespace webrtc { +namespace { + +// Wrapper over legacy RtpDepacketizer interface. +// TODO(bugs.webrtc.org/11152): Delete when all RtpDepacketizers updated to +// the VideoRtpDepacketizer interface. +class LegacyRtpDepacketizer : public VideoRtpDepacketizer { + public: + explicit LegacyRtpDepacketizer(VideoCodecType codec) : codec_(codec) {} + ~LegacyRtpDepacketizer() override = default; + + absl::optional Parse( + rtc::CopyOnWriteBuffer rtp_payload) override { + auto depacketizer = absl::WrapUnique(RtpDepacketizer::Create(codec_)); + RTC_CHECK(depacketizer); + RtpDepacketizer::ParsedPayload parsed_payload; + if (!depacketizer->Parse(&parsed_payload, rtp_payload.cdata(), + rtp_payload.size())) { + return absl::nullopt; + } + absl::optional result(absl::in_place); + result->video_header = parsed_payload.video; + result->video_payload.SetData(parsed_payload.payload, + parsed_payload.payload_length); + return result; + } + + private: + const VideoCodecType codec_; +}; + +} // namespace + +std::unique_ptr CreateVideoRtpDepacketizer( + VideoCodecType codec) { + // TODO(bugs.webrtc.org/11152): switch on codec and create specialized + // VideoRtpDepacketizers when they are migrated to new interface. + return std::make_unique(codec); +} + +} // namespace webrtc diff --git a/modules/rtp_rtcp/source/create_video_rtp_depacketizer.h b/modules/rtp_rtcp/source/create_video_rtp_depacketizer.h new file mode 100644 index 0000000000..102cacf598 --- /dev/null +++ b/modules/rtp_rtcp/source/create_video_rtp_depacketizer.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2019 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. + */ + +#ifndef MODULES_RTP_RTCP_SOURCE_CREATE_VIDEO_RTP_DEPACKETIZER_H_ +#define MODULES_RTP_RTCP_SOURCE_CREATE_VIDEO_RTP_DEPACKETIZER_H_ + +#include + +#include "api/video/video_codec_type.h" +#include "modules/rtp_rtcp/source/video_rtp_depacketizer.h" + +namespace webrtc { + +std::unique_ptr CreateVideoRtpDepacketizer( + VideoCodecType codec); + +} // namespace webrtc + +#endif // MODULES_RTP_RTCP_SOURCE_CREATE_VIDEO_RTP_DEPACKETIZER_H_ diff --git a/modules/rtp_rtcp/source/video_rtp_depacketizer_raw.cc b/modules/rtp_rtcp/source/video_rtp_depacketizer_raw.cc new file mode 100644 index 0000000000..81b4e4ab53 --- /dev/null +++ b/modules/rtp_rtcp/source/video_rtp_depacketizer_raw.cc @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2019 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 "modules/rtp_rtcp/source/video_rtp_depacketizer_raw.h" + +#include + +#include "absl/types/optional.h" +#include "modules/rtp_rtcp/source/video_rtp_depacketizer.h" +#include "rtc_base/copy_on_write_buffer.h" + +namespace webrtc { + +absl::optional +VideoRtpDepacketizerRaw::Parse(rtc::CopyOnWriteBuffer rtp_payload) { + absl::optional parsed(absl::in_place); + parsed->video_payload = std::move(rtp_payload); + return parsed; +} + +} // namespace webrtc diff --git a/modules/rtp_rtcp/source/video_rtp_depacketizer_raw.h b/modules/rtp_rtcp/source/video_rtp_depacketizer_raw.h new file mode 100644 index 0000000000..59c8695352 --- /dev/null +++ b/modules/rtp_rtcp/source/video_rtp_depacketizer_raw.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019 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. + */ + +#ifndef MODULES_RTP_RTCP_SOURCE_VIDEO_RTP_DEPACKETIZER_RAW_H_ +#define MODULES_RTP_RTCP_SOURCE_VIDEO_RTP_DEPACKETIZER_RAW_H_ + +#include "absl/types/optional.h" +#include "modules/rtp_rtcp/source/video_rtp_depacketizer.h" +#include "rtc_base/copy_on_write_buffer.h" + +namespace webrtc { + +class VideoRtpDepacketizerRaw : public VideoRtpDepacketizer { + public: + ~VideoRtpDepacketizerRaw() override = default; + + absl::optional Parse( + rtc::CopyOnWriteBuffer rtp_payload) override; +}; + +} // namespace webrtc + +#endif // MODULES_RTP_RTCP_SOURCE_VIDEO_RTP_DEPACKETIZER_RAW_H_ diff --git a/modules/rtp_rtcp/source/video_rtp_depacketizer_raw_unittest.cc b/modules/rtp_rtcp/source/video_rtp_depacketizer_raw_unittest.cc new file mode 100644 index 0000000000..36c826ab84 --- /dev/null +++ b/modules/rtp_rtcp/source/video_rtp_depacketizer_raw_unittest.cc @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2019 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 "modules/rtp_rtcp/source/video_rtp_depacketizer_raw.h" + +#include + +#include "absl/types/optional.h" +#include "rtc_base/copy_on_write_buffer.h" +#include "test/gtest.h" + +namespace webrtc { +namespace { + +TEST(VideoRtpDepacketizerRaw, PassRtpPayloadAsVideoPayload) { + const uint8_t kPayload[] = {0x05, 0x25, 0x52}; + rtc::CopyOnWriteBuffer rtp_payload(kPayload); + + VideoRtpDepacketizerRaw depacketizer; + absl::optional parsed = + depacketizer.Parse(rtp_payload); + + ASSERT_TRUE(parsed); + EXPECT_EQ(parsed->video_payload.size(), rtp_payload.size()); + // Check there was no memcpy involved by verifying return and original buffers + // point to the same buffer. + EXPECT_EQ(parsed->video_payload.cdata(), rtp_payload.cdata()); +} + +TEST(VideoRtpDepacketizerRaw, UsesDefaultValuesForVideoHeader) { + const uint8_t kPayload[] = {0x05, 0x25, 0x52}; + rtc::CopyOnWriteBuffer rtp_payload(kPayload); + + VideoRtpDepacketizerRaw depacketizer; + absl::optional parsed = + depacketizer.Parse(rtp_payload); + + ASSERT_TRUE(parsed); + EXPECT_FALSE(parsed->video_header.generic); + EXPECT_EQ(parsed->video_header.codec, kVideoCodecGeneric); +} + +} // namespace +} // namespace webrtc