blob: d74c6c2ed08fe9b109ad8009f856aab81e0d88e6 [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
14#ifndef WEBRTC_VIDEO_ENGINE_ENCODER_STATE_FEEDBACK_H_
15#define WEBRTC_VIDEO_ENGINE_ENCODER_STATE_FEEDBACK_H_
16
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
Peter Boström5cb9ce42015-05-05 15:16:30 +020038 // Update SSRCs for an encoder.
39 void UpdateSsrcs(const std::vector<uint32_t>& ssrc, ViEEncoder* encoder);
40
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000041 // Adds an encoder to receive feedback for a unique ssrc.
42 bool AddEncoder(uint32_t ssrc, ViEEncoder* encoder);
43
44 // Removes a registered ViEEncoder.
mflodman@webrtc.orgd6ec3862012-10-25 11:30:29 +000045 void RemoveEncoder(const ViEEncoder* encoder);
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000046
47 // Returns an observer to register at the requesting class. The observer has
48 // the same lifetime as the EncoderStateFeedback instance.
49 RtcpIntraFrameObserver* GetRtcpIntraFrameObserver();
50
51 protected:
52 // Called by EncoderStateFeedbackObserver when a new key frame is requested.
53 void OnReceivedIntraFrameRequest(uint32_t ssrc);
54 void OnReceivedSLI(uint32_t ssrc, uint8_t picture_id);
55 void OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id);
mflodman@webrtc.orgaca26292012-10-05 16:17:41 +000056 void OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc);
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000057
58 private:
59 typedef std::map<uint32_t, ViEEncoder*> SsrcEncoderMap;
60
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000061 rtc::scoped_ptr<CriticalSectionWrapper> crit_;
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000062
63 // Instance registered at the class requesting new key frames.
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000064 rtc::scoped_ptr<EncoderStateFeedbackObserver> observer_;
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000065
66 // Maps a unique ssrc to the given encoder.
67 SsrcEncoderMap encoders_;
68
69 DISALLOW_COPY_AND_ASSIGN(EncoderStateFeedback);
70};
71
72} // namespace webrtc
73
74#endif // WEBRTC_VIDEO_ENGINE_ENCODER_STATE_FEEDBACK_H_