Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: talk/app/webrtc/java/jni/androidmediaencoder_jni.cc

Issue 1470043002: Support texture scaling in Androids MediaEncoder (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Revert changes in QualityScaler. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 const webrtc::QualityScaler::Resolution scaled_resolution =
581 const VideoFrame& input_frame = 581 quality_scaler_.GetScaledResolution();
582 scale_ ? quality_scaler_.GetScaledFrame(frame) : frame; 582 if (scaled_resolution.width != frame.width() ||
583 scaled_resolution.height != frame.height()) {
584 if (frame.native_handle() != nullptr) {
585 rtc::scoped_refptr<webrtc::VideoFrameBuffer> scaled_buffer(
586 static_cast<AndroidTextureBuffer*>(
587 frame.video_frame_buffer().get())->CropAndScale(
588 frame.width(),
589 frame.height(),
590 scaled_resolution.width,
591 scaled_resolution.height));
592 input_frame.set_video_frame_buffer(scaled_buffer);
593 } else {
594 input_frame = quality_scaler_.GetScaledFrame(frame);
595 }
596 }
597 }
583 598
584 if (!MaybeReconfigureEncoderOnCodecThread(input_frame)) { 599 if (!MaybeReconfigureEncoderOnCodecThread(input_frame)) {
585 ALOGE << "Failed to reconfigure encoder."; 600 ALOGE << "Failed to reconfigure encoder.";
586 return WEBRTC_VIDEO_CODEC_ERROR; 601 return WEBRTC_VIDEO_CODEC_ERROR;
587 } 602 }
588 603
589 // Check if we accumulated too many frames in encoder input buffers 604 // Check if we accumulated too many frames in encoder input buffers
590 // or the encoder latency exceeds 70 ms and drop frame if so. 605 // or the encoder latency exceeds 70 ms and drop frame if so.
591 if (frames_in_queue_ > 0 && last_input_timestamp_ms_ >= 0) { 606 if (frames_in_queue_ > 0 && last_input_timestamp_ms_ >= 0) {
592 int encoder_latency_ms = last_input_timestamp_ms_ - 607 int encoder_latency_ms = last_input_timestamp_ms_ -
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 } 1161 }
1147 1162
1148 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( 1163 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder(
1149 webrtc::VideoEncoder* encoder) { 1164 webrtc::VideoEncoder* encoder) {
1150 ALOGD << "Destroy video encoder."; 1165 ALOGD << "Destroy video encoder.";
1151 delete encoder; 1166 delete encoder;
1152 } 1167 }
1153 1168
1154 } // namespace webrtc_jni 1169 } // namespace webrtc_jni
1155 1170
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698