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 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 VCMGenericEncoder::VCMGenericEncoder(VideoEncoder* encoder, | 54 VCMGenericEncoder::VCMGenericEncoder(VideoEncoder* encoder, |
55 VideoEncoderRateObserver* rate_observer, | 55 VideoEncoderRateObserver* rate_observer, |
56 bool internalSource) | 56 bool internalSource) |
57 : encoder_(encoder), | 57 : encoder_(encoder), |
58 rate_observer_(rate_observer), | 58 rate_observer_(rate_observer), |
59 vcm_encoded_frame_callback_(nullptr), | 59 vcm_encoded_frame_callback_(nullptr), |
60 bit_rate_(0), | 60 bit_rate_(0), |
61 frame_rate_(0), | 61 frame_rate_(0), |
62 internal_source_(internalSource), | 62 internal_source_(internalSource), |
63 rotation_(kVideoRotation_0) { | 63 rotation_(kVideoRotation_0), |
64 } | 64 is_screenshare_(false) {} |
65 | 65 |
66 VCMGenericEncoder::~VCMGenericEncoder() | 66 VCMGenericEncoder::~VCMGenericEncoder() |
67 { | 67 { |
68 } | 68 } |
69 | 69 |
70 int32_t VCMGenericEncoder::Release() | 70 int32_t VCMGenericEncoder::Release() |
71 { | 71 { |
72 { | 72 { |
73 rtc::CritScope lock(&rates_lock_); | 73 rtc::CritScope lock(&rates_lock_); |
74 bit_rate_ = 0; | 74 bit_rate_ = 0; |
75 frame_rate_ = 0; | 75 frame_rate_ = 0; |
76 vcm_encoded_frame_callback_ = nullptr; | 76 vcm_encoded_frame_callback_ = nullptr; |
77 } | 77 } |
78 | 78 |
79 return encoder_->Release(); | 79 return encoder_->Release(); |
80 } | 80 } |
81 | 81 |
82 int32_t | 82 int32_t |
83 VCMGenericEncoder::InitEncode(const VideoCodec* settings, | 83 VCMGenericEncoder::InitEncode(const VideoCodec* settings, |
84 int32_t numberOfCores, | 84 int32_t numberOfCores, |
85 size_t maxPayloadSize) | 85 size_t maxPayloadSize) |
86 { | 86 { |
87 { | 87 { |
88 rtc::CritScope lock(&rates_lock_); | 88 rtc::CritScope lock(&rates_lock_); |
89 bit_rate_ = settings->startBitrate * 1000; | 89 bit_rate_ = settings->startBitrate * 1000; |
90 frame_rate_ = settings->maxFramerate; | 90 frame_rate_ = settings->maxFramerate; |
91 } | 91 } |
92 | 92 |
| 93 is_screenshare_ = settings->mode == VideoCodecMode::kScreensharing; |
93 if (encoder_->InitEncode(settings, numberOfCores, maxPayloadSize) != 0) { | 94 if (encoder_->InitEncode(settings, numberOfCores, maxPayloadSize) != 0) { |
94 LOG(LS_ERROR) << "Failed to initialize the encoder associated with " | 95 LOG(LS_ERROR) << "Failed to initialize the encoder associated with " |
95 "payload name: " << settings->plName; | 96 "payload name: " << settings->plName; |
96 return -1; | 97 return -1; |
97 } | 98 } |
98 return 0; | 99 return 0; |
99 } | 100 } |
100 | 101 |
101 int32_t VCMGenericEncoder::Encode(const VideoFrame& inputFrame, | 102 int32_t VCMGenericEncoder::Encode(const VideoFrame& inputFrame, |
102 const CodecSpecificInfo* codecSpecificInfo, | 103 const CodecSpecificInfo* codecSpecificInfo, |
103 const std::vector<FrameType>& frameTypes) { | 104 const std::vector<FrameType>& frameTypes) { |
104 std::vector<VideoFrameType> video_frame_types(frameTypes.size(), | 105 std::vector<VideoFrameType> video_frame_types(frameTypes.size(), |
105 kDeltaFrame); | 106 kDeltaFrame); |
106 VCMEncodedFrame::ConvertFrameTypes(frameTypes, &video_frame_types); | 107 VCMEncodedFrame::ConvertFrameTypes(frameTypes, &video_frame_types); |
107 | 108 |
108 rotation_ = inputFrame.rotation(); | 109 rotation_ = inputFrame.rotation(); |
109 | 110 |
110 if (vcm_encoded_frame_callback_) { | 111 if (vcm_encoded_frame_callback_) { |
111 // Keep track of the current frame rotation and apply to the output of the | 112 // Keep track of the current frame rotation and apply to the output of the |
112 // encoder. There might not be exact as the encoder could have one frame | 113 // encoder. There might not be exact as the encoder could have one frame |
113 // delay but it should be close enough. | 114 // delay but it should be close enough. |
114 vcm_encoded_frame_callback_->SetRotation(rotation_); | 115 vcm_encoded_frame_callback_->SetRotation(rotation_); |
115 } | 116 } |
116 | 117 |
117 return encoder_->Encode(inputFrame, codecSpecificInfo, &video_frame_types); | 118 int32_t result = |
| 119 encoder_->Encode(inputFrame, codecSpecificInfo, &video_frame_types); |
| 120 if (is_screenshare_ && |
| 121 result == WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT) { |
| 122 // Target bitrate exceeded, encoder state has been reset - try again. |
| 123 return encoder_->Encode(inputFrame, codecSpecificInfo, &video_frame_types); |
| 124 } |
| 125 |
| 126 return result; |
118 } | 127 } |
119 | 128 |
120 int32_t | 129 int32_t |
121 VCMGenericEncoder::SetChannelParameters(int32_t packetLoss, int64_t rtt) | 130 VCMGenericEncoder::SetChannelParameters(int32_t packetLoss, int64_t rtt) |
122 { | 131 { |
123 return encoder_->SetChannelParameters(packetLoss, rtt); | 132 return encoder_->SetChannelParameters(packetLoss, rtt); |
124 } | 133 } |
125 | 134 |
126 int32_t | 135 int32_t |
127 VCMGenericEncoder::SetRates(uint32_t newBitRate, uint32_t frameRate) | 136 VCMGenericEncoder::SetRates(uint32_t newBitRate, uint32_t frameRate) |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 288 } |
280 | 289 |
281 void | 290 void |
282 VCMEncodedFrameCallback::SetMediaOpt( | 291 VCMEncodedFrameCallback::SetMediaOpt( |
283 media_optimization::MediaOptimization *mediaOpt) | 292 media_optimization::MediaOptimization *mediaOpt) |
284 { | 293 { |
285 _mediaOpt = mediaOpt; | 294 _mediaOpt = mediaOpt; |
286 } | 295 } |
287 | 296 |
288 } // namespace webrtc | 297 } // namespace webrtc |
OLD | NEW |