| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 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 |
| 11 package org.webrtc; | 11 package org.webrtc; |
| 12 | 12 |
| 13 import android.annotation.TargetApi; | 13 import android.annotation.TargetApi; |
| 14 import android.media.MediaCodec; | 14 import android.media.MediaCodec; |
| 15 import android.media.MediaCodecInfo; | 15 import android.media.MediaCodecInfo; |
| 16 import android.media.MediaCodecInfo.CodecCapabilities; | 16 import android.media.MediaCodecInfo.CodecCapabilities; |
| 17 import android.media.MediaCodecList; | 17 import android.media.MediaCodecList; |
| 18 import android.media.MediaFormat; | 18 import android.media.MediaFormat; |
| 19 import android.opengl.GLES20; | 19 import android.opengl.GLES20; |
| 20 import android.os.Build; | 20 import android.os.Build; |
| 21 import android.os.Bundle; | 21 import android.os.Bundle; |
| 22 import android.view.Surface; | 22 import android.view.Surface; |
| 23 | |
| 24 import java.nio.ByteBuffer; | 23 import java.nio.ByteBuffer; |
| 24 import java.util.ArrayList; |
| 25 import java.util.Arrays; | 25 import java.util.Arrays; |
| 26 import java.util.HashSet; | 26 import java.util.HashSet; |
| 27 import java.util.List; | 27 import java.util.List; |
| 28 import java.util.Set; | 28 import java.util.Set; |
| 29 import java.util.concurrent.CountDownLatch; | 29 import java.util.concurrent.CountDownLatch; |
| 30 import java.util.concurrent.TimeUnit; | 30 import java.util.concurrent.TimeUnit; |
| 31 | 31 |
| 32 // Java-side of peerconnection_jni.cc:MediaCodecVideoEncoder. | 32 // Java-side of peerconnection_jni.cc:MediaCodecVideoEncoder. |
| 33 // This class is an implementation detail of the Java PeerConnection API. | 33 // This class is an implementation detail of the Java PeerConnection API. |
| 34 @TargetApi(19) | 34 @TargetApi(19) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 this.minSdk = minSdk; | 107 this.minSdk = minSdk; |
| 108 this.bitrateAdjustmentType = bitrateAdjustmentType; | 108 this.bitrateAdjustmentType = bitrateAdjustmentType; |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 // List of supported HW VP8 encoders. | 112 // List of supported HW VP8 encoders. |
| 113 private static final MediaCodecProperties qcomVp8HwProperties = new MediaCodec
Properties( | 113 private static final MediaCodecProperties qcomVp8HwProperties = new MediaCodec
Properties( |
| 114 "OMX.qcom.", Build.VERSION_CODES.KITKAT, BitrateAdjustmentType.NO_ADJUSTME
NT); | 114 "OMX.qcom.", Build.VERSION_CODES.KITKAT, BitrateAdjustmentType.NO_ADJUSTME
NT); |
| 115 private static final MediaCodecProperties exynosVp8HwProperties = new MediaCod
ecProperties( | 115 private static final MediaCodecProperties exynosVp8HwProperties = new MediaCod
ecProperties( |
| 116 "OMX.Exynos.", Build.VERSION_CODES.M, BitrateAdjustmentType.DYNAMIC_ADJUST
MENT); | 116 "OMX.Exynos.", Build.VERSION_CODES.M, BitrateAdjustmentType.DYNAMIC_ADJUST
MENT); |
| 117 private static final MediaCodecProperties[] vp8HwList = | 117 private static final MediaCodecProperties intelVp8HwProperties = new MediaCode
cProperties( |
| 118 new MediaCodecProperties[] {qcomVp8HwProperties, exynosVp8HwProperties}; | 118 "OMX.Intel.", Build.VERSION_CODES.LOLLIPOP, BitrateAdjustmentType.NO_ADJUS
TMENT); |
| 119 private static MediaCodecProperties[] vp8HwList() { |
| 120 final ArrayList<MediaCodecProperties> supported_codecs = new ArrayList<Media
CodecProperties>(); |
| 121 supported_codecs.add(qcomVp8HwProperties); |
| 122 supported_codecs.add(exynosVp8HwProperties); |
| 123 if (PeerConnectionFactory.fieldTrialsFindFullName("WebRTC-IntelVP8").equals(
"Enabled")) { |
| 124 supported_codecs.add(intelVp8HwProperties); |
| 125 } |
| 126 return supported_codecs.toArray(new MediaCodecProperties[supported_codecs.si
ze()]); |
| 127 } |
| 119 | 128 |
| 120 // List of supported HW VP9 encoders. | 129 // List of supported HW VP9 encoders. |
| 121 private static final MediaCodecProperties qcomVp9HwProperties = new MediaCodec
Properties( | 130 private static final MediaCodecProperties qcomVp9HwProperties = new MediaCodec
Properties( |
| 122 "OMX.qcom.", Build.VERSION_CODES.M, BitrateAdjustmentType.NO_ADJUSTMENT); | 131 "OMX.qcom.", Build.VERSION_CODES.M, BitrateAdjustmentType.NO_ADJUSTMENT); |
| 123 private static final MediaCodecProperties exynosVp9HwProperties = new MediaCod
ecProperties( | 132 private static final MediaCodecProperties exynosVp9HwProperties = new MediaCod
ecProperties( |
| 124 "OMX.Exynos.", Build.VERSION_CODES.M, BitrateAdjustmentType.NO_ADJUSTMENT)
; | 133 "OMX.Exynos.", Build.VERSION_CODES.M, BitrateAdjustmentType.NO_ADJUSTMENT)
; |
| 125 private static final MediaCodecProperties[] vp9HwList = | 134 private static final MediaCodecProperties[] vp9HwList = |
| 126 new MediaCodecProperties[] {qcomVp9HwProperties, exynosVp9HwProperties}; | 135 new MediaCodecProperties[] {qcomVp9HwProperties, exynosVp9HwProperties}; |
| 127 | 136 |
| 128 // List of supported HW H.264 encoders. | 137 // List of supported HW H.264 encoders. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 205 } |
| 197 | 206 |
| 198 public static void disableH264HwCodec() { | 207 public static void disableH264HwCodec() { |
| 199 Logging.w(TAG, "H.264 encoding is disabled by application."); | 208 Logging.w(TAG, "H.264 encoding is disabled by application."); |
| 200 hwEncoderDisabledTypes.add(H264_MIME_TYPE); | 209 hwEncoderDisabledTypes.add(H264_MIME_TYPE); |
| 201 } | 210 } |
| 202 | 211 |
| 203 // Functions to query if HW encoding is supported. | 212 // Functions to query if HW encoding is supported. |
| 204 public static boolean isVp8HwSupported() { | 213 public static boolean isVp8HwSupported() { |
| 205 return !hwEncoderDisabledTypes.contains(VP8_MIME_TYPE) | 214 return !hwEncoderDisabledTypes.contains(VP8_MIME_TYPE) |
| 206 && (findHwEncoder(VP8_MIME_TYPE, vp8HwList, supportedColorList) != null)
; | 215 && (findHwEncoder(VP8_MIME_TYPE, vp8HwList(), supportedColorList) != nul
l); |
| 207 } | 216 } |
| 208 | 217 |
| 209 public static EncoderProperties vp8HwEncoderProperties() { | 218 public static EncoderProperties vp8HwEncoderProperties() { |
| 210 if (hwEncoderDisabledTypes.contains(VP8_MIME_TYPE)) { | 219 if (hwEncoderDisabledTypes.contains(VP8_MIME_TYPE)) { |
| 211 return null; | 220 return null; |
| 212 } else { | 221 } else { |
| 213 return findHwEncoder(VP8_MIME_TYPE, vp8HwList, supportedColorList); | 222 return findHwEncoder(VP8_MIME_TYPE, vp8HwList(), supportedColorList); |
| 214 } | 223 } |
| 215 } | 224 } |
| 216 | 225 |
| 217 public static boolean isVp9HwSupported() { | 226 public static boolean isVp9HwSupported() { |
| 218 return !hwEncoderDisabledTypes.contains(VP9_MIME_TYPE) | 227 return !hwEncoderDisabledTypes.contains(VP9_MIME_TYPE) |
| 219 && (findHwEncoder(VP9_MIME_TYPE, vp9HwList, supportedColorList) != null)
; | 228 && (findHwEncoder(VP9_MIME_TYPE, vp9HwList, supportedColorList) != null)
; |
| 220 } | 229 } |
| 221 | 230 |
| 222 public static boolean isH264HwSupported() { | 231 public static boolean isH264HwSupported() { |
| 223 return !hwEncoderDisabledTypes.contains(H264_MIME_TYPE) | 232 return !hwEncoderDisabledTypes.contains(H264_MIME_TYPE) |
| 224 && (findHwEncoder(H264_MIME_TYPE, h264HwList, supportedColorList) != nul
l); | 233 && (findHwEncoder(H264_MIME_TYPE, h264HwList, supportedColorList) != nul
l); |
| 225 } | 234 } |
| 226 | 235 |
| 227 public static boolean isVp8HwSupportedUsingTextures() { | 236 public static boolean isVp8HwSupportedUsingTextures() { |
| 228 return !hwEncoderDisabledTypes.contains(VP8_MIME_TYPE) | 237 return !hwEncoderDisabledTypes.contains(VP8_MIME_TYPE) |
| 229 && (findHwEncoder(VP8_MIME_TYPE, vp8HwList, supportedSurfaceColorList) !
= null); | 238 && (findHwEncoder(VP8_MIME_TYPE, vp8HwList(), supportedSurfaceColorList)
!= null); |
| 230 } | 239 } |
| 231 | 240 |
| 232 public static boolean isVp9HwSupportedUsingTextures() { | 241 public static boolean isVp9HwSupportedUsingTextures() { |
| 233 return !hwEncoderDisabledTypes.contains(VP9_MIME_TYPE) | 242 return !hwEncoderDisabledTypes.contains(VP9_MIME_TYPE) |
| 234 && (findHwEncoder(VP9_MIME_TYPE, vp9HwList, supportedSurfaceColorList) !
= null); | 243 && (findHwEncoder(VP9_MIME_TYPE, vp9HwList, supportedSurfaceColorList) !
= null); |
| 235 } | 244 } |
| 236 | 245 |
| 237 public static boolean isH264HwSupportedUsingTextures() { | 246 public static boolean isH264HwSupportedUsingTextures() { |
| 238 return !hwEncoderDisabledTypes.contains(H264_MIME_TYPE) | 247 return !hwEncoderDisabledTypes.contains(H264_MIME_TYPE) |
| 239 && (findHwEncoder(H264_MIME_TYPE, h264HwList, supportedSurfaceColorList)
!= null); | 248 && (findHwEncoder(H264_MIME_TYPE, h264HwList, supportedSurfaceColorList)
!= null); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 this.height = height; | 389 this.height = height; |
| 381 if (mediaCodecThread != null) { | 390 if (mediaCodecThread != null) { |
| 382 throw new RuntimeException("Forgot to release()?"); | 391 throw new RuntimeException("Forgot to release()?"); |
| 383 } | 392 } |
| 384 EncoderProperties properties = null; | 393 EncoderProperties properties = null; |
| 385 String mime = null; | 394 String mime = null; |
| 386 int keyFrameIntervalSec = 0; | 395 int keyFrameIntervalSec = 0; |
| 387 if (type == VideoCodecType.VIDEO_CODEC_VP8) { | 396 if (type == VideoCodecType.VIDEO_CODEC_VP8) { |
| 388 mime = VP8_MIME_TYPE; | 397 mime = VP8_MIME_TYPE; |
| 389 properties = findHwEncoder( | 398 properties = findHwEncoder( |
| 390 VP8_MIME_TYPE, vp8HwList, useSurface ? supportedSurfaceColorList : sup
portedColorList); | 399 VP8_MIME_TYPE, vp8HwList(), useSurface ? supportedSurfaceColorList : s
upportedColorList); |
| 391 keyFrameIntervalSec = 100; | 400 keyFrameIntervalSec = 100; |
| 392 } else if (type == VideoCodecType.VIDEO_CODEC_VP9) { | 401 } else if (type == VideoCodecType.VIDEO_CODEC_VP9) { |
| 393 mime = VP9_MIME_TYPE; | 402 mime = VP9_MIME_TYPE; |
| 394 properties = findHwEncoder( | 403 properties = findHwEncoder( |
| 395 VP9_MIME_TYPE, vp9HwList, useSurface ? supportedSurfaceColorList : sup
portedColorList); | 404 VP9_MIME_TYPE, vp9HwList, useSurface ? supportedSurfaceColorList : sup
portedColorList); |
| 396 keyFrameIntervalSec = 100; | 405 keyFrameIntervalSec = 100; |
| 397 } else if (type == VideoCodecType.VIDEO_CODEC_H264) { | 406 } else if (type == VideoCodecType.VIDEO_CODEC_H264) { |
| 398 mime = H264_MIME_TYPE; | 407 mime = H264_MIME_TYPE; |
| 399 properties = findHwEncoder( | 408 properties = findHwEncoder( |
| 400 H264_MIME_TYPE, h264HwList, useSurface ? supportedSurfaceColorList : s
upportedColorList); | 409 H264_MIME_TYPE, h264HwList, useSurface ? supportedSurfaceColorList : s
upportedColorList); |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 checkOnMediaCodecThread(); | 779 checkOnMediaCodecThread(); |
| 771 try { | 780 try { |
| 772 mediaCodec.releaseOutputBuffer(index, false); | 781 mediaCodec.releaseOutputBuffer(index, false); |
| 773 return true; | 782 return true; |
| 774 } catch (IllegalStateException e) { | 783 } catch (IllegalStateException e) { |
| 775 Logging.e(TAG, "releaseOutputBuffer failed", e); | 784 Logging.e(TAG, "releaseOutputBuffer failed", e); |
| 776 return false; | 785 return false; |
| 777 } | 786 } |
| 778 } | 787 } |
| 779 } | 788 } |
| OLD | NEW |