Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #ifndef WEBRTC_SDK_ANDROID_SRC_JNI_VIDEOENCODERWRAPPER_H_ | |
| 12 #define WEBRTC_SDK_ANDROID_SRC_JNI_VIDEOENCODERWRAPPER_H_ | |
| 13 | |
| 14 #include <jni.h> | |
| 15 #include <string> | |
| 16 #include <vector> | |
| 17 | |
| 18 #include "webrtc/api/video_codecs/video_encoder.h" | |
| 19 #include "webrtc/common_video/h264/h264_bitstream_parser.h" | |
| 20 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9_globals.h" | |
| 21 #include "webrtc/sdk/android/src/jni/jni_helpers.h" | |
| 22 #include "webrtc/sdk/android/src/jni/native_handle_impl.h" | |
| 23 | |
| 24 namespace webrtc_jni { | |
|
magjed_webrtc
2017/08/28 16:54:23
Nest the namespaces instead.
sakal
2017/08/29 12:59:39
Done.
| |
| 25 | |
| 26 // Wraps a Java decoder and delegates all calls to it. Passes | |
| 27 // VideoEncoderWrapperCallback to the decoder on InitDecode. Wraps the received | |
| 28 // frames to AndroidVideoBuffer. | |
| 29 class VideoEncoderWrapper : public webrtc::VideoEncoder { | |
| 30 public: | |
| 31 VideoEncoderWrapper(JNIEnv* jni, jobject j_encoder); | |
| 32 | |
| 33 // 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.
| |
| 34 // | |
| 35 // Input: | |
| 36 // - codec_settings : Codec settings | |
| 37 // - number_of_cores : Number of cores available for the encoder | |
| 38 // - max_payload_size : The maximum size each payload is allowed | |
| 39 // to have. Usually MTU - overhead. | |
| 40 // | |
| 41 // Return value : Set bit rate if OK | |
| 42 // <0 - Errors: | |
| 43 // WEBRTC_VIDEO_CODEC_ERR_PARAMETER | |
| 44 // WEBRTC_VIDEO_CODEC_ERR_SIZE | |
| 45 // WEBRTC_VIDEO_CODEC_LEVEL_EXCEEDED | |
| 46 // WEBRTC_VIDEO_CODEC_MEMORY | |
| 47 // WEBRTC_VIDEO_CODEC_ERROR | |
| 48 int32_t InitEncode(const webrtc::VideoCodec* codec_settings, | |
| 49 int32_t number_of_cores, | |
| 50 size_t max_payload_size) override; | |
| 51 | |
| 52 // Register an encode complete callback object. | |
| 53 // | |
| 54 // Input: | |
| 55 // - callback : Callback object which handles encoded images. | |
| 56 // | |
| 57 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. | |
| 58 int32_t RegisterEncodeCompleteCallback( | |
| 59 webrtc::EncodedImageCallback* callback) override; | |
| 60 | |
| 61 // Free encoder memory. | |
| 62 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. | |
| 63 int32_t Release() override; | |
| 64 | |
| 65 // Encode an I420 image (as a part of a video stream) override. The encoded | |
| 66 // image will be returned to the user through the encode complete callback. | |
| 67 // | |
| 68 // Input: | |
| 69 // - frame : Image to be encoded | |
| 70 // - frame_types : Frame type to be generated by the encoder. | |
| 71 // | |
| 72 // Return value : WEBRTC_VIDEO_CODEC_OK if OK | |
| 73 // <0 - Errors: | |
| 74 // WEBRTC_VIDEO_CODEC_ERR_PARAMETER | |
| 75 // WEBRTC_VIDEO_CODEC_MEMORY | |
| 76 // WEBRTC_VIDEO_CODEC_ERROR | |
| 77 // WEBRTC_VIDEO_CODEC_TIMEOUT | |
| 78 int32_t Encode(const webrtc::VideoFrame& frame, | |
| 79 const webrtc::CodecSpecificInfo* codec_specific_info, | |
| 80 const std::vector<webrtc::FrameType>* frame_types) override; | |
| 81 | |
| 82 // Inform the encoder of the new packet loss rate and the round-trip time of | |
| 83 // the network. | |
| 84 // | |
| 85 // Input: | |
| 86 // - packet_loss : Fraction lost | |
| 87 // (loss rate in percent = 100 * packetLoss / 255) | |
| 88 // override | |
| 89 // - rtt : Round-trip time in milliseconds | |
| 90 // Return value : WEBRTC_VIDEO_CODEC_OK if OK | |
| 91 // <0 - Errors: WEBRTC_VIDEO_CODEC_ERROR | |
| 92 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; | |
| 93 | |
| 94 // Inform the encoder about the new target bit rate. | |
| 95 // | |
| 96 // Input: | |
| 97 // - bitrate : New target bit rate | |
| 98 // - framerate : The target frame rate | |
| 99 // | |
| 100 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. | |
| 101 int32_t SetRateAllocation(const webrtc::BitrateAllocation& allocation, | |
| 102 uint32_t framerate) override; | |
| 103 | |
| 104 // Any encoder implementation wishing to use the WebRTC provided | |
| 105 // quality scaler must implement this method. | |
| 106 ScalingSettings GetScalingSettings() const override; | |
| 107 | |
| 108 bool SupportsNativeHandle() const override { return true; } | |
| 109 | |
| 110 // Should only be called by JNI. | |
| 111 void OnEncodedFrame(JNIEnv* jni, | |
| 112 jobject j_buffer, | |
| 113 jint encoded_width, | |
| 114 jint encoded_height, | |
| 115 jlong capture_time_ms, | |
| 116 jint frame_type, | |
| 117 jint rotation, | |
| 118 jboolean complete_frame, | |
| 119 jobject j_qp); | |
| 120 | |
| 121 const char* ImplementationName() const override; | |
| 122 | |
| 123 private: | |
| 124 int32_t InitEncodeInternal(JNIEnv* jni); | |
| 125 | |
| 126 // Takes Java VideoCodecStatus, handles it and returns WEBRTC_VIDEO_CODEC_* | |
| 127 // status code. | |
| 128 int32_t HandleReturnCode(JNIEnv* jni, jobject code); | |
| 129 | |
| 130 webrtc::RTPFragmentationHeader ParseFragmentationHeader(uint8_t* buffer, | |
| 131 size_t buffer_size); | |
| 132 int ParseQp(uint8_t* buffer, size_t buffer_size); | |
| 133 webrtc::CodecSpecificInfo ParseCodecSpecificInfo( | |
| 134 const webrtc::EncodedImage& frame); | |
| 135 jobject ToJavaBitrateAllocation(JNIEnv* jni, | |
| 136 const webrtc::BitrateAllocation& allocation); | |
| 137 std::string GetImplementationName(JNIEnv* jni) const; | |
| 138 | |
| 139 const ScopedGlobalRef<jobject> encoder_; | |
| 140 const ScopedGlobalRef<jclass> settings_class_; | |
| 141 const ScopedGlobalRef<jclass> encode_info_class_; | |
| 142 const ScopedGlobalRef<jclass> frame_type_class_; | |
| 143 const ScopedGlobalRef<jclass> bitrate_allocation_class_; | |
| 144 const ScopedGlobalRef<jclass> int_array_class_; | |
| 145 | |
| 146 jmethodID init_encode_method_; | |
| 147 jmethodID release_method_; | |
| 148 jmethodID encode_method_; | |
| 149 jmethodID set_channel_parameters_method_; | |
| 150 jmethodID set_rate_allocation_method_; | |
| 151 jmethodID get_scaling_settings_method_; | |
| 152 jmethodID get_implementation_name_method_; | |
| 153 | |
| 154 jmethodID settings_constructor_; | |
| 155 | |
| 156 jmethodID encode_info_constructor_; | |
| 157 | |
| 158 jmethodID frame_type_from_native_method_; | |
| 159 | |
| 160 jmethodID bitrate_allocation_constructor_; | |
| 161 | |
| 162 jfieldID scaling_settings_on_field_; | |
| 163 jfieldID scaling_settings_low_field_; | |
| 164 jfieldID scaling_settings_high_field_; | |
| 165 | |
| 166 jmethodID get_number_method_; | |
| 167 | |
| 168 jmethodID int_value_method_; | |
| 169 | |
| 170 std::string implementation_name_; | |
| 171 | |
| 172 JavaVideoFrameFactory video_frame_factory_; | |
| 173 webrtc::EncodedImageCallback* callback_; | |
| 174 bool initialized_; | |
| 175 int num_resets_; | |
| 176 int number_of_cores_; | |
| 177 webrtc::VideoCodec codec_settings_; | |
| 178 webrtc::H264BitstreamParser h264_bitstream_parser_; | |
| 179 | |
| 180 // RTP state. | |
| 181 uint16_t picture_id_; | |
| 182 uint8_t tl0_pic_idx_; | |
| 183 | |
| 184 // VP9 variables to populate codec specific structure. | |
| 185 webrtc::GofInfoVP9 gof_; // Contains each frame's temporal information for | |
| 186 // non-flexible VP9 mode. | |
| 187 size_t gof_idx_; | |
| 188 }; | |
| 189 | |
| 190 } // namespace webrtc_jni | |
| 191 | |
| 192 #endif // WEBRTC_SDK_ANDROID_SRC_JNI_VIDEOENCODERWRAPPER_H_ | |
| OLD | NEW |