Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 void ResetCodec(); | 112 void ResetCodec(); |
| 113 | 113 |
| 114 // Implementation of webrtc::VideoEncoder methods above, all running on the | 114 // Implementation of webrtc::VideoEncoder methods above, all running on the |
| 115 // codec thread exclusively. | 115 // codec thread exclusively. |
| 116 // | 116 // |
| 117 // If width==0 then this is assumed to be a re-initialization and the | 117 // If width==0 then this is assumed to be a re-initialization and the |
| 118 // previously-current values are reused instead of the passed parameters | 118 // previously-current values are reused instead of the passed parameters |
| 119 // (makes it easier to reason about thread-safety). | 119 // (makes it easier to reason about thread-safety). |
| 120 int32_t InitEncodeOnCodecThread(int width, int height, int kbps, int fps); | 120 int32_t InitEncodeOnCodecThread(int width, int height, int kbps, int fps); |
| 121 int32_t EncodeOnCodecThread( | 121 int32_t EncodeOnCodecThread( |
| 122 const webrtc::VideoFrame& input_image, | 122 const webrtc::VideoFrame* input_image, |
|
magjed_webrtc
2015/10/23 05:17:01
Leave this unchanged - implicit copies of webrtc::
noahric
2015/10/23 06:02:16
SGTM. Done.
| |
| 123 const std::vector<webrtc::FrameType>* frame_types); | 123 const std::vector<webrtc::FrameType>* frame_types); |
| 124 int32_t RegisterEncodeCompleteCallbackOnCodecThread( | 124 int32_t RegisterEncodeCompleteCallbackOnCodecThread( |
| 125 webrtc::EncodedImageCallback* callback); | 125 webrtc::EncodedImageCallback* callback); |
| 126 int32_t ReleaseOnCodecThread(); | 126 int32_t ReleaseOnCodecThread(); |
| 127 int32_t SetRatesOnCodecThread(uint32_t new_bit_rate, uint32_t frame_rate); | 127 int32_t SetRatesOnCodecThread(uint32_t new_bit_rate, uint32_t frame_rate); |
| 128 | 128 |
| 129 // Helper accessors for MediaCodecVideoEncoder$OutputBufferInfo members. | 129 // Helper accessors for MediaCodecVideoEncoder$OutputBufferInfo members. |
| 130 int GetOutputBufferInfoIndex(JNIEnv* jni, jobject j_output_buffer_info); | 130 int GetOutputBufferInfoIndex(JNIEnv* jni, jobject j_output_buffer_info); |
| 131 jobject GetOutputBufferInfoBuffer(JNIEnv* jni, jobject j_output_buffer_info); | 131 jobject GetOutputBufferInfoBuffer(JNIEnv* jni, jobject j_output_buffer_info); |
| 132 bool GetOutputBufferInfoIsKeyFrame(JNIEnv* jni, jobject j_output_buffer_info); | 132 bool GetOutputBufferInfoIsKeyFrame(JNIEnv* jni, jobject j_output_buffer_info); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 codec_settings->height, | 332 codec_settings->height, |
| 333 codec_settings->startBitrate, | 333 codec_settings->startBitrate, |
| 334 codec_settings->maxFramerate)); | 334 codec_settings->maxFramerate)); |
| 335 } | 335 } |
| 336 | 336 |
| 337 int32_t MediaCodecVideoEncoder::Encode( | 337 int32_t MediaCodecVideoEncoder::Encode( |
| 338 const webrtc::VideoFrame& frame, | 338 const webrtc::VideoFrame& frame, |
| 339 const webrtc::CodecSpecificInfo* /* codec_specific_info */, | 339 const webrtc::CodecSpecificInfo* /* codec_specific_info */, |
| 340 const std::vector<webrtc::FrameType>* frame_types) { | 340 const std::vector<webrtc::FrameType>* frame_types) { |
| 341 return codec_thread_->Invoke<int32_t>(Bind( | 341 return codec_thread_->Invoke<int32_t>(Bind( |
| 342 &MediaCodecVideoEncoder::EncodeOnCodecThread, this, frame, frame_types)); | 342 &MediaCodecVideoEncoder::EncodeOnCodecThread, this, &frame, frame_types)); |
| 343 } | 343 } |
| 344 | 344 |
| 345 int32_t MediaCodecVideoEncoder::RegisterEncodeCompleteCallback( | 345 int32_t MediaCodecVideoEncoder::RegisterEncodeCompleteCallback( |
| 346 webrtc::EncodedImageCallback* callback) { | 346 webrtc::EncodedImageCallback* callback) { |
| 347 return codec_thread_->Invoke<int32_t>( | 347 return codec_thread_->Invoke<int32_t>( |
| 348 Bind(&MediaCodecVideoEncoder::RegisterEncodeCompleteCallbackOnCodecThread, | 348 Bind(&MediaCodecVideoEncoder::RegisterEncodeCompleteCallbackOnCodecThread, |
| 349 this, | 349 this, |
| 350 callback)); | 350 callback)); |
| 351 } | 351 } |
| 352 | 352 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 CHECK_EXCEPTION(jni); | 492 CHECK_EXCEPTION(jni); |
| 493 RTC_CHECK(yuv_buffer_capacity >= yuv_size_) << "Insufficient capacity"; | 493 RTC_CHECK(yuv_buffer_capacity >= yuv_size_) << "Insufficient capacity"; |
| 494 } | 494 } |
| 495 CHECK_EXCEPTION(jni); | 495 CHECK_EXCEPTION(jni); |
| 496 | 496 |
| 497 codec_thread_->PostDelayed(kMediaCodecPollMs, this); | 497 codec_thread_->PostDelayed(kMediaCodecPollMs, this); |
| 498 return WEBRTC_VIDEO_CODEC_OK; | 498 return WEBRTC_VIDEO_CODEC_OK; |
| 499 } | 499 } |
| 500 | 500 |
| 501 int32_t MediaCodecVideoEncoder::EncodeOnCodecThread( | 501 int32_t MediaCodecVideoEncoder::EncodeOnCodecThread( |
| 502 const webrtc::VideoFrame& frame, | 502 const webrtc::VideoFrame* frame, |
| 503 const std::vector<webrtc::FrameType>* frame_types) { | 503 const std::vector<webrtc::FrameType>* frame_types) { |
| 504 CheckOnCodecThread(); | 504 CheckOnCodecThread(); |
| 505 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 505 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
| 506 ScopedLocalRefFrame local_ref_frame(jni); | 506 ScopedLocalRefFrame local_ref_frame(jni); |
| 507 | 507 |
| 508 if (!inited_) { | 508 if (!inited_) { |
| 509 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 509 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
| 510 } | 510 } |
| 511 frames_received_++; | 511 frames_received_++; |
| 512 if (!DeliverPendingOutputs(jni)) { | 512 if (!DeliverPendingOutputs(jni)) { |
| 513 ResetCodec(); | 513 ResetCodec(); |
| 514 // Continue as if everything's fine. | 514 // Continue as if everything's fine. |
| 515 } | 515 } |
| 516 | 516 |
| 517 if (drop_next_input_frame_) { | 517 if (drop_next_input_frame_) { |
| 518 ALOGV("Encoder drop frame - failed callback."); | 518 ALOGV("Encoder drop frame - failed callback."); |
| 519 drop_next_input_frame_ = false; | 519 drop_next_input_frame_ = false; |
| 520 return WEBRTC_VIDEO_CODEC_OK; | 520 return WEBRTC_VIDEO_CODEC_OK; |
| 521 } | 521 } |
| 522 | 522 |
| 523 RTC_CHECK(frame_types->size() == 1) << "Unexpected stream count"; | 523 RTC_CHECK(frame_types->size() == 1) << "Unexpected stream count"; |
| 524 // Check framerate before spatial resolution change. | 524 // Check framerate before spatial resolution change. |
| 525 if (scale_) | 525 if (scale_) |
| 526 quality_scaler_.OnEncodeFrame(frame); | 526 quality_scaler_.OnEncodeFrame(*frame); |
| 527 | 527 |
| 528 const VideoFrame& input_frame = | 528 const VideoFrame& input_frame = |
| 529 scale_ ? quality_scaler_.GetScaledFrame(frame) : frame; | 529 scale_ ? quality_scaler_.GetScaledFrame(*frame) : *frame; |
| 530 | 530 |
| 531 if (input_frame.width() != width_ || input_frame.height() != height_) { | 531 if (input_frame.width() != width_ || input_frame.height() != height_) { |
| 532 ALOGD << "Frame resolution change from " << width_ << " x " << height_ << | 532 ALOGD << "Frame resolution change from " << width_ << " x " << height_ << |
| 533 " to " << input_frame.width() << " x " << input_frame.height(); | 533 " to " << input_frame.width() << " x " << input_frame.height(); |
| 534 width_ = input_frame.width(); | 534 width_ = input_frame.width(); |
| 535 height_ = input_frame.height(); | 535 height_ = input_frame.height(); |
| 536 ResetCodec(); | 536 ResetCodec(); |
| 537 return WEBRTC_VIDEO_CODEC_OK; | 537 return WEBRTC_VIDEO_CODEC_OK; |
| 538 } | 538 } |
| 539 | 539 |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 955 } | 955 } |
| 956 | 956 |
| 957 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 957 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
| 958 webrtc::VideoEncoder* encoder) { | 958 webrtc::VideoEncoder* encoder) { |
| 959 ALOGD << "Destroy video encoder."; | 959 ALOGD << "Destroy video encoder."; |
| 960 delete encoder; | 960 delete encoder; |
| 961 } | 961 } |
| 962 | 962 |
| 963 } // namespace webrtc_jni | 963 } // namespace webrtc_jni |
| 964 | 964 |
| OLD | NEW |