OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_VIDEO_VIE_ENCODER_H_ | 11 #ifndef WEBRTC_VIDEO_VIE_ENCODER_H_ |
12 #define WEBRTC_VIDEO_VIE_ENCODER_H_ | 12 #define WEBRTC_VIDEO_VIE_ENCODER_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/base/criticalsection.h" | 17 #include "webrtc/base/criticalsection.h" |
18 #include "webrtc/base/scoped_ref_ptr.h" | 18 #include "webrtc/base/scoped_ref_ptr.h" |
19 #include "webrtc/base/thread_annotations.h" | 19 #include "webrtc/base/thread_annotations.h" |
20 #include "webrtc/common_types.h" | 20 #include "webrtc/common_types.h" |
21 #include "webrtc/video_encoder.h" | |
22 #include "webrtc/media/base/videosinkinterface.h" | 21 #include "webrtc/media/base/videosinkinterface.h" |
23 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 22 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
24 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 23 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
25 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" | 24 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
26 #include "webrtc/modules/video_processing/include/video_processing.h" | 25 #include "webrtc/modules/video_processing/include/video_processing.h" |
27 #include "webrtc/typedefs.h" | 26 #include "webrtc/typedefs.h" |
28 | 27 |
29 namespace webrtc { | 28 namespace webrtc { |
30 | 29 |
31 class Config; | 30 class Config; |
32 class EncodedImageCallback; | 31 class EncodedImageCallback; |
33 class OveruseFrameDetector; | 32 class OveruseFrameDetector; |
34 class PacedSender; | 33 class PacedSender; |
35 class PayloadRouter; | 34 class PayloadRouter; |
36 class ProcessThread; | 35 class ProcessThread; |
37 class QMVideoSettingsCallback; | 36 class QMVideoSettingsCallback; |
38 class SendStatisticsProxy; | 37 class SendStatisticsProxy; |
39 class ViEBitrateObserver; | 38 class ViEBitrateObserver; |
40 class ViEEffectFilter; | 39 class ViEEffectFilter; |
41 class VideoCodingModule; | 40 class VideoCodingModule; |
42 class VideoEncoder; | 41 class VideoEncoder; |
43 | 42 |
44 class ViEEncoder : public VideoEncoderRateObserver, | 43 class ViEEncoder : public VideoEncoderRateObserver, |
45 public EncodedImageCallback, | |
46 public VCMPacketizationCallback, | 44 public VCMPacketizationCallback, |
47 public VCMSendStatisticsCallback { | 45 public VCMSendStatisticsCallback { |
48 public: | 46 public: |
49 friend class ViEBitrateObserver; | 47 friend class ViEBitrateObserver; |
50 | 48 |
51 ViEEncoder(uint32_t number_of_cores, | 49 ViEEncoder(uint32_t number_of_cores, |
52 const std::vector<uint32_t>& ssrcs, | 50 const std::vector<uint32_t>& ssrcs, |
53 ProcessThread* module_process_thread, | 51 ProcessThread* module_process_thread, |
54 SendStatisticsProxy* stats_proxy, | 52 SendStatisticsProxy* stats_proxy, |
55 // TODO(nisse): Used only for tests, delete? | 53 // TODO(nisse): Used only for tests, delete? |
56 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 54 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
57 OveruseFrameDetector* overuse_detector, | 55 OveruseFrameDetector* overuse_detector, |
58 PacedSender* pacer, | 56 PacedSender* pacer, |
59 PayloadRouter* payload_router, | 57 PayloadRouter* payload_router); |
60 EncodedImageCallback* post_encode_callback); | |
61 ~ViEEncoder(); | 58 ~ViEEncoder(); |
62 | 59 |
63 bool Init(); | 60 bool Init(); |
64 | 61 |
65 VideoCodingModule* vcm() const; | 62 VideoCodingModule* vcm() const; |
66 | 63 |
67 void SetNetworkTransmissionState(bool is_transmitting); | 64 void SetNetworkTransmissionState(bool is_transmitting); |
68 | 65 |
69 // Returns the id of the owning channel. | 66 // Returns the id of the owning channel. |
70 int Owner() const; | 67 int Owner() const; |
(...skipping 17 matching lines...) Expand all Loading... |
88 // Loss protection. Must be called before SetEncoder() to have max packet size | 85 // Loss protection. Must be called before SetEncoder() to have max packet size |
89 // updated according to protection. | 86 // updated according to protection. |
90 // TODO(pbos): Set protection method on construction or extract vcm_ outside | 87 // TODO(pbos): Set protection method on construction or extract vcm_ outside |
91 // this class and set it on construction there. | 88 // this class and set it on construction there. |
92 void SetProtectionMethod(bool nack, bool fec); | 89 void SetProtectionMethod(bool nack, bool fec); |
93 | 90 |
94 // Implements VideoEncoderRateObserver. | 91 // Implements VideoEncoderRateObserver. |
95 void OnSetRates(uint32_t bitrate_bps, int framerate) override; | 92 void OnSetRates(uint32_t bitrate_bps, int framerate) override; |
96 | 93 |
97 // Implements VCMPacketizationCallback. | 94 // Implements VCMPacketizationCallback. |
| 95 int32_t SendData(uint8_t payload_type, |
| 96 const EncodedImage& encoded_image, |
| 97 const RTPFragmentationHeader* fragmentation_header, |
| 98 const RTPVideoHeader* rtp_video_hdr) override; |
98 void OnEncoderImplementationName(const char* implementation_name) override; | 99 void OnEncoderImplementationName(const char* implementation_name) override; |
99 | 100 |
100 // Implements EncodedImageCallback. | |
101 int32_t Encoded(const EncodedImage& encoded_image, | |
102 const CodecSpecificInfo* codec_specific_info, | |
103 const RTPFragmentationHeader* fragmentation) override; | |
104 | |
105 // Implements VideoSendStatisticsCallback. | 101 // Implements VideoSendStatisticsCallback. |
106 int32_t SendStatistics(const uint32_t bit_rate, | 102 int32_t SendStatistics(const uint32_t bit_rate, |
107 const uint32_t frame_rate) override; | 103 const uint32_t frame_rate) override; |
108 | 104 |
109 // virtual to test EncoderStateFeedback with mocks. | 105 // virtual to test EncoderStateFeedback with mocks. |
110 virtual void OnReceivedIntraFrameRequest(uint32_t ssrc); | 106 virtual void OnReceivedIntraFrameRequest(uint32_t ssrc); |
111 virtual void OnReceivedSLI(uint32_t ssrc, uint8_t picture_id); | 107 virtual void OnReceivedSLI(uint32_t ssrc, uint8_t picture_id); |
112 virtual void OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id); | 108 virtual void OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id); |
113 | 109 |
| 110 // New-style callbacks, used by VideoSendStream. |
| 111 void RegisterPostEncodeImageCallback( |
| 112 EncodedImageCallback* post_encode_callback); |
| 113 |
114 int GetPaddingNeededBps() const; | 114 int GetPaddingNeededBps() const; |
115 | 115 |
116 void OnBitrateUpdated(uint32_t bitrate_bps, | 116 void OnBitrateUpdated(uint32_t bitrate_bps, |
117 uint8_t fraction_lost, | 117 uint8_t fraction_lost, |
118 int64_t round_trip_time_ms); | 118 int64_t round_trip_time_ms); |
119 | 119 |
120 private: | 120 private: |
121 static const bool kEnableFrameRecording = false; | 121 static const bool kEnableFrameRecording = false; |
122 static const int kMaxLayers = 3; | 122 static const int kMaxLayers = 3; |
123 | 123 |
124 bool EncoderPaused() const EXCLUSIVE_LOCKS_REQUIRED(data_cs_); | 124 bool EncoderPaused() const EXCLUSIVE_LOCKS_REQUIRED(data_cs_); |
125 void TraceFrameDropStart() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); | 125 void TraceFrameDropStart() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); |
126 void TraceFrameDropEnd() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); | 126 void TraceFrameDropEnd() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); |
127 | 127 |
128 const uint32_t number_of_cores_; | 128 const uint32_t number_of_cores_; |
129 const std::vector<uint32_t> ssrcs_; | 129 const std::vector<uint32_t> ssrcs_; |
130 | 130 |
131 const std::unique_ptr<VideoProcessing> vp_; | 131 const std::unique_ptr<VideoProcessing> vp_; |
132 const std::unique_ptr<QMVideoSettingsCallback> qm_callback_; | 132 const std::unique_ptr<QMVideoSettingsCallback> qm_callback_; |
133 const std::unique_ptr<VideoCodingModule> vcm_; | 133 const std::unique_ptr<VideoCodingModule> vcm_; |
134 | 134 |
135 rtc::CriticalSection data_cs_; | 135 rtc::CriticalSection data_cs_; |
136 | 136 |
137 SendStatisticsProxy* const stats_proxy_; | 137 SendStatisticsProxy* const stats_proxy_; |
138 rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_; | 138 rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_; |
139 OveruseFrameDetector* const overuse_detector_; | 139 OveruseFrameDetector* const overuse_detector_; |
140 PacedSender* const pacer_; | 140 PacedSender* const pacer_; |
141 PayloadRouter* const send_payload_router_; | 141 PayloadRouter* const send_payload_router_; |
142 EncodedImageCallback* const post_encode_callback_; | |
143 | 142 |
144 // The time we last received an input frame or encoded frame. This is used to | 143 // The time we last received an input frame or encoded frame. This is used to |
145 // track when video is stopped long enough that we also want to stop sending | 144 // track when video is stopped long enough that we also want to stop sending |
146 // padding. | 145 // padding. |
147 int64_t time_of_last_frame_activity_ms_ GUARDED_BY(data_cs_); | 146 int64_t time_of_last_frame_activity_ms_ GUARDED_BY(data_cs_); |
148 VideoCodec encoder_config_ GUARDED_BY(data_cs_); | 147 VideoCodec encoder_config_ GUARDED_BY(data_cs_); |
149 int min_transmit_bitrate_bps_ GUARDED_BY(data_cs_); | 148 int min_transmit_bitrate_bps_ GUARDED_BY(data_cs_); |
150 uint32_t last_observed_bitrate_bps_ GUARDED_BY(data_cs_); | 149 uint32_t last_observed_bitrate_bps_ GUARDED_BY(data_cs_); |
151 bool network_is_transmitting_ GUARDED_BY(data_cs_); | 150 bool network_is_transmitting_ GUARDED_BY(data_cs_); |
152 bool encoder_paused_ GUARDED_BY(data_cs_); | 151 bool encoder_paused_ GUARDED_BY(data_cs_); |
153 bool encoder_paused_and_dropped_frame_ GUARDED_BY(data_cs_); | 152 bool encoder_paused_and_dropped_frame_ GUARDED_BY(data_cs_); |
154 std::vector<int64_t> time_last_intra_request_ms_ GUARDED_BY(data_cs_); | 153 std::vector<int64_t> time_last_intra_request_ms_ GUARDED_BY(data_cs_); |
155 | 154 |
156 ProcessThread* module_process_thread_; | 155 ProcessThread* module_process_thread_; |
157 | 156 |
158 bool has_received_sli_ GUARDED_BY(data_cs_); | 157 bool has_received_sli_ GUARDED_BY(data_cs_); |
159 uint8_t picture_id_sli_ GUARDED_BY(data_cs_); | 158 uint8_t picture_id_sli_ GUARDED_BY(data_cs_); |
160 bool has_received_rpsi_ GUARDED_BY(data_cs_); | 159 bool has_received_rpsi_ GUARDED_BY(data_cs_); |
161 uint64_t picture_id_rpsi_ GUARDED_BY(data_cs_); | 160 uint64_t picture_id_rpsi_ GUARDED_BY(data_cs_); |
162 | 161 |
163 bool video_suspended_ GUARDED_BY(data_cs_); | 162 bool video_suspended_ GUARDED_BY(data_cs_); |
164 | 163 |
165 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers] GUARDED_BY(data_cs_); | 164 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers] GUARDED_BY(data_cs_); |
166 }; | 165 }; |
167 | 166 |
168 } // namespace webrtc | 167 } // namespace webrtc |
169 | 168 |
170 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ | 169 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ |
OLD | NEW |