硬编码可以和网页互通,硬解码不通,目前业务没用到
修改库:
libmediasoupclient (v3) 3.2.0
其中 SendTransport::ProduceData方法编译不过注掉就行。
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 70f0a0b..aa62c91 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,6 +74,7 @@ set(
src/sdp/MediaSection.cpp
src/sdp/RemoteSdp.cpp
src/sdp/Utils.cpp
+ src/AndroidHardwareCodec.cpp
include/Consumer.hpp
include/Device.hpp
include/Handler.hpp
@@ -88,6 +89,7 @@ set(
include/sdp/MediaSection.hpp
include/sdp/RemoteSdp.hpp
include/sdp/Utils.hpp
+ include/AndroidHardwareCodec.hpp
)
# Create target.
@@ -128,10 +130,21 @@ target_include_directories(${PROJECT_NAME} PUBLIC
)
# Public (interface) dependencies.
-target_link_libraries(${PROJECT_NAME} PUBLIC
- sdptransform
- ${LIBWEBRTC_BINARY_PATH}/libwebrtc${CMAKE_STATIC_LIBRARY_SUFFIX}
-)
+if("${ANDROID_ABI}" STREQUAL "")
+ target_link_libraries(${PROJECT_NAME} PUBLIC
+ sdptransform
+ ${LIBWEBRTC_BINARY_PATH}/libwebrtc${CMAKE_STATIC_LIBRARY_SUFFIX}
+ )
+else()
+ # Add '-whole-archive' to keep symbols from peerconnection_jni.
+ # https://stackoverflow.com/a/5687860/2085408
+ SET (webrtc -Wl,--whole-archive ${LIBWEBRTC_BINARY_PATH}/${ANDROID_ABI}/libwebrtc${CMAKE_STATIC_LIBRARY_SUFFIX} -Wl,--no-whole-archive)
+
+ target_link_libraries(${PROJECT_NAME} PUBLIC
+ sdptransform
+ ${webrtc}
+ )
+endif()
# Compile definitions for libwebrtc.
target_compile_definitions(${PROJECT_NAME} PUBLIC
diff --git a/src/PeerConnection.cpp b/src/PeerConnection.cpp
index 849db1f..4d157d3 100644
--- a/src/PeerConnection.cpp
+++ b/src/PeerConnection.cpp
@@ -11,6 +11,10 @@
#include
#include
+#ifdef __ANDROID__
+#include "AndroidHardwareCodec.hpp"
+#endif
+
using json = nlohmann::json;
namespace mediasoupclient
@@ -63,6 +67,7 @@ namespace mediasoupclient
PeerConnection::PrivateListener* privateListener, const PeerConnection::Options* options)
{
MSC_TRACE();
+ rtc::LogMessage::LogToDebug(rtc::LS_INFO);
webrtc::PeerConnectionInterface::RTCConfiguration config;
@@ -97,8 +102,13 @@ namespace mediasoupclient
nullptr ,
webrtc::CreateBuiltinAudioEncoderFactory(),
webrtc::CreateBuiltinAudioDecoderFactory(),
+#ifdef __ANDROID__
+ android_hardware::CreateAndroidEncoderFactory(),
+ android_hardware::CreateAndroidDecoderFactory(),
+#else
webrtc::CreateBuiltinVideoEncoderFactory(),
webrtc::CreateBuiltinVideoDecoderFactory(),
+#endif
nullptr ,
nullptr );
}
抄代码webrtc-checkoutsrcmodulesvideo_codingcodecstestandroid_codec_factory_helper.x
AndroidHardwareCodec.hpp
#ifdef __ANDROID__ #ifndef __ANDROID_HARDWARE_CODEC_H__ #define __ANDROID_HARDWARE_CODEC_H__ #include#include "api/video_codecs/video_decoder_factory.h" #include "api/video_codecs/video_encoder_factory.h" using namespace webrtc; #define ANDROID_HW_SDK_VERSION_STRING "sdk_version" #define ANDROID_HW_PHONE_MODEL_STRING "phone_model" #define ANDROID_HW_CHIP_NAME_STRING "chip_name" namespace android_hardware { std::unique_ptr CreateAndroidEncoderFactory(); std::unique_ptr CreateAndroidDecoderFactory(); } // namespace android_hardware #endif #endif
AndroidHardwareCodec.cpp
#ifdef __ANDROID__ #include#include #include
webrtc m84 -------4147
diff --git a/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java b/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java
index 8fe8b36909..fe72eafd7c 100644
--- a/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java
+++ b/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java
@@ -102,10 +102,10 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
}
String codecName = info.getName();
- String mime = type.mimeType();
- Integer surfaceColorFormat = MediaCodecUtils.selectColorFormat(
+ String mime = type.mimeType(); //wzw200
+ Integer surfaceColorFormat = MediaCodecUtils.selectColorFormat(codecName, true,
MediaCodecUtils.TEXTURE_COLOR_FORMATS, info.getCapabilitiesForType(mime));
- Integer yuvColorFormat = MediaCodecUtils.selectColorFormat(
+ Integer yuvColorFormat = MediaCodecUtils.selectColorFormat(codecName, true,
MediaCodecUtils.ENCODER_COLOR_FORMATS, info.getCapabilitiesForType(mime));
if (type == VideoCodecMimeType.H264) {
@@ -183,13 +183,13 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
if (!MediaCodecUtils.codecSupportsType(info, type)) {
return false;
}
- // Check for a supported color format.
+ // Check for a supported color format. //wzw200
if (MediaCodecUtils.selectColorFormat(
- MediaCodecUtils.ENCODER_COLOR_FORMATS, info.getCapabilitiesForType(type.mimeType()))
+ info.getName(), true, MediaCodecUtils.ENCODER_COLOR_FORMATS, info.getCapabilitiesForType(type.mimeType()))
== null) {
return false;
}
- return isHardwareSupportedInCurrentSdk(info, type) && isMediaCodecAllowed(info);
+ return isHardwareSupportedInCurrentSdk(info, type); //wzw200 && isMediaCodecAllowed(info);
}
// Returns true if the given MediaCodecInfo indicates a hardware module that is supported on the
@@ -224,8 +224,9 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
}
- private boolean isHardwareSupportedInCurrentSdkH264(MediaCodecInfo info) {
- // First, H264 hardware might perform poorly on this model.
+ private boolean isHardwareSupportedInCurrentSdkH264(MediaCodecInfo info) { //wzw200
+
+ return true;
}
private boolean isMediaCodecAllowed(MediaCodecInfo info) {
@@ -250,7 +253,7 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
case VP9:
return 100;
case H264:
- return 20;
+ return 1; //wzw200
}
throw new IllegalArgumentException("Unsupported VideoCodecMimeType " + type);
}
@@ -284,8 +287,11 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
return new baseBitrateAdjuster();
}
- private boolean isH264HighProfileSupported(MediaCodecInfo info) {
+ private boolean isH264HighProfileSupported(MediaCodecInfo info) {//wzw200
+ return true;
+
}
}
diff --git a/sdk/android/src/java/org/webrtc/MediaCodecUtils.java b/sdk/android/src/java/org/webrtc/MediaCodecUtils.java
index 9028cc3ae4..08a32fa988 100644
--- a/sdk/android/src/java/org/webrtc/MediaCodecUtils.java
+++ b/sdk/android/src/java/org/webrtc/MediaCodecUtils.java
@@ -64,13 +64,16 @@ class MediaCodecUtils {
}
}
- static @Nullable Integer selectColorFormat(
- int[] supportedColorFormats, CodecCapabilities capabilities) {
- for (int supportedColorFormat : supportedColorFormats) {
- for (int codecColorFormat : capabilities.colorFormats) {
- if (codecColorFormat == supportedColorFormat) {
- return codecColorFormat;
- }
+ static @Nullable Integer selectColorFormat( //wzw200
+ String codeName, boolean isEncode,int[] supportedColorFormats, CodecCapabilities capabilities) {
+
+ for (int supportedColorFormat : supportedColorFormats) {
+ for (int codecColorFormat : capabilities.colorFormats) {
+ if (codecColorFormat == supportedColorFormat &&
+ (isEncode || !codeName.startsWith("OMX.MTK") || supportedColorFormat != CodecCapabilities.COLOR_FormatYUV420Planar) &&
+ (!isEncode || !codeName.startsWith("OMX.IMG.TOPAZ") || supportedColorFormat != CodecCapabilities.COLOR_FormatYUV420Planar)) {
+ return codecColorFormat;
+ }
}
}
return null;
diff --git a/sdk/android/src/java/org/webrtc/MediaCodecVideoDecoderFactory.java b/sdk/android/src/java/org/webrtc/MediaCodecVideoDecoderFactory.java
index 036aca5822..1a994061d1 100644
--- a/sdk/android/src/java/org/webrtc/MediaCodecVideoDecoderFactory.java
+++ b/sdk/android/src/java/org/webrtc/MediaCodecVideoDecoderFactory.java
@@ -53,9 +53,9 @@ class MediaCodecVideoDecoderFactory implements VideoDecoderFactory {
return null;
}
- CodecCapabilities capabilities = info.getCapabilitiesForType(type.mimeType());
+ CodecCapabilities capabilities = info.getCapabilitiesForType(type.mimeType()); //wzw200
return new AndroidVideoDecoder(new MediaCodecWrapperFactoryImpl(), info.getName(), type,
- MediaCodecUtils.selectColorFormat(MediaCodecUtils.DECODER_COLOR_FORMATS, capabilities),
+ MediaCodecUtils.selectColorFormat(info.getName(), false, MediaCodecUtils.DECODER_COLOR_FORMATS, capabilities),
sharedContext);
}
@@ -114,20 +114,23 @@ class MediaCodecVideoDecoderFactory implements VideoDecoderFactory {
if (!MediaCodecUtils.codecSupportsType(info, type)) {
return false;
}
- // Check for a supported color format.
+ // Check for a supported color format. //wzw200
if (MediaCodecUtils.selectColorFormat(
- MediaCodecUtils.DECODER_COLOR_FORMATS, info.getCapabilitiesForType(type.mimeType()))
+ info.getName(), false, MediaCodecUtils.DECODER_COLOR_FORMATS, info.getCapabilitiesForType(type.mimeType()))
== null) {
return false;
}
return isCodecAllowed(info);
}
- private boolean isCodecAllowed(MediaCodecInfo info) {
+ private boolean isCodecAllowed(MediaCodecInfo info) { //wzw200
+
+ return true;
}
private boolean isH264HighProfileSupported(MediaCodecInfo info) {
webrtc 编译参数 m84
git checkout -b 4147 branch-heads/4147 ----------------------Android arm64 debug----------------------- mkdir -p out/android/arm64/debug gn gen --args="is_debug=true target_os="android" target_cpu="arm64" symbol_level=2 use_rtti=false rtc_include_tests=false rtc_libvpx_build_vp9=true enable_iterator_debugging=false proprietary_codecs=true rtc_opus_variable_complexity=true rtc_use_h264=true treat_warnings_as_errors=false use_custom_libcxx=false" out/android/arm64/debug ninja -C out/android/arm64/debug



