mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 1 | /* |
| 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 Holmer | a2f1533 | 2018-07-11 17:11:31 +0200 | [diff] [blame] | 11 | #ifndef CALL_PAYLOAD_ROUTER_H_ |
| 12 | #define CALL_PAYLOAD_ROUTER_H_ |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 13 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 14 | #include <map> |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/video_codecs/video_encoder.h" |
Stefan Holmer | 1da4d79 | 2018-07-16 15:03:08 +0200 | [diff] [blame^] | 18 | #include "call/rtp_payload_params.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 19 | #include "common_types.h" // NOLINT(build/include) |
philipel | 1a4746a | 2018-07-09 15:52:29 +0200 | [diff] [blame] | 20 | #include "modules/rtp_rtcp/source/rtp_video_header.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "rtc_base/constructormagic.h" |
| 22 | #include "rtc_base/criticalsection.h" |
| 23 | #include "rtc_base/thread_annotations.h" |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 27 | class RTPFragmentationHeader; |
| 28 | class RtpRtcp; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 29 | |
| 30 | // PayloadRouter routes outgoing data to the correct sending RTP module, based |
| 31 | // on the simulcast layer in RTPVideoHeader. |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 32 | class PayloadRouter : public EncodedImageCallback { |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 33 | public: |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 34 | // Rtp modules are assumed to be sorted in simulcast index order. |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 35 | PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules, |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 36 | const std::vector<uint32_t>& ssrcs, |
| 37 | int payload_type, |
| 38 | const std::map<uint32_t, RtpPayloadState>& states); |
Stefan Holmer | a2f1533 | 2018-07-11 17:11:31 +0200 | [diff] [blame] | 39 | ~PayloadRouter() override; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 40 | |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 41 | // PayloadRouter will only route packets if being active, all packets will be |
| 42 | // dropped otherwise. |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 43 | void SetActive(bool active); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 44 | // 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); |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 47 | bool IsActive(); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 48 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 49 | std::map<uint32_t, RtpPayloadState> GetRtpPayloadStates() const; |
| 50 | |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 51 | // Implements EncodedImageCallback. |
| 52 | // Returns 0 if the packet was routed / sent, -1 otherwise. |
Sergey Ulanov | 525df3f | 2016-08-02 17:46:41 -0700 | [diff] [blame] | 53 | EncodedImageCallback::Result OnEncodedImage( |
| 54 | const EncodedImage& encoded_image, |
| 55 | const CodecSpecificInfo* codec_specific_info, |
| 56 | const RTPFragmentationHeader* fragmentation) override; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 57 | |
Erik Språng | 566124a | 2018-04-23 12:32:22 +0200 | [diff] [blame] | 58 | void OnBitrateAllocationUpdated(const VideoBitrateAllocation& bitrate); |
sprang | 1a646ee | 2016-12-01 06:34:11 -0800 | [diff] [blame] | 59 | |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 60 | private: |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 61 | void UpdateModuleSendingState() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
Peter Boström | 8b79b07 | 2016-02-26 16:31:37 +0100 | [diff] [blame] | 62 | |
pbos | d8de115 | 2016-02-01 09:00:51 -0800 | [diff] [blame] | 63 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 64 | bool active_ RTC_GUARDED_BY(crit_); |
mflodman@webrtc.org | 7ac374a | 2015-02-20 12:45:40 +0000 | [diff] [blame] | 65 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 66 | // Rtp modules are assumed to be sorted in simulcast index order. Not owned. |
| 67 | const std::vector<RtpRtcp*> rtp_modules_; |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 68 | const int payload_type_; |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 69 | |
Åsa Persson | 4bece9a | 2017-10-06 10:04:04 +0200 | [diff] [blame] | 70 | std::vector<RtpPayloadParams> params_ RTC_GUARDED_BY(crit_); |
| 71 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 72 | RTC_DISALLOW_COPY_AND_ASSIGN(PayloadRouter); |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | } // namespace webrtc |
| 76 | |
Stefan Holmer | a2f1533 | 2018-07-11 17:11:31 +0200 | [diff] [blame] | 77 | #endif // CALL_PAYLOAD_ROUTER_H_ |