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