This reverts commit 42d8c93ec351b68554825b58a3dc6525a7dc84da. Reason for revert: Got Aliby for FEC test flakes Original change's description: > Revert "Delete rtc::TaskQueue::Current in favor of webrtc::TaskQueueBase::Current" > > This reverts commit 304e9d2df347630d71fd4423f5971f30dac73e41. > > Reason for revert: Breaks downstream projects. > Seems to make VideoSendStreamTest.SupportsFlexfecSimulcastVp8 flaky. > > Original change's description: > > Delete rtc::TaskQueue::Current in favor of webrtc::TaskQueueBase::Current > > > > Bug: webrtc:10191 > > Change-Id: I506cc50a90c73a6a4f6a3de36de0999cca72f5ba > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/126230 > > Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> > > Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#27035} > > TBR=danilchap@webrtc.org,kwiberg@webrtc.org > > Change-Id: If98324f88e4b3d18bf2fe33597dfb9711867c243 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:10191 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/126484 > Reviewed-by: Yves Gerey <yvesg@webrtc.org> > Commit-Queue: Yves Gerey <yvesg@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#27041} TBR=danilchap@webrtc.org,kwiberg@webrtc.org,yvesg@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:10191 Change-Id: Id87a17ae415142b8e0b11ba03ae7bad84a473fb0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/126720 Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Yves Gerey <yvesg@webrtc.org> Commit-Queue: Yves Gerey <yvesg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27056}
124 lines
4.1 KiB
C++
124 lines
4.1 KiB
C++
/*
|
|
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#ifndef SDK_ANDROID_SRC_JNI_VIDEO_ENCODER_WRAPPER_H_
|
|
#define SDK_ANDROID_SRC_JNI_VIDEO_ENCODER_WRAPPER_H_
|
|
|
|
#include <jni.h>
|
|
#include <deque>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "api/task_queue/task_queue_base.h"
|
|
#include "api/video_codecs/video_encoder.h"
|
|
#include "common_video/h264/h264_bitstream_parser.h"
|
|
#include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
|
|
#include "sdk/android/src/jni/jni_helpers.h"
|
|
#include "sdk/android/src/jni/video_frame.h"
|
|
|
|
namespace webrtc {
|
|
namespace jni {
|
|
|
|
// Wraps a Java encoder and delegates all calls to it.
|
|
class VideoEncoderWrapper : public VideoEncoder {
|
|
public:
|
|
VideoEncoderWrapper(JNIEnv* jni, const JavaRef<jobject>& j_encoder);
|
|
~VideoEncoderWrapper() override;
|
|
|
|
int32_t InitEncode(const VideoCodec* codec_settings,
|
|
int32_t number_of_cores,
|
|
size_t max_payload_size) override;
|
|
|
|
int32_t RegisterEncodeCompleteCallback(
|
|
EncodedImageCallback* callback) override;
|
|
|
|
int32_t Release() override;
|
|
|
|
int32_t Encode(const VideoFrame& frame,
|
|
const CodecSpecificInfo* codec_specific_info,
|
|
const std::vector<VideoFrameType>* frame_types) override;
|
|
|
|
int32_t SetRateAllocation(const VideoBitrateAllocation& allocation,
|
|
uint32_t framerate) override;
|
|
|
|
EncoderInfo GetEncoderInfo() const override;
|
|
|
|
// Should only be called by JNI.
|
|
void OnEncodedFrame(JNIEnv* jni,
|
|
const JavaRef<jobject>& j_caller,
|
|
const JavaRef<jobject>& j_buffer,
|
|
jint encoded_width,
|
|
jint encoded_height,
|
|
jlong capture_time_ms,
|
|
jint frame_type,
|
|
jint rotation,
|
|
jboolean complete_frame,
|
|
const JavaRef<jobject>& j_qp);
|
|
|
|
private:
|
|
struct FrameExtraInfo {
|
|
int64_t capture_time_ns; // Used as an identifier of the frame.
|
|
|
|
uint32_t timestamp_rtp;
|
|
};
|
|
|
|
int32_t InitEncodeInternal(JNIEnv* jni);
|
|
|
|
// Takes Java VideoCodecStatus, handles it and returns WEBRTC_VIDEO_CODEC_*
|
|
// status code.
|
|
int32_t HandleReturnCode(JNIEnv* jni,
|
|
const JavaRef<jobject>& j_value,
|
|
const char* method_name);
|
|
|
|
RTPFragmentationHeader ParseFragmentationHeader(
|
|
const std::vector<uint8_t>& buffer);
|
|
int ParseQp(const std::vector<uint8_t>& buffer);
|
|
CodecSpecificInfo ParseCodecSpecificInfo(const EncodedImage& frame);
|
|
ScopedJavaLocalRef<jobject> ToJavaBitrateAllocation(
|
|
JNIEnv* jni,
|
|
const VideoBitrateAllocation& allocation);
|
|
std::string GetImplementationName(JNIEnv* jni) const;
|
|
|
|
ScalingSettings GetScalingSettingsInternal(JNIEnv* jni) const;
|
|
|
|
const ScopedJavaGlobalRef<jobject> encoder_;
|
|
const ScopedJavaGlobalRef<jclass> int_array_class_;
|
|
|
|
rtc::CriticalSection encoder_queue_crit_;
|
|
TaskQueueBase* encoder_queue_ RTC_GUARDED_BY(encoder_queue_crit_);
|
|
std::deque<FrameExtraInfo> frame_extra_infos_;
|
|
EncodedImageCallback* callback_;
|
|
bool initialized_;
|
|
int num_resets_;
|
|
int number_of_cores_;
|
|
VideoCodec codec_settings_;
|
|
EncoderInfo encoder_info_;
|
|
H264BitstreamParser h264_bitstream_parser_;
|
|
|
|
// VP9 variables to populate codec specific structure.
|
|
GofInfoVP9 gof_; // Contains each frame's temporal information for
|
|
// non-flexible VP9 mode.
|
|
size_t gof_idx_;
|
|
};
|
|
|
|
/* If the j_encoder is a wrapped native encoder, unwrap it. If it is not,
|
|
* wrap it in a VideoEncoderWrapper.
|
|
*/
|
|
std::unique_ptr<VideoEncoder> JavaToNativeVideoEncoder(
|
|
JNIEnv* jni,
|
|
const JavaRef<jobject>& j_encoder);
|
|
|
|
bool IsHardwareVideoEncoder(JNIEnv* jni, const JavaRef<jobject>& j_encoder);
|
|
|
|
} // namespace jni
|
|
} // namespace webrtc
|
|
|
|
#endif // SDK_ANDROID_SRC_JNI_VIDEO_ENCODER_WRAPPER_H_
|