blob: dc6284d03f6d1d92b8c3ad575fef8a9b39b1acf1 [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
Niels Möller9d138fc2018-02-15 16:58:43 +010029// Currently only VP8/VP9 specific.
30struct RtpPayloadState {
31 int16_t picture_id = -1;
Niels Möllerbb894ff2018-03-15 12:28:53 +010032 uint8_t tl0_pic_idx = 0;
Niels Möller9d138fc2018-02-15 16:58:43 +010033};
34
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000035// PayloadRouter routes outgoing data to the correct sending RTP module, based
36// on the simulcast layer in RTPVideoHeader.
kjellander02b3d272016-04-20 05:05:54 -070037class PayloadRouter : public EncodedImageCallback {
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000038 public:
Per83d09102016-04-15 14:59:13 +020039 // Rtp modules are assumed to be sorted in simulcast index order.
Sergey Ulanov525df3f2016-08-02 17:46:41 -070040 PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules,
Åsa Persson4bece9a2017-10-06 10:04:04 +020041 const std::vector<uint32_t>& ssrcs,
42 int payload_type,
43 const std::map<uint32_t, RtpPayloadState>& states);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000044 ~PayloadRouter();
45
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000046 // PayloadRouter will only route packets if being active, all packets will be
47 // dropped otherwise.
sprang1a646ee2016-12-01 06:34:11 -080048 void SetActive(bool active);
Seth Hampsoncc7125f2018-02-02 08:46:16 -080049 // Sets the sending status of the rtp modules and appropriately sets the
50 // payload router to active if any rtp modules are active.
51 void SetActiveModules(const std::vector<bool> active_modules);
sprang1a646ee2016-12-01 06:34:11 -080052 bool IsActive();
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000053
Åsa Persson4bece9a2017-10-06 10:04:04 +020054 std::map<uint32_t, RtpPayloadState> GetRtpPayloadStates() const;
55
kjellander02b3d272016-04-20 05:05:54 -070056 // Implements EncodedImageCallback.
57 // Returns 0 if the packet was routed / sent, -1 otherwise.
Sergey Ulanov525df3f2016-08-02 17:46:41 -070058 EncodedImageCallback::Result OnEncodedImage(
59 const EncodedImage& encoded_image,
60 const CodecSpecificInfo* codec_specific_info,
61 const RTPFragmentationHeader* fragmentation) override;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000062
Erik Språng566124a2018-04-23 12:32:22 +020063 void OnBitrateAllocationUpdated(const VideoBitrateAllocation& bitrate);
sprang1a646ee2016-12-01 06:34:11 -080064
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000065 private:
Åsa Persson4bece9a2017-10-06 10:04:04 +020066 class RtpPayloadParams;
67
danilchapa37de392017-09-09 04:17:22 -070068 void UpdateModuleSendingState() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
Peter Boström8b79b072016-02-26 16:31:37 +010069
pbosd8de1152016-02-01 09:00:51 -080070 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -070071 bool active_ RTC_GUARDED_BY(crit_);
mflodman@webrtc.org7ac374a2015-02-20 12:45:40 +000072
Per83d09102016-04-15 14:59:13 +020073 // Rtp modules are assumed to be sorted in simulcast index order. Not owned.
74 const std::vector<RtpRtcp*> rtp_modules_;
kjellander02b3d272016-04-20 05:05:54 -070075 const int payload_type_;
Per83d09102016-04-15 14:59:13 +020076
Åsa Persson4bece9a2017-10-06 10:04:04 +020077 std::vector<RtpPayloadParams> params_ RTC_GUARDED_BY(crit_);
78
henrikg3c089d72015-09-16 05:37:44 -070079 RTC_DISALLOW_COPY_AND_ASSIGN(PayloadRouter);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000080};
81
82} // namespace webrtc
83
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020084#endif // VIDEO_PAYLOAD_ROUTER_H_