Add QP for MediaCodec decoder.

BUG=webrtc:6541

Review-Url: https://codereview.webrtc.org/2653183004
Cr-Commit-Position: refs/heads/master@{#16662}
This commit is contained in:
sakal
2017-02-17 03:26:10 -08:00
committed by Commit bot
parent f9d9154808
commit 9c997a3b9e
2 changed files with 33 additions and 10 deletions

View File

@ -1,6 +1,8 @@
include_rules = [ include_rules = [
"+third_party/libyuv", "+third_party/libyuv",
"+webrtc/common_video/h264/h264_bitstream_parser.h",
"+webrtc/common_video/libyuv/include/webrtc_libyuv.h", "+webrtc/common_video/libyuv/include/webrtc_libyuv.h",
"+webrtc/modules/video_coding/utility/vp8_header_parser.h",
"+webrtc/pc", "+webrtc/pc",
"+webrtc/voice_engine/include/voe_base.h", "+webrtc/voice_engine/include/voe_base.h",
] ]

View File

@ -9,6 +9,7 @@
*/ */
#include <algorithm> #include <algorithm>
#include <deque>
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -19,18 +20,20 @@
#include "third_party/libyuv/include/libyuv/convert.h" #include "third_party/libyuv/include/libyuv/convert.h"
#include "third_party/libyuv/include/libyuv/convert_from.h" #include "third_party/libyuv/include/libyuv/convert_from.h"
#include "third_party/libyuv/include/libyuv/video_common.h" #include "third_party/libyuv/include/libyuv/video_common.h"
#include "webrtc/sdk/android/src/jni/androidmediacodeccommon.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/native_handle_impl.h"
#include "webrtc/sdk/android/src/jni/surfacetexturehelper_jni.h"
#include "webrtc/base/bind.h" #include "webrtc/base/bind.h"
#include "webrtc/base/checks.h" #include "webrtc/base/checks.h"
#include "webrtc/base/logging.h" #include "webrtc/base/logging.h"
#include "webrtc/base/scoped_ref_ptr.h" #include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/base/thread.h" #include "webrtc/base/thread.h"
#include "webrtc/base/timeutils.h" #include "webrtc/base/timeutils.h"
#include "webrtc/common_video/h264/h264_bitstream_parser.h"
#include "webrtc/common_video/include/i420_buffer_pool.h" #include "webrtc/common_video/include/i420_buffer_pool.h"
#include "webrtc/modules/video_coding/include/video_codec_interface.h" #include "webrtc/modules/video_coding/include/video_codec_interface.h"
#include "webrtc/modules/video_coding/utility/vp8_header_parser.h"
#include "webrtc/sdk/android/src/jni/androidmediacodeccommon.h"
#include "webrtc/sdk/android/src/jni/classreferenceholder.h"
#include "webrtc/sdk/android/src/jni/native_handle_impl.h"
#include "webrtc/sdk/android/src/jni/surfacetexturehelper_jni.h"
#include "webrtc/system_wrappers/include/logcat_trace_context.h" #include "webrtc/system_wrappers/include/logcat_trace_context.h"
using rtc::Bind; using rtc::Bind;
@ -132,6 +135,8 @@ class MediaCodecVideoDecoder : public webrtc::VideoDecoder,
int current_decoding_time_ms_; // Overall decoding time in the current second int current_decoding_time_ms_; // Overall decoding time in the current second
int current_delay_time_ms_; // Overall delay time in the current second. int current_delay_time_ms_; // Overall delay time in the current second.
uint32_t max_pending_frames_; // Maximum number of pending input frames. uint32_t max_pending_frames_; // Maximum number of pending input frames.
webrtc::H264BitstreamParser h264_bitstream_parser_;
std::deque<rtc::Optional<uint8_t>> pending_frame_qps_;
// State that is constant for the lifetime of this object once the ctor // State that is constant for the lifetime of this object once the ctor
// returns. // returns.
@ -323,6 +328,7 @@ void MediaCodecVideoDecoder::ResetVariables() {
current_bytes_ = 0; current_bytes_ = 0;
current_decoding_time_ms_ = 0; current_decoding_time_ms_ = 0;
current_delay_time_ms_ = 0; current_delay_time_ms_ = 0;
pending_frame_qps_.clear();
} }
int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() { int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() {
@ -653,6 +659,21 @@ int32_t MediaCodecVideoDecoder::DecodeOnCodecThread(
// Save input image timestamps for later output. // Save input image timestamps for later output.
frames_received_++; frames_received_++;
current_bytes_ += inputImage._length; current_bytes_ += inputImage._length;
rtc::Optional<uint8_t> qp;
if (codecType_ == kVideoCodecVP8) {
int qp_int;
if (webrtc::vp8::GetQp(inputImage._buffer, inputImage._length, &qp_int)) {
qp = rtc::Optional<uint8_t>(qp_int);
}
} else if (codecType_ == kVideoCodecH264) {
h264_bitstream_parser_.ParseBitstream(inputImage._buffer,
inputImage._length);
int qp_int;
if (h264_bitstream_parser_.GetLastSliceQp(&qp_int)) {
qp = rtc::Optional<uint8_t>(qp_int);
}
}
pending_frame_qps_.push_back(qp);
// Feed input to decoder. // Feed input to decoder.
bool success = jni->CallBooleanMethod( bool success = jni->CallBooleanMethod(
@ -679,6 +700,7 @@ int32_t MediaCodecVideoDecoder::DecodeOnCodecThread(
bool MediaCodecVideoDecoder::DeliverPendingOutputs( bool MediaCodecVideoDecoder::DeliverPendingOutputs(
JNIEnv* jni, int dequeue_timeout_ms) { JNIEnv* jni, int dequeue_timeout_ms) {
CheckOnCodecThread();
if (frames_received_ <= frames_decoded_) { if (frames_received_ <= frames_decoded_) {
// No need to query for output buffers - decoder is drained. // No need to query for output buffers - decoder is drained.
return true; return true;
@ -861,11 +883,10 @@ bool MediaCodecVideoDecoder::DeliverPendingOutputs(
decoded_frame.set_timestamp(output_timestamps_ms); decoded_frame.set_timestamp(output_timestamps_ms);
decoded_frame.set_ntp_time_ms(output_ntp_timestamps_ms); decoded_frame.set_ntp_time_ms(output_ntp_timestamps_ms);
const int32_t callback_status = rtc::Optional<uint8_t> qp = pending_frame_qps_.front();
callback_->Decoded(decoded_frame, decode_time_ms); pending_frame_qps_.pop_front();
if (callback_status > 0) { callback_->Decoded(decoded_frame, rtc::Optional<int32_t>(decode_time_ms),
ALOGE << "callback error"; qp);
}
} }
return true; return true;
} }