blob: 4e0cdc35fc55b59317f07d78ac137b005120d80f [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>
18
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000019#include "webrtc/system_wrappers/interface/constructor_magic.h"
20#include "webrtc/system_wrappers/interface/scoped_ptr.h"
21#include "webrtc/typedefs.h"
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000022
23namespace webrtc {
24
25class CriticalSectionWrapper;
26class EncoderStateFeedbackObserver;
27class RtcpIntraFrameObserver;
28class ViEEncoder;
29
30class EncoderStateFeedback {
31 public:
32 friend class EncoderStateFeedbackObserver;
33
34 EncoderStateFeedback();
35 ~EncoderStateFeedback();
36
37 // Adds an encoder to receive feedback for a unique ssrc.
38 bool AddEncoder(uint32_t ssrc, ViEEncoder* encoder);
39
40 // Removes a registered ViEEncoder.
mflodman@webrtc.orgd6ec3862012-10-25 11:30:29 +000041 void RemoveEncoder(const ViEEncoder* encoder);
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000042
43 // Returns an observer to register at the requesting class. The observer has
44 // the same lifetime as the EncoderStateFeedback instance.
45 RtcpIntraFrameObserver* GetRtcpIntraFrameObserver();
46
47 protected:
48 // Called by EncoderStateFeedbackObserver when a new key frame is requested.
49 void OnReceivedIntraFrameRequest(uint32_t ssrc);
50 void OnReceivedSLI(uint32_t ssrc, uint8_t picture_id);
51 void OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id);
mflodman@webrtc.orgaca26292012-10-05 16:17:41 +000052 void OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc);
mflodman@webrtc.org3be58632012-09-06 08:19:40 +000053
54 private:
55 typedef std::map<uint32_t, ViEEncoder*> SsrcEncoderMap;
56
57 scoped_ptr<CriticalSectionWrapper> crit_;
58
59 // Instance registered at the class requesting new key frames.
60 scoped_ptr<EncoderStateFeedbackObserver> observer_;
61
62 // Maps a unique ssrc to the given encoder.
63 SsrcEncoderMap encoders_;
64
65 DISALLOW_COPY_AND_ASSIGN(EncoderStateFeedback);
66};
67
68} // namespace webrtc
69
70#endif // WEBRTC_VIDEO_ENGINE_ENCODER_STATE_FEEDBACK_H_