IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> mediasoup-demo-android输出硬编码H264流 -> 正文阅读

[移动开发]mediasoup-demo-android输出硬编码H264流

硬编码可以和网页互通,硬解码不通,目前业务没用到
修改库:
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 <api/video_codecs/builtin_video_encoder_factory.h>
 #include <rtc_base/ssl_adapter.h>
 
+#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 /*default_adm*/,
 			  webrtc::CreateBuiltinAudioEncoderFactory(),
 			  webrtc::CreateBuiltinAudioDecoderFactory(),
+#ifdef __ANDROID__
+			  android_hardware::CreateAndroidEncoderFactory(),
+			  android_hardware::CreateAndroidDecoderFactory(),
+#else
 			  webrtc::CreateBuiltinVideoEncoderFactory(),
 			  webrtc::CreateBuiltinVideoDecoderFactory(),
+#endif
 			  nullptr /*audio_mixer*/,
 			  nullptr /*audio_processing*/);
 		}

抄代码webrtc-checkout\src\modules\video_coding\codecs\test\android_codec_factory_helper.x
AndroidHardwareCodec.hpp

#ifdef __ANDROID__

#ifndef __ANDROID_HARDWARE_CODEC_H__
#define __ANDROID_HARDWARE_CODEC_H__

#include <memory>

#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<VideoEncoderFactory> CreateAndroidEncoderFactory();
std::unique_ptr<VideoDecoderFactory> CreateAndroidDecoderFactory();
} // namespace android_hardware

#endif /* android_hardware_codec_h */

#endif

AndroidHardwareCodec.cpp

#ifdef __ANDROID__

#include <pthread.h>
#include <memory>
#include <map>
#include <jni.h>

#include "rtc_base/checks.h"
#include "rtc_base/ignore_wundef.h"
#include "absl/strings/match.h"
#include "media/base/codec.h"
#include "api/video_codecs/sdp_video_format.h"
#include "sdk/android/native_api/base/init.h"
#include "sdk/android/native_api/codecs/wrapper.h"
#include "sdk/android/native_api/jni/class_loader.h"
#include "sdk/android/native_api/jni/jvm.h"
#include "sdk/android/native_api/jni/scoped_java_ref.h"

#include "AndroidHardwareCodec.hpp"

using namespace webrtc;
namespace android_hardware
{
static std::string g_currentAndroidHwInfo = "";

std::unique_ptr<VideoEncoderFactory> CreateAndroidEncoderFactory()
{
	JNIEnv* env = AttachCurrentThreadIfNeeded();
	ScopedJavaLocalRef<jclass> factory_class =
	    GetClass(env, "org/webrtc/HardwareVideoEncoderFactory");
	jmethodID factory_constructor = env->GetMethodID(
	                                    factory_class.obj(), "<init>", "(Lorg/webrtc/EglBase$Context;ZZ)V");
	ScopedJavaLocalRef<jobject> factory_object(
	    env, env->NewObject(factory_class.obj(), factory_constructor,
	                        nullptr /* shared_context */,
	                        false /* enable_intel_vp8_encoder */,
	                        true /* enable_h264_high_profile */));
	return JavaToNativeVideoEncoderFactory(env, factory_object.obj());
}

std::unique_ptr<VideoDecoderFactory> CreateAndroidDecoderFactory()
{
	JNIEnv* env = AttachCurrentThreadIfNeeded();
	ScopedJavaLocalRef<jclass> factory_class =
	    GetClass(env, "org/webrtc/HardwareVideoDecoderFactory");
	jmethodID factory_constructor = env->GetMethodID(
	                                    factory_class.obj(), "<init>", "(Lorg/webrtc/EglBase$Context;)V");
	ScopedJavaLocalRef<jobject> factory_object(
	    env, env->NewObject(factory_class.obj(), factory_constructor,
	                        nullptr /* shared_context */));
	return JavaToNativeVideoDecoderFactory(env, factory_object.obj());
}

} // namespace android_hardware

#endif

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
+    /*
+         // First, H264 hardware might perform poorly on this model.
     if (H264_HW_EXCEPTION_MODELS.contains(Build.MODEL)) {
       return false;
     }
@@ -235,6 +236,8 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory {
         // Exynos H264 encoder is supported in LOLLIPOP or later.
         || (name.startsWith(EXYNOS_PREFIX)
                && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
+       */
+         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;
+         /*
     return enableH264HighProfile && Build.VERSION.SDK_INT > Build.VERSION_CODES.M
         && info.getName().startsWith(EXYNOS_PREFIX);
+       */
   }
 }
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
+         /*
     if (codecAllowedPredicate == null) {
       return true;
     }
     return codecAllowedPredicate.test(info);
+    */
+         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

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2021-10-22 11:03:19  更:2021-10-22 11:04:58 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 0:39:05-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码