blob: 9ddbce19884145a39bc1d31d48e696679f03e3c0 [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
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000014#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/video_codecs/video_encoder.h"
17#include "common_types.h"
18#include "rtc_base/constructormagic.h"
19#include "rtc_base/criticalsection.h"
20#include "rtc_base/thread_annotations.h"
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000021
22namespace webrtc {
23
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000024class RTPFragmentationHeader;
25class RtpRtcp;
26struct RTPVideoHeader;
27
28// PayloadRouter routes outgoing data to the correct sending RTP module, based
29// on the simulcast layer in RTPVideoHeader.
kjellander02b3d272016-04-20 05:05:54 -070030class PayloadRouter : public EncodedImageCallback {
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000031 public:
Per83d09102016-04-15 14:59:13 +020032 // Rtp modules are assumed to be sorted in simulcast index order.
Sergey Ulanov525df3f2016-08-02 17:46:41 -070033 PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules,
34 int payload_type);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000035 ~PayloadRouter();
36
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000037 // PayloadRouter will only route packets if being active, all packets will be
38 // dropped otherwise.
sprang1a646ee2016-12-01 06:34:11 -080039 void SetActive(bool active);
40 bool IsActive();
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000041
kjellander02b3d272016-04-20 05:05:54 -070042 // Implements EncodedImageCallback.
43 // Returns 0 if the packet was routed / sent, -1 otherwise.
Sergey Ulanov525df3f2016-08-02 17:46:41 -070044 EncodedImageCallback::Result OnEncodedImage(
45 const EncodedImage& encoded_image,
46 const CodecSpecificInfo* codec_specific_info,
47 const RTPFragmentationHeader* fragmentation) override;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000048
sprang1a646ee2016-12-01 06:34:11 -080049 void OnBitrateAllocationUpdated(const BitrateAllocation& bitrate);
50
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000051 private:
danilchapa37de392017-09-09 04:17:22 -070052 void UpdateModuleSendingState() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
Peter Boström8b79b072016-02-26 16:31:37 +010053
pbosd8de1152016-02-01 09:00:51 -080054 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -070055 bool active_ RTC_GUARDED_BY(crit_);
mflodman@webrtc.org7ac374a2015-02-20 12:45:40 +000056
Per83d09102016-04-15 14:59:13 +020057 // Rtp modules are assumed to be sorted in simulcast index order. Not owned.
58 const std::vector<RtpRtcp*> rtp_modules_;
kjellander02b3d272016-04-20 05:05:54 -070059 const int payload_type_;
Per83d09102016-04-15 14:59:13 +020060
henrikg3c089d72015-09-16 05:37:44 -070061 RTC_DISALLOW_COPY_AND_ASSIGN(PayloadRouter);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000062};
63
64} // namespace webrtc
65
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020066#endif // VIDEO_PAYLOAD_ROUTER_H_