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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 RTC_NOTREACHED() << "Unsupported codec without configured QP thresholds."; | 412 RTC_NOTREACHED() << "Unsupported codec without configured QP thresholds."; |
413 scale_ = false; | 413 scale_ = false; |
414 } | 414 } |
415 QualityScaler::Resolution res = quality_scaler_.GetScaledResolution(); | 415 QualityScaler::Resolution res = quality_scaler_.GetScaledResolution(); |
416 init_width = res.width; | 416 init_width = res.width; |
417 init_height = res.height; | 417 init_height = res.height; |
418 ALOGD << "Scaled resolution: " << init_width << " x " << init_height; | 418 ALOGD << "Scaled resolution: " << init_width << " x " << init_height; |
419 } | 419 } |
420 | 420 |
421 return codec_thread_->Invoke<int32_t>( | 421 return codec_thread_->Invoke<int32_t>( |
422 Bind(&MediaCodecVideoEncoder::InitEncodeOnCodecThread, | 422 FROM_HERE, Bind(&MediaCodecVideoEncoder::InitEncodeOnCodecThread, this, |
423 this, | 423 init_width, init_height, codec_settings->startBitrate, |
424 init_width, | 424 codec_settings->maxFramerate, false /* use_surface */)); |
425 init_height, | |
426 codec_settings->startBitrate, | |
427 codec_settings->maxFramerate, | |
428 false /* use_surface */)); | |
429 } | 425 } |
430 | 426 |
431 int32_t MediaCodecVideoEncoder::Encode( | 427 int32_t MediaCodecVideoEncoder::Encode( |
432 const webrtc::VideoFrame& frame, | 428 const webrtc::VideoFrame& frame, |
433 const webrtc::CodecSpecificInfo* /* codec_specific_info */, | 429 const webrtc::CodecSpecificInfo* /* codec_specific_info */, |
434 const std::vector<webrtc::FrameType>* frame_types) { | 430 const std::vector<webrtc::FrameType>* frame_types) { |
435 return codec_thread_->Invoke<int32_t>(Bind( | 431 return codec_thread_->Invoke<int32_t>( |
436 &MediaCodecVideoEncoder::EncodeOnCodecThread, this, frame, frame_types)); | 432 FROM_HERE, Bind(&MediaCodecVideoEncoder::EncodeOnCodecThread, this, frame, |
| 433 frame_types)); |
437 } | 434 } |
438 | 435 |
439 int32_t MediaCodecVideoEncoder::RegisterEncodeCompleteCallback( | 436 int32_t MediaCodecVideoEncoder::RegisterEncodeCompleteCallback( |
440 webrtc::EncodedImageCallback* callback) { | 437 webrtc::EncodedImageCallback* callback) { |
441 return codec_thread_->Invoke<int32_t>( | 438 return codec_thread_->Invoke<int32_t>( |
| 439 FROM_HERE, |
442 Bind(&MediaCodecVideoEncoder::RegisterEncodeCompleteCallbackOnCodecThread, | 440 Bind(&MediaCodecVideoEncoder::RegisterEncodeCompleteCallbackOnCodecThread, |
443 this, | 441 this, callback)); |
444 callback)); | |
445 } | 442 } |
446 | 443 |
447 int32_t MediaCodecVideoEncoder::Release() { | 444 int32_t MediaCodecVideoEncoder::Release() { |
448 ALOGD << "EncoderRelease request"; | 445 ALOGD << "EncoderRelease request"; |
449 return codec_thread_->Invoke<int32_t>( | 446 return codec_thread_->Invoke<int32_t>( |
450 Bind(&MediaCodecVideoEncoder::ReleaseOnCodecThread, this)); | 447 FROM_HERE, Bind(&MediaCodecVideoEncoder::ReleaseOnCodecThread, this)); |
451 } | 448 } |
452 | 449 |
453 int32_t MediaCodecVideoEncoder::SetChannelParameters(uint32_t /* packet_loss */, | 450 int32_t MediaCodecVideoEncoder::SetChannelParameters(uint32_t /* packet_loss */, |
454 int64_t /* rtt */) { | 451 int64_t /* rtt */) { |
455 return WEBRTC_VIDEO_CODEC_OK; | 452 return WEBRTC_VIDEO_CODEC_OK; |
456 } | 453 } |
457 | 454 |
458 int32_t MediaCodecVideoEncoder::SetRates(uint32_t new_bit_rate, | 455 int32_t MediaCodecVideoEncoder::SetRates(uint32_t new_bit_rate, |
459 uint32_t frame_rate) { | 456 uint32_t frame_rate) { |
460 return codec_thread_->Invoke<int32_t>( | 457 return codec_thread_->Invoke<int32_t>( |
461 Bind(&MediaCodecVideoEncoder::SetRatesOnCodecThread, | 458 FROM_HERE, Bind(&MediaCodecVideoEncoder::SetRatesOnCodecThread, this, |
462 this, | 459 new_bit_rate, frame_rate)); |
463 new_bit_rate, | |
464 frame_rate)); | |
465 } | 460 } |
466 | 461 |
467 void MediaCodecVideoEncoder::OnMessage(rtc::Message* msg) { | 462 void MediaCodecVideoEncoder::OnMessage(rtc::Message* msg) { |
468 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread()); | 463 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread()); |
469 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 464 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
470 ScopedLocalRefFrame local_ref_frame(jni); | 465 ScopedLocalRefFrame local_ref_frame(jni); |
471 | 466 |
472 // We only ever send one message to |this| directly (not through a Bind()'d | 467 // We only ever send one message to |this| directly (not through a Bind()'d |
473 // functor), so expect no ID/data. | 468 // functor), so expect no ID/data. |
474 RTC_CHECK(!msg->message_id) << "Unexpected message!"; | 469 RTC_CHECK(!msg->message_id) << "Unexpected message!"; |
475 RTC_CHECK(!msg->pdata) << "Unexpected message!"; | 470 RTC_CHECK(!msg->pdata) << "Unexpected message!"; |
476 if (!inited_) { | 471 if (!inited_) { |
477 return; | 472 return; |
478 } | 473 } |
479 | 474 |
480 // It would be nice to recover from a failure here if one happened, but it's | 475 // It would be nice to recover from a failure here if one happened, but it's |
481 // unclear how to signal such a failure to the app, so instead we stay silent | 476 // unclear how to signal such a failure to the app, so instead we stay silent |
482 // about it and let the next app-called API method reveal the borkedness. | 477 // about it and let the next app-called API method reveal the borkedness. |
483 DeliverPendingOutputs(jni); | 478 DeliverPendingOutputs(jni); |
484 codec_thread_->PostDelayed(kMediaCodecPollMs, this); | 479 codec_thread_->PostDelayed(FROM_HERE, kMediaCodecPollMs, this); |
485 } | 480 } |
486 | 481 |
487 bool MediaCodecVideoEncoder::ResetCodecOnCodecThread() { | 482 bool MediaCodecVideoEncoder::ResetCodecOnCodecThread() { |
488 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread()); | 483 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread()); |
489 ALOGE << "ResetOnCodecThread"; | 484 ALOGE << "ResetOnCodecThread"; |
490 if (ReleaseOnCodecThread() != WEBRTC_VIDEO_CODEC_OK || | 485 if (ReleaseOnCodecThread() != WEBRTC_VIDEO_CODEC_OK || |
491 InitEncodeOnCodecThread(width_, height_, 0, 0, false) != | 486 InitEncodeOnCodecThread(width_, height_, 0, 0, false) != |
492 WEBRTC_VIDEO_CODEC_OK) { | 487 WEBRTC_VIDEO_CODEC_OK) { |
493 // TODO(fischman): wouldn't it be nice if there was a way to gracefully | 488 // TODO(fischman): wouldn't it be nice if there was a way to gracefully |
494 // degrade to a SW encoder at this point? There isn't one AFAICT :( | 489 // degrade to a SW encoder at this point? There isn't one AFAICT :( |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 input_buffers_[i] = | 583 input_buffers_[i] = |
589 jni->NewGlobalRef(jni->GetObjectArrayElement(input_buffers, i)); | 584 jni->NewGlobalRef(jni->GetObjectArrayElement(input_buffers, i)); |
590 int64_t yuv_buffer_capacity = | 585 int64_t yuv_buffer_capacity = |
591 jni->GetDirectBufferCapacity(input_buffers_[i]); | 586 jni->GetDirectBufferCapacity(input_buffers_[i]); |
592 CHECK_EXCEPTION(jni); | 587 CHECK_EXCEPTION(jni); |
593 RTC_CHECK(yuv_buffer_capacity >= yuv_size_) << "Insufficient capacity"; | 588 RTC_CHECK(yuv_buffer_capacity >= yuv_size_) << "Insufficient capacity"; |
594 } | 589 } |
595 } | 590 } |
596 | 591 |
597 inited_ = true; | 592 inited_ = true; |
598 codec_thread_->PostDelayed(kMediaCodecPollMs, this); | 593 codec_thread_->PostDelayed(FROM_HERE, kMediaCodecPollMs, this); |
599 return WEBRTC_VIDEO_CODEC_OK; | 594 return WEBRTC_VIDEO_CODEC_OK; |
600 } | 595 } |
601 | 596 |
602 int32_t MediaCodecVideoEncoder::EncodeOnCodecThread( | 597 int32_t MediaCodecVideoEncoder::EncodeOnCodecThread( |
603 const webrtc::VideoFrame& frame, | 598 const webrtc::VideoFrame& frame, |
604 const std::vector<webrtc::FrameType>* frame_types) { | 599 const std::vector<webrtc::FrameType>* frame_types) { |
605 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread()); | 600 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread()); |
606 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 601 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
607 ScopedLocalRefFrame local_ref_frame(jni); | 602 ScopedLocalRefFrame local_ref_frame(jni); |
608 | 603 |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 return (int32_t)(head - buffer); | 1160 return (int32_t)(head - buffer); |
1166 } | 1161 } |
1167 return -1; | 1162 return -1; |
1168 } | 1163 } |
1169 | 1164 |
1170 void MediaCodecVideoEncoder::OnDroppedFrame() { | 1165 void MediaCodecVideoEncoder::OnDroppedFrame() { |
1171 // Methods running on the codec thread should call OnDroppedFrameOnCodecThread | 1166 // Methods running on the codec thread should call OnDroppedFrameOnCodecThread |
1172 // directly. | 1167 // directly. |
1173 RTC_DCHECK(!codec_thread_checker_.CalledOnValidThread()); | 1168 RTC_DCHECK(!codec_thread_checker_.CalledOnValidThread()); |
1174 codec_thread_->Invoke<void>( | 1169 codec_thread_->Invoke<void>( |
| 1170 FROM_HERE, |
1175 Bind(&MediaCodecVideoEncoder::OnDroppedFrameOnCodecThread, this)); | 1171 Bind(&MediaCodecVideoEncoder::OnDroppedFrameOnCodecThread, this)); |
1176 } | 1172 } |
1177 | 1173 |
1178 void MediaCodecVideoEncoder::OnDroppedFrameOnCodecThread() { | 1174 void MediaCodecVideoEncoder::OnDroppedFrameOnCodecThread() { |
1179 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread()); | 1175 RTC_DCHECK(codec_thread_checker_.CalledOnValidThread()); |
1180 // Report dropped frame to quality_scaler_. | 1176 // Report dropped frame to quality_scaler_. |
1181 if (scale_) | 1177 if (scale_) |
1182 quality_scaler_.ReportDroppedFrame(); | 1178 quality_scaler_.ReportDroppedFrame(); |
1183 } | 1179 } |
1184 | 1180 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 return supported_codecs_; | 1265 return supported_codecs_; |
1270 } | 1266 } |
1271 | 1267 |
1272 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 1268 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
1273 webrtc::VideoEncoder* encoder) { | 1269 webrtc::VideoEncoder* encoder) { |
1274 ALOGD << "Destroy video encoder."; | 1270 ALOGD << "Destroy video encoder."; |
1275 delete encoder; | 1271 delete encoder; |
1276 } | 1272 } |
1277 | 1273 |
1278 } // namespace webrtc_jni | 1274 } // namespace webrtc_jni |
OLD | NEW |