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 */ |
11 | 11 |
12 #include "webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.h" | 12 #include "webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.h" |
13 | 13 |
14 #include <limits> | 14 #include <limits> |
15 | 15 |
16 #include "third_party/openh264/src/codec/api/svc/codec_api.h" | 16 #include "third_party/openh264/src/codec/api/svc/codec_api.h" |
17 #include "third_party/openh264/src/codec/api/svc/codec_app_def.h" | 17 #include "third_party/openh264/src/codec/api/svc/codec_app_def.h" |
18 #include "third_party/openh264/src/codec/api/svc/codec_def.h" | 18 #include "third_party/openh264/src/codec/api/svc/codec_def.h" |
| 19 #include "third_party/openh264/src/codec/api/svc/codec_ver.h" |
19 | 20 |
20 #include "webrtc/base/checks.h" | 21 #include "webrtc/base/checks.h" |
21 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 23 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
23 #include "webrtc/system_wrappers/include/metrics.h" | 24 #include "webrtc/system_wrappers/include/metrics.h" |
24 | 25 |
25 namespace webrtc { | 26 namespace webrtc { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // Copy the entire layer's data (including start codes). | 143 // Copy the entire layer's data (including start codes). |
143 memcpy(encoded_image->_buffer + encoded_image->_length, | 144 memcpy(encoded_image->_buffer + encoded_image->_length, |
144 layerInfo.pBsBuf, | 145 layerInfo.pBsBuf, |
145 layer_len); | 146 layer_len); |
146 encoded_image->_length += layer_len; | 147 encoded_image->_length += layer_len; |
147 } | 148 } |
148 } | 149 } |
149 | 150 |
150 H264EncoderImpl::H264EncoderImpl() | 151 H264EncoderImpl::H264EncoderImpl() |
151 : openh264_encoder_(nullptr), | 152 : openh264_encoder_(nullptr), |
| 153 number_of_cores_(0), |
152 encoded_image_callback_(nullptr), | 154 encoded_image_callback_(nullptr), |
153 has_reported_init_(false), | 155 has_reported_init_(false), |
154 has_reported_error_(false) { | 156 has_reported_error_(false) {} |
155 } | |
156 | 157 |
157 H264EncoderImpl::~H264EncoderImpl() { | 158 H264EncoderImpl::~H264EncoderImpl() { |
158 Release(); | 159 Release(); |
159 } | 160 } |
160 | 161 |
161 int32_t H264EncoderImpl::InitEncode(const VideoCodec* codec_settings, | 162 int32_t H264EncoderImpl::InitEncode(const VideoCodec* codec_settings, |
162 int32_t number_of_cores, | 163 int32_t number_of_cores, |
163 size_t /*max_payload_size*/) { | 164 size_t /*max_payload_size*/) { |
164 ReportInit(); | 165 ReportInit(); |
165 if (!codec_settings || | 166 if (!codec_settings || |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 encoder_params.iMultipleThreadIdc = NumberOfThreads( | 432 encoder_params.iMultipleThreadIdc = NumberOfThreads( |
432 encoder_params.iPicWidth, encoder_params.iPicHeight, number_of_cores_); | 433 encoder_params.iPicWidth, encoder_params.iPicHeight, number_of_cores_); |
433 // The base spatial layer 0 is the only one we use. | 434 // The base spatial layer 0 is the only one we use. |
434 encoder_params.sSpatialLayers[0].iVideoWidth = encoder_params.iPicWidth; | 435 encoder_params.sSpatialLayers[0].iVideoWidth = encoder_params.iPicWidth; |
435 encoder_params.sSpatialLayers[0].iVideoHeight = encoder_params.iPicHeight; | 436 encoder_params.sSpatialLayers[0].iVideoHeight = encoder_params.iPicHeight; |
436 encoder_params.sSpatialLayers[0].fFrameRate = encoder_params.fMaxFrameRate; | 437 encoder_params.sSpatialLayers[0].fFrameRate = encoder_params.fMaxFrameRate; |
437 encoder_params.sSpatialLayers[0].iSpatialBitrate = | 438 encoder_params.sSpatialLayers[0].iSpatialBitrate = |
438 encoder_params.iTargetBitrate; | 439 encoder_params.iTargetBitrate; |
439 encoder_params.sSpatialLayers[0].iMaxSpatialBitrate = | 440 encoder_params.sSpatialLayers[0].iMaxSpatialBitrate = |
440 encoder_params.iMaxBitrate; | 441 encoder_params.iMaxBitrate; |
| 442 #if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5) |
441 // Slice num according to number of threads. | 443 // Slice num according to number of threads. |
442 encoder_params.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_AUTO_SLICE; | 444 encoder_params.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_AUTO_SLICE; |
| 445 #else |
| 446 // When uiSliceMode = SM_FIXEDSLCNUM_SLICE, uiSliceNum = 0 means auto design |
| 447 // it with cpu core number. |
| 448 encoder_params.sSpatialLayers[0].sSliceArgument.uiSliceNum = 0; |
| 449 encoder_params.sSpatialLayers[0].sSliceArgument.uiSliceMode = |
| 450 SM_FIXEDSLCNUM_SLICE; |
| 451 #endif |
443 | 452 |
444 return encoder_params; | 453 return encoder_params; |
445 } | 454 } |
446 | 455 |
447 void H264EncoderImpl::ReportInit() { | 456 void H264EncoderImpl::ReportInit() { |
448 if (has_reported_init_) | 457 if (has_reported_init_) |
449 return; | 458 return; |
450 RTC_HISTOGRAM_ENUMERATION("WebRTC.Video.H264EncoderImpl.Event", | 459 RTC_HISTOGRAM_ENUMERATION("WebRTC.Video.H264EncoderImpl.Event", |
451 kH264EncoderEventInit, | 460 kH264EncoderEventInit, |
452 kH264EncoderEventMax); | 461 kH264EncoderEventMax); |
(...skipping 16 matching lines...) Expand all Loading... |
469 | 478 |
470 int32_t H264EncoderImpl::SetPeriodicKeyFrames(bool enable) { | 479 int32_t H264EncoderImpl::SetPeriodicKeyFrames(bool enable) { |
471 return WEBRTC_VIDEO_CODEC_OK; | 480 return WEBRTC_VIDEO_CODEC_OK; |
472 } | 481 } |
473 | 482 |
474 void H264EncoderImpl::OnDroppedFrame() { | 483 void H264EncoderImpl::OnDroppedFrame() { |
475 quality_scaler_.ReportDroppedFrame(); | 484 quality_scaler_.ReportDroppedFrame(); |
476 } | 485 } |
477 | 486 |
478 } // namespace webrtc | 487 } // namespace webrtc |
OLD | NEW |