blob: 169eda4996990b9e7b81d62fee3f809dc4f4abb3 [file] [log] [blame]
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +00001/*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef VIDEO_PAYLOAD_ROUTER_H_
12#define VIDEO_PAYLOAD_ROUTER_H_
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000013
Åsa Persson4bece9a2017-10-06 10:04:04 +020014#include <map>
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000015#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/video_codecs/video_encoder.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020018#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "rtc_base/constructormagic.h"
20#include "rtc_base/criticalsection.h"
21#include "rtc_base/thread_annotations.h"
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000022
23namespace webrtc {
24
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000025class RTPFragmentationHeader;
26class RtpRtcp;
27struct RTPVideoHeader;
28
Niels Möller9d138fc2018-02-15 16:58:43 +010029// Currently only VP8/VP9 specific.
30struct RtpPayloadState {
31 int16_t picture_id = -1;
32};
33
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000034// PayloadRouter routes outgoing data to the correct sending RTP module, based
35// on the simulcast layer in RTPVideoHeader.
kjellander02b3d272016-04-20 05:05:54 -070036class PayloadRouter : public EncodedImageCallback {
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000037 public:
Per83d09102016-04-15 14:59:13 +020038 // Rtp modules are assumed to be sorted in simulcast index order.
Sergey Ulanov525df3f2016-08-02 17:46:41 -070039 PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules,
Åsa Persson4bece9a2017-10-06 10:04:04 +020040 const std::vector<uint32_t>& ssrcs,
41 int payload_type,
42 const std::map<uint32_t, RtpPayloadState>& states);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000043 ~PayloadRouter();
44
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000045 // PayloadRouter will only route packets if being active, all packets will be
46 // dropped otherwise.
sprang1a646ee2016-12-01 06:34:11 -080047 void SetActive(bool active);
Seth Hampsoncc7125f2018-02-02 08:46:16 -080048 // Sets the sending status of the rtp modules and appropriately sets the
49 // payload router to active if any rtp modules are active.
50 void SetActiveModules(const std::vector<bool> active_modules);
sprang1a646ee2016-12-01 06:34:11 -080051 bool IsActive();
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000052
Åsa Persson4bece9a2017-10-06 10:04:04 +020053 std::map<uint32_t, RtpPayloadState> GetRtpPayloadStates() const;
54
kjellander02b3d272016-04-20 05:05:54 -070055 // Implements EncodedImageCallback.
56 // Returns 0 if the packet was routed / sent, -1 otherwise.
Sergey Ulanov525df3f2016-08-02 17:46:41 -070057 EncodedImageCallback::Result OnEncodedImage(
58 const EncodedImage& encoded_image,
59 const CodecSpecificInfo* codec_specific_info,
60 const RTPFragmentationHeader* fragmentation) override;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000061
sprang1a646ee2016-12-01 06:34:11 -080062 void OnBitrateAllocationUpdated(const BitrateAllocation& bitrate);
63
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000064 private:
Åsa Persson4bece9a2017-10-06 10:04:04 +020065 class RtpPayloadParams;
66
danilchapa37de392017-09-09 04:17:22 -070067 void UpdateModuleSendingState() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
Peter Boström8b79b072016-02-26 16:31:37 +010068
pbosd8de1152016-02-01 09:00:51 -080069 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -070070 bool active_ RTC_GUARDED_BY(crit_);
mflodman@webrtc.org7ac374a2015-02-20 12:45:40 +000071
Per83d09102016-04-15 14:59:13 +020072 // Rtp modules are assumed to be sorted in simulcast index order. Not owned.
73 const std::vector<RtpRtcp*> rtp_modules_;
kjellander02b3d272016-04-20 05:05:54 -070074 const int payload_type_;
Per83d09102016-04-15 14:59:13 +020075
Åsa Persson4bece9a2017-10-06 10:04:04 +020076 const bool forced_fallback_enabled_;
77 std::vector<RtpPayloadParams> params_ RTC_GUARDED_BY(crit_);
78
henrikg3c089d72015-09-16 05:37:44 -070079 RTC_DISALLOW_COPY_AND_ASSIGN(PayloadRouter);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000080};
81
82} // namespace webrtc
83
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020084#endif // VIDEO_PAYLOAD_ROUTER_H_