OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 SFrameBSInfo* info, | 88 SFrameBSInfo* info, |
89 RTPFragmentationHeader* frag_header) { | 89 RTPFragmentationHeader* frag_header) { |
90 // Calculate minimum buffer size required to hold encoded data. | 90 // Calculate minimum buffer size required to hold encoded data. |
91 size_t required_size = 0; | 91 size_t required_size = 0; |
92 size_t fragments_count = 0; | 92 size_t fragments_count = 0; |
93 for (int layer = 0; layer < info->iLayerNum; ++layer) { | 93 for (int layer = 0; layer < info->iLayerNum; ++layer) { |
94 const SLayerBSInfo& layerInfo = info->sLayerInfo[layer]; | 94 const SLayerBSInfo& layerInfo = info->sLayerInfo[layer]; |
95 for (int nal = 0; nal < layerInfo.iNalCount; ++nal, ++fragments_count) { | 95 for (int nal = 0; nal < layerInfo.iNalCount; ++nal, ++fragments_count) { |
96 RTC_CHECK_GE(layerInfo.pNalLengthInByte[nal], 0); | 96 RTC_CHECK_GE(layerInfo.pNalLengthInByte[nal], 0); |
97 // Ensure |required_size| will not overflow. | 97 // Ensure |required_size| will not overflow. |
98 RTC_CHECK_LE(static_cast<size_t>(layerInfo.pNalLengthInByte[nal]), | 98 RTC_CHECK_LE(layerInfo.pNalLengthInByte[nal], |
99 std::numeric_limits<size_t>::max() - required_size); | 99 std::numeric_limits<size_t>::max() - required_size); |
100 required_size += layerInfo.pNalLengthInByte[nal]; | 100 required_size += layerInfo.pNalLengthInByte[nal]; |
101 } | 101 } |
102 } | 102 } |
103 if (encoded_image->_size < required_size) { | 103 if (encoded_image->_size < required_size) { |
104 // Increase buffer size. Allocate enough to hold an unencoded image, this | 104 // Increase buffer size. Allocate enough to hold an unencoded image, this |
105 // should be more than enough to hold any encoded data of future frames of | 105 // should be more than enough to hold any encoded data of future frames of |
106 // the same size (avoiding possible future reallocation due to variations in | 106 // the same size (avoiding possible future reallocation due to variations in |
107 // required size). | 107 // required size). |
108 encoded_image->_size = | 108 encoded_image->_size = |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 width_ = frame_buffer->width(); | 319 width_ = frame_buffer->width(); |
320 height_ = frame_buffer->height(); | 320 height_ = frame_buffer->height(); |
321 SEncParamExt encoder_params = CreateEncoderParams(); | 321 SEncParamExt encoder_params = CreateEncoderParams(); |
322 openh264_encoder_->SetOption(ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, | 322 openh264_encoder_->SetOption(ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, |
323 &encoder_params); | 323 &encoder_params); |
324 } | 324 } |
325 | 325 |
326 bool force_key_frame = false; | 326 bool force_key_frame = false; |
327 if (frame_types != nullptr) { | 327 if (frame_types != nullptr) { |
328 // We only support a single stream. | 328 // We only support a single stream. |
329 RTC_DCHECK_EQ(frame_types->size(), static_cast<size_t>(1)); | 329 RTC_DCHECK_EQ(frame_types->size(), 1); |
330 // Skip frame? | 330 // Skip frame? |
331 if ((*frame_types)[0] == kEmptyFrame) { | 331 if ((*frame_types)[0] == kEmptyFrame) { |
332 return WEBRTC_VIDEO_CODEC_OK; | 332 return WEBRTC_VIDEO_CODEC_OK; |
333 } | 333 } |
334 // Force key frame? | 334 // Force key frame? |
335 force_key_frame = (*frame_types)[0] == kVideoFrameKey; | 335 force_key_frame = (*frame_types)[0] == kVideoFrameKey; |
336 } | 336 } |
337 if (force_key_frame) { | 337 if (force_key_frame) { |
338 // API doc says ForceIntraFrame(false) does nothing, but calling this | 338 // API doc says ForceIntraFrame(false) does nothing, but calling this |
339 // function forces a key frame regardless of the |bIDR| argument's value. | 339 // function forces a key frame regardless of the |bIDR| argument's value. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 498 |
499 int32_t H264EncoderImpl::SetPeriodicKeyFrames(bool enable) { | 499 int32_t H264EncoderImpl::SetPeriodicKeyFrames(bool enable) { |
500 return WEBRTC_VIDEO_CODEC_OK; | 500 return WEBRTC_VIDEO_CODEC_OK; |
501 } | 501 } |
502 | 502 |
503 void H264EncoderImpl::OnDroppedFrame() { | 503 void H264EncoderImpl::OnDroppedFrame() { |
504 quality_scaler_.ReportDroppedFrame(); | 504 quality_scaler_.ReportDroppedFrame(); |
505 } | 505 } |
506 | 506 |
507 } // namespace webrtc | 507 } // namespace webrtc |
OLD | NEW |