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" |
21 #include "webrtc/media/base/videosinkinterface.h" | 22 #include "webrtc/media/base/videosinkinterface.h" |
22 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 23 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
23 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 24 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
24 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" | 25 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
25 #include "webrtc/modules/video_processing/include/video_processing.h" | 26 #include "webrtc/modules/video_processing/include/video_processing.h" |
26 #include "webrtc/typedefs.h" | 27 #include "webrtc/typedefs.h" |
27 | 28 |
28 namespace webrtc { | 29 namespace webrtc { |
29 | 30 |
30 class Config; | 31 class Config; |
31 class EncodedImageCallback; | 32 class EncodedImageCallback; |
32 class OveruseFrameDetector; | 33 class OveruseFrameDetector; |
33 class PacedSender; | 34 class PacedSender; |
34 class PayloadRouter; | 35 class PayloadRouter; |
35 class ProcessThread; | 36 class ProcessThread; |
36 class QMVideoSettingsCallback; | 37 class QMVideoSettingsCallback; |
37 class SendStatisticsProxy; | 38 class SendStatisticsProxy; |
38 class ViEBitrateObserver; | 39 class ViEBitrateObserver; |
39 class ViEEffectFilter; | 40 class ViEEffectFilter; |
40 class VideoCodingModule; | 41 class VideoCodingModule; |
41 class VideoEncoder; | 42 class VideoEncoder; |
42 | 43 |
43 class ViEEncoder : public VideoEncoderRateObserver, | 44 class ViEEncoder : public VideoEncoderRateObserver, |
| 45 public EncodedImageCallback, |
44 public VCMPacketizationCallback, | 46 public VCMPacketizationCallback, |
45 public VCMSendStatisticsCallback { | 47 public VCMSendStatisticsCallback { |
46 public: | 48 public: |
47 friend class ViEBitrateObserver; | 49 friend class ViEBitrateObserver; |
48 | 50 |
49 ViEEncoder(uint32_t number_of_cores, | 51 ViEEncoder(uint32_t number_of_cores, |
50 const std::vector<uint32_t>& ssrcs, | 52 const std::vector<uint32_t>& ssrcs, |
51 ProcessThread* module_process_thread, | 53 ProcessThread* module_process_thread, |
52 SendStatisticsProxy* stats_proxy, | 54 SendStatisticsProxy* stats_proxy, |
53 // TODO(nisse): Used only for tests, delete? | 55 // TODO(nisse): Used only for tests, delete? |
54 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 56 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
55 OveruseFrameDetector* overuse_detector, | 57 OveruseFrameDetector* overuse_detector, |
56 PacedSender* pacer, | 58 PacedSender* pacer, |
57 PayloadRouter* payload_router); | 59 PayloadRouter* payload_router, |
| 60 EncodedImageCallback* post_encode_callback); |
58 ~ViEEncoder(); | 61 ~ViEEncoder(); |
59 | 62 |
60 bool Init(); | 63 bool Init(); |
61 | 64 |
62 VideoCodingModule* vcm() const; | 65 VideoCodingModule* vcm() const; |
63 | 66 |
64 void SetNetworkTransmissionState(bool is_transmitting); | 67 void SetNetworkTransmissionState(bool is_transmitting); |
65 | 68 |
66 // Returns the id of the owning channel. | 69 // Returns the id of the owning channel. |
67 int Owner() const; | 70 int Owner() const; |
(...skipping 17 matching lines...) Expand all Loading... |
85 // Loss protection. Must be called before SetEncoder() to have max packet size | 88 // Loss protection. Must be called before SetEncoder() to have max packet size |
86 // updated according to protection. | 89 // updated according to protection. |
87 // TODO(pbos): Set protection method on construction or extract vcm_ outside | 90 // TODO(pbos): Set protection method on construction or extract vcm_ outside |
88 // this class and set it on construction there. | 91 // this class and set it on construction there. |
89 void SetProtectionMethod(bool nack, bool fec); | 92 void SetProtectionMethod(bool nack, bool fec); |
90 | 93 |
91 // Implements VideoEncoderRateObserver. | 94 // Implements VideoEncoderRateObserver. |
92 void OnSetRates(uint32_t bitrate_bps, int framerate) override; | 95 void OnSetRates(uint32_t bitrate_bps, int framerate) override; |
93 | 96 |
94 // Implements VCMPacketizationCallback. | 97 // 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; | |
99 void OnEncoderImplementationName(const char* implementation_name) override; | 98 void OnEncoderImplementationName(const char* implementation_name) override; |
100 | 99 |
| 100 // Implements EncodedImageCallback. |
| 101 int32_t Encoded(const EncodedImage& encoded_image, |
| 102 const CodecSpecificInfo* codec_specific_info, |
| 103 const RTPFragmentationHeader* fragmentation) override; |
| 104 |
101 // Implements VideoSendStatisticsCallback. | 105 // Implements VideoSendStatisticsCallback. |
102 int32_t SendStatistics(const uint32_t bit_rate, | 106 int32_t SendStatistics(const uint32_t bit_rate, |
103 const uint32_t frame_rate) override; | 107 const uint32_t frame_rate) override; |
104 | 108 |
105 // virtual to test EncoderStateFeedback with mocks. | 109 // virtual to test EncoderStateFeedback with mocks. |
106 virtual void OnReceivedIntraFrameRequest(uint32_t ssrc); | 110 virtual void OnReceivedIntraFrameRequest(uint32_t ssrc); |
107 virtual void OnReceivedSLI(uint32_t ssrc, uint8_t picture_id); | 111 virtual void OnReceivedSLI(uint32_t ssrc, uint8_t picture_id); |
108 virtual void OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id); | 112 virtual void OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id); |
109 | 113 |
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_; |
142 | 143 |
143 // The time we last received an input frame or encoded frame. This is used to | 144 // The time we last received an input frame or encoded frame. This is used to |
144 // track when video is stopped long enough that we also want to stop sending | 145 // track when video is stopped long enough that we also want to stop sending |
145 // padding. | 146 // padding. |
146 int64_t time_of_last_frame_activity_ms_ GUARDED_BY(data_cs_); | 147 int64_t time_of_last_frame_activity_ms_ GUARDED_BY(data_cs_); |
147 VideoCodec encoder_config_ GUARDED_BY(data_cs_); | 148 VideoCodec encoder_config_ GUARDED_BY(data_cs_); |
148 int min_transmit_bitrate_bps_ GUARDED_BY(data_cs_); | 149 int min_transmit_bitrate_bps_ GUARDED_BY(data_cs_); |
149 uint32_t last_observed_bitrate_bps_ GUARDED_BY(data_cs_); | 150 uint32_t last_observed_bitrate_bps_ GUARDED_BY(data_cs_); |
150 bool network_is_transmitting_ GUARDED_BY(data_cs_); | 151 bool network_is_transmitting_ GUARDED_BY(data_cs_); |
151 bool encoder_paused_ GUARDED_BY(data_cs_); | 152 bool encoder_paused_ GUARDED_BY(data_cs_); |
152 bool encoder_paused_and_dropped_frame_ GUARDED_BY(data_cs_); | 153 bool encoder_paused_and_dropped_frame_ GUARDED_BY(data_cs_); |
153 std::vector<int64_t> time_last_intra_request_ms_ GUARDED_BY(data_cs_); | 154 std::vector<int64_t> time_last_intra_request_ms_ GUARDED_BY(data_cs_); |
154 | 155 |
155 ProcessThread* module_process_thread_; | 156 ProcessThread* module_process_thread_; |
156 | 157 |
157 bool has_received_sli_ GUARDED_BY(data_cs_); | 158 bool has_received_sli_ GUARDED_BY(data_cs_); |
158 uint8_t picture_id_sli_ GUARDED_BY(data_cs_); | 159 uint8_t picture_id_sli_ GUARDED_BY(data_cs_); |
159 bool has_received_rpsi_ GUARDED_BY(data_cs_); | 160 bool has_received_rpsi_ GUARDED_BY(data_cs_); |
160 uint64_t picture_id_rpsi_ GUARDED_BY(data_cs_); | 161 uint64_t picture_id_rpsi_ GUARDED_BY(data_cs_); |
161 | 162 |
162 bool video_suspended_ GUARDED_BY(data_cs_); | 163 bool video_suspended_ GUARDED_BY(data_cs_); |
163 | 164 |
164 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers] GUARDED_BY(data_cs_); | 165 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers] GUARDED_BY(data_cs_); |
165 }; | 166 }; |
166 | 167 |
167 } // namespace webrtc | 168 } // namespace webrtc |
168 | 169 |
169 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ | 170 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ |
OLD | NEW |