blob: 620e382d89060769c277075cc2b9665121074b6c [file] [log] [blame]
mflodman@webrtc.org3be58632012-09-06 08:19:40 +00001/*
2 * Copyright (c) 2012 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
11// TODO(mflodman) ViEEncoder has a time check to not send key frames too often,
12// move the logic to this class.
13
Peter Boström7623ce42015-12-09 12:13:30 +010014#ifndef WEBRTC_VIDEO_ENCODER_STATE_FEEDBACK_H_
15#define WEBRTC_VIDEO_ENCODER_STATE_FEEDBACK_H_
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000016
17#include <map>
Peter Boström5cb9ce42015-05-05 15:16:30 +020018#include <vector>
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000019
henrike@webrtc.org88fbb2d2014-05-21 21:18:46 +000020#include "webrtc/base/constructormagic.h"
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000021#include "webrtc/base/scoped_ptr.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000022#include "webrtc/typedefs.h"
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000023
24namespace webrtc {
25
26class CriticalSectionWrapper;
27class EncoderStateFeedbackObserver;
28class RtcpIntraFrameObserver;
29class ViEEncoder;
30
31class EncoderStateFeedback {
32 public:
33 friend class EncoderStateFeedbackObserver;
34
35 EncoderStateFeedback();
36 ~EncoderStateFeedback();
37
pbos8ff04d62015-07-20 08:01:17 -070038 // Adds an encoder to receive feedback for a set of SSRCs.
39 void AddEncoder(const std::vector<uint32_t>& ssrc, ViEEncoder* encoder);
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000040
41 // Removes a registered ViEEncoder.
mflodman@webrtc.orgd6ec3862012-10-25 11:30:29 +000042 void RemoveEncoder(const ViEEncoder* encoder);
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000043
44 // Returns an observer to register at the requesting class. The observer has
45 // the same lifetime as the EncoderStateFeedback instance.
46 RtcpIntraFrameObserver* GetRtcpIntraFrameObserver();
47
48 protected:
49 // Called by EncoderStateFeedbackObserver when a new key frame is requested.
50 void OnReceivedIntraFrameRequest(uint32_t ssrc);
51 void OnReceivedSLI(uint32_t ssrc, uint8_t picture_id);
52 void OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id);
mflodman@webrtc.orgaca26292012-10-05 16:17:41 +000053 void OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc);
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000054
55 private:
56 typedef std::map<uint32_t, ViEEncoder*> SsrcEncoderMap;
57
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000058 rtc::scoped_ptr<CriticalSectionWrapper> crit_;
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000059
60 // Instance registered at the class requesting new key frames.
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000061 rtc::scoped_ptr<EncoderStateFeedbackObserver> observer_;
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000062
63 // Maps a unique ssrc to the given encoder.
64 SsrcEncoderMap encoders_;
65
henrikg3c089d72015-09-16 05:37:44 -070066 RTC_DISALLOW_COPY_AND_ASSIGN(EncoderStateFeedback);
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000067};
68
69} // namespace webrtc
70
Peter Boström7623ce42015-12-09 12:13:30 +010071#endif // WEBRTC_VIDEO_ENCODER_STATE_FEEDBACK_H_