Index: webrtc/sdk/android/src/jni/videoencoderwrapper.h |
diff --git a/webrtc/sdk/android/src/jni/videoencoderwrapper.h b/webrtc/sdk/android/src/jni/videoencoderwrapper.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cc9a29083957886475d985307c54160c2a02e138 |
--- /dev/null |
+++ b/webrtc/sdk/android/src/jni/videoencoderwrapper.h |
@@ -0,0 +1,192 @@ |
+/* |
+ * 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 WEBRTC_SDK_ANDROID_SRC_JNI_VIDEOENCODERWRAPPER_H_ |
+#define WEBRTC_SDK_ANDROID_SRC_JNI_VIDEOENCODERWRAPPER_H_ |
+ |
+#include <jni.h> |
+#include <string> |
+#include <vector> |
+ |
+#include "webrtc/api/video_codecs/video_encoder.h" |
+#include "webrtc/common_video/h264/h264_bitstream_parser.h" |
+#include "webrtc/modules/video_coding/codecs/vp9/include/vp9_globals.h" |
+#include "webrtc/sdk/android/src/jni/jni_helpers.h" |
+#include "webrtc/sdk/android/src/jni/native_handle_impl.h" |
+ |
+namespace webrtc_jni { |
magjed_webrtc
2017/08/28 16:54:23
Nest the namespaces instead.
sakal
2017/08/29 12:59:39
Done.
|
+ |
+// Wraps a Java decoder and delegates all calls to it. Passes |
+// VideoEncoderWrapperCallback to the decoder on InitDecode. Wraps the received |
+// frames to AndroidVideoBuffer. |
+class VideoEncoderWrapper : public webrtc::VideoEncoder { |
+ public: |
+ VideoEncoderWrapper(JNIEnv* jni, jobject j_encoder); |
+ |
+ // Initialize the encoder with the information from the codecSettings |
magjed_webrtc
2017/08/28 16:54:23
You don't have to copy the documentation for overr
sakal
2017/08/29 12:59:38
Done.
|
+ // |
+ // Input: |
+ // - codec_settings : Codec settings |
+ // - number_of_cores : Number of cores available for the encoder |
+ // - max_payload_size : The maximum size each payload is allowed |
+ // to have. Usually MTU - overhead. |
+ // |
+ // Return value : Set bit rate if OK |
+ // <0 - Errors: |
+ // WEBRTC_VIDEO_CODEC_ERR_PARAMETER |
+ // WEBRTC_VIDEO_CODEC_ERR_SIZE |
+ // WEBRTC_VIDEO_CODEC_LEVEL_EXCEEDED |
+ // WEBRTC_VIDEO_CODEC_MEMORY |
+ // WEBRTC_VIDEO_CODEC_ERROR |
+ int32_t InitEncode(const webrtc::VideoCodec* codec_settings, |
+ int32_t number_of_cores, |
+ size_t max_payload_size) override; |
+ |
+ // Register an encode complete callback object. |
+ // |
+ // Input: |
+ // - callback : Callback object which handles encoded images. |
+ // |
+ // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. |
+ int32_t RegisterEncodeCompleteCallback( |
+ webrtc::EncodedImageCallback* callback) override; |
+ |
+ // Free encoder memory. |
+ // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. |
+ int32_t Release() override; |
+ |
+ // Encode an I420 image (as a part of a video stream) override. The encoded |
+ // image will be returned to the user through the encode complete callback. |
+ // |
+ // Input: |
+ // - frame : Image to be encoded |
+ // - frame_types : Frame type to be generated by the encoder. |
+ // |
+ // Return value : WEBRTC_VIDEO_CODEC_OK if OK |
+ // <0 - Errors: |
+ // WEBRTC_VIDEO_CODEC_ERR_PARAMETER |
+ // WEBRTC_VIDEO_CODEC_MEMORY |
+ // WEBRTC_VIDEO_CODEC_ERROR |
+ // WEBRTC_VIDEO_CODEC_TIMEOUT |
+ int32_t Encode(const webrtc::VideoFrame& frame, |
+ const webrtc::CodecSpecificInfo* codec_specific_info, |
+ const std::vector<webrtc::FrameType>* frame_types) override; |
+ |
+ // Inform the encoder of the new packet loss rate and the round-trip time of |
+ // the network. |
+ // |
+ // Input: |
+ // - packet_loss : Fraction lost |
+ // (loss rate in percent = 100 * packetLoss / 255) |
+ // override |
+ // - rtt : Round-trip time in milliseconds |
+ // Return value : WEBRTC_VIDEO_CODEC_OK if OK |
+ // <0 - Errors: WEBRTC_VIDEO_CODEC_ERROR |
+ int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; |
+ |
+ // Inform the encoder about the new target bit rate. |
+ // |
+ // Input: |
+ // - bitrate : New target bit rate |
+ // - framerate : The target frame rate |
+ // |
+ // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. |
+ int32_t SetRateAllocation(const webrtc::BitrateAllocation& allocation, |
+ uint32_t framerate) override; |
+ |
+ // Any encoder implementation wishing to use the WebRTC provided |
+ // quality scaler must implement this method. |
+ ScalingSettings GetScalingSettings() const override; |
+ |
+ bool SupportsNativeHandle() const override { return true; } |
+ |
+ // Should only be called by JNI. |
+ void OnEncodedFrame(JNIEnv* jni, |
+ jobject j_buffer, |
+ jint encoded_width, |
+ jint encoded_height, |
+ jlong capture_time_ms, |
+ jint frame_type, |
+ jint rotation, |
+ jboolean complete_frame, |
+ jobject j_qp); |
+ |
+ const char* ImplementationName() const override; |
+ |
+ private: |
+ int32_t InitEncodeInternal(JNIEnv* jni); |
+ |
+ // Takes Java VideoCodecStatus, handles it and returns WEBRTC_VIDEO_CODEC_* |
+ // status code. |
+ int32_t HandleReturnCode(JNIEnv* jni, jobject code); |
+ |
+ webrtc::RTPFragmentationHeader ParseFragmentationHeader(uint8_t* buffer, |
+ size_t buffer_size); |
+ int ParseQp(uint8_t* buffer, size_t buffer_size); |
+ webrtc::CodecSpecificInfo ParseCodecSpecificInfo( |
+ const webrtc::EncodedImage& frame); |
+ jobject ToJavaBitrateAllocation(JNIEnv* jni, |
+ const webrtc::BitrateAllocation& allocation); |
+ std::string GetImplementationName(JNIEnv* jni) const; |
+ |
+ const ScopedGlobalRef<jobject> encoder_; |
+ const ScopedGlobalRef<jclass> settings_class_; |
+ const ScopedGlobalRef<jclass> encode_info_class_; |
+ const ScopedGlobalRef<jclass> frame_type_class_; |
+ const ScopedGlobalRef<jclass> bitrate_allocation_class_; |
+ const ScopedGlobalRef<jclass> int_array_class_; |
+ |
+ jmethodID init_encode_method_; |
+ jmethodID release_method_; |
+ jmethodID encode_method_; |
+ jmethodID set_channel_parameters_method_; |
+ jmethodID set_rate_allocation_method_; |
+ jmethodID get_scaling_settings_method_; |
+ jmethodID get_implementation_name_method_; |
+ |
+ jmethodID settings_constructor_; |
+ |
+ jmethodID encode_info_constructor_; |
+ |
+ jmethodID frame_type_from_native_method_; |
+ |
+ jmethodID bitrate_allocation_constructor_; |
+ |
+ jfieldID scaling_settings_on_field_; |
+ jfieldID scaling_settings_low_field_; |
+ jfieldID scaling_settings_high_field_; |
+ |
+ jmethodID get_number_method_; |
+ |
+ jmethodID int_value_method_; |
+ |
+ std::string implementation_name_; |
+ |
+ JavaVideoFrameFactory video_frame_factory_; |
+ webrtc::EncodedImageCallback* callback_; |
+ bool initialized_; |
+ int num_resets_; |
+ int number_of_cores_; |
+ webrtc::VideoCodec codec_settings_; |
+ webrtc::H264BitstreamParser h264_bitstream_parser_; |
+ |
+ // RTP state. |
+ uint16_t picture_id_; |
+ uint8_t tl0_pic_idx_; |
+ |
+ // VP9 variables to populate codec specific structure. |
+ webrtc::GofInfoVP9 gof_; // Contains each frame's temporal information for |
+ // non-flexible VP9 mode. |
+ size_t gof_idx_; |
+}; |
+ |
+} // namespace webrtc_jni |
+ |
+#endif // WEBRTC_SDK_ANDROID_SRC_JNI_VIDEOENCODERWRAPPER_H_ |