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 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 for (size_t i = 0; i < key_frame_request_.size() && i < send_stream_.size(); | 785 for (size_t i = 0; i < key_frame_request_.size() && i < send_stream_.size(); |
786 ++i) { | 786 ++i) { |
787 if (key_frame_request_[i] && send_stream_[i]) { | 787 if (key_frame_request_[i] && send_stream_[i]) { |
788 send_key_frame = true; | 788 send_key_frame = true; |
789 break; | 789 break; |
790 } | 790 } |
791 } | 791 } |
792 if (!send_key_frame && frame_types) { | 792 if (!send_key_frame && frame_types) { |
793 for (size_t i = 0; i < frame_types->size() && i < send_stream_.size(); | 793 for (size_t i = 0; i < frame_types->size() && i < send_stream_.size(); |
794 ++i) { | 794 ++i) { |
795 if ((*frame_types)[i] == kKeyFrame && send_stream_[i]) { | 795 if ((*frame_types)[i] == kVideoFrameKey && send_stream_[i]) { |
796 send_key_frame = true; | 796 send_key_frame = true; |
797 break; | 797 break; |
798 } | 798 } |
799 } | 799 } |
800 } | 800 } |
801 // The flag modification below (due to forced key frame, RPS, etc.,) for now | 801 // The flag modification below (due to forced key frame, RPS, etc.,) for now |
802 // will be the same for all encoders/spatial layers. | 802 // will be the same for all encoders/spatial layers. |
803 // TODO(marpan/holmer): Allow for key frame request to be set per encoder. | 803 // TODO(marpan/holmer): Allow for key frame request to be set per encoder. |
804 bool only_predict_from_key_frame = false; | 804 bool only_predict_from_key_frame = false; |
805 if (send_key_frame) { | 805 if (send_key_frame) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 int bw_resolutions_disabled = | 963 int bw_resolutions_disabled = |
964 (encoders_.size() > 1) ? NumStreamsDisabled(send_stream_) : -1; | 964 (encoders_.size() > 1) ? NumStreamsDisabled(send_stream_) : -1; |
965 | 965 |
966 int stream_idx = static_cast<int>(encoders_.size()) - 1; | 966 int stream_idx = static_cast<int>(encoders_.size()) - 1; |
967 int result = WEBRTC_VIDEO_CODEC_OK; | 967 int result = WEBRTC_VIDEO_CODEC_OK; |
968 for (size_t encoder_idx = 0; encoder_idx < encoders_.size(); | 968 for (size_t encoder_idx = 0; encoder_idx < encoders_.size(); |
969 ++encoder_idx, --stream_idx) { | 969 ++encoder_idx, --stream_idx) { |
970 vpx_codec_iter_t iter = NULL; | 970 vpx_codec_iter_t iter = NULL; |
971 int part_idx = 0; | 971 int part_idx = 0; |
972 encoded_images_[encoder_idx]._length = 0; | 972 encoded_images_[encoder_idx]._length = 0; |
973 encoded_images_[encoder_idx]._frameType = kDeltaFrame; | 973 encoded_images_[encoder_idx]._frameType = kVideoFrameDelta; |
974 RTPFragmentationHeader frag_info; | 974 RTPFragmentationHeader frag_info; |
975 // token_partitions_ is number of bits used. | 975 // token_partitions_ is number of bits used. |
976 frag_info.VerifyAndAllocateFragmentationHeader((1 << token_partitions_) | 976 frag_info.VerifyAndAllocateFragmentationHeader((1 << token_partitions_) |
977 + 1); | 977 + 1); |
978 CodecSpecificInfo codec_specific; | 978 CodecSpecificInfo codec_specific; |
979 const vpx_codec_cx_pkt_t *pkt = NULL; | 979 const vpx_codec_cx_pkt_t *pkt = NULL; |
980 while ((pkt = vpx_codec_get_cx_data(&encoders_[encoder_idx], | 980 while ((pkt = vpx_codec_get_cx_data(&encoders_[encoder_idx], |
981 &iter)) != NULL) { | 981 &iter)) != NULL) { |
982 switch (pkt->kind) { | 982 switch (pkt->kind) { |
983 case VPX_CODEC_CX_FRAME_PKT: { | 983 case VPX_CODEC_CX_FRAME_PKT: { |
(...skipping 10 matching lines...) Expand all Loading... |
994 ++part_idx; | 994 ++part_idx; |
995 break; | 995 break; |
996 } | 996 } |
997 default: | 997 default: |
998 break; | 998 break; |
999 } | 999 } |
1000 // End of frame | 1000 // End of frame |
1001 if ((pkt->data.frame.flags & VPX_FRAME_IS_FRAGMENT) == 0) { | 1001 if ((pkt->data.frame.flags & VPX_FRAME_IS_FRAGMENT) == 0) { |
1002 // check if encoded frame is a key frame | 1002 // check if encoded frame is a key frame |
1003 if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) { | 1003 if (pkt->data.frame.flags & VPX_FRAME_IS_KEY) { |
1004 encoded_images_[encoder_idx]._frameType = kKeyFrame; | 1004 encoded_images_[encoder_idx]._frameType = kVideoFrameKey; |
1005 rps_.EncodedKeyFrame(picture_id_[stream_idx]); | 1005 rps_.EncodedKeyFrame(picture_id_[stream_idx]); |
1006 } | 1006 } |
1007 PopulateCodecSpecific(&codec_specific, *pkt, stream_idx, | 1007 PopulateCodecSpecific(&codec_specific, *pkt, stream_idx, |
1008 input_image.timestamp(), | 1008 input_image.timestamp(), |
1009 only_predicting_from_key_frame); | 1009 only_predicting_from_key_frame); |
1010 break; | 1010 break; |
1011 } | 1011 } |
1012 } | 1012 } |
1013 encoded_images_[encoder_idx]._timeStamp = input_image.timestamp(); | 1013 encoded_images_[encoder_idx]._timeStamp = input_image.timestamp(); |
1014 encoded_images_[encoder_idx].capture_time_ms_ = | 1014 encoded_images_[encoder_idx].capture_time_ms_ = |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 if (last_frame_width_ * last_frame_height_ <= 640 * 360) { | 1165 if (last_frame_width_ * last_frame_height_ <= 640 * 360) { |
1166 ppcfg.post_proc_flag |= VP8_DEMACROBLOCK; | 1166 ppcfg.post_proc_flag |= VP8_DEMACROBLOCK; |
1167 } | 1167 } |
1168 // Strength of deblocking filter. Valid range:[0,16] | 1168 // Strength of deblocking filter. Valid range:[0,16] |
1169 ppcfg.deblocking_level = 3; | 1169 ppcfg.deblocking_level = 3; |
1170 vpx_codec_control(decoder_, VP8_SET_POSTPROC, &ppcfg); | 1170 vpx_codec_control(decoder_, VP8_SET_POSTPROC, &ppcfg); |
1171 #endif | 1171 #endif |
1172 | 1172 |
1173 // Always start with a complete key frame. | 1173 // Always start with a complete key frame. |
1174 if (key_frame_required_) { | 1174 if (key_frame_required_) { |
1175 if (input_image._frameType != kKeyFrame) | 1175 if (input_image._frameType != kVideoFrameKey) |
1176 return WEBRTC_VIDEO_CODEC_ERROR; | 1176 return WEBRTC_VIDEO_CODEC_ERROR; |
1177 // We have a key frame - is it complete? | 1177 // We have a key frame - is it complete? |
1178 if (input_image._completeFrame) { | 1178 if (input_image._completeFrame) { |
1179 key_frame_required_ = false; | 1179 key_frame_required_ = false; |
1180 } else { | 1180 } else { |
1181 return WEBRTC_VIDEO_CODEC_ERROR; | 1181 return WEBRTC_VIDEO_CODEC_ERROR; |
1182 } | 1182 } |
1183 } | 1183 } |
1184 // Restrict error propagation using key frame requests. Disabled when | 1184 // Restrict error propagation using key frame requests. Disabled when |
1185 // the feedback mode is enabled (RPS). | 1185 // the feedback mode is enabled (RPS). |
1186 // Reset on a key frame refresh. | 1186 // Reset on a key frame refresh. |
1187 if (!feedback_mode_) { | 1187 if (!feedback_mode_) { |
1188 if (input_image._frameType == kKeyFrame && input_image._completeFrame) { | 1188 if (input_image._frameType == kVideoFrameKey && |
| 1189 input_image._completeFrame) { |
1189 propagation_cnt_ = -1; | 1190 propagation_cnt_ = -1; |
1190 // Start count on first loss. | 1191 // Start count on first loss. |
1191 } else if ((!input_image._completeFrame || missing_frames) && | 1192 } else if ((!input_image._completeFrame || missing_frames) && |
1192 propagation_cnt_ == -1) { | 1193 propagation_cnt_ == -1) { |
1193 propagation_cnt_ = 0; | 1194 propagation_cnt_ = 0; |
1194 } | 1195 } |
1195 if (propagation_cnt_ >= 0) { | 1196 if (propagation_cnt_ >= 0) { |
1196 propagation_cnt_++; | 1197 propagation_cnt_++; |
1197 } | 1198 } |
1198 } | 1199 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 VPX_DL_REALTIME)) { | 1232 VPX_DL_REALTIME)) { |
1232 // Reset to avoid requesting key frames too often. | 1233 // Reset to avoid requesting key frames too often. |
1233 if (propagation_cnt_ > 0) { | 1234 if (propagation_cnt_ > 0) { |
1234 propagation_cnt_ = 0; | 1235 propagation_cnt_ = 0; |
1235 } | 1236 } |
1236 return WEBRTC_VIDEO_CODEC_ERROR; | 1237 return WEBRTC_VIDEO_CODEC_ERROR; |
1237 } | 1238 } |
1238 #endif | 1239 #endif |
1239 | 1240 |
1240 // Store encoded frame if key frame. (Used in Copy method.) | 1241 // Store encoded frame if key frame. (Used in Copy method.) |
1241 if (input_image._frameType == kKeyFrame && input_image._buffer != NULL) { | 1242 if (input_image._frameType == kVideoFrameKey && input_image._buffer != NULL) { |
1242 const uint32_t bytes_to_copy = input_image._length; | 1243 const uint32_t bytes_to_copy = input_image._length; |
1243 if (last_keyframe_._size < bytes_to_copy) { | 1244 if (last_keyframe_._size < bytes_to_copy) { |
1244 delete [] last_keyframe_._buffer; | 1245 delete [] last_keyframe_._buffer; |
1245 last_keyframe_._buffer = NULL; | 1246 last_keyframe_._buffer = NULL; |
1246 last_keyframe_._size = 0; | 1247 last_keyframe_._size = 0; |
1247 } | 1248 } |
1248 uint8_t* temp_buffer = last_keyframe_._buffer; // Save buffer ptr. | 1249 uint8_t* temp_buffer = last_keyframe_._buffer; // Save buffer ptr. |
1249 uint32_t temp_size = last_keyframe_._size; // Save size. | 1250 uint32_t temp_size = last_keyframe_._size; // Save size. |
1250 last_keyframe_ = input_image; // Shallow copy. | 1251 last_keyframe_ = input_image; // Shallow copy. |
1251 last_keyframe_._buffer = temp_buffer; // Restore buffer ptr. | 1252 last_keyframe_._buffer = temp_buffer; // Restore buffer ptr. |
(...skipping 13 matching lines...) Expand all Loading... |
1265 if (ret != 0) { | 1266 if (ret != 0) { |
1266 // Reset to avoid requesting key frames too often. | 1267 // Reset to avoid requesting key frames too often. |
1267 if (ret < 0 && propagation_cnt_ > 0) | 1268 if (ret < 0 && propagation_cnt_ > 0) |
1268 propagation_cnt_ = 0; | 1269 propagation_cnt_ = 0; |
1269 return ret; | 1270 return ret; |
1270 } | 1271 } |
1271 if (feedback_mode_) { | 1272 if (feedback_mode_) { |
1272 // Whenever we receive an incomplete key frame all reference buffers will | 1273 // Whenever we receive an incomplete key frame all reference buffers will |
1273 // be corrupt. If that happens we must request new key frames until we | 1274 // be corrupt. If that happens we must request new key frames until we |
1274 // decode a complete key frame. | 1275 // decode a complete key frame. |
1275 if (input_image._frameType == kKeyFrame && !input_image._completeFrame) | 1276 if (input_image._frameType == kVideoFrameKey && !input_image._completeFrame) |
1276 return WEBRTC_VIDEO_CODEC_ERROR; | 1277 return WEBRTC_VIDEO_CODEC_ERROR; |
1277 // Check for reference updates and last reference buffer corruption and | 1278 // Check for reference updates and last reference buffer corruption and |
1278 // signal successful reference propagation or frame corruption to the | 1279 // signal successful reference propagation or frame corruption to the |
1279 // encoder. | 1280 // encoder. |
1280 int reference_updates = 0; | 1281 int reference_updates = 0; |
1281 if (vpx_codec_control(decoder_, VP8D_GET_LAST_REF_UPDATES, | 1282 if (vpx_codec_control(decoder_, VP8D_GET_LAST_REF_UPDATES, |
1282 &reference_updates)) { | 1283 &reference_updates)) { |
1283 // Reset to avoid requesting key frames too often. | 1284 // Reset to avoid requesting key frames too often. |
1284 if (propagation_cnt_ > 0) { | 1285 if (propagation_cnt_ > 0) { |
1285 propagation_cnt_ = 0; | 1286 propagation_cnt_ = 0; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 return -1; | 1408 return -1; |
1408 } | 1409 } |
1409 if (vpx_codec_control(copy->decoder_, VP8_SET_REFERENCE, ref_frame_) | 1410 if (vpx_codec_control(copy->decoder_, VP8_SET_REFERENCE, ref_frame_) |
1410 != VPX_CODEC_OK) { | 1411 != VPX_CODEC_OK) { |
1411 return -1; | 1412 return -1; |
1412 } | 1413 } |
1413 return 0; | 1414 return 0; |
1414 } | 1415 } |
1415 | 1416 |
1416 } // namespace webrtc | 1417 } // namespace webrtc |
OLD | NEW |