OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 }; | 256 }; |
257 std::list<InputFrameInfo> input_frame_infos_; | 257 std::list<InputFrameInfo> input_frame_infos_; |
258 int32_t output_timestamp_; // Last output frame timestamp from | 258 int32_t output_timestamp_; // Last output frame timestamp from |
259 // |input_frame_infos_|. | 259 // |input_frame_infos_|. |
260 int64_t output_render_time_ms_; // Last output frame render time from | 260 int64_t output_render_time_ms_; // Last output frame render time from |
261 // |input_frame_infos_|. | 261 // |input_frame_infos_|. |
262 webrtc::VideoRotation output_rotation_; // Last output frame rotation from | 262 webrtc::VideoRotation output_rotation_; // Last output frame rotation from |
263 // |input_frame_infos_|. | 263 // |input_frame_infos_|. |
264 // Frame size in bytes fed to MediaCodec. | 264 // Frame size in bytes fed to MediaCodec. |
265 int yuv_size_; | 265 int yuv_size_; |
266 // True only when between a callback_->OnEncodedImage() call return a positive | 266 // True only when between a callback_->Encoded() call return a positive value |
267 // value and the next Encode() call being ignored. | 267 // and the next Encode() call being ignored. |
268 bool drop_next_input_frame_; | 268 bool drop_next_input_frame_; |
269 // Global references; must be deleted in Release(). | 269 // Global references; must be deleted in Release(). |
270 std::vector<jobject> input_buffers_; | 270 std::vector<jobject> input_buffers_; |
271 QualityScaler quality_scaler_; | 271 QualityScaler quality_scaler_; |
272 // Dynamic resolution change, off by default. | 272 // Dynamic resolution change, off by default. |
273 bool scale_; | 273 bool scale_; |
274 | 274 |
275 // H264 bitstream parser, used to extract QP from encoded bitstreams. | 275 // H264 bitstream parser, used to extract QP from encoded bitstreams. |
276 webrtc::H264BitstreamParser h264_bitstream_parser_; | 276 webrtc::H264BitstreamParser h264_bitstream_parser_; |
277 | 277 |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 size_t payload_size = jni->GetDirectBufferCapacity(j_output_buffer); | 1056 size_t payload_size = jni->GetDirectBufferCapacity(j_output_buffer); |
1057 uint8_t* payload = reinterpret_cast<uint8_t*>( | 1057 uint8_t* payload = reinterpret_cast<uint8_t*>( |
1058 jni->GetDirectBufferAddress(j_output_buffer)); | 1058 jni->GetDirectBufferAddress(j_output_buffer)); |
1059 if (CheckException(jni)) { | 1059 if (CheckException(jni)) { |
1060 ALOGE << "Exception in get direct buffer address."; | 1060 ALOGE << "Exception in get direct buffer address."; |
1061 ProcessHWErrorOnCodecThread(true /* reset_if_fallback_unavailable */); | 1061 ProcessHWErrorOnCodecThread(true /* reset_if_fallback_unavailable */); |
1062 return WEBRTC_VIDEO_CODEC_ERROR; | 1062 return WEBRTC_VIDEO_CODEC_ERROR; |
1063 } | 1063 } |
1064 | 1064 |
1065 // Callback - return encoded frame. | 1065 // Callback - return encoded frame. |
1066 webrtc::EncodedImageCallback::Result callback_result( | 1066 int32_t callback_status = 0; |
1067 webrtc::EncodedImageCallback::Result::OK); | |
1068 if (callback_) { | 1067 if (callback_) { |
1069 std::unique_ptr<webrtc::EncodedImage> image( | 1068 std::unique_ptr<webrtc::EncodedImage> image( |
1070 new webrtc::EncodedImage(payload, payload_size, payload_size)); | 1069 new webrtc::EncodedImage(payload, payload_size, payload_size)); |
1071 image->_encodedWidth = width_; | 1070 image->_encodedWidth = width_; |
1072 image->_encodedHeight = height_; | 1071 image->_encodedHeight = height_; |
1073 image->_timeStamp = output_timestamp_; | 1072 image->_timeStamp = output_timestamp_; |
1074 image->capture_time_ms_ = output_render_time_ms_; | 1073 image->capture_time_ms_ = output_render_time_ms_; |
1075 image->rotation_ = output_rotation_; | 1074 image->rotation_ = output_rotation_; |
1076 image->_frameType = | 1075 image->_frameType = |
1077 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta); | 1076 (key_frame ? webrtc::kVideoFrameKey : webrtc::kVideoFrameDelta); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 header.VerifyAndAllocateFragmentationHeader(scPositionsLength); | 1167 header.VerifyAndAllocateFragmentationHeader(scPositionsLength); |
1169 for (size_t i = 0; i < scPositionsLength; i++) { | 1168 for (size_t i = 0; i < scPositionsLength; i++) { |
1170 header.fragmentationOffset[i] = scPositions[i] + H264_SC_LENGTH; | 1169 header.fragmentationOffset[i] = scPositions[i] + H264_SC_LENGTH; |
1171 header.fragmentationLength[i] = | 1170 header.fragmentationLength[i] = |
1172 scPositions[i + 1] - header.fragmentationOffset[i]; | 1171 scPositions[i + 1] - header.fragmentationOffset[i]; |
1173 header.fragmentationPlType[i] = 0; | 1172 header.fragmentationPlType[i] = 0; |
1174 header.fragmentationTimeDiff[i] = 0; | 1173 header.fragmentationTimeDiff[i] = 0; |
1175 } | 1174 } |
1176 } | 1175 } |
1177 | 1176 |
1178 callback_result = callback_->OnEncodedImage(*image, &info, &header); | 1177 callback_status = callback_->Encoded(*image, &info, &header); |
1179 } | 1178 } |
1180 | 1179 |
1181 // Return output buffer back to the encoder. | 1180 // Return output buffer back to the encoder. |
1182 bool success = jni->CallBooleanMethod(*j_media_codec_video_encoder_, | 1181 bool success = jni->CallBooleanMethod(*j_media_codec_video_encoder_, |
1183 j_release_output_buffer_method_, | 1182 j_release_output_buffer_method_, |
1184 output_buffer_index); | 1183 output_buffer_index); |
1185 if (CheckException(jni) || !success) { | 1184 if (CheckException(jni) || !success) { |
1186 ProcessHWErrorOnCodecThread(true /* reset_if_fallback_unavailable */); | 1185 ProcessHWErrorOnCodecThread(true /* reset_if_fallback_unavailable */); |
1187 return false; | 1186 return false; |
1188 } | 1187 } |
(...skipping 13 matching lines...) Expand all Loading... |
1202 ". EncTime: " << frame_encoding_time_ms; | 1201 ". EncTime: " << frame_encoding_time_ms; |
1203 } | 1202 } |
1204 | 1203 |
1205 // Calculate and print encoding statistics - every 3 seconds. | 1204 // Calculate and print encoding statistics - every 3 seconds. |
1206 frames_encoded_++; | 1205 frames_encoded_++; |
1207 current_frames_++; | 1206 current_frames_++; |
1208 current_bytes_ += payload_size; | 1207 current_bytes_ += payload_size; |
1209 current_encoding_time_ms_ += frame_encoding_time_ms; | 1208 current_encoding_time_ms_ += frame_encoding_time_ms; |
1210 LogStatistics(false); | 1209 LogStatistics(false); |
1211 | 1210 |
1212 // Errors in callback_result are currently ignored. | 1211 if (callback_status > 0) { |
1213 if (callback_result.drop_next_frame) | |
1214 drop_next_input_frame_ = true; | 1212 drop_next_input_frame_ = true; |
| 1213 // Theoretically could handle callback_status<0 here, but unclear what |
| 1214 // that would mean for us. |
| 1215 } |
1215 } | 1216 } |
1216 return true; | 1217 return true; |
1217 } | 1218 } |
1218 | 1219 |
1219 void MediaCodecVideoEncoder::LogStatistics(bool force_log) { | 1220 void MediaCodecVideoEncoder::LogStatistics(bool force_log) { |
1220 int statistic_time_ms = rtc::TimeMillis() - stat_start_time_ms_; | 1221 int statistic_time_ms = rtc::TimeMillis() - stat_start_time_ms_; |
1221 if ((statistic_time_ms >= kMediaCodecStatisticsIntervalMs || force_log) | 1222 if ((statistic_time_ms >= kMediaCodecStatisticsIntervalMs || force_log) |
1222 && statistic_time_ms > 0) { | 1223 && statistic_time_ms > 0) { |
1223 // Prevent division by zero. | 1224 // Prevent division by zero. |
1224 int current_frames_divider = current_frames_ != 0 ? current_frames_ : 1; | 1225 int current_frames_divider = current_frames_ != 0 ? current_frames_ : 1; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 return supported_codecs_; | 1371 return supported_codecs_; |
1371 } | 1372 } |
1372 | 1373 |
1373 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 1374 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
1374 webrtc::VideoEncoder* encoder) { | 1375 webrtc::VideoEncoder* encoder) { |
1375 ALOGD << "Destroy video encoder."; | 1376 ALOGD << "Destroy video encoder."; |
1376 delete encoder; | 1377 delete encoder; |
1377 } | 1378 } |
1378 | 1379 |
1379 } // namespace webrtc_jni | 1380 } // namespace webrtc_jni |
OLD | NEW |