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 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 EncodedImageCallback* callback) { | 1092 EncodedImageCallback* callback) { |
1093 encoded_complete_callback_ = callback; | 1093 encoded_complete_callback_ = callback; |
1094 return WEBRTC_VIDEO_CODEC_OK; | 1094 return WEBRTC_VIDEO_CODEC_OK; |
1095 } | 1095 } |
1096 | 1096 |
1097 VP8DecoderImpl::VP8DecoderImpl() | 1097 VP8DecoderImpl::VP8DecoderImpl() |
1098 : decode_complete_callback_(NULL), | 1098 : decode_complete_callback_(NULL), |
1099 inited_(false), | 1099 inited_(false), |
1100 feedback_mode_(false), | 1100 feedback_mode_(false), |
1101 decoder_(NULL), | 1101 decoder_(NULL), |
1102 last_keyframe_(), | |
1103 image_format_(VPX_IMG_FMT_NONE), | 1102 image_format_(VPX_IMG_FMT_NONE), |
1104 ref_frame_(NULL), | 1103 ref_frame_(NULL), |
1105 propagation_cnt_(-1), | 1104 propagation_cnt_(-1), |
1106 last_frame_width_(0), | 1105 last_frame_width_(0), |
1107 last_frame_height_(0), | 1106 last_frame_height_(0), |
1108 key_frame_required_(true) {} | 1107 key_frame_required_(true) {} |
1109 | 1108 |
1110 VP8DecoderImpl::~VP8DecoderImpl() { | 1109 VP8DecoderImpl::~VP8DecoderImpl() { |
1111 inited_ = true; // in order to do the actual release | 1110 inited_ = true; // in order to do the actual release |
1112 Release(); | 1111 Release(); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 if (vpx_codec_decode(decoder_, buffer, input_image._length, 0, | 1251 if (vpx_codec_decode(decoder_, buffer, input_image._length, 0, |
1253 VPX_DL_REALTIME)) { | 1252 VPX_DL_REALTIME)) { |
1254 // Reset to avoid requesting key frames too often. | 1253 // Reset to avoid requesting key frames too often. |
1255 if (propagation_cnt_ > 0) { | 1254 if (propagation_cnt_ > 0) { |
1256 propagation_cnt_ = 0; | 1255 propagation_cnt_ = 0; |
1257 } | 1256 } |
1258 return WEBRTC_VIDEO_CODEC_ERROR; | 1257 return WEBRTC_VIDEO_CODEC_ERROR; |
1259 } | 1258 } |
1260 #endif | 1259 #endif |
1261 | 1260 |
1262 // Store encoded frame if key frame. (Used in Copy method.) | |
1263 if (input_image._frameType == kVideoFrameKey && input_image._buffer != NULL) { | |
1264 const uint32_t bytes_to_copy = input_image._length; | |
1265 if (last_keyframe_._size < bytes_to_copy) { | |
1266 delete[] last_keyframe_._buffer; | |
1267 last_keyframe_._buffer = NULL; | |
1268 last_keyframe_._size = 0; | |
1269 } | |
1270 uint8_t* temp_buffer = last_keyframe_._buffer; // Save buffer ptr. | |
1271 uint32_t temp_size = last_keyframe_._size; // Save size. | |
1272 last_keyframe_ = input_image; // Shallow copy. | |
1273 last_keyframe_._buffer = temp_buffer; // Restore buffer ptr. | |
1274 last_keyframe_._size = temp_size; // Restore buffer size. | |
1275 if (!last_keyframe_._buffer) { | |
1276 // Allocate memory. | |
1277 last_keyframe_._size = bytes_to_copy; | |
1278 last_keyframe_._buffer = new uint8_t[last_keyframe_._size]; | |
1279 } | |
1280 // Copy encoded frame. | |
1281 memcpy(last_keyframe_._buffer, input_image._buffer, bytes_to_copy); | |
1282 last_keyframe_._length = bytes_to_copy; | |
1283 } | |
1284 | |
1285 img = vpx_codec_get_frame(decoder_, &iter); | 1261 img = vpx_codec_get_frame(decoder_, &iter); |
1286 ret = ReturnFrame(img, input_image._timeStamp, input_image.ntp_time_ms_); | 1262 ret = ReturnFrame(img, input_image._timeStamp, input_image.ntp_time_ms_); |
1287 if (ret != 0) { | 1263 if (ret != 0) { |
1288 // Reset to avoid requesting key frames too often. | 1264 // Reset to avoid requesting key frames too often. |
1289 if (ret < 0 && propagation_cnt_ > 0) | 1265 if (ret < 0 && propagation_cnt_ > 0) |
1290 propagation_cnt_ = 0; | 1266 propagation_cnt_ = 0; |
1291 return ret; | 1267 return ret; |
1292 } | 1268 } |
1293 if (feedback_mode_) { | 1269 if (feedback_mode_) { |
1294 // Whenever we receive an incomplete key frame all reference buffers will | 1270 // Whenever we receive an incomplete key frame all reference buffers will |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 return WEBRTC_VIDEO_CODEC_OK; | 1368 return WEBRTC_VIDEO_CODEC_OK; |
1393 } | 1369 } |
1394 | 1370 |
1395 int VP8DecoderImpl::RegisterDecodeCompleteCallback( | 1371 int VP8DecoderImpl::RegisterDecodeCompleteCallback( |
1396 DecodedImageCallback* callback) { | 1372 DecodedImageCallback* callback) { |
1397 decode_complete_callback_ = callback; | 1373 decode_complete_callback_ = callback; |
1398 return WEBRTC_VIDEO_CODEC_OK; | 1374 return WEBRTC_VIDEO_CODEC_OK; |
1399 } | 1375 } |
1400 | 1376 |
1401 int VP8DecoderImpl::Release() { | 1377 int VP8DecoderImpl::Release() { |
1402 if (last_keyframe_._buffer != NULL) { | |
1403 delete[] last_keyframe_._buffer; | |
1404 last_keyframe_._buffer = NULL; | |
1405 } | |
1406 if (decoder_ != NULL) { | 1378 if (decoder_ != NULL) { |
1407 if (vpx_codec_destroy(decoder_)) { | 1379 if (vpx_codec_destroy(decoder_)) { |
1408 return WEBRTC_VIDEO_CODEC_MEMORY; | 1380 return WEBRTC_VIDEO_CODEC_MEMORY; |
1409 } | 1381 } |
1410 delete decoder_; | 1382 delete decoder_; |
1411 decoder_ = NULL; | 1383 decoder_ = NULL; |
1412 } | 1384 } |
1413 if (ref_frame_ != NULL) { | 1385 if (ref_frame_ != NULL) { |
1414 vpx_img_free(&ref_frame_->img); | 1386 vpx_img_free(&ref_frame_->img); |
1415 delete ref_frame_; | 1387 delete ref_frame_; |
(...skipping 16 matching lines...) Expand all Loading... |
1432 return -1; | 1404 return -1; |
1433 } | 1405 } |
1434 if (vpx_codec_control(copy->decoder_, VP8_SET_REFERENCE, ref_frame_) != | 1406 if (vpx_codec_control(copy->decoder_, VP8_SET_REFERENCE, ref_frame_) != |
1435 VPX_CODEC_OK) { | 1407 VPX_CODEC_OK) { |
1436 return -1; | 1408 return -1; |
1437 } | 1409 } |
1438 return 0; | 1410 return 0; |
1439 } | 1411 } |
1440 | 1412 |
1441 } // namespace webrtc | 1413 } // namespace webrtc |
OLD | NEW |