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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 LOG(LS_ERROR) << "Wrong color format."; | 465 LOG(LS_ERROR) << "Wrong color format."; |
466 return WEBRTC_VIDEO_CODEC_ERROR; | 466 return WEBRTC_VIDEO_CODEC_ERROR; |
467 } | 467 } |
468 size_t num_input_buffers = jni->GetArrayLength(input_buffers); | 468 size_t num_input_buffers = jni->GetArrayLength(input_buffers); |
469 RTC_CHECK(input_buffers_.empty()) | 469 RTC_CHECK(input_buffers_.empty()) |
470 << "Unexpected double InitEncode without Release"; | 470 << "Unexpected double InitEncode without Release"; |
471 input_buffers_.resize(num_input_buffers); | 471 input_buffers_.resize(num_input_buffers); |
472 for (size_t i = 0; i < num_input_buffers; ++i) { | 472 for (size_t i = 0; i < num_input_buffers; ++i) { |
473 input_buffers_[i] = | 473 input_buffers_[i] = |
474 jni->NewGlobalRef(jni->GetObjectArrayElement(input_buffers, i)); | 474 jni->NewGlobalRef(jni->GetObjectArrayElement(input_buffers, i)); |
475 int64 yuv_buffer_capacity = | 475 int64_t yuv_buffer_capacity = |
476 jni->GetDirectBufferCapacity(input_buffers_[i]); | 476 jni->GetDirectBufferCapacity(input_buffers_[i]); |
477 CHECK_EXCEPTION(jni); | 477 CHECK_EXCEPTION(jni); |
478 RTC_CHECK(yuv_buffer_capacity >= yuv_size_) << "Insufficient capacity"; | 478 RTC_CHECK(yuv_buffer_capacity >= yuv_size_) << "Insufficient capacity"; |
479 } | 479 } |
480 CHECK_EXCEPTION(jni); | 480 CHECK_EXCEPTION(jni); |
481 | 481 |
482 codec_thread_->PostDelayed(kMediaCodecPollMs, this); | 482 codec_thread_->PostDelayed(kMediaCodecPollMs, this); |
483 return WEBRTC_VIDEO_CODEC_OK; | 483 return WEBRTC_VIDEO_CODEC_OK; |
484 } | 484 } |
485 | 485 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 } | 551 } |
552 if (j_input_buffer_index == -2) { | 552 if (j_input_buffer_index == -2) { |
553 ResetCodec(); | 553 ResetCodec(); |
554 return WEBRTC_VIDEO_CODEC_ERROR; | 554 return WEBRTC_VIDEO_CODEC_ERROR; |
555 } | 555 } |
556 | 556 |
557 ALOGV("Encoder frame in # %d. TS: %lld. Q: %d", | 557 ALOGV("Encoder frame in # %d. TS: %lld. Q: %d", |
558 frames_received_ - 1, current_timestamp_us_ / 1000, frames_in_queue_); | 558 frames_received_ - 1, current_timestamp_us_ / 1000, frames_in_queue_); |
559 | 559 |
560 jobject j_input_buffer = input_buffers_[j_input_buffer_index]; | 560 jobject j_input_buffer = input_buffers_[j_input_buffer_index]; |
561 uint8* yuv_buffer = | 561 uint8_t* yuv_buffer = |
562 reinterpret_cast<uint8*>(jni->GetDirectBufferAddress(j_input_buffer)); | 562 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_input_buffer)); |
563 CHECK_EXCEPTION(jni); | 563 CHECK_EXCEPTION(jni); |
564 RTC_CHECK(yuv_buffer) << "Indirect buffer??"; | 564 RTC_CHECK(yuv_buffer) << "Indirect buffer??"; |
565 RTC_CHECK(!libyuv::ConvertFromI420( | 565 RTC_CHECK(!libyuv::ConvertFromI420( |
566 input_frame.buffer(webrtc::kYPlane), input_frame.stride(webrtc::kYPlane), | 566 input_frame.buffer(webrtc::kYPlane), input_frame.stride(webrtc::kYPlane), |
567 input_frame.buffer(webrtc::kUPlane), input_frame.stride(webrtc::kUPlane), | 567 input_frame.buffer(webrtc::kUPlane), input_frame.stride(webrtc::kUPlane), |
568 input_frame.buffer(webrtc::kVPlane), input_frame.stride(webrtc::kVPlane), | 568 input_frame.buffer(webrtc::kVPlane), input_frame.stride(webrtc::kVPlane), |
569 yuv_buffer, width_, width_, height_, encoder_fourcc_)) | 569 yuv_buffer, width_, width_, height_, encoder_fourcc_)) |
570 << "ConvertFromI420 failed"; | 570 << "ConvertFromI420 failed"; |
571 last_input_timestamp_ms_ = current_timestamp_us_ / 1000; | 571 last_input_timestamp_ms_ = current_timestamp_us_ / 1000; |
572 frames_in_queue_++; | 572 frames_in_queue_++; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 timestamps_.erase(timestamps_.begin()); | 705 timestamps_.erase(timestamps_.begin()); |
706 output_render_time_ms_ = render_times_ms_.front(); | 706 output_render_time_ms_ = render_times_ms_.front(); |
707 render_times_ms_.erase(render_times_ms_.begin()); | 707 render_times_ms_.erase(render_times_ms_.begin()); |
708 frame_encoding_time_ms = GetCurrentTimeMs() - frame_rtc_times_ms_.front(); | 708 frame_encoding_time_ms = GetCurrentTimeMs() - frame_rtc_times_ms_.front(); |
709 frame_rtc_times_ms_.erase(frame_rtc_times_ms_.begin()); | 709 frame_rtc_times_ms_.erase(frame_rtc_times_ms_.begin()); |
710 frames_in_queue_--; | 710 frames_in_queue_--; |
711 } | 711 } |
712 | 712 |
713 // Extract payload. | 713 // Extract payload. |
714 size_t payload_size = jni->GetDirectBufferCapacity(j_output_buffer); | 714 size_t payload_size = jni->GetDirectBufferCapacity(j_output_buffer); |
715 uint8* payload = reinterpret_cast<uint8_t*>( | 715 uint8_t* payload = reinterpret_cast<uint8_t*>( |
716 jni->GetDirectBufferAddress(j_output_buffer)); | 716 jni->GetDirectBufferAddress(j_output_buffer)); |
717 CHECK_EXCEPTION(jni); | 717 CHECK_EXCEPTION(jni); |
718 | 718 |
719 ALOGV("Encoder frame out # %d. Key: %d. Size: %d. TS: %lld." | 719 ALOGV("Encoder frame out # %d. Key: %d. Size: %d. TS: %lld." |
720 " Latency: %lld. EncTime: %lld", | 720 " Latency: %lld. EncTime: %lld", |
721 frames_encoded_, key_frame, payload_size, | 721 frames_encoded_, key_frame, payload_size, |
722 last_output_timestamp_ms_, | 722 last_output_timestamp_ms_, |
723 last_input_timestamp_ms_ - last_output_timestamp_ms_, | 723 last_input_timestamp_ms_ - last_output_timestamp_ms_, |
724 frame_encoding_time_ms); | 724 frame_encoding_time_ms); |
725 | 725 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 } | 930 } |
931 | 931 |
932 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 932 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
933 webrtc::VideoEncoder* encoder) { | 933 webrtc::VideoEncoder* encoder) { |
934 ALOGD("Destroy video encoder."); | 934 ALOGD("Destroy video encoder."); |
935 delete encoder; | 935 delete encoder; |
936 } | 936 } |
937 | 937 |
938 } // namespace webrtc_jni | 938 } // namespace webrtc_jni |
939 | 939 |
OLD | NEW |