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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 const bool encode_status = jni->CallBooleanMethod( | 499 const bool encode_status = jni->CallBooleanMethod( |
500 *j_media_codec_video_encoder_, j_init_encode_method_, | 500 *j_media_codec_video_encoder_, j_init_encode_method_, |
501 j_video_codec_enum, width, height, kbps, fps, | 501 j_video_codec_enum, width, height, kbps, fps, |
502 (use_surface ? egl_context_ : nullptr)); | 502 (use_surface ? egl_context_ : nullptr)); |
503 if (!encode_status) { | 503 if (!encode_status) { |
504 ALOGE << "Failed to configure encoder."; | 504 ALOGE << "Failed to configure encoder."; |
505 return WEBRTC_VIDEO_CODEC_ERROR; | 505 return WEBRTC_VIDEO_CODEC_ERROR; |
506 } | 506 } |
507 CHECK_EXCEPTION(jni); | 507 CHECK_EXCEPTION(jni); |
508 | 508 |
509 if (use_surface) { | 509 if (!use_surface) { |
510 scale_ = false; // TODO(perkj): Implement scaling when using textures. | |
511 } else { | |
512 jobjectArray input_buffers = reinterpret_cast<jobjectArray>( | 510 jobjectArray input_buffers = reinterpret_cast<jobjectArray>( |
513 jni->CallObjectMethod(*j_media_codec_video_encoder_, | 511 jni->CallObjectMethod(*j_media_codec_video_encoder_, |
514 j_get_input_buffers_method_)); | 512 j_get_input_buffers_method_)); |
515 CHECK_EXCEPTION(jni); | 513 CHECK_EXCEPTION(jni); |
516 if (IsNull(jni, input_buffers)) { | 514 if (IsNull(jni, input_buffers)) { |
517 return WEBRTC_VIDEO_CODEC_ERROR; | 515 return WEBRTC_VIDEO_CODEC_ERROR; |
518 } | 516 } |
519 | 517 |
520 switch (GetIntField(jni, *j_media_codec_video_encoder_, | 518 switch (GetIntField(jni, *j_media_codec_video_encoder_, |
521 j_color_format_field_)) { | 519 j_color_format_field_)) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 return WEBRTC_VIDEO_CODEC_ERROR; | 565 return WEBRTC_VIDEO_CODEC_ERROR; |
568 } | 566 } |
569 | 567 |
570 if (drop_next_input_frame_) { | 568 if (drop_next_input_frame_) { |
571 ALOGW << "Encoder drop frame - failed callback."; | 569 ALOGW << "Encoder drop frame - failed callback."; |
572 drop_next_input_frame_ = false; | 570 drop_next_input_frame_ = false; |
573 return WEBRTC_VIDEO_CODEC_OK; | 571 return WEBRTC_VIDEO_CODEC_OK; |
574 } | 572 } |
575 | 573 |
576 RTC_CHECK(frame_types->size() == 1) << "Unexpected stream count"; | 574 RTC_CHECK(frame_types->size() == 1) << "Unexpected stream count"; |
577 // Check framerate before spatial resolution change. | 575 |
578 if (scale_) | 576 VideoFrame input_frame = frame; |
577 if (scale_) { | |
578 // Check framerate before spatial resolution change. | |
579 quality_scaler_.OnEncodeFrame(frame); | 579 quality_scaler_.OnEncodeFrame(frame); |
580 | 580 if (quality_scaler_.GetScaledResolution().width != frame.width() || |
pbos-webrtc
2015/11/26 09:41:37
Get scaled resolution once, this looks clunky. Oth
perkj_webrtc
2015/11/26 12:58:48
Done.
| |
581 const VideoFrame& input_frame = | 581 quality_scaler_.GetScaledResolution().height != frame.height()) { |
582 scale_ ? quality_scaler_.GetScaledFrame(frame) : frame; | 582 if (frame.native_handle() != nullptr) { |
583 rtc::scoped_refptr<webrtc::VideoFrameBuffer> scaled_buffer( | |
pbos-webrtc
2015/11/26 09:41:37
If you wanna put a comment on how the crop-and-sca
perkj_webrtc
2015/11/26 12:58:48
No I don't :-> Read the code...
| |
584 static_cast<AndroidTextureBuffer*>( | |
585 frame.video_frame_buffer().get())->CropAndScale( | |
586 frame.width(), | |
587 frame.height(), | |
588 quality_scaler_.GetScaledResolution().width, | |
589 quality_scaler_.GetScaledResolution().height)); | |
590 input_frame.set_video_frame_buffer(scaled_buffer); | |
591 } else { | |
592 input_frame.ShallowCopy(quality_scaler_.GetScaledFrame(frame)); | |
593 } | |
594 } | |
595 } | |
583 | 596 |
584 if (!MaybeReconfigureEncoderOnCodecThread(input_frame)) { | 597 if (!MaybeReconfigureEncoderOnCodecThread(input_frame)) { |
585 ALOGE << "Failed to reconfigure encoder."; | 598 ALOGE << "Failed to reconfigure encoder."; |
586 return WEBRTC_VIDEO_CODEC_ERROR; | 599 return WEBRTC_VIDEO_CODEC_ERROR; |
587 } | 600 } |
588 | 601 |
589 // Check if we accumulated too many frames in encoder input buffers | 602 // Check if we accumulated too many frames in encoder input buffers |
590 // or the encoder latency exceeds 70 ms and drop frame if so. | 603 // or the encoder latency exceeds 70 ms and drop frame if so. |
591 if (frames_in_queue_ > 0 && last_input_timestamp_ms_ >= 0) { | 604 if (frames_in_queue_ > 0 && last_input_timestamp_ms_ >= 0) { |
592 int encoder_latency_ms = last_input_timestamp_ms_ - | 605 int encoder_latency_ms = last_input_timestamp_ms_ - |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1146 } | 1159 } |
1147 | 1160 |
1148 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 1161 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
1149 webrtc::VideoEncoder* encoder) { | 1162 webrtc::VideoEncoder* encoder) { |
1150 ALOGD << "Destroy video encoder."; | 1163 ALOGD << "Destroy video encoder."; |
1151 delete encoder; | 1164 delete encoder; |
1152 } | 1165 } |
1153 | 1166 |
1154 } // namespace webrtc_jni | 1167 } // namespace webrtc_jni |
1155 | 1168 |
OLD | NEW |