OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 } | 1157 } |
1158 | 1158 |
1159 int MediaCodecVideoEncoder::GetTargetFramerate() { | 1159 int MediaCodecVideoEncoder::GetTargetFramerate() { |
1160 return scale_ ? quality_scaler_.GetTargetFramerate() : -1; | 1160 return scale_ ? quality_scaler_.GetTargetFramerate() : -1; |
1161 } | 1161 } |
1162 | 1162 |
1163 const char* MediaCodecVideoEncoder::ImplementationName() const { | 1163 const char* MediaCodecVideoEncoder::ImplementationName() const { |
1164 return "MediaCodec"; | 1164 return "MediaCodec"; |
1165 } | 1165 } |
1166 | 1166 |
1167 MediaCodecVideoEncoderFactory::MediaCodecVideoEncoderFactory() { | 1167 MediaCodecVideoEncoderFactory::MediaCodecVideoEncoderFactory() |
| 1168 : egl_context_(nullptr) { |
1168 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 1169 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
1169 ScopedLocalRefFrame local_ref_frame(jni); | 1170 ScopedLocalRefFrame local_ref_frame(jni); |
1170 jclass j_encoder_class = FindClass(jni, "org/webrtc/MediaCodecVideoEncoder"); | 1171 jclass j_encoder_class = FindClass(jni, "org/webrtc/MediaCodecVideoEncoder"); |
1171 supported_codecs_.clear(); | 1172 supported_codecs_.clear(); |
1172 | 1173 |
1173 bool is_vp8_hw_supported = jni->CallStaticBooleanMethod( | 1174 bool is_vp8_hw_supported = jni->CallStaticBooleanMethod( |
1174 j_encoder_class, | 1175 j_encoder_class, |
1175 GetStaticMethodID(jni, j_encoder_class, "isVp8HwSupported", "()Z")); | 1176 GetStaticMethodID(jni, j_encoder_class, "isVp8HwSupported", "()Z")); |
1176 CHECK_EXCEPTION(jni); | 1177 CHECK_EXCEPTION(jni); |
1177 if (is_vp8_hw_supported) { | 1178 if (is_vp8_hw_supported) { |
(...skipping 18 matching lines...) Expand all Loading... |
1196 CHECK_EXCEPTION(jni); | 1197 CHECK_EXCEPTION(jni); |
1197 if (is_h264_hw_supported) { | 1198 if (is_h264_hw_supported) { |
1198 ALOGD << "H.264 HW Encoder supported."; | 1199 ALOGD << "H.264 HW Encoder supported."; |
1199 supported_codecs_.push_back(VideoCodec(kVideoCodecH264, "H264", | 1200 supported_codecs_.push_back(VideoCodec(kVideoCodecH264, "H264", |
1200 MAX_VIDEO_WIDTH, MAX_VIDEO_HEIGHT, MAX_VIDEO_FPS)); | 1201 MAX_VIDEO_WIDTH, MAX_VIDEO_HEIGHT, MAX_VIDEO_FPS)); |
1201 } | 1202 } |
1202 } | 1203 } |
1203 | 1204 |
1204 MediaCodecVideoEncoderFactory::~MediaCodecVideoEncoderFactory() { | 1205 MediaCodecVideoEncoderFactory::~MediaCodecVideoEncoderFactory() { |
1205 ALOGD << "MediaCodecVideoEncoderFactory dtor"; | 1206 ALOGD << "MediaCodecVideoEncoderFactory dtor"; |
| 1207 if (egl_context_) { |
| 1208 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
| 1209 jni->DeleteGlobalRef(egl_context_); |
| 1210 } |
1206 } | 1211 } |
1207 | 1212 |
1208 void MediaCodecVideoEncoderFactory::SetEGLContext( | 1213 void MediaCodecVideoEncoderFactory::SetEGLContext( |
1209 JNIEnv* jni, jobject render_egl_context) { | 1214 JNIEnv* jni, jobject egl_context) { |
1210 ALOGD << "MediaCodecVideoEncoderFactory::SetEGLContext"; | 1215 ALOGD << "MediaCodecVideoEncoderFactory::SetEGLContext"; |
1211 if (!egl_base_.CreateEglBase(jni, render_egl_context)) { | 1216 RTC_DCHECK(!egl_context_); |
1212 ALOGW << "Invalid EGL context - HW surface encoding is disabled."; | 1217 egl_context_ = jni->NewGlobalRef(egl_context); |
| 1218 if (CheckException(jni)) { |
| 1219 ALOGE << "error calling NewGlobalRef for EGL Context."; |
1213 } | 1220 } |
1214 } | 1221 } |
1215 | 1222 |
1216 webrtc::VideoEncoder* MediaCodecVideoEncoderFactory::CreateVideoEncoder( | 1223 webrtc::VideoEncoder* MediaCodecVideoEncoderFactory::CreateVideoEncoder( |
1217 VideoCodecType type) { | 1224 VideoCodecType type) { |
1218 if (supported_codecs_.empty()) { | 1225 if (supported_codecs_.empty()) { |
1219 ALOGW << "No HW video encoder for type " << (int)type; | 1226 ALOGW << "No HW video encoder for type " << (int)type; |
1220 return nullptr; | 1227 return nullptr; |
1221 } | 1228 } |
1222 for (std::vector<VideoCodec>::const_iterator it = supported_codecs_.begin(); | 1229 for (std::vector<VideoCodec>::const_iterator it = supported_codecs_.begin(); |
1223 it != supported_codecs_.end(); ++it) { | 1230 it != supported_codecs_.end(); ++it) { |
1224 if (it->type == type) { | 1231 if (it->type == type) { |
1225 ALOGD << "Create HW video encoder for type " << (int)type << | 1232 ALOGD << "Create HW video encoder for type " << (int)type << |
1226 " (" << it->name << ")."; | 1233 " (" << it->name << ")."; |
1227 return new MediaCodecVideoEncoder(AttachCurrentThreadIfNeeded(), type, | 1234 return new MediaCodecVideoEncoder(AttachCurrentThreadIfNeeded(), type, |
1228 egl_base_.egl_base_context()); | 1235 egl_context_); |
1229 } | 1236 } |
1230 } | 1237 } |
1231 ALOGW << "Can not find HW video encoder for type " << (int)type; | 1238 ALOGW << "Can not find HW video encoder for type " << (int)type; |
1232 return nullptr; | 1239 return nullptr; |
1233 } | 1240 } |
1234 | 1241 |
1235 const std::vector<MediaCodecVideoEncoderFactory::VideoCodec>& | 1242 const std::vector<MediaCodecVideoEncoderFactory::VideoCodec>& |
1236 MediaCodecVideoEncoderFactory::codecs() const { | 1243 MediaCodecVideoEncoderFactory::codecs() const { |
1237 return supported_codecs_; | 1244 return supported_codecs_; |
1238 } | 1245 } |
1239 | 1246 |
1240 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 1247 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
1241 webrtc::VideoEncoder* encoder) { | 1248 webrtc::VideoEncoder* encoder) { |
1242 ALOGD << "Destroy video encoder."; | 1249 ALOGD << "Destroy video encoder."; |
1243 delete encoder; | 1250 delete encoder; |
1244 } | 1251 } |
1245 | 1252 |
1246 } // namespace webrtc_jni | 1253 } // namespace webrtc_jni |
1247 | 1254 |
OLD | NEW |