blob: c62bc75f97ef29f23b721fb9328ded3053a35cf8 [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
Stefan Holmera2f15332018-07-11 17:11:31 +020011#ifndef CALL_PAYLOAD_ROUTER_H_
12#define CALL_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"
Stefan Holmer1da4d792018-07-16 15:03:08 +020018#include "call/rtp_payload_params.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020019#include "common_types.h" // NOLINT(build/include)
philipel1a4746a2018-07-09 15:52:29 +020020#include "modules/rtp_rtcp/source/rtp_video_header.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "rtc_base/constructormagic.h"
22#include "rtc_base/criticalsection.h"
23#include "rtc_base/thread_annotations.h"
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000024
25namespace webrtc {
26
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000027class RTPFragmentationHeader;
28class RtpRtcp;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000029
30// PayloadRouter routes outgoing data to the correct sending RTP module, based
31// on the simulcast layer in RTPVideoHeader.
kjellander02b3d272016-04-20 05:05:54 -070032class PayloadRouter : public EncodedImageCallback {
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000033 public:
Per83d09102016-04-15 14:59:13 +020034 // Rtp modules are assumed to be sorted in simulcast index order.
Sergey Ulanov525df3f2016-08-02 17:46:41 -070035 PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules,
Åsa Persson4bece9a2017-10-06 10:04:04 +020036 const std::vector<uint32_t>& ssrcs,
37 int payload_type,
38 const std::map<uint32_t, RtpPayloadState>& states);
Stefan Holmera2f15332018-07-11 17:11:31 +020039 ~PayloadRouter() override;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000040
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000041 // PayloadRouter will only route packets if being active, all packets will be
42 // dropped otherwise.
sprang1a646ee2016-12-01 06:34:11 -080043 void SetActive(bool active);
Seth Hampsoncc7125f2018-02-02 08:46:16 -080044 // Sets the sending status of the rtp modules and appropriately sets the
45 // payload router to active if any rtp modules are active.
46 void SetActiveModules(const std::vector<bool> active_modules);
sprang1a646ee2016-12-01 06:34:11 -080047 bool IsActive();
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000048
Åsa Persson4bece9a2017-10-06 10:04:04 +020049 std::map<uint32_t, RtpPayloadState> GetRtpPayloadStates() const;
50
kjellander02b3d272016-04-20 05:05:54 -070051 // Implements EncodedImageCallback.
52 // Returns 0 if the packet was routed / sent, -1 otherwise.
Sergey Ulanov525df3f2016-08-02 17:46:41 -070053 EncodedImageCallback::Result OnEncodedImage(
54 const EncodedImage& encoded_image,
55 const CodecSpecificInfo* codec_specific_info,
56 const RTPFragmentationHeader* fragmentation) override;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000057
Erik Språng566124a2018-04-23 12:32:22 +020058 void OnBitrateAllocationUpdated(const VideoBitrateAllocation& bitrate);
sprang1a646ee2016-12-01 06:34:11 -080059
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000060 private:
danilchapa37de392017-09-09 04:17:22 -070061 void UpdateModuleSendingState() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
Peter Boström8b79b072016-02-26 16:31:37 +010062
pbosd8de1152016-02-01 09:00:51 -080063 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -070064 bool active_ RTC_GUARDED_BY(crit_);
mflodman@webrtc.org7ac374a2015-02-20 12:45:40 +000065
Per83d09102016-04-15 14:59:13 +020066 // Rtp modules are assumed to be sorted in simulcast index order. Not owned.
67 const std::vector<RtpRtcp*> rtp_modules_;
kjellander02b3d272016-04-20 05:05:54 -070068 const int payload_type_;
Per83d09102016-04-15 14:59:13 +020069
Åsa Persson4bece9a2017-10-06 10:04:04 +020070 std::vector<RtpPayloadParams> params_ RTC_GUARDED_BY(crit_);
71
henrikg3c089d72015-09-16 05:37:44 -070072 RTC_DISALLOW_COPY_AND_ASSIGN(PayloadRouter);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000073};
74
75} // namespace webrtc
76
Stefan Holmera2f15332018-07-11 17:11:31 +020077#endif // CALL_PAYLOAD_ROUTER_H_