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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 LOG(LS_ERROR) << "Wrong color format."; | 480 LOG(LS_ERROR) << "Wrong color format."; |
481 return WEBRTC_VIDEO_CODEC_ERROR; | 481 return WEBRTC_VIDEO_CODEC_ERROR; |
482 } | 482 } |
483 size_t num_input_buffers = jni->GetArrayLength(input_buffers); | 483 size_t num_input_buffers = jni->GetArrayLength(input_buffers); |
484 RTC_CHECK(input_buffers_.empty()) | 484 RTC_CHECK(input_buffers_.empty()) |
485 << "Unexpected double InitEncode without Release"; | 485 << "Unexpected double InitEncode without Release"; |
486 input_buffers_.resize(num_input_buffers); | 486 input_buffers_.resize(num_input_buffers); |
487 for (size_t i = 0; i < num_input_buffers; ++i) { | 487 for (size_t i = 0; i < num_input_buffers; ++i) { |
488 input_buffers_[i] = | 488 input_buffers_[i] = |
489 jni->NewGlobalRef(jni->GetObjectArrayElement(input_buffers, i)); | 489 jni->NewGlobalRef(jni->GetObjectArrayElement(input_buffers, i)); |
490 int64 yuv_buffer_capacity = | 490 int64_t yuv_buffer_capacity = |
491 jni->GetDirectBufferCapacity(input_buffers_[i]); | 491 jni->GetDirectBufferCapacity(input_buffers_[i]); |
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 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 } | 565 } |
566 if (j_input_buffer_index == -2) { | 566 if (j_input_buffer_index == -2) { |
567 ResetCodec(); | 567 ResetCodec(); |
568 return WEBRTC_VIDEO_CODEC_ERROR; | 568 return WEBRTC_VIDEO_CODEC_ERROR; |
569 } | 569 } |
570 | 570 |
571 ALOGV("Encoder frame in # %d. TS: %lld. Q: %d", | 571 ALOGV("Encoder frame in # %d. TS: %lld. Q: %d", |
572 frames_received_ - 1, current_timestamp_us_ / 1000, frames_in_queue_); | 572 frames_received_ - 1, current_timestamp_us_ / 1000, frames_in_queue_); |
573 | 573 |
574 jobject j_input_buffer = input_buffers_[j_input_buffer_index]; | 574 jobject j_input_buffer = input_buffers_[j_input_buffer_index]; |
575 uint8* yuv_buffer = | 575 uint8_t* yuv_buffer = |
576 reinterpret_cast<uint8*>(jni->GetDirectBufferAddress(j_input_buffer)); | 576 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_input_buffer)); |
577 CHECK_EXCEPTION(jni); | 577 CHECK_EXCEPTION(jni); |
578 RTC_CHECK(yuv_buffer) << "Indirect buffer??"; | 578 RTC_CHECK(yuv_buffer) << "Indirect buffer??"; |
579 RTC_CHECK(!libyuv::ConvertFromI420( | 579 RTC_CHECK(!libyuv::ConvertFromI420( |
580 input_frame.buffer(webrtc::kYPlane), input_frame.stride(webrtc::kYPlane), | 580 input_frame.buffer(webrtc::kYPlane), input_frame.stride(webrtc::kYPlane), |
581 input_frame.buffer(webrtc::kUPlane), input_frame.stride(webrtc::kUPlane), | 581 input_frame.buffer(webrtc::kUPlane), input_frame.stride(webrtc::kUPlane), |
582 input_frame.buffer(webrtc::kVPlane), input_frame.stride(webrtc::kVPlane), | 582 input_frame.buffer(webrtc::kVPlane), input_frame.stride(webrtc::kVPlane), |
583 yuv_buffer, width_, width_, height_, encoder_fourcc_)) | 583 yuv_buffer, width_, width_, height_, encoder_fourcc_)) |
584 << "ConvertFromI420 failed"; | 584 << "ConvertFromI420 failed"; |
585 last_input_timestamp_ms_ = current_timestamp_us_ / 1000; | 585 last_input_timestamp_ms_ = current_timestamp_us_ / 1000; |
586 frames_in_queue_++; | 586 frames_in_queue_++; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 timestamps_.erase(timestamps_.begin()); | 719 timestamps_.erase(timestamps_.begin()); |
720 output_render_time_ms_ = render_times_ms_.front(); | 720 output_render_time_ms_ = render_times_ms_.front(); |
721 render_times_ms_.erase(render_times_ms_.begin()); | 721 render_times_ms_.erase(render_times_ms_.begin()); |
722 frame_encoding_time_ms = GetCurrentTimeMs() - frame_rtc_times_ms_.front(); | 722 frame_encoding_time_ms = GetCurrentTimeMs() - frame_rtc_times_ms_.front(); |
723 frame_rtc_times_ms_.erase(frame_rtc_times_ms_.begin()); | 723 frame_rtc_times_ms_.erase(frame_rtc_times_ms_.begin()); |
724 frames_in_queue_--; | 724 frames_in_queue_--; |
725 } | 725 } |
726 | 726 |
727 // Extract payload. | 727 // Extract payload. |
728 size_t payload_size = jni->GetDirectBufferCapacity(j_output_buffer); | 728 size_t payload_size = jni->GetDirectBufferCapacity(j_output_buffer); |
729 uint8* payload = reinterpret_cast<uint8_t*>( | 729 uint8_t* payload = reinterpret_cast<uint8_t*>( |
730 jni->GetDirectBufferAddress(j_output_buffer)); | 730 jni->GetDirectBufferAddress(j_output_buffer)); |
731 CHECK_EXCEPTION(jni); | 731 CHECK_EXCEPTION(jni); |
732 | 732 |
733 ALOGV("Encoder frame out # %d. Key: %d. Size: %d. TS: %lld." | 733 ALOGV("Encoder frame out # %d. Key: %d. Size: %d. TS: %lld." |
734 " Latency: %lld. EncTime: %lld", | 734 " Latency: %lld. EncTime: %lld", |
735 frames_encoded_, key_frame, payload_size, | 735 frames_encoded_, key_frame, payload_size, |
736 last_output_timestamp_ms_, | 736 last_output_timestamp_ms_, |
737 last_input_timestamp_ms_ - last_output_timestamp_ms_, | 737 last_input_timestamp_ms_ - last_output_timestamp_ms_, |
738 frame_encoding_time_ms); | 738 frame_encoding_time_ms); |
739 | 739 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 } | 949 } |
950 | 950 |
951 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 951 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
952 webrtc::VideoEncoder* encoder) { | 952 webrtc::VideoEncoder* encoder) { |
953 ALOGD("Destroy video encoder."); | 953 ALOGD("Destroy video encoder."); |
954 delete encoder; | 954 delete encoder; |
955 } | 955 } |
956 | 956 |
957 } // namespace webrtc_jni | 957 } // namespace webrtc_jni |
958 | 958 |
OLD | NEW |