blob: 13b6cae7ce8159f74884abe172ab64ce95256498 [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
29// PayloadRouter routes outgoing data to the correct sending RTP module, based
30// on the simulcast layer in RTPVideoHeader.
kjellander02b3d272016-04-20 05:05:54 -070031class PayloadRouter : public EncodedImageCallback {
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000032 public:
Per83d09102016-04-15 14:59:13 +020033 // Rtp modules are assumed to be sorted in simulcast index order.
Sergey Ulanov525df3f2016-08-02 17:46:41 -070034 PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules,
Åsa Persson4bece9a2017-10-06 10:04:04 +020035 const std::vector<uint32_t>& ssrcs,
36 int payload_type,
37 const std::map<uint32_t, RtpPayloadState>& states);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000038 ~PayloadRouter();
39
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000040 // PayloadRouter will only route packets if being active, all packets will be
41 // dropped otherwise.
sprang1a646ee2016-12-01 06:34:11 -080042 void SetActive(bool active);
43 bool IsActive();
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000044
Åsa Persson4bece9a2017-10-06 10:04:04 +020045 std::map<uint32_t, RtpPayloadState> GetRtpPayloadStates() const;
46
kjellander02b3d272016-04-20 05:05:54 -070047 // Implements EncodedImageCallback.
48 // Returns 0 if the packet was routed / sent, -1 otherwise.
Sergey Ulanov525df3f2016-08-02 17:46:41 -070049 EncodedImageCallback::Result OnEncodedImage(
50 const EncodedImage& encoded_image,
51 const CodecSpecificInfo* codec_specific_info,
52 const RTPFragmentationHeader* fragmentation) override;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000053
sprang1a646ee2016-12-01 06:34:11 -080054 void OnBitrateAllocationUpdated(const BitrateAllocation& bitrate);
55
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000056 private:
Åsa Persson4bece9a2017-10-06 10:04:04 +020057 class RtpPayloadParams;
58
danilchapa37de392017-09-09 04:17:22 -070059 void UpdateModuleSendingState() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
Peter Boström8b79b072016-02-26 16:31:37 +010060
pbosd8de1152016-02-01 09:00:51 -080061 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -070062 bool active_ RTC_GUARDED_BY(crit_);
mflodman@webrtc.org7ac374a2015-02-20 12:45:40 +000063
Per83d09102016-04-15 14:59:13 +020064 // Rtp modules are assumed to be sorted in simulcast index order. Not owned.
65 const std::vector<RtpRtcp*> rtp_modules_;
kjellander02b3d272016-04-20 05:05:54 -070066 const int payload_type_;
Per83d09102016-04-15 14:59:13 +020067
Åsa Persson4bece9a2017-10-06 10:04:04 +020068 const bool forced_fallback_enabled_;
69 std::vector<RtpPayloadParams> params_ RTC_GUARDED_BY(crit_);
70
henrikg3c089d72015-09-16 05:37:44 -070071 RTC_DISALLOW_COPY_AND_ASSIGN(PayloadRouter);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000072};
73
74} // namespace webrtc
75
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020076#endif // VIDEO_PAYLOAD_ROUTER_H_