GStreamer for Android

本文主要是梳理GStreamer 官方demo写的随手笔记

文章目录

  • GStreamer for Android
    • 一、编译过程
      • 1.1 环境搭建
      • 1.2 JNI mk文件配置
        • 1.2.1 gradle配置
        • 1.2.2 Application.mk
        • 1.2.3 Android.mk
        • 1.2.3 plugins.mk
      • 1.3 SDK里的NDK build
        • 1.3.1 gstreamer-1.0.mk
        • 1.3.2 Tools.mk
        • 1.3.3 Gstreamer_prebuilt.mk
    • 二、初始化GStreamer
      • 2.1 GStreamer.java 基础类
      • 2.2 Gstreamer_android-1.0.c.in 安卓平台初始化专用 jni
      • 2.3 gst_android_init 初始化
      • 2.4 init context初始化操作
      • 2.5 gst_android_register_static_plugins
      • 2.6 gst_android_load_gio_modules 获取gio modeule
    • 三、API示例
      • 3.1 tutorial-1 获取版本信息
        • 3.1.1 示例代码
        • 3.1.2 gst_native_get_gstreamer_info
      • 3.2 tutorial-2 播放音频
        • 3.2.1 示例代码
          • 3.2.1.1 播放逻辑代码
          • 3.2.1.2 setMessage native回调
          • 3.2.1.3 onGStreamerInitialized native回调初始化完成
        • 3.2.2 JNI method对应表
        • 3.2.3 CustomData 自定义APP信息
        • 3.2.3 gst_native_class_init 将java层的class与GStreamer关联
        • 3.2.4 gst_native_init 初始化thread
        • 3.2.5 app_function thread循环
        • 3.2.6 gst_native_play 开始播放
        • 3.2.7 gst_native_pause 暂停
        • 3.2.8 gst_native_finalize 释放资源
      • 3.3 tutorial-3 简单视频播放
        • 3.3.1 实例代码
          • 3.3.1.1 SurfaceView
          • 3.3.1.2 播放逻辑代码
          • 3.3.1.4 native回调函数
        • 3.3.2 JNI method对应表
        • 3.3.3 app_function 与tutorial-2差别
        • 3.3.4 gst_native_surface_init surface显示初始化
        • 3.3.5 check_initialization_complete 回调初始化完成
        • 3.3.6 gst_native_surface_finalize 释放
      • 3.4 tutorial-4 视频播放
        • 3.4.1实例代码
          • 3.3.1.1 界面控间初始化
          • 3.3.1.2 SurfaceHolder.Callback
          • 3.3.1.3 onGStreamerInitialized GStreamer初始化完成
        • 3.4.2 JNI method列表
        • 3.4.3 app_function
        • 3.4.4 state_changed_cb 状态改变回调
        • 3.4.5 check_media_size 检查媒体的size
        • 3.4.6 clock_lost_cb 当计时器丢失时回调
        • 3.4.7 buffering_cb 播放流媒体 0%-》100%
        • 3.4.8 duration_cb 时长进度回调
        • 3.4.9 eos_cb 播放结束
        • 3.4.10 error_cb 错误回调
        • 3.4.11 delayed_seek_cb 延时seek回调
        • 3.4.12 关键 execute_seek 执行seek操作
        • 3.4.13 gst_native_set_position设置 pos
        • 3.4.14 set_current_ui_position 通知UI时长和pos
      • 3.5 turorial-5 完整播放器
        • 3.5.1 实例代码
        • 3.5.2 打开文件管理,从中选择播放
        • 3.5.3 本地文件夹播放 多种文件支持

一、编译过程

1.1 环境搭建

下载GStreamer SDK https://gstreamer.freedesktop.org/data/pkg/android/

下载Demo https://gitlab.freedesktop.org/gstreamer/gst-docs/

下载NDK

本文使用为 NDK 21.3.65 + gstream 17.1

在gradle.properties中增加配置文件

gstAndroidRoot=D:\\GitHubSample\\gstreamer\\gstreamer-1.0-android-universal-1.17.1.tar\\gstreamer-1.0-android-universal-1.17.1

如出现GradleException 找不到的问题 将 GradleException改成Exception

如出现?android:attr/colorError 错误

更改到合适版本号

android {compileSdkVersion 28buildToolsVersion '28.0.3'

1.2 JNI mk文件配置

APP会加载 两个NDK lib 一个是gstreamer_android包含初始化等,一个是私有的native库提供gstreamer的接口封装

tutorial-5也是依赖gstreamer_android的

    static {System.loadLibrary("gstreamer_android");System.loadLibrary("tutorial-5");nativeClassInit();}

1.2.1 gradle配置

gstAndroidRoot为GStreamer SDK的路径

		externalNativeBuild {ndkBuild {def gstRootif (project.hasProperty('gstAndroidRoot'))gstRoot = project.gstAndroidRootelsegstRoot = System.env.GSTREAMER_ROOT_ANDROIDif (gstRoot == null)throw new Exception('GSTREAMER_ROOT_ANDROID must be set, or "gstAndroidRoot" must be defined in your gradle.properties in the top level directory of the unpacked universal GStreamer Android binaries')
//路径赋值 arguments "NDK_APPLICATION_MK=jni/Application.mk", "GSTREAMER_JAVA_SRC_DIR=src", "GSTREAMER_ROOT_ANDROID=$gstRoot", "GSTREAMER_ASSETS_DIR=src/assets"targets "tutorial-1"// All archs except MIPS and MIPS64 are supportedabiFilters  'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'}}

1.2.2 Application.mk

APP_ABI = armeabi armeabi-v7a arm64-v8a x86 x86_64
APP_STL = c++_shared

1.2.3 Android.mk

编译生成tutorial-5

LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE    := tutorial-5
LOCAL_SRC_FILES := tutorial-5.c dummy.cpp
LOCAL_SHARED_LIBRARIES := gstreamer_android
LOCAL_LDLIBS := -llog -landroid
include $(BUILD_SHARED_LIBRARY)ifndef GSTREAMER_ROOT_ANDROID
$(error GSTREAMER_ROOT_ANDROID is not defined!)
endififeq ($(TARGET_ARCH_ABI),armeabi)
GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/arm
else ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/armv7
else ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/arm64
else ifeq ($(TARGET_ARCH_ABI),x86)
GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/x86
else ifeq ($(TARGET_ARCH_ABI),x86_64)
GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/x86_64
else
$(error Target arch ABI not supported: $(TARGET_ARCH_ABI))
endif
#NDK buildpath
GSTREAMER_NDK_BUILD_PATH  := $(GSTREAMER_ROOT)/share/gst-android/ndk-build/
#插件 mk
include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk
GSTREAMER_PLUGINS         := $(GSTREAMER_PLUGINS_CORE) $(GSTREAMER_PLUGINS_PLAYBACK) $(GSTREAMER_PLUGINS_CODECS) $(GSTREAMER_PLUGINS_NET) $(GSTREAMER_PLUGINS_SYS)
G_IO_MODULES              := openssl
GSTREAMER_EXTRA_DEPS      := gstreamer-video-1.0
#gstreamer 初始化的 mk
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer-1.0.mk

1.2.3 plugins.mk

在Android.mk里

#插件 mk
include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk
GSTREAMER_PLUGINS         := $(GSTREAMER_PLUGINS_CORE) $(GSTREAMER_PLUGINS_PLAYBACK) $(GSTREAMER_PLUGINS_CODECS) $(GSTREAMER_PLUGINS_NET) $(GSTREAMER_PLUGINS_SYS)
G_IO_MODULES              := openssl
GSTREAMER_EXTRA_DEPS      := gstreamer-video-1.0

plugins.mk 里预设了好多插件

如GSTREAMER_PLUGINS_PLAYBACK 对应了GSTREAMER_PLUGINS_PLAYBACK := playback

GSTREAMER_PLUGINS_CORE := coreelements coretracers adder app audioconvert audiomixer audiorate audioresample audiotestsrc compositor gio overlaycomposition pango rawparse typefindfunctions videoconvert videorate videoscale videotestsrc volume autodetect videofilter
GSTREAMER_PLUGINS_CODECS := subparse ogg theora vorbis opus ivorbisdec alaw apetag audioparsers auparse avi dv flac flv flxdec icydemux id3demux isomp4 jpeg lame matroska mpg123 mulaw multipart png speex taglib vpx wavenc wavpack wavparse y4menc adpcmdec adpcmenc bz2 dash dvbsuboverlay dvdspu hls id3tag kate midi mxf openh264 opusparse pcapparse pnm rfbsrc siren smoothstreaming subenc videoparsersbad y4mdec jpegformat gdp rsvg openjpeg spandsp sbc zbar androidmedia
GSTREAMER_PLUGINS_ENCODING := encoding
GSTREAMER_PLUGINS_NET := tcp rtsp rtp rtpmanager soup udp dtls netsim rtmp2 sctp sdpelem srtp srt webrtc nice rtspclientsink
GSTREAMER_PLUGINS_PLAYBACK := playback
GSTREAMER_PLUGINS_SYS := opengl ipcpipeline opensles
GSTREAMER_PLUGINS_VIS := libvisual goom goom2k1 audiovisualizers
GSTREAMER_PLUGINS_EFFECTS := alpha alphacolor audiofx cairo cutter debug deinterlace dtmf effectv equalizer gdkpixbuf imagefreeze interleave level multifile replaygain shapewipe smpte spectrum videobox videocrop videomixer accurip aiff audiobuffersplit audiofxbad audiolatency audiomixmatrix autoconvert bayer coloreffects closedcaption debugutilsbad fieldanalysis freeverb frei0r gaudieffects geometrictransform inter interlace ivtc legacyrawparse proxy removesilence segmentclip smooth speed soundtouch timecode videofiltersbad videoframe_audiolevel webrtcdsp ladspa
GSTREAMER_PLUGINS_CAPTURE := camerabin
GSTREAMER_PLUGINS_CODECS_GPL := assrender
GSTREAMER_PLUGINS_CODECS_RESTRICTED := asfmux dtsdec mpegpsdemux mpegpsmux mpegtsdemux mpegtsmux voaacenc a52dec amrnb amrwbdec asf dvdsub dvdlpcmdec xingmux realmedia x264 libav
GSTREAMER_PLUGINS_NET_RESTRICTED := mms rtmp
GSTREAMER_PLUGINS_VULKAN := vulkan
GSTREAMER_PLUGINS_GES := nle ges

在初始化阶段会将这些插件regist进去

genstatic_$(TARGET_ARCH_ABI):$(hide)$(HOST_ECHO) "GStreamer      : [GEN] => $(PRIV_C)"$(hide)$(call host-mkdir,$(PRIV_B_DIR))$(hide)$(SED_LOCAL) "s/@PLUGINS_DECLARATION@/$(PRIV_P_D)/g" $(PRIV_C_IN) | $(SED_LOCAL) "s/@PLUGINS_REGISTRATION@/$(PRIV_P_R)/g" | $(SED_LOCAL) "s/@G_IO_MODULES_LOAD@/$(PRIV_G_L)/g" | $(SED_LOCAL) "s/@G_IO_MODULES_DECLARE@/$(PRIV_G_R)/g" > $(PRIV_C)

@PLUGINS_REGISTRATION@ 引用这个

/* Call this function to register static plugins */
void
gst_android_register_static_plugins (void)
{@PLUGINS_REGISTRATION@
}

最后编译过程中就是 GST_PLUGIN_STATIC_REGISTER(playback); 是其中一个

/* Call this function to register static plugins */
void
gst_android_register_static_plugins (void)
{GST_PLUGIN_STATIC_REGISTER(coreelements);  GST_PLUGIN_STATIC_REGISTER(coretracers);  GST_PLUGIN_STATIC_REGISTER(adder);  GST_PLUGIN_STATIC_REGISTER(app);  GST_PLUGIN_STATIC_REGISTER(audioconvert);  GST_PLUGIN_STATIC_REGISTER(audiomixer);  GST_PLUGIN_STATIC_REGISTER(audiorate);  GST_PLUGIN_STATIC_REGISTER(audioresample);  GST_PLUGIN_STATIC_REGISTER(audiotestsrc);  GST_PLUGIN_STATIC_REGISTER(compositor);  GST_PLUGIN_STATIC_REGISTER(gio);  GST_PLUGIN_STATIC_REGISTER(overlaycomposition);  GST_PLUGIN_STATIC_REGISTER(pango);  GST_PLUGIN_STATIC_REGISTER(rawparse);  GST_PLUGIN_STATIC_REGISTER(typefindfunctions);  GST_PLUGIN_STATIC_REGISTER(videoconvert);  GST_PLUGIN_STATIC_REGISTER(videorate);  GST_PLUGIN_STATIC_REGISTER(videoscale);  GST_PLUGIN_STATIC_REGISTER(videotestsrc);  GST_PLUGIN_STATIC_REGISTER(volume);  GST_PLUGIN_STATIC_REGISTER(autodetect);  GST_PLUGIN_STATIC_REGISTER(videofilter);  GST_PLUGIN_STATIC_REGISTER(playback);  GST_PLUGIN_STATIC_REGISTER(subparse);  GST_PLUGIN_STATIC_REGISTER(ogg);  GST_PLUGIN_STATIC_REGISTER(theora);  GST_PLUGIN_STATIC_REGISTER(vorbis);  GST_PLUGIN_STATIC_REGISTER(opus);  GST_PLUGIN_STATIC_REGISTER(ivorbisdec);  GST_PLUGIN_STATIC_REGISTER(alaw);  GST_PLUGIN_STATIC_REGISTER(apetag);  GST_PLUGIN_STATIC_REGISTER(audioparsers);  GST_PLUGIN_STATIC_REGISTER(auparse);  GST_PLUGIN_STATIC_REGISTER(avi);  GST_PLUGIN_STATIC_REGISTER(dv);  GST_PLUGIN_STATIC_REGISTER(flac);  GST_PLUGIN_STATIC_REGISTER(flv);  GST_PLUGIN_STATIC_REGISTER(flxdec);  GST_PLUGIN_STATIC_REGISTER(icydemux);  GST_PLUGIN_STATIC_REGISTER(id3demux);  GST_PLUGIN_STATIC_REGISTER(isomp4);  GST_PLUGIN_STATIC_REGISTER(jpeg);  GST_PLUGIN_STATIC_REGISTER(lame);  GST_PLUGIN_STATIC_REGISTER(matroska);  GST_PLUGIN_STATIC_REGISTER(mpg123);  GST_PLUGIN_STATIC_REGISTER(mulaw);  GST_PLUGIN_STATIC_REGISTER(multipart);  GST_PLUGIN_STATIC_REGISTER(png);  GST_PLUGIN_STATIC_REGISTER(speex);  GST_PLUGIN_STATIC_REGISTER(taglib);  GST_PLUGIN_STATIC_REGISTER(vpx);  GST_PLUGIN_STATIC_REGISTER(wavenc);  GST_PLUGIN_STATIC_REGISTER(wavpack);  GST_PLUGIN_STATIC_REGISTER(wavparse);  GST_PLUGIN_STATIC_REGISTER(y4menc);  GST_PLUGIN_STATIC_REGISTER(adpcmdec);  GST_PLUGIN_STATIC_REGISTER(adpcmenc);  GST_PLUGIN_STATIC_REGISTER(bz2);  GST_PLUGIN_STATIC_REGISTER(dash);  GST_PLUGIN_STATIC_REGISTER(dvbsuboverlay);  GST_PLUGIN_STATIC_REGISTER(dvdspu);  GST_PLUGIN_STATIC_REGISTER(hls);  GST_PLUGIN_STATIC_REGISTER(id3tag);  GST_PLUGIN_STATIC_REGISTER(kate);  GST_PLUGIN_STATIC_REGISTER(midi);  GST_PLUGIN_STATIC_REGISTER(mxf);  GST_PLUGIN_STATIC_REGISTER(openh264);  GST_PLUGIN_STATIC_REGISTER(opusparse);  GST_PLUGIN_STATIC_REGISTER(pcapparse);  GST_PLUGIN_STATIC_REGISTER(pnm);  GST_PLUGIN_STATIC_REGISTER(rfbsrc);  GST_PLUGIN_STATIC_REGISTER(siren);  GST_PLUGIN_STATIC_REGISTER(smoothstreaming);  GST_PLUGIN_STATIC_REGISTER(subenc);  GST_PLUGIN_STATIC_REGISTER(videoparsersbad);  GST_PLUGIN_STATIC_REGISTER(y4mdec);  GST_PLUGIN_STATIC_REGISTER(jpegformat);  GST_PLUGIN_STATIC_REGISTER(gdp);  GST_PLUGIN_STATIC_REGISTER(rsvg);  GST_PLUGIN_STATIC_REGISTER(openjpeg);  GST_PLUGIN_STATIC_REGISTER(spandsp);  GST_PLUGIN_STATIC_REGISTER(sbc);  GST_PLUGIN_STATIC_REGISTER(zbar);  GST_PLUGIN_STATIC_REGISTER(androidmedia);  GST_PLUGIN_STATIC_REGISTER(tcp);  GST_PLUGIN_STATIC_REGISTER(rtsp);  GST_PLUGIN_STATIC_REGISTER(rtp);  GST_PLUGIN_STATIC_REGISTER(rtpmanager);  GST_PLUGIN_STATIC_REGISTER(soup);  GST_PLUGIN_STATIC_REGISTER(udp);  GST_PLUGIN_STATIC_REGISTER(dtls);  GST_PLUGIN_STATIC_REGISTER(netsim);  GST_PLUGIN_STATIC_REGISTER(rtmp2);  GST_PLUGIN_STATIC_REGISTER(sctp);  GST_PLUGIN_STATIC_REGISTER(sdpelem);  GST_PLUGIN_STATIC_REGISTER(srtp);  GST_PLUGIN_STATIC_REGISTER(srt);  GST_PLUGIN_STATIC_REGISTER(webrtc);  GST_PLUGIN_STATIC_REGISTER(nice);  GST_PLUGIN_STATIC_REGISTER(rtspclientsink);  GST_PLUGIN_STATIC_REGISTER(opengl);  GST_PLUGIN_STATIC_REGISTER(ipcpipeline);  GST_PLUGIN_STATIC_REGISTER(opensles);
}

@G_IO_MODULES_DECLARE@

void
gst_android_load_gio_modules (void)
{GTlsBackend *backend;const gchar *ca_certs;GST_G_IO_MODULE_LOAD(openssl);

1.3 SDK里的NDK build

SDK里有以下几个mk

gstreamer-1.0.mk
gstreamer_prebilt.mk
plugins.mk    //
tools.mk

1.3.1 gstreamer-1.0.mk

初始化资源路径路径变量相关 GSTREAMER_ROOT为SDK根目录

$(call assert-defined, GSTREAMER_ROOT)
$(if $(wildcard $(GSTREAMER_ROOT)),,\$(error "The directory GSTREAMER_ROOT=$(GSTREAMER_ROOT) does not exists")\
)#####################
#  Setup variables  #
#####################ifndef GSTREAMER_PLUGINS$(info "The list of GSTREAMER_PLUGINS is empty")
endif# Expand home directory (~/)
GSTREAMER_ROOT := $(wildcard $(GSTREAMER_ROOT))# Path for GStreamer static plugins
GSTREAMER_STATIC_PLUGINS_PATH := $(GSTREAMER_ROOT)/lib/gstreamer-1.0# Path for the NDK integration makefiles
GSTREAMER_NDK_BUILD_PATH := $(GSTREAMER_ROOT)/share/gst-android/ndk-buildifndef GSTREAMER_INCLUDE_FONTS
GSTREAMER_INCLUDE_FONTS := yes
endififndef GSTREAMER_INCLUDE_CA_CERTIFICATES
GSTREAMER_INCLUDE_CA_CERTIFICATES := yes
endififndef GSTREAMER_JAVA_SRC_DIR
GSTREAMER_JAVA_SRC_DIR := src
endif

加载tools.mk 和工具相关变量

# Include tools
include $(GSTREAMER_NDK_BUILD_PATH)/tools.mk# Path for the static GIO modules
G_IO_MODULES_PATH := $(GSTREAMER_ROOT)/lib/gio/modules# Path for libc++_shared
CXX_SHARED_ROOT := $(NDK_ROOT)/sources/cxx-stl/llvm-libc++/libs/$(TARGET_ARCH_ABI)# Host tools
ifeq ($(HOST_OS),windows)SED := $(GSTREAMER_NDK_BUILD_PATH)/tools/windows/sedSED_LOCAL := "$(GSTREAMER_NDK_BUILD_PATH)/tools/windows/sed"EXE_SUFFIX := .exe
elseSED := sedSED_LOCAL := sedEXE_SUFFIX :=
endif

编译变量和编译module信息 生成gstreamer_android 的库

ifndef GSTREAMER_ANDROID_MODULE_NAME
GSTREAMER_ANDROID_MODULE_NAME := gstreamer_android
endif
GSTREAMER_BUILD_DIR           := gst-build-$(TARGET_ARCH_ABI)
GSTREAMER_ANDROID_O           := $(GSTREAMER_BUILD_DIR)/$(GSTREAMER_ANDROID_MODULE_NAME).o
GSTREAMER_ANDROID_SO          := $(GSTREAMER_BUILD_DIR)/lib$(GSTREAMER_ANDROID_MODULE_NAME).so
GSTREAMER_ANDROID_C           := $(GSTREAMER_BUILD_DIR)/$(GSTREAMER_ANDROID_MODULE_NAME).c
GSTREAMER_ANDROID_C_IN        := $(GSTREAMER_NDK_BUILD_PATH)/gstreamer_android-1.0.c.in
GSTREAMER_DEPS                := $(GSTREAMER_EXTRA_DEPS) gstreamer-1.0
GSTREAMER_LD                  := -fuse-ld=gold$(EXE_SUFFIX) -Wl,-soname,lib$(GSTREAMER_ANDROID_MODULE_NAME).so
# for setting the default GTlsDatabase
ifeq ($(GSTREAMER_INCLUDE_CA_CERTIFICATES),yes)
GSTREAMER_DEPS                += gio-2.0
endif################################
#  NDK Build Prebuilt library  #
################################# Declare a prebuilt library module, a shared library including
# gstreamer, its dependencies and all its plugins.
# Since the shared library is not really prebuilt, but will be built
# using the defined rules in this file, we can't use the
# PREBUILT_SHARED_LIBRARY makefiles like explained in the docs,
# as it checks for the existance of the shared library. We therefore
# use a custom gstreamer_prebuilt.mk, which skips this stepinclude $(CLEAR_VARS)
LOCAL_MODULE            := $(GSTREAMER_ANDROID_MODULE_NAME)
LOCAL_SRC_FILES         := $(GSTREAMER_ANDROID_SO)
LOCAL_BUILD_SCRIPT      := PREBUILT_SHARED_LIBRARY
LOCAL_MODULE_CLASS      := PREBUILT_SHARED_LIBRARY
LOCAL_MAKEFILE          := $(local-makefile)
LOCAL_PREBUILT_PREFIX   := lib
LOCAL_PREBUILT_SUFFIX   := .so
LOCAL_EXPORT_C_INCLUDES := $(subst -I$1, $1, $(call pkg-config-get-includes,$(GSTREAMER_DEPS)))
LOCAL_EXPORT_C_INCLUDES += $(GSTREAMER_ROOT)/include

开始加载plugin 其中会加载到 prebuilt.mk

##################################################################
#   Our custom rules to create a shared libray with gstreamer    #
#   and the requested plugins in GSTREAMER_PLUGINS starts here   #
##################################################################include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer_prebuilt.mkfix-deps = \$(subst $1,$1 $2,$(GSTREAMER_ANDROID_LIBS))# Generate list of plugin links (eg: -lcoreelements -lvideoscale)
GSTREAMER_PLUGINS_LIBS       := $(foreach plugin, $(GSTREAMER_PLUGINS), -lgst$(plugin) )GSTREAMER_PLUGINS_CLASSES    := $(strip \$(subst $(GSTREAMER_NDK_BUILD_PATH),, \$(foreach plugin,$(GSTREAMER_PLUGINS), \$(wildcard $(GSTREAMER_NDK_BUILD_PATH)/$(plugin)/*.java))))GSTREAMER_PLUGINS_WITH_CLASSES := $(strip \$(subst $(GSTREAMER_NDK_BUILD_PATH),, \$(foreach plugin, $(GSTREAMER_PLUGINS), \$(wildcard $(GSTREAMER_NDK_BUILD_PATH)/$(plugin)))))# Generate the plugins' declaration strings
GSTREAMER_PLUGINS_DECLARE    := $(foreach plugin, $(GSTREAMER_PLUGINS), \GST_PLUGIN_STATIC_DECLARE($(plugin));)
# Generate the plugins' registration strings
GSTREAMER_PLUGINS_REGISTER   := $(foreach plugin, $(GSTREAMER_PLUGINS), \GST_PLUGIN_STATIC_REGISTER($(plugin));)

IO模块

# Generate list of gio modules
G_IO_MODULES_LIBS            := $(foreach module, $(G_IO_MODULES), $(G_IO_MODULES_PATH)/libgio$(module).a)
G_IO_MODULES_DECLARE         := $(foreach module, $(G_IO_MODULES), \GST_G_IO_MODULE_DECLARE($(module));)
G_IO_MODULES_LOAD            := $(foreach module, $(G_IO_MODULES), \GST_G_IO_MODULE_LOAD($(module));)# Get the full list of libraries
# link at least to gstreamer-1.0 in case the plugins list is empty
GSTREAMER_ANDROID_LIBS       := $(call pkg-config-get-libs,$(GSTREAMER_DEPS))
GSTREAMER_ANDROID_LIBS       += $(GSTREAMER_PLUGINS_LIBS) $(G_IO_MODULES_LIBS) $(GSTREAMER_EXTRA_LIBS) -llog -lz
GSTREAMER_ANDROID_WHOLE_AR   := $(call pkg-config-get-libs-no-deps,$(GSTREAMER_DEPS)) $(GSTREAMER_EXTRA_LIBS)
GSTREAMER_ANDROID_CFLAGS     := $(call pkg-config-get-includes,$(GSTREAMER_DEPS)) -I$(GSTREAMER_ROOT)/include

NDK相关 和 Android cmd

# In newer NDK, SYSROOT is replaced by SYSROOT_INC and SYSROOT_LINK, which
# now points to the root directory. But this will probably change in the future from:
# https://android.googlesource.com/platform/ndk/+/fa8c1b4338c1bef2813ecee0ee298e9498a1aaa7
ifdef SYSROOTSYSROOT_GST_INC := $(SYSROOT)SYSROOT_GST_LINK_ARG := --sysroot=$(SYSROOT)
elseifdef SYSROOT_LINKifdef SYSROOT_LINKSYSROOT_GST_INC := $(SYSROOT_INC)#  SYSROOT_GST_LINK_ARG := --sysroot=$(SYSROOT_LINK)SYSROOT_GST_LINK_ARG := --sysroot=$(SYSROOT_INC)endifelseifdef SYSROOT_LIB_DIR# https://android.googlesource.com/platform/ndk/+/8afb627a222005272e61d4b222b50c69e760d77d# introduced SYSROOT_LIB_DIRSYSROOT_GST_INC := $(SYSROOT_INC)SYSROOT_GST_LINK_ARG := -L$(SYSROOT_API_LIB_DIR) -L$(SYSROOT_LIB_DIR)elseSYSROOT_GST_INC := $(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-$(TARGET_ARCH)SYSROOT_GST_LINK_ARG := -L$(SYSROOT_GST_INC)endifendif
endif# Create the link command
GSTREAMER_ANDROID_CMD        := $(call libtool-link,$(TARGET_CXX) $(GLOBAL_LDFLAGS) $(TARGET_LDFLAGS) -nostdlib++ -shared $(SYSROOT_GST_LINK_ARG) \-o $(GSTREAMER_ANDROID_SO) $(GSTREAMER_ANDROID_O) \-L$(GSTREAMER_ROOT)/lib -L$(GSTREAMER_STATIC_PLUGINS_PATH) -L$(CXX_SHARED_ROOT) \$(GSTREAMER_ANDROID_LIBS), $(GSTREAMER_LD)) -Wl,-no-undefined $(GSTREAMER_LD)
GSTREAMER_ANDROID_CMD        := $(call libtool-whole-archive,$(GSTREAMER_ANDROID_CMD),$(GSTREAMER_ANDROID_WHOLE_AR))

重点 用户自定义 包含插件 字体 签名

# This triggers the build of our library using our custom rules
$(GSTREAMER_ANDROID_SO): buildsharedlibrary_$(TARGET_ARCH_ABI)
$(GSTREAMER_ANDROID_SO): copyjavasource_$(TARGET_ARCH_ABI)
ifeq ($(GSTREAMER_INCLUDE_FONTS),yes)
$(GSTREAMER_ANDROID_SO): copyfontsres_$(TARGET_ARCH_ABI)
endif
ifeq ($(GSTREAMER_INCLUDE_CA_CERTIFICATES),yes)
$(GSTREAMER_ANDROID_SO): copycacertificatesres_$(TARGET_ARCH_ABI)
endifdelsharedlib_$(TARGET_ARCH_ABI): PRIV_B_DIR := $(GSTREAMER_BUILD_DIR)
delsharedlib_$(TARGET_ARCH_ABI):$(hide)$(call host-rm,$(prebuilt))$(hide)$(foreach path,$(wildcard $(PRIV_B_DIR)/sed*), $(call host-rm,$(path)) && ) echo Done rm
$(LOCAL_INSTALLED): delsharedlib_$(TARGET_ARCH_ABI)# Generates a source file that declares and registers all the required plugins
# about the sed command, android-studio doesn't seem to like line continuation characters when executing shell commands
genstatic_$(TARGET_ARCH_ABI): PRIV_C := $(GSTREAMER_ANDROID_C)
genstatic_$(TARGET_ARCH_ABI): PRIV_B_DIR := $(GSTREAMER_BUILD_DIR)
genstatic_$(TARGET_ARCH_ABI): PRIV_C_IN := $(GSTREAMER_ANDROID_C_IN)
genstatic_$(TARGET_ARCH_ABI): PRIV_P_D := $(GSTREAMER_PLUGINS_DECLARE)
genstatic_$(TARGET_ARCH_ABI): PRIV_P_R := $(GSTREAMER_PLUGINS_REGISTER)
genstatic_$(TARGET_ARCH_ABI): PRIV_G_L := $(G_IO_MODULES_LOAD)
genstatic_$(TARGET_ARCH_ABI): PRIV_G_R := $(G_IO_MODULES_DECLARE)
genstatic_$(TARGET_ARCH_ABI):$(hide)$(HOST_ECHO) "GStreamer      : [GEN] => $(PRIV_C)"$(hide)$(call host-mkdir,$(PRIV_B_DIR))$(hide)$(SED_LOCAL) "s/@PLUGINS_DECLARATION@/$(PRIV_P_D)/g" $(PRIV_C_IN) | $(SED_LOCAL) "s/@PLUGINS_REGISTRATION@/$(PRIV_P_R)/g" | $(SED_LOCAL) "s/@G_IO_MODULES_LOAD@/$(PRIV_G_L)/g" | $(SED_LOCAL) "s/@G_IO_MODULES_DECLARE@/$(PRIV_G_R)/g" > $(PRIV_C)# Compile the source file
$(GSTREAMER_ANDROID_O): PRIV_C := $(GSTREAMER_ANDROID_C)
$(GSTREAMER_ANDROID_O): PRIV_CC_CMD := $(TARGET_CC) --sysroot=$(SYSROOT_GST_INC) $(SYSROOT_ARCH_INC_ARG) $(GLOBAL_CFLAGS) $(TARGET_CFLAGS) \-c $(GSTREAMER_ANDROID_C) -Wall -Werror -o $(GSTREAMER_ANDROID_O) $(GSTREAMER_ANDROID_CFLAGS)
$(GSTREAMER_ANDROID_O): PRIV_GST_CFLAGS := $(GSTREAMER_ANDROID_CFLAGS) $(TARGET_CFLAGS)
$(GSTREAMER_ANDROID_O): genstatic_$(TARGET_ARCH_ABI)$(hide)$(HOST_ECHO) "GStreamer      : [COMPILE] => $(PRIV_C)"$(hide)$(PRIV_CC_CMD)# Creates a shared library including gstreamer, its plugins and all the dependencies
buildsharedlibrary_$(TARGET_ARCH_ABI): PRIV_CMD := $(GSTREAMER_ANDROID_CMD)
buildsharedlibrary_$(TARGET_ARCH_ABI): PRIV_SO := $(GSTREAMER_ANDROID_SO)
buildsharedlibrary_$(TARGET_ARCH_ABI): $(GSTREAMER_ANDROID_O)$(hide)$(HOST_ECHO) "GStreamer      : [LINK] => $(PRIV_SO)"$(hide)$(PRIV_CMD)ifeq ($(GSTREAMER_INCLUDE_FONTS),yes)
GSTREAMER_INCLUDE_FONTS_SUBST :=
else
GSTREAMER_INCLUDE_FONTS_SUBST := //
endififeq ($(GSTREAMER_INCLUDE_CA_CERTIFICATES),yes)
GSTREAMER_INCLUDE_CA_CERTIFICATES_SUBST := 
else
GSTREAMER_INCLUDE_CA_CERTIFICATES_SUBST := //
endififneq (,$(findstring yes,$(GSTREAMER_INCLUDE_FONTS)$(GSTREAMER_INCLUDE_CA_CERTIFICATES)))
GSTREAMER_COPY_FILE_SUBST := 
else
GSTREAMER_COPY_FILE_SUBST := //
endif# about the sed command, android-studio doesn't seem to like line continuation characters when executing shell commands
copyjavasource_$(TARGET_ARCH_ABI):$(hide)$(call host-mkdir,$(GSTREAMER_JAVA_SRC_DIR)/org/freedesktop/gstreamer)$(hide)$(foreach plugin,$(GSTREAMER_PLUGINS_WITH_CLASSES), \$(call host-mkdir,$(GSTREAMER_JAVA_SRC_DIR)/org/freedesktop/gstreamer/$(plugin)) && ) echo Done mkdir$(hide)$(foreach file,$(GSTREAMER_PLUGINS_CLASSES), \$(call host-cp,$(GSTREAMER_NDK_BUILD_PATH)$(file),$(GSTREAMER_JAVA_SRC_DIR)/org/freedesktop/gstreamer/$(file)) && ) echo Done cp$(hide)$(SED_LOCAL) "s;@INCLUDE_FONTS@;$(GSTREAMER_INCLUDE_FONTS_SUBST);g" $(GSTREAMER_NDK_BUILD_PATH)/GStreamer.java | $(SED_LOCAL) "s;@INCLUDE_CA_CERTIFICATES@;$(GSTREAMER_INCLUDE_CA_CERTIFICATES_SUBST);g" | $(SED_LOCAL) "s;@INCLUDE_COPY_FILE@;$(GSTREAMER_COPY_FILE_SUBST);g" > $(GSTREAMER_JAVA_SRC_DIR)/org/freedesktop/gstreamer/GStreamer.javaifndef GSTREAMER_ASSETS_DIR
GSTREAMER_ASSETS_DIR := src/main/assets
endifcopyfontsres_$(TARGET_ARCH_ABI):$(hide)$(call host-mkdir,$(GSTREAMER_ASSETS_DIR)/fontconfig)$(hide)$(call host-mkdir,$(GSTREAMER_ASSETS_DIR)/fontconfig/fonts/truetype/)$(hide)$(call host-cp,$(GSTREAMER_NDK_BUILD_PATH)/fontconfig/fonts.conf,$(GSTREAMER_ASSETS_DIR)/fontconfig)$(hide)$(call host-cp,$(GSTREAMER_NDK_BUILD_PATH)/fontconfig/fonts/Ubuntu-R.ttf,$(GSTREAMER_ASSETS_DIR)/fontconfig/fonts/truetype)
copycacertificatesres_$(TARGET_ARCH_ABI):$(hide)$(call host-mkdir,$(GSTREAMER_ASSETS_DIR)/ssl/certs)$(hide)$(call host-cp,$(GSTREAMER_ROOT)/etc/ssl/certs/ca-certificates.crt,$(GSTREAMER_ASSETS_DIR)/ssl/certs)

1.3.2 Tools.mk

加载一堆lib库

1.3.3 Gstreamer_prebuilt.mk

最终加载到build-module.mk

include $(BUILD_SYSTEM)/build-module.mk

二、初始化GStreamer

        try {GStreamer.init(this);} catch (Exception e) {Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();finish();return;}

2.1 GStreamer.java 基础类

public class GStreamer {private static native void nativeInit(Context context) throws Exception;public static void init(Context context) throws Exception {//将assets中签名证书copy到应用的files目录copyCaCertificates(context);//将assets字体格式设置copy到应用饿files目录copyFonts(context);//调用 native初始化nativeInit(context);}

2.2 Gstreamer_android-1.0.c.in 安卓平台初始化专用 jni

jint
JNI_OnLoad (JavaVM * vm, void * reserved)
{JNIEnv *env = NULL;GModule *module;if ((*vm)->GetEnv (vm, (void **) &env, JNI_VERSION_1_4) != JNI_OK) {__android_log_print (ANDROID_LOG_ERROR, "GStreamer","Could not retrieve JNIEnv");return 0;}// 找到 GStreamer里的java类  适配需要修改这个路径jclass klass = (*env)->FindClass (env, "org/freedesktop/gstreamer/GStreamer");if (!klass) {__android_log_print (ANDROID_LOG_ERROR, "GStreamer","Could not retrieve class org.freedesktop.gstreamer.GStreamer");return 0;}//注册JNI函数if ((*env)->RegisterNatives (env, klass, native_methods,G_N_ELEMENTS (native_methods))) {__android_log_print (ANDROID_LOG_ERROR, "GStreamer","Could not register native methods for org.freedesktop.gstreamer.GStreamer");return 0;}/* Remember Java VM */_java_vm = vm;
// 打开模块 set java vm虚拟机/* Tell the androidmedia plugin about the Java VM if we can */module = g_module_open (NULL, G_MODULE_BIND_LOCAL);if (module) {void (*set_java_vm) (JavaVM *) = NULL;if (g_module_symbol (module, "gst_amc_jni_set_java_vm",(gpointer *) & set_java_vm) && set_java_vm) {set_java_vm (vm);}g_module_close (module);}return JNI_VERSION_1_4;
}

Gmodule.h

/*** GModuleFlags:* @G_MODULE_BIND_LAZY: specifies that symbols are only resolved when*     needed. The default action is to bind all symbols when the module*     is loaded.* @G_MODULE_BIND_LOCAL: specifies that symbols in the module should*     not be added to the global name space. The default action on most*     platforms is to place symbols in the module in the global name space,*     which may cause conflicts with existing symbols.* @G_MODULE_BIND_MASK: mask for all flags.** Flags passed to g_module_open().* Note that these flags are not supported on all platforms.*/
typedef enum
{G_MODULE_BIND_LAZY	= 1 << 0,  //懒加载G_MODULE_BIND_LOCAL	= 1 << 1,   //命名空间 localG_MODULE_BIND_MASK	= 0x03     //以上两个集合
} GModuleFlags;/* open a module 'file_name' and return handle, which is NULL on error */
GLIB_AVAILABLE_IN_ALL
GModule*              g_module_open          (const gchar  *file_name,GModuleFlags  flags);

2.3 gst_android_init 初始化

void
gst_android_init (JNIEnv * env, jobject context)
{
//1. init android context    if (!init (env, context)) {__android_log_print (ANDROID_LOG_INFO, "GStreamer","GStreamer failed to initialize");}
// 初始化already判定    if (gst_is_initialized ()) {__android_log_print (ANDROID_LOG_INFO, "GStreamer","GStreamer already initialized");return;}
//2. 获取存有证书签名和字体config的文件路径    获取APP的 cache目录和 files目录if (!get_application_dirs (env, context, &cache_dir, &files_dir)) {__android_log_print (ANDROID_LOG_ERROR, "GStreamer","Failed to get application dirs");} 
// 设置环境变量  缓存路径和  home路径    if (cache_dir) {g_setenv ("TMP", cache_dir, TRUE);registry = g_build_filename (cache_dir, "registry.bin", NULL);  //注册g_setenv ("GST_REGISTRY", registry, TRUE);g_free (registry);····}if (files_dir) {gchar *fontconfig, *certs;g_setenv ("HOME", files_dir, TRUE);···fontconfig = g_build_filename (files_dir, "fontconfig", NULL);  //字体g_setenv ("FONTCONFIG_PATH", fontconfig, TRUE);g_free (fontconfig);certs = g_build_filename (files_dir, "ssl", "certs", "ca-certificates.crt", NULL); //证书g_setenv ("CA_CERTIFICATES", certs, TRUE);g_free (certs);}//设置输出打印 handler/* Set GLib print handlers */g_set_print_handler (glib_print_handler);g_set_printerr_handler (glib_printerr_handler);g_log_set_default_handler (glib_log_handler, NULL);  //未知  /* Call this function to register static plugins */ gst_android_register_static_plugins ();/* Call this function to load GIO modules */gst_android_load_gio_modules ();    }

2.4 init context初始化操作

static gboolean
init (JNIEnv *env, jobject context)
{jclass context_cls = NULL;jmethodID get_class_loader_id = 0;jobject class_loader = NULL;
// 获得java层的 context对象context_cls = (*env)->GetObjectClass (env, context);get_class_loader_id = (*env)->GetMethodID (env, context_cls,"getClassLoader", "()Ljava/lang/ClassLoader;");if ((*env)->ExceptionCheck (env)) {(*env)->ExceptionDescribe (env);(*env)->ExceptionClear (env);return FALSE;}
//获取 class loader对象class_loader = (*env)->CallObjectMethod (env, context, get_class_loader_id);
//context 和 classloader 赋值给全局变量  if (_context) {(*env)->DeleteGlobalRef (env, _context);}_context = (*env)->NewGlobalRef (env, context);if (_class_loader) {(*env)->DeleteGlobalRef (env, _class_loader);}_class_loader = (*env)->NewGlobalRef (env, class_loader);return TRUE;
}

2.5 gst_android_register_static_plugins

未知用法

void
gst_android_register_static_plugins (void)
{//编译替代 @PLUGINS_REGISTRATION@
}/* Call this function to register static plugins */
void
gst_android_register_static_plugins (void)
{GST_PLUGIN_STATIC_REGISTER(coreelements);  GST_PLUGIN_STATIC_REGISTER(coretracers);  GST_PLUGIN_STATIC_REGISTER(adder);  GST_PLUGIN_STATIC_REGISTER(app);  GST_PLUGIN_STATIC_REGISTER(audioconvert);  GST_PLUGIN_STATIC_REGISTER(audiomixer);  GST_PLUGIN_STATIC_REGISTER(audiorate);  GST_PLUGIN_STATIC_REGISTER(audioresample);  GST_PLUGIN_STATIC_REGISTER(audiotestsrc);  GST_PLUGIN_STATIC_REGISTER(compositor);  GST_PLUGIN_STATIC_REGISTER(gio);  GST_PLUGIN_STATIC_REGISTER(overlaycomposition);  GST_PLUGIN_STATIC_REGISTER(pango);  GST_PLUGIN_STATIC_REGISTER(rawparse);  GST_PLUGIN_STATIC_REGISTER(typefindfunctions);  GST_PLUGIN_STATIC_REGISTER(videoconvert);  GST_PLUGIN_STATIC_REGISTER(videorate);  GST_PLUGIN_STATIC_REGISTER(videoscale);  GST_PLUGIN_STATIC_REGISTER(videotestsrc);  GST_PLUGIN_STATIC_REGISTER(volume);  GST_PLUGIN_STATIC_REGISTER(autodetect);  GST_PLUGIN_STATIC_REGISTER(videofilter);  GST_PLUGIN_STATIC_REGISTER(opengl);  GST_PLUGIN_STATIC_REGISTER(ipcpipeline);  GST_PLUGIN_STATIC_REGISTER(opensles);
}

2.6 gst_android_load_gio_modules 获取gio modeule

void
gst_android_load_gio_modules (void)
{GTlsBackend *backend;const gchar *ca_certs;@G_IO_MODULES_LOAD@ca_certs = g_getenv ("CA_CERTIFICATES");
//获取后端backend = g_tls_backend_get_default ();if (backend && ca_certs) {GTlsDatabase *db;GError *error = NULL;
//创建dbdb = g_tls_file_database_new (ca_certs, &error);if (db) {//关联后端和DB       g_tls_backend_set_default_database (backend, db);g_object_unref (db);} else {g_warning ("Failed to create a database from file: %s",error ? error->message : "Unknown");}}
}

三、API示例

3.1 tutorial-1 获取版本信息

3.1.1 示例代码

    static {System.loadLibrary("gstreamer_android");System.loadLibrary("tutorial-1");}public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);try {GStreamer.init(this);} catch (Exception e) {Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();finish();return;}setContentView(R.layout.main);TextView tv = (TextView)findViewById(R.id.textview_info);tv.setText("Welcome to " + nativeGetGStreamerInfo() + " !");}
private native String nativeGetGStreamerInfo();

3.1.2 gst_native_get_gstreamer_info

static jstring
gst_native_get_gstreamer_info (JNIEnv * env, jobject thiz)
{char *version_utf8 = gst_version_string ();jstring *version_jstring = (*env)->NewStringUTF (env, version_utf8);g_free (version_utf8);return version_jstring;
}

3.2 tutorial-2 播放音频

3.2.1 示例代码

3.2.1.1 播放逻辑代码
    static {System.loadLibrary("gstreamer_android");System.loadLibrary("tutorial-2");nativeClassInit();}private native void nativeInit();     // Initialize native code, build pipeline, etcprivate native void nativeFinalize(); // Destroy pipeline and shutdown native codeprivate native void nativePlay();     // Set pipeline to PLAYINGprivate native void nativePause();    // Set pipeline to PAUSEDprivate static native boolean nativeClassInit(); // Initialize native class: cache Method IDs for callbacks
//native 可操作属性变量private long native_custom_data;      // Native code will use this to keep private datavoid onCreate(){ImageButton play = (ImageButton) this.findViewById(R.id.button_play);play.setOnClickListener(new OnClickListener() {public void onClick(View v) {is_playing_desired = true;//播放 nativePlay();}});ImageButton pause = (ImageButton) this.findViewById(R.id.button_stop);pause.setOnClickListener(new OnClickListener() {public void onClick(View v) {is_playing_desired = false;//暂停nativePause();}});//初始化播放nativeInit();
}
//用于native的回调   使用 nativeClasssInit回调private void onGStreamerInitialized () {Log.i ("GStreamer", "Gst initialized. Restoring state, playing:" + is_playing_desired);// Restore previous playing stateif (is_playing_desired) {nativePlay();} else {nativePause();}// Re-enable buttons, now that GStreamer is initializedfinal Activity activity = this;runOnUiThread(new Runnable() {public void run() {activity.findViewById(R.id.button_play).setEnabled(true);activity.findViewById(R.id.button_stop).setEnabled(true);}});}protected void onDestroy() {//完成播放nativeFinalize();super.onDestroy();}
3.2.1.2 setMessage native回调
    // Called from native code. This sets the content of the TextView from the UI thread.private void setMessage(final String message) {final TextView tv = (TextView) this.findViewById(R.id.textview_message);runOnUiThread (new Runnable() {public void run() {tv.setText(message);}});}
3.2.1.3 onGStreamerInitialized native回调初始化完成
//用于native的回调   使用 nativeClasssInit回调private void onGStreamerInitialized () {Log.i ("GStreamer", "Gst initialized. Restoring state, playing:" + is_playing_desired);// Restore previous playing stateif (is_playing_desired) {nativePlay();} else {nativePause();}// Re-enable buttons, now that GStreamer is initializedfinal Activity activity = this;runOnUiThread(new Runnable() {public void run() {activity.findViewById(R.id.button_play).setEnabled(true);activity.findViewById(R.id.button_stop).setEnabled(true);}});}

3.2.2 JNI method对应表

static JNINativeMethod native_methods[] = {{"nativeInit", "()V", (void *) gst_native_init},{"nativeFinalize", "()V", (void *) gst_native_finalize},{"nativePlay", "()V", (void *) gst_native_play},{"nativePause", "()V", (void *) gst_native_pause},{"nativeClassInit", "()Z", (void *) gst_native_class_init}
};

3.2.3 CustomData 自定义APP信息

typedef struct _CustomData
{jobject app;                  /* Application instance, used to call its methods. A global reference is kept. */GstElement *pipeline;         /* The running pipeline */GMainContext *context;        /* GLib context used to run the main loop */GMainLoop *main_loop;         /* GLib main loop */gboolean initialized;         /* To avoid informing the UI multiple times about the initialization */
} CustomData;

3.2.3 gst_native_class_init 将java层的class与GStreamer关联

/* Static class initializer: retrieve method and field IDs */
static jboolean
gst_native_class_init (JNIEnv * env, jclass klass)
{//设置三个回调函数custom_data_field_id =(*env)->GetFieldID (env, klass, "native_custom_data", "J");set_message_method_id =(*env)->GetMethodID (env, klass, "setMessage", "(Ljava/lang/String;)V");on_gstreamer_initialized_method_id =(*env)->GetMethodID (env, klass, "onGStreamerInitialized", "()V");

3.2.4 gst_native_init 初始化thread

static void
gst_native_init (JNIEnv * env, jobject thiz)
{//初始化CustomDataCustomData *data = g_new0 (CustomData, 1);//回调设置 属性变量  native_custom_dataSET_CUSTOM_DATA (env, thiz, custom_data_field_id, data);//设置debug logGST_DEBUG_CATEGORY_INIT (debug_category, "tutorial-2", 0,"Android tutorial 2");gst_debug_set_threshold_for_name ("tutorial-2", GST_LEVEL_DEBUG);GST_DEBUG ("Created CustomData at %p", data);
//将 java层的 引用对象放到 data->app    data->app = (*env)->NewGlobalRef (env, thiz);GST_DEBUG ("Created GlobalRef for app object at %p", data->app);
// 创建gst_app_thread   便传入 thread创建好了 的__start_routine functionpthread_create (&gst_app_thread, NULL, &app_function, data);
}

3.2.5 app_function thread循环

/* Main method for the native code. This is executed on its own thread. */
static void *
app_function (void *userdata)
{JavaVMAttachArgs args;GstBus *bus;CustomData *data = (CustomData *) userdata;GSource *bus_source;GError *error = NULL;GST_DEBUG ("Creating pipeline in CustomData at %p", data);
//1.context 赋值/* Create our own GLib Main Context and make it the default one */data->context = g_main_context_new ();g_main_context_push_thread_default (data->context);
//2. 创建pipeline pipeline_description包括 src convert sample sink/* Build pipeline */data->pipeline =gst_parse_launch("audiotestsrc ! audioconvert ! audioresample ! autoaudiosink", &error);if (error) {gchar *message =g_strdup_printf ("Unable to build pipeline: %s", error->message);g_clear_error (&error);set_ui_message (message, data);g_free (message);return NULL;}
//3. 获取 元件bus/* Instruct the bus to emit signals for each received message, and connect to the interesting signals */bus = gst_element_get_bus (data->pipeline);bus_source = gst_bus_create_watch (bus);g_source_set_callback (bus_source, (GSourceFunc) gst_bus_async_signal_func,NULL, NULL);g_source_attach (bus_source, data->context);g_source_unref (bus_source);g_signal_connect (G_OBJECT (bus), "message::error", (GCallback) error_cb,data);g_signal_connect (G_OBJECT (bus), "message::state-changed",(GCallback) state_changed_cb, data);gst_object_unref (bus);
// 4. 主线程死循环 /* Create a GLib Main Loop and set it to run */GST_DEBUG ("Entering main loop... (CustomData:%p)", data);data->main_loop = g_main_loop_new (data->context, FALSE);check_initialization_complete (data);g_main_loop_run (data->main_loop);GST_DEBUG ("Exited main loop");//循环结束g_main_loop_unref (data->main_loop);data->main_loop = NULL;
// 5. 资源释放/* Free resources */g_main_context_pop_thread_default (data->context);g_main_context_unref (data->context);gst_element_set_state (data->pipeline, GST_STATE_NULL);gst_object_unref (data->pipeline);return NULL;
}

3.2.6 gst_native_play 开始播放

/* Set pipeline to PLAYING state */
static void
gst_native_play (JNIEnv * env, jobject thiz)
{CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);if (!data)return;GST_DEBUG ("Setting state to PLAYING");gst_element_set_state (data->pipeline, GST_STATE_PLAYING);
}

3.2.7 gst_native_pause 暂停

/* Set pipeline to PAUSED state */
static void
gst_native_pause (JNIEnv * env, jobject thiz)
{CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);if (!data)return;GST_DEBUG ("Setting state to PAUSED");gst_element_set_state (data->pipeline, GST_STATE_PAUSED);
}

3.2.8 gst_native_finalize 释放资源

/* Quit the main loop, remove the native thread and free resources */
static void
gst_native_finalize (JNIEnv * env, jobject thiz)
{CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);if (!data)return;GST_DEBUG ("Quitting main loop...");//退出主线程g_main_loop_quit (data->main_loop);GST_DEBUG ("Waiting for thread to finish...");pthread_join (gst_app_thread, NULL);GST_DEBUG ("Deleting GlobalRef for app object at %p", data->app);(*env)->DeleteGlobalRef (env, data->app);GST_DEBUG ("Freeing CustomData at %p", data);g_free (data);SET_CUSTOM_DATA (env, thiz, custom_data_field_id, NULL);GST_DEBUG ("Done finalizing");
}

3.3 tutorial-3 简单视频播放

    /* The main loop is running and we received a native window, inform the sink about it */gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (data->video_sink),(guintptr) data->native_window);gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (data->video_sink),(guintptr) NULL);     

3.3.1 实例代码

3.3.1.1 SurfaceView
public class GStreamerSurfaceView extends SurfaceView {public int media_width = 320;public int media_height = 240;
//根据 media_width 和 media_height进行 measure    // Called by the layout manager to find out our size and give us some rules.// We will try to maximize our size, and preserve the media's aspect ratio if// we are given the freedom to do so.@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { }
}
3.3.1.2 播放逻辑代码
    static {System.loadLibrary("gstreamer_android");System.loadLibrary("tutorial-3");nativeClassInit();}public void onCreate(Bundle savedInstanceState){GStreamer.init(this);SurfaceView sv = (SurfaceView) this.findViewById(R.id.surface_video);SurfaceHolder sh = sv.getHolder();sh.addCallback(this);ImageButton play = (ImageButton) this.findViewById(R.id.button_play);play.setOnClickListener(new OnClickListener() {public void onClick(View v) {is_playing_desired = true;nativePlay();}});ImageButton pause = (ImageButton) this.findViewById(R.id.button_stop);pause.setOnClickListener(new OnClickListener() {public void onClick(View v) {is_playing_desired = false;nativePause();}});nativeInit();
}

3.3.1.3 SurfaceHolder.Callback

//implements SurfaceHolder.Callbackpublic void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {Log.d("GStreamer", "Surface changed to format " + format + " width "+ width + " height " + height);nativeSurfaceInit (holder.getSurface());}public void surfaceCreated(SurfaceHolder holder) {Log.d("GStreamer", "Surface created: " + holder.getSurface());}public void surfaceDestroyed(SurfaceHolder holder) {Log.d("GStreamer", "Surface destroyed");nativeSurfaceFinalize ();}
3.3.1.4 native回调函数

与audio示例相同

  custom_data_field_id =(*env)->GetFieldID (env, klass, "native_custom_data", "J");set_message_method_id =(*env)->GetMethodID (env, klass, "setMessage", "(Ljava/lang/String;)V");on_gstreamer_initialized_method_id =(*env)->GetMethodID (env, klass, "onGStreamerInitialized", "()V");

3.3.2 JNI method对应表

/* List of implemented native methods */
static JNINativeMethod native_methods[] = {{"nativeInit", "()V", (void *) gst_native_init},{"nativeFinalize", "()V", (void *) gst_native_finalize},{"nativePlay", "()V", (void *) gst_native_play},{"nativePause", "()V", (void *) gst_native_pause},{"nativeSurfaceInit", "(Ljava/lang/Object;)V",(void *) gst_native_surface_init},{"nativeSurfaceFinalize", "()V", (void *) gst_native_surface_finalize},{"nativeClassInit", "()Z", (void *) gst_native_class_init}
};

3.3.3 app_function 与tutorial-2差别

/* Main method for the native code. This is executed on its own thread. */
static void *
app_function (void *userdata)
{JavaVMAttachArgs args;GstBus *bus;CustomData *data = (CustomData *) userdata;GSource *bus_source;GError *error = NULL;GST_DEBUG ("Creating pipeline in CustomData at %p", data);/* Create our own GLib Main Context and make it the default one */data->context = g_main_context_new ();g_main_context_push_thread_default (data->context);/* Build pipeline *///pipe 描述 增加video相关描述data->pipeline =    gst_parse_launch ("videotestsrc ! warptv ! videoconvert ! autovideosink",&error);if (error) {gchar *message =g_strdup_printf ("Unable to build pipeline: %s", error->message);g_clear_error (&error);set_ui_message (message, data);g_free (message);return NULL;}/* Set the pipeline to READY, so it can already accept a window handle, if we have one */gst_element_set_state (data->pipeline, GST_STATE_READY);
//video_sink 赋值data->video_sink =gst_bin_get_by_interface (GST_BIN (data->pipeline),GST_TYPE_VIDEO_OVERLAY);if (!data->video_sink) {GST_ERROR ("Could not retrieve video sink");return NULL;}/* Instruct the bus to emit signals for each received message, and connect to the interesting signals */bus = gst_element_get_bus (data->pipeline);bus_source = gst_bus_create_watch (bus);g_source_set_callback (bus_source, (GSourceFunc) gst_bus_async_signal_func,NULL, NULL);g_source_attach (bus_source, data->context);g_source_unref (bus_source);g_signal_connect (G_OBJECT (bus), "message::error", (GCallback) error_cb,data);g_signal_connect (G_OBJECT (bus), "message::state-changed",(GCallback) state_changed_cb, data);gst_object_unref (bus);/* Create a GLib Main Loop and set it to run */GST_DEBUG ("Entering main loop... (CustomData:%p)", data);data->main_loop = g_main_loop_new (data->context, FALSE);check_initialization_complete (data);g_main_loop_run (data->main_loop);GST_DEBUG ("Exited main loop");g_main_loop_unref (data->main_loop);data->main_loop = NULL;/* Free resources */g_main_context_pop_thread_default (data->context);g_main_context_unref (data->context);gst_element_set_state (data->pipeline, GST_STATE_NULL);//释放 video_sinkgst_object_unref (data->video_sink);gst_object_unref (data->pipeline);return NULL;
}

3.3.4 gst_native_surface_init surface显示初始化

static void
gst_native_surface_init (JNIEnv * env, jobject thiz, jobject surface)
{CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);if (!data)return;// jni方法 转化 surfaceviewANativeWindow *new_native_window = ANativeWindow_fromSurface (env, surface);GST_DEBUG ("Received surface %p (native window %p)", surface,new_native_window);if (data->native_window) {//release之前surface绘制ANativeWindow_release (data->native_window);if (data->native_window == new_native_window) {// 相同 重写覆盖 video_sinkGST_DEBUG ("New native window is the same as the previous one %p",data->native_window);if (data->video_sink) {gst_video_overlay_expose (GST_VIDEO_OVERLAY (data->video_sink));gst_video_overlay_expose (GST_VIDEO_OVERLAY (data->video_sink));}return;} else {GST_DEBUG ("Released previous native window %p", data->native_window);data->initialized = FALSE;}}data->native_window = new_native_window;check_initialization_complete (data);
}

3.3.5 check_initialization_complete 回调初始化完成

static void
check_initialization_complete (CustomData * data)
{JNIEnv *env = get_jni_env ();if (!data->initialized && data->native_window && data->main_loop) {GST_DEBUG("Initialization complete, notifying application. native_window:%p main_loop:%p",data->native_window, data->main_loop);/* The main loop is running and we received a native window, inform the sink about it */gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (data->video_sink),(guintptr) data->native_window);// 回调 java层 onGStreamerInitialized对应的方法(*env)->CallVoidMethod (env, data->app, on_gstreamer_initialized_method_id);if ((*env)->ExceptionCheck (env)) {GST_ERROR ("Failed to call Java method");(*env)->ExceptionClear (env);}data->initialized = TRUE;}
}

3.3.6 gst_native_surface_finalize 释放

static void
gst_native_surface_finalize (JNIEnv * env, jobject thiz)
{CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);if (!data)return;GST_DEBUG ("Releasing Native Window %p", data->native_window);if (data->video_sink) {gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (data->video_sink),(guintptr) NULL);gst_element_set_state (data->pipeline, GST_STATE_READY);}ANativeWindow_release (data->native_window);data->native_window = NULL;data->initialized = FALSE;
}

3.4 tutorial-4 视频播放

播放的流媒体,与tutorial 3相比多了,进度调整, 画面调整,设置了流媒体uri

native方法

    private native void nativeInit();     // Initialize native code, build pipeline, etcprivate native void nativeFinalize(); // Destroy pipeline and shutdown native codeprivate native void nativeSetUri(String uri); // Set the URI of the media to playprivate native void nativePlay();     // Set pipeline to PLAYINGprivate native void nativeSetPosition(int milliseconds); // Seek to the indicated position, in millisecondsprivate native void nativePause();    // Set pipeline to PAUSEDprivate static native boolean nativeClassInit(); // Initialize native class: cache Method IDs for callbacksprivate native void nativeSurfaceInit(Object surface); // A new surface is availableprivate native void nativeSurfaceFinalize(); // Surface about to be destroyedprivate long native_custom_data;      // Native code will use this to keep private data

3.4.1实例代码

3.3.1.1 界面控间初始化
    @Overridepublic void onCreate(Bundle savedInstanceState){GStreamer.init(this); ImageButton play = (ImageButton) this.findViewById(R.id.button_play);play.setOnClickListener(new OnClickListener() {public void onClick(View v) {is_playing_desired = true;nativePlay();}});ImageButton pause = (ImageButton) this.findViewById(R.id.button_stop);pause.setOnClickListener(new OnClickListener() {public void onClick(View v) {is_playing_desired = false;nativePause();}});  SurfaceView sv = (SurfaceView) this.findViewById(R.id.surface_video);SurfaceHolder sh = sv.getHolder();sh.addCallback(this);SeekBar sb = (SeekBar) this.findViewById(R.id.seek_bar);sb.setOnSeekBarChangeListener(this);// Start with disabled buttons, until native code is initializedthis.findViewById(R.id.button_play).setEnabled(false);this.findViewById(R.id.button_stop).setEnabled(false);nativeInit();}
3.3.1.2 SurfaceHolder.Callback
public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {Log.d("GStreamer", "Surface changed to format " + format + " width "+ width + " height " + height);nativeSurfaceInit (holder.getSurface());}public void surfaceCreated(SurfaceHolder holder) {Log.d("GStreamer", "Surface created: " + holder.getSurface());}public void surfaceDestroyed(SurfaceHolder holder) {Log.d("GStreamer", "Surface destroyed");nativeSurfaceFinalize ();}
3.3.1.3 onGStreamerInitialized GStreamer初始化完成
    private void onGStreamerInitialized () {Log.i ("GStreamer", "GStreamer initialized:");Log.i ("GStreamer", "  playing:" + is_playing_desired + " position:" + position + " uri: " + mediaUri);
//设置uri// Restore previous playing statesetMediaUri ();nativeSetPosition (position);if (is_playing_desired) {nativePlay();} else {nativePause();}// Re-enable buttons, now that GStreamer is initializedfinal Activity activity = this;runOnUiThread(new Runnable() {public void run() {activity.findViewById(R.id.button_play).setEnabled(true);activity.findViewById(R.id.button_stop).setEnabled(true);}});}

3.3.1.4 setMediaUri 设置uri

    private void setMediaUri() {nativeSetUri (mediaUri);is_local_media = mediaUri.startsWith("file://");}

3.3.1.5 onMediaSizeChanged 尺寸更新

    // Called from native code when the size of the media changes or is first detected.// Inform the video surface about the new size and recalculate the layout.private void onMediaSizeChanged (int width, int height) {Log.i ("GStreamer", "Media size changed to " + width + "x" + height);final GStreamerSurfaceView gsv = (GStreamerSurfaceView) this.findViewById(R.id.surface_video);gsv.media_width = width;gsv.media_height = height;runOnUiThread(new Runnable() {public void run() {gsv.requestLayout();}});}

3.4.2 JNI method列表

/* List of implemented native methods */
static JNINativeMethod native_methods[] = {{"nativeInit", "()V", (void *) gst_native_init},{"nativeFinalize", "()V", (void *) gst_native_finalize},{"nativeSetUri", "(Ljava/lang/String;)V", (void *) gst_native_set_uri},{"nativePlay", "()V", (void *) gst_native_play},{"nativePause", "()V", (void *) gst_native_pause},{"nativeSetPosition", "(I)V", (void *) gst_native_set_position},{"nativeSurfaceInit", "(Ljava/lang/Object;)V",(void *) gst_native_surface_init},{"nativeSurfaceFinalize", "()V", (void *) gst_native_surface_finalize},{"nativeClassInit", "()Z", (void *) gst_native_class_init}
};

回调方法

static jboolean
gst_native_class_init (JNIEnv * env, jclass klass)
{custom_data_field_id =(*env)->GetFieldID (env, klass, "native_custom_data", "J");set_message_method_id =(*env)->GetMethodID (env, klass, "setMessage", "(Ljava/lang/String;)V");set_current_position_method_id =(*env)->GetMethodID (env, klass, "setCurrentPosition", "(II)V");on_gstreamer_initialized_method_id =(*env)->GetMethodID (env, klass, "onGStreamerInitialized", "()V");on_media_size_changed_method_id =(*env)->GetMethodID (env, klass, "onMediaSizeChanged", "(II)V");

3.4.3 app_function

开始变得复杂了,新增了很多回调,包括播放状态、时长、EOS回调,一秒刷新4次UI refresh_ui

/* Main method for the native code. This is executed on its own thread. */
static void *
app_function (void *userdata)
{JavaVMAttachArgs args;GstBus *bus;CustomData *data = (CustomData *) userdata;GSource *timeout_source;GSource *bus_source;GError *error = NULL;guint flags;GST_DEBUG ("Creating pipeline in CustomData at %p", data);/* Create our own GLib Main Context and make it the default one */data->context = g_main_context_new ();g_main_context_push_thread_default (data->context);/* Build pipeline */data->pipeline = gst_parse_launch ("playbin", &error);if (error) {gchar *message =g_strdup_printf ("Unable to build pipeline: %s", error->message);g_clear_error (&error);set_ui_message (message, data);g_free (message);return NULL;}
//添加字幕/* Disable subtitles */g_object_get (data->pipeline, "flags", &flags, NULL);flags &= ~GST_PLAY_FLAG_TEXT;g_object_set (data->pipeline, "flags", flags, NULL);/* Set the pipeline to READY, so it can already accept a window handle, if we have one */data->target_state = GST_STATE_READY;gst_element_set_state (data->pipeline, GST_STATE_READY);/* Instruct the bus to emit signals for each received message, and connect to the interesting signals */bus = gst_element_get_bus (data->pipeline);bus_source = gst_bus_create_watch (bus);g_source_set_callback (bus_source, (GSourceFunc) gst_bus_async_signal_func,NULL, NULL);g_source_attach (bus_source, data->context);g_source_unref (bus_source);
//添加了各种回调//错误回调g_signal_connect (G_OBJECT (bus), "message::error", (GCallback) error_cb,data);//eos 播放完毕回调g_signal_connect (G_OBJECT (bus), "message::eos", (GCallback) eos_cb, data);//状态改变回调g_signal_connect (G_OBJECT (bus), "message::state-changed",(GCallback) state_changed_cb, data);//时长回调g_signal_connect (G_OBJECT (bus), "message::duration",(GCallback) duration_cb, data);//得到buffer回调g_signal_connect (G_OBJECT (bus), "message::buffering",(GCallback) buffering_cb, data);//时钟丢失回调g_signal_connect (G_OBJECT (bus), "message::clock-lost",(GCallback) clock_lost_cb, data);gst_object_unref (bus);
//一秒刷新4次UI   refresh_ui/* Register a function that GLib will call 4 times per second */timeout_source = g_timeout_source_new (250);//refresh_ui 返回true 循环回调g_source_set_callback (timeout_source, (GSourceFunc) refresh_ui, data, NULL);g_source_attach (timeout_source, data->context);g_source_unref (timeout_source);/* Create a GLib Main Loop and set it to run */GST_DEBUG ("Entering main loop... (CustomData:%p)", data);data->main_loop = g_main_loop_new (data->context, FALSE);check_initialization_complete (data);g_main_loop_run (data->main_loop);GST_DEBUG ("Exited main loop");g_main_loop_unref (data->main_loop);data->main_loop = NULL;/* Free resources */g_main_context_pop_thread_default (data->context);g_main_context_unref (data->context);data->target_state = GST_STATE_NULL;gst_element_set_state (data->pipeline, GST_STATE_NULL);gst_object_unref (data->pipeline);return NULL;
}

3.4.4 state_changed_cb 状态改变回调

/* Notify UI about pipeline state changes */
static void
state_changed_cb (GstBus * bus, GstMessage * msg, CustomData * data)
{GstState old_state, new_state, pending_state;gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state);/* Only pay attention to messages coming from the pipeline, not its children */if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data->pipeline)) {data->state = new_state;gchar *message = g_strdup_printf ("State changed to %s",gst_element_state_get_name (new_state));//回调java层的 setUiMessageset_ui_message (message, data);g_free (message);if (new_state == GST_STATE_NULL || new_state == GST_STATE_READY)data->is_live = FALSE;/* The Ready to Paused state change is particularly interesting: */if (old_state == GST_STATE_READY && new_state == GST_STATE_PAUSED) {/* By now the sink already knows the media size *///检查 media的size 回调重设上层surfaceview大小check_media_size (data);//如果seek的时候在暂停状态  在这个时候来执行seek/* If there was a scheduled seek, perform it now that we have moved to the Paused state */if (GST_CLOCK_TIME_IS_VALID (data->desired_position))execute_seek (data->desired_position, data);}}
}

3.4.5 check_media_size 检查媒体的size

/* Retrieve the video sink's Caps and tell the application about the media size */
static void
check_media_size (CustomData * data)
{JNIEnv *env = get_jni_env ();GstElement *video_sink;GstPad *video_sink_pad;GstCaps *caps;GstVideoInfo info;/* Retrieve the Caps at the entrance of the video sink *///获取video sink =》pad =》capsg_object_get (data->pipeline, "video-sink", &video_sink, NULL);video_sink_pad = gst_element_get_static_pad (video_sink, "sink");caps = gst_pad_get_current_caps (video_sink_pad);//从caps获取videoinfo  if (gst_video_info_from_caps (&info, caps)) {info.width = info.width * info.par_n / info.par_d;GST_DEBUG ("Media size is %dx%d, notifying application", info.width,info.height);//回调java层 onMediaSizeChange(*env)->CallVoidMethod (env, data->app, on_media_size_changed_method_id,(jint) info.width, (jint) info.height);if ((*env)->ExceptionCheck (env)) {GST_ERROR ("Failed to call Java method");(*env)->ExceptionClear (env);}}gst_caps_unref (caps);gst_object_unref (video_sink_pad);gst_object_unref (video_sink);
}

3.4.6 clock_lost_cb 当计时器丢失时回调

pause-》playing

/* Called when the clock is lost */
static void
clock_lost_cb (GstBus * bus, GstMessage * msg, CustomData * data)
{if (data->target_state >= GST_STATE_PLAYING) {gst_element_set_state (data->pipeline, GST_STATE_PAUSED);gst_element_set_state (data->pipeline, GST_STATE_PLAYING);}
}

3.4.7 buffering_cb 播放流媒体 0%-》100%

/* Called when buffering messages are received. We inform the UI about the current buffering level and* keep the pipeline paused until 100% buffering is reached. At that point, set the desired state. */
static void
buffering_cb (GstBus * bus, GstMessage * msg, CustomData * data)
{gint percent;if (data->is_live)return;gst_message_parse_buffering (msg, &percent);if (percent < 100 && data->target_state >= GST_STATE_PAUSED) {//小于100% 更新UIgchar *message_string = g_strdup_printf ("Buffering %d%%", percent);gst_element_set_state (data->pipeline, GST_STATE_PAUSED);set_ui_message (message_string, data);g_free (message_string);} else if (data->target_state >= GST_STATE_PLAYING) {//根据 target 进行状态改变gst_element_set_state (data->pipeline, GST_STATE_PLAYING);} else if (data->target_state >= GST_STATE_PAUSED) {set_ui_message ("Buffering complete", data);}
}

3.4.8 duration_cb 时长进度回调

设置成none 下次UI刷新 进行获取

/* Called when the duration of the media changes. Just mark it as unknown, so we re-query it in the next UI refresh. */
static void
duration_cb (GstBus * bus, GstMessage * msg, CustomData * data)
{data->duration = GST_CLOCK_TIME_NONE;
}

3.4.9 eos_cb 播放结束

target_state 设置成pause , seek to 0号位

/* Called when the End Of the Stream is reached. Just move to the beginning of the media and pause. */
static void
eos_cb (GstBus * bus, GstMessage * msg, CustomData * data)
{data->target_state = GST_STATE_PAUSED;data->is_live |=(gst_element_set_state (data->pipeline,GST_STATE_PAUSED) == GST_STATE_CHANGE_NO_PREROLL);execute_seek (0, data);
}

3.4.10 error_cb 错误回调

/* Retrieve errors from the bus and show them on the UI */
static void
error_cb (GstBus * bus, GstMessage * msg, CustomData * data)
{GError *err;gchar *debug_info;gchar *message_string;gst_message_parse_error (msg, &err, &debug_info);message_string =g_strdup_printf ("Error received from element %s: %s",GST_OBJECT_NAME (msg->src), err->message);g_clear_error (&err);g_free (debug_info);//更新UIset_ui_message (message_string, data);g_free (message_string);//target_state = nulldata->target_state = GST_STATE_NULL;gst_element_set_state (data->pipeline, GST_STATE_NULL);
}

3.4.11 delayed_seek_cb 延时seek回调

/* Delayed seek callback. This gets called by the timer setup in the above function. */
static gboolean
delayed_seek_cb (CustomData * data)
{GST_DEBUG ("Doing delayed seek to %" GST_TIME_FORMAT,GST_TIME_ARGS (data->desired_position));execute_seek (data->desired_position, data);return FALSE;
}

3.4.12 关键 execute_seek 执行seek操作

/* Perform seek, if we are not too close to the previous seek. Otherwise, schedule the seek for* some time in the future. */
static void
execute_seek (gint64 desired_position, CustomData * data)
{gint64 diff;
//没有期望 pos 返回if (desired_position == GST_CLOCK_TIME_NONE)return;
//获取上次seek的时间diff = gst_util_get_timestamp () - data->last_seek_time;
//和上次的seek时间太近了  延时这一次if (GST_CLOCK_TIME_IS_VALID (data->last_seek_time) && diff < SEEK_MIN_DELAY) {/* The previous seek was too close, delay this one */GSource *timeout_source;if (data->desired_position == GST_CLOCK_TIME_NONE) {/* There was no previous seek scheduled. Setup a timer for some time in the future *///添加时间回调  时间到了回调delayed_seek_cbtimeout_source =g_timeout_source_new ((SEEK_MIN_DELAY - diff) / GST_MSECOND);// delayed_seek_cb 返回false 执行一次g_source_set_callback (timeout_source, (GSourceFunc) delayed_seek_cb,data, NULL);g_source_attach (timeout_source, data->context);g_source_unref (timeout_source);}/* Update the desired seek position. If multiple petitions are received before it is time* to perform a seek, only the last one is remembered. *///上次的seek也没有执行  跟新期望pos 延时seek到这次的pos 连续拖动casedata->desired_position = desired_position;GST_DEBUG ("Throttling seek to %" GST_TIME_FORMAT ", will be in %"GST_TIME_FORMAT, GST_TIME_ARGS (desired_position),GST_TIME_ARGS (SEEK_MIN_DELAY - diff));} else {//直接seek /* Perform the seek now */GST_DEBUG ("Seeking to %" GST_TIME_FORMAT,GST_TIME_ARGS (desired_position));//记录lastseektimedata->last_seek_time = gst_util_get_timestamp ();//进行seekgst_element_seek_simple (data->pipeline, GST_FORMAT_TIME,GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT, desired_position);data->desired_position = GST_CLOCK_TIME_NONE;}
}

3.4.13 关键 refresh_ui 刷新UI

/* If we have pipeline and it is running, query the current position and clip duration and inform* the application */
static gboolean
refresh_ui (CustomData * data)
{gint64 current = -1;gint64 position;/* We do not want to update anything unless we have a working pipeline in the PAUSED or PLAYING state */if (!data || !data->pipeline || data->state < GST_STATE_PAUSED)return TRUE;
//播放状态  刷新duration/* If we didn't know it yet, query the stream duration */if (!GST_CLOCK_TIME_IS_VALID (data->duration)) {if (!gst_element_query_duration (data->pipeline, GST_FORMAT_TIME,&data->duration)) {GST_WARNING("Could not query current duration (normal for still pictures)");data->duration = 0;}}if (!gst_element_query_position (data->pipeline, GST_FORMAT_TIME, &position)) {GST_WARNING("Could not query current position (normal for still pictures)");position = 0;}
//回调到 UI/* Java expects these values in milliseconds, and GStreamer provides nanoseconds */set_current_ui_position (position / GST_MSECOND, data->duration / GST_MSECOND,data);return TRUE;
}

3.4.13 关键gst_native_set_uri 设置播放uri

/* Set playbin's URI */
void
gst_native_set_uri (JNIEnv * env, jobject thiz, jstring uri)
{CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);if (!data || !data->pipeline)return;const gchar *char_uri = (*env)->GetStringUTFChars (env, uri, NULL);GST_DEBUG ("Setting URI to %s", char_uri);//更新状态到readyif (data->target_state >= GST_STATE_READY)gst_element_set_state (data->pipeline, GST_STATE_READY);//设置urig_object_set (data->pipeline, "uri", char_uri, NULL);(*env)->ReleaseStringUTFChars (env, uri, char_uri);data->duration = GST_CLOCK_TIME_NONE;data->is_live =(gst_element_set_state (data->pipeline,data->target_state) == GST_STATE_CHANGE_NO_PREROLL);
}

3.4.13 gst_native_set_position设置 pos

/* Instruct the pipeline to seek to a different position */
void
gst_native_set_position (JNIEnv * env, jobject thiz, int milliseconds)
{CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);//校验 dataif (!data)return;//设置期望posgint64 desired_position = (gint64) (milliseconds * GST_MSECOND);if (data->state >= GST_STATE_PAUSED) {execute_seek (desired_position, data);} else {//ready null void pending状态GST_DEBUG ("Scheduling seek to %" GST_TIME_FORMAT " for later",GST_TIME_ARGS (desired_position));data->desired_position = desired_position;}
}

3.4.14 set_current_ui_position 通知UI时长和pos

/* Tell the application what is the current position and clip duration */
static void
set_current_ui_position (gint position, gint duration, CustomData * data)
{JNIEnv *env = get_jni_env ();(*env)->CallVoidMethod (env, data->app, set_current_position_method_id,position, duration);if ((*env)->ExceptionCheck (env)) {GST_ERROR ("Failed to call Java method");(*env)->ExceptionClear (env);}
}

3.5 turorial-5 完整播放器

增加了本地文件的支持,jni代码基本一样,有小部分更新

//使用data->is_live |=   替代 data->is_live =
data->is_live |=

在state_change_cb

    if (new_state == GST_STATE_NULL || new_state == GST_STATE_READY)data->is_live = FALSE;

在refresh_ui中添加了 获取当前pos失败的处理

  /* If we didn't know it yet, query the stream duration */if (!GST_CLOCK_TIME_IS_VALID (data->duration)) {if (!gst_element_query_duration (data->pipeline, GST_FORMAT_TIME,&data->duration)) {GST_WARNING("Could not query current duration (normal for still pictures)");data->duration = 0;}}if (!gst_element_query_position (data->pipeline, GST_FORMAT_TIME, &position)) {GST_WARNING("Could not query current position (normal for still pictures)");//设置成0position = 0;}/* Java expects these values in milliseconds, and GStreamer provides nanoseconds */set_current_ui_position (position / GST_MSECOND, data->duration / GST_MSECOND,data);return TRUE;
}

3.5.1 实例代码

3.5.1 powerManager 管理 保持唤醒,不灭屏

保持唤醒,不灭屏

 PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);wake_lock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GStreamer tutorial 5");wake_lock.setReferenceCounted(false);ImageButton play = (ImageButton) this.findViewById(R.id.button_play);play.setOnClickListener(new OnClickListener() {public void onClick(View v) {is_playing_desired = true;//保持唤醒wake_lock.acquire();nativePlay();}});ImageButton pause = (ImageButton) this.findViewById(R.id.button_stop);pause.setOnClickListener(new OnClickListener() {public void onClick(View v) {is_playing_desired = false;//release 唤醒锁wake_lock.release();}});

3.5.2 打开文件管理,从中选择播放

//打开file dialog

        ImageButton select = (ImageButton) this.findViewById(R.id.button_select);select.setOnClickListener(new OnClickListener() {public void onClick(View v) {Intent i = new Intent(getBaseContext(), FileDialog.class);i.putExtra(FileDialog.START_PATH, last_folder);startActivityForResult(i, PICK_FILE_CODE);}});

3.5.3 本地文件夹播放 多种文件支持

    @Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data){if (resultCode == RESULT_OK && requestCode == PICK_FILE_CODE) {mediaUri = "file://" + data.getStringExtra(FileDialog.RESULT_PATH);position = 0;last_folder = new File (data.getStringExtra(FileDialog.RESULT_PATH)).getParent();Log.i("GStreamer", "Setting last_folder to " + last_folder);setMediaUri();}}

intent支持类型

<applicationandroid:icon="@drawable/gstreamer_logo_5"android:label="@string/app_name" ><activityandroid:name=".Tutorial5"android:label="@string/app_name" ><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter><!-- Local files whose MIME type is known to Android --><intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><data android:mimeType="audio/*" /><data android:mimeType="video/*" /><data android:mimeType="image/*" /></intent-filter><!-- Local files with unknown MIME type.The list of extensions and supported protocols can certainly be extended. --><intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><data android:scheme="file" /><data android:mimeType="*/*" /><data android:pathPattern=".*\\.avi" /><data android:pathPattern=".*\\.AVI" /><data android:pathPattern=".*\\.mkv" /><data android:pathPattern=".*\\.MKV" /><data android:pathPattern=".*\\.webm" /><data android:pathPattern=".*\\.WEBM" /><data android:pathPattern=".*\\.ogv" /><data android:pathPattern=".*\\.OGV" /><data android:pathPattern=".*\\.mp4" /><data android:pathPattern=".*\\.MP4" /><data android:pathPattern=".*\\.mov" /><data android:pathPattern=".*\\.MOV" /></intent-filter><!-- Remote files. These typically have unknown MIME type.The list of extensions and supported protocols can certainly be extended. --><intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><data android:scheme="http" /><data android:pathPattern=".*\\.avi" /><data android:pathPattern=".*\\.AVI" /><data android:pathPattern=".*\\.mkv" /><data android:pathPattern=".*\\.MKV" /><data android:pathPattern=".*\\.webm" /><data android:pathPattern=".*\\.WEBM" /><data android:pathPattern=".*\\.ogv" /><data android:pathPattern=".*\\.OGV" /><data android:pathPattern=".*\\.mp4" /><data android:pathPattern=".*\\.MP4" /><data android:pathPattern=".*\\.mov" /><data android:pathPattern=".*\\.MOV" /></intent-filter></activity><activityandroid:name="com.lamerman.FileDialog"android:label="@string/filechooser_name" ></activity></application>

3.5.4 状态保存savedInstanceState

// Retrieve our previous state, or initialize it to default valuesif (savedInstanceState != null) {is_playing_desired = savedInstanceState.getBoolean("playing");position = savedInstanceState.getInt("position");duration = savedInstanceState.getInt("duration");mediaUri = savedInstanceState.getString("mediaUri");last_folder = savedInstanceState.getString("last_folder");Log.i ("GStreamer", "Activity created with saved state:");} else {is_playing_desired = false;position = duration = 0;last_folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath();Intent intent = getIntent();android.net.Uri uri = intent.getData();if (uri == null)mediaUri = defaultMediaUri;else {Log.i ("GStreamer", "Received URI: " + uri);if (uri.getScheme().equals("content")) {android.database.Cursor cursor = getContentResolver().query(uri, null, null, null, null);cursor.moveToFirst();mediaUri = "file://" + cursor.getString(cursor.getColumnIndex(android.provider.MediaStore.Video.Media.DATA));cursor.close();} elsemediaUri = uri.toString();}Log.i ("GStreamer", "Activity created with no saved state:");}
查看全文
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

相关文章

  1. C++ Lirary -- string

    1. 字符串(string): 字符串库2. 数据定义:以\0 结尾3. 数据支持的操作(函数):--- 下面仅仅罗列支持的函数,具体用法 请参考c++ library的说明。如有任何问题,请留言讨论。(constrcutor) : operator=:Iterators(迭代器):begin:end:rbegin:rend:Capacity…...

    2024/5/1 2:35:09
  2. Gmapping、hector、Cartographer三种激光SLAM算法简单对比

    一、Gmapping是基于粒子滤波的算法。 缺点:严重依赖里程计,无法适应无人机及地面不平坦的区域,无回环(激光SLAM很难做回环检测),大的场景,粒子较多的情况下,特别消耗资源。源码的核心函数:processScan() 算法框架: ① drawFromMotion()运动模型(因为有这步,所以…...

    2024/5/1 2:25:22
  3. codeup 习题 Problem B

    题目描述请写一个程序,对于一个m行m列的(1<m<10)的方阵,求其每一行,每一列及主对角线元素之和,最后按照从大到小的顺序依次输出。输入共一组数据,输入的第一行为一个正整数,表示m,接下来的m行,每行m个整数表示方阵元素。输出从大到小排列的一行整数,每个整数后…...

    2024/5/1 0:53:50
  4. 教你monkey自动化测试

    Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中。它向系统发送伪随机的用户事件流(如按键输入、触摸屏输入、手势输入等),实现对正在开发的应用程序进行压力测试。Monkey测试是一种为了测试软件的稳定性、健壮性的快速有效的方法。(其实可以想象成一只猴…...

    2024/5/1 0:23:20
  5. Leetcode--剑指 Offer 09--用两个栈实现队列【C++,清晰代码】

    来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 题目描述 用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 appendTail和 delet…...

    2024/5/1 0:36:15
  6. 某些特定场景的多线程安全问题分析

    场景1:一个方法中先查询表中最新的一条数据,然后根据这条数据的值新增另一条数据:public Test1PO testTransactional3() {Test1PO po = test1Mapper.getLast();po.setValue(po.getValue() + "b");test1Mapper.add(po);return po; }<select id="getLast&qu…...

    2024/4/30 22:28:10
  7. 如何用veeam给windows服务器做备份?

    1、安装veeam backup & replication console: 先在server端(存储端)安装veeam backup & replication console,可能会要求你先装.net 4.7(装.net4.7之前先安装KB2919442-x64,再安装KB2919355-x64),同时防火墙开放tcp以下端口:2502 ,6160 ,6183, 6210 ,9392…...

    2024/4/30 22:04:32
  8. 老男孩学习Day07

    目录1.for循环与range联用2.可变与不可变类型3.数字类型一:整型int二:浮点型float4.字符串类型1、用途:记录描述性质的状态,例如名字、性别、国籍等2、定义方式:在引号(,"",,""""""")内包含一串字符串3、常用操作+内置的…...

    2024/4/30 23:28:30
  9. docker学习总结第五篇-深入kubernetes

    我以 Docker 项目为例,一步步剖析了 Linux 容器的具体实现方式。通过这些讲解你应该能够明白:一个“容器”,实际上是一个由 Linux Namespace、Linux Cgroups 和 rootfs 三种技术构建出来的进程的隔离环境。 从这个结构中我们不难看出,一个正在运行的 Linux 容器,其实可以被…...

    2024/4/16 1:13:55
  10. tab切换

    jquery实现的tab切换效果,效果网址:http://www.keleyi.com/keleyi/phtml/tabswitch/plus/2.htm以下是源代码:1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">2 …...

    2024/4/30 20:46:05
  11. J - Air Raid HDU - 1151(最小路径覆盖数)

    题目链接 解题思路:裸的最小路径覆盖,不过因为时间复杂度,要把普通的二分图匹配改为hk匹配AC代码: // Test1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // //DAG的最小路径覆盖数 = DAG图中的节点数 - 相应二分图中的最大匹配数 #include <…...

    2024/4/30 19:04:53
  12. 你还在自学CFA吗?你还在考虑自学CFA吗?看完这篇文章你在考虑!

    也许有人说,自己就是完全自学,然后顺利的通过了CFA考试。但事实上,之所以一个半月的自学就崩溃了,是因为CFA根本不是想象中的那样简单,和融跃一起去看看,看完你在考虑是否自学! CFA考试各级别侧重内容CFA一级(Level I)考试:侧重知识、理解,注重工具及技术,包括资产…...

    2024/4/16 1:15:11
  13. Spring AOP 之 Introductions

    0. 前言首先啊,这个introductions 我个人感觉不太常用,但是我再spring文档中看到了,就想分享一下啊。我也没有正式的用过,具体的业务场景中的使用我也不知道。有再项目中用过的大佬,可以指正一下。spring 官方链接如下:点击进入1. 介绍啥意思呢?自己翻译一下,反正翻译出…...

    2024/5/1 0:15:00
  14. HTML5--canvas绘制多边形

    1. 绘制图形展示效果2. 代码 <!doctype html> <html> <head> <meta charset="utf-8"> <title>绘制多边形</title> <style>body{background-color: darkgray}#myc{border: 1px solid #000;margin: auto;display: block} &l…...

    2024/4/30 23:29:00
  15. Python 爬取 13966 条运维招聘信息,这些岗位最吃香!

    经常会收到读者关于一系列咨询运维方面的事情,比如:运维到底是做什么的呀?运维的薪资水平/ 待遇怎么样呢?能帮忙看下这个岗位的招聘需要对于小白来说,能否胜任的了呢?等等。杰哥带着一种好奇心的想法,结合自身的工作经验与业界全国关于招聘运维工程师的岗位做一个初步型…...

    2024/4/16 1:14:20
  16. 【SpringBoot】快速入门

    前言 SpringBoot和SpringMVC区别 两者没有必然的联系,SpringBoot相当于SpringMVC的升级版 SpringBoot特点 1.化繁为简,简化配置 2.备受关注,是下一代框架 3.微服务的入门级微框架 当前流行架构是微服务,Spring家族为微服务提供一整套组件统称SpringCloud,SpringCloud是建立…...

    2024/4/16 1:14:20
  17. angular和vue对比

    框架对比1.体积和性能 相较于vue,angular显得比较臃肿,比如一个包含了 Vuex + Vue Router 的 Vue 项目 (gzip 之后 30kB) ,而 angular-cli 生成的默认项目尺寸 (~65KB) 还是要小得多。 在渲染性能上,这两个框架都很快,性能上几乎没有差别。2.开发效率 都提供了各自的脚手架…...

    2024/4/16 1:15:57
  18. 图形学常见的点、线、面位置关系判断算法及其代码实现

    图形学的基础之一就是计算几何,它没有理论数学那么高深莫测,而且它很有实践性。具体来说图形学除了常用的计算几何方法外,还涉及到向量、点线关系以及点与多边形关系求解等数学知识,还有一些平面几何的基本原理。当然如果单从实用的图形学所涉及到的数学基础,或者说想学会…...

    2024/4/16 1:14:51
  19. 回文链表(Java)

    package leetCoder;import java.util.ArrayList; import java.util.Stack;/*** @author : zhaoliang* @program :newCoder* @description : 回文链表* @create : 2020/07/11 09:20*/ public class LeetCode234 {//请判断一个链表是否为回文链表。//栈public boolean isPalindro…...

    2024/4/30 6:06:39
  20. .net core 3.x webapi的输入验证和自定义错误

    记录一下自己在.net core 3.0中使用webapi的一些输入验证输入验证 1.1 Data Annotations在使用post/put/patch等请求过程中,api通常会接收model类型参数,可以使用DataAnnotations特性来约束一般参数,在需要验证的参数上直接加上注解,如下:[Display(Name = "名字&quo…...

    2024/4/16 1:14:51

最新文章

  1. Linux修改文件权限命令 chmod

    【例子引入】 以下面命令为例&#xff1a; chmod 777 Random.py 当写入下面名为Random.py的代码后&#xff1a; 如果直接运行&#xff0c;会显示权限不够 当输入 chmod 777 Random.py 更改权限后&#xff0c;才能够正常运行 在终端中输入 这条命令是关于Linux或Unix-like系…...

    2024/5/1 2:56:31
  2. 梯度消失和梯度爆炸的一些处理方法

    在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言&#xff0c;在此感激不尽。 权重和梯度的更新公式如下&#xff1a; w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...

    2024/3/20 10:50:27
  3. OpenCV单通道图像按像素成倍比例放大(无高斯平滑处理)

    OpenCV中的resize函数可以对图像做任意比例的放大(/缩小)处理&#xff0c;该处理过程会对图像做高斯模糊化以保证图像在进行放大&#xff08;/缩小&#xff09;后尽可能保留源图像所展现的具体内容&#xff08;消除固定频率插值/采样带来的香农采样信息损失&#xff09;&#x…...

    2024/4/30 6:11:08
  4. Flink中几个关键问题总结

    硬核&#xff01;八张图搞懂 Flink 端到端精准一次处理语义 Exactly-once&#xff08;深入原理&#xff0c;建议收藏&#xff09; Flink可靠性的基石-checkpoint机制详细解析 硬核&#xff01;一文学完Flink流计算常用算子&#xff08;Flink算子大全&#xff09;...

    2024/4/30 20:59:01
  5. 【外汇早评】美通胀数据走低,美元调整

    原标题:【外汇早评】美通胀数据走低,美元调整昨日美国方面公布了新一期的核心PCE物价指数数据,同比增长1.6%,低于前值和预期值的1.7%,距离美联储的通胀目标2%继续走低,通胀压力较低,且此前美国一季度GDP初值中的消费部分下滑明显,因此市场对美联储后续更可能降息的政策…...

    2024/4/29 23:16:47
  6. 【原油贵金属周评】原油多头拥挤,价格调整

    原标题:【原油贵金属周评】原油多头拥挤,价格调整本周国际劳动节,我们喜迎四天假期,但是整个金融市场确实流动性充沛,大事频发,各个商品波动剧烈。美国方面,在本周四凌晨公布5月份的利率决议和新闻发布会,维持联邦基金利率在2.25%-2.50%不变,符合市场预期。同时美联储…...

    2024/4/30 18:14:14
  7. 【外汇周评】靓丽非农不及疲软通胀影响

    原标题:【外汇周评】靓丽非农不及疲软通胀影响在刚结束的周五,美国方面公布了新一期的非农就业数据,大幅好于前值和预期,新增就业重新回到20万以上。具体数据: 美国4月非农就业人口变动 26.3万人,预期 19万人,前值 19.6万人。 美国4月失业率 3.6%,预期 3.8%,前值 3…...

    2024/4/29 2:29:43
  8. 【原油贵金属早评】库存继续增加,油价收跌

    原标题:【原油贵金属早评】库存继续增加,油价收跌周三清晨公布美国当周API原油库存数据,上周原油库存增加281万桶至4.692亿桶,增幅超过预期的74.4万桶。且有消息人士称,沙特阿美据悉将于6月向亚洲炼油厂额外出售更多原油,印度炼油商预计将每日获得至多20万桶的额外原油供…...

    2024/4/30 18:21:48
  9. 【外汇早评】日本央行会议纪要不改日元强势

    原标题:【外汇早评】日本央行会议纪要不改日元强势近两日日元大幅走强与近期市场风险情绪上升,避险资金回流日元有关,也与前一段时间的美日贸易谈判给日本缓冲期,日本方面对汇率问题也避免继续贬值有关。虽然今日早间日本央行公布的利率会议纪要仍然是支持宽松政策,但这符…...

    2024/4/27 17:58:04
  10. 【原油贵金属早评】欧佩克稳定市场,填补伊朗问题的影响

    原标题:【原油贵金属早评】欧佩克稳定市场,填补伊朗问题的影响近日伊朗局势升温,导致市场担忧影响原油供给,油价试图反弹。此时OPEC表态稳定市场。据消息人士透露,沙特6月石油出口料将低于700万桶/日,沙特已经收到石油消费国提出的6月份扩大出口的“适度要求”,沙特将满…...

    2024/4/27 14:22:49
  11. 【外汇早评】美欲与伊朗重谈协议

    原标题:【外汇早评】美欲与伊朗重谈协议美国对伊朗的制裁遭到伊朗的抗议,昨日伊朗方面提出将部分退出伊核协议。而此行为又遭到欧洲方面对伊朗的谴责和警告,伊朗外长昨日回应称,欧洲国家履行它们的义务,伊核协议就能保证存续。据传闻伊朗的导弹已经对准了以色列和美国的航…...

    2024/4/28 1:28:33
  12. 【原油贵金属早评】波动率飙升,市场情绪动荡

    原标题:【原油贵金属早评】波动率飙升,市场情绪动荡因中美贸易谈判不安情绪影响,金融市场各资产品种出现明显的波动。随着美国与中方开启第十一轮谈判之际,美国按照既定计划向中国2000亿商品征收25%的关税,市场情绪有所平复,已经开始接受这一事实。虽然波动率-恐慌指数VI…...

    2024/4/30 9:43:09
  13. 【原油贵金属周评】伊朗局势升温,黄金多头跃跃欲试

    原标题:【原油贵金属周评】伊朗局势升温,黄金多头跃跃欲试美国和伊朗的局势继续升温,市场风险情绪上升,避险黄金有向上突破阻力的迹象。原油方面稍显平稳,近期美国和OPEC加大供给及市场需求回落的影响,伊朗局势并未推升油价走强。近期中美贸易谈判摩擦再度升级,美国对中…...

    2024/4/27 17:59:30
  14. 【原油贵金属早评】市场情绪继续恶化,黄金上破

    原标题:【原油贵金属早评】市场情绪继续恶化,黄金上破周初中国针对于美国加征关税的进行的反制措施引发市场情绪的大幅波动,人民币汇率出现大幅的贬值动能,金融市场受到非常明显的冲击。尤其是波动率起来之后,对于股市的表现尤其不安。隔夜美国股市出现明显的下行走势,这…...

    2024/4/25 18:39:16
  15. 【外汇早评】美伊僵持,风险情绪继续升温

    原标题:【外汇早评】美伊僵持,风险情绪继续升温昨日沙特两艘油轮再次发生爆炸事件,导致波斯湾局势进一步恶化,市场担忧美伊可能会出现摩擦生火,避险品种获得支撑,黄金和日元大幅走强。美指受中美贸易问题影响而在低位震荡。继5月12日,四艘商船在阿联酋领海附近的阿曼湾、…...

    2024/4/28 1:34:08
  16. 【原油贵金属早评】贸易冲突导致需求低迷,油价弱势

    原标题:【原油贵金属早评】贸易冲突导致需求低迷,油价弱势近日虽然伊朗局势升温,中东地区几起油船被袭击事件影响,但油价并未走高,而是出于调整结构中。由于市场预期局势失控的可能性较低,而中美贸易问题导致的全球经济衰退风险更大,需求会持续低迷,因此油价调整压力较…...

    2024/4/26 19:03:37
  17. 氧生福地 玩美北湖(上)——为时光守候两千年

    原标题:氧生福地 玩美北湖(上)——为时光守候两千年一次说走就走的旅行,只有一张高铁票的距离~ 所以,湖南郴州,我来了~ 从广州南站出发,一个半小时就到达郴州西站了。在动车上,同时改票的南风兄和我居然被分到了一个车厢,所以一路非常愉快地聊了过来。 挺好,最起…...

    2024/4/29 20:46:55
  18. 氧生福地 玩美北湖(中)——永春梯田里的美与鲜

    原标题:氧生福地 玩美北湖(中)——永春梯田里的美与鲜一觉醒来,因为大家太爱“美”照,在柳毅山庄去寻找龙女而错过了早餐时间。近十点,向导坏坏还是带着饥肠辘辘的我们去吃郴州最富有盛名的“鱼头粉”。说这是“十二分推荐”,到郴州必吃的美食之一。 哇塞!那个味美香甜…...

    2024/4/30 22:21:04
  19. 氧生福地 玩美北湖(下)——奔跑吧骚年!

    原标题:氧生福地 玩美北湖(下)——奔跑吧骚年!让我们红尘做伴 活得潇潇洒洒 策马奔腾共享人世繁华 对酒当歌唱出心中喜悦 轰轰烈烈把握青春年华 让我们红尘做伴 活得潇潇洒洒 策马奔腾共享人世繁华 对酒当歌唱出心中喜悦 轰轰烈烈把握青春年华 啊……啊……啊 两…...

    2024/4/26 23:04:58
  20. 扒开伪装医用面膜,翻六倍价格宰客,小姐姐注意了!

    原标题:扒开伪装医用面膜,翻六倍价格宰客,小姐姐注意了!扒开伪装医用面膜,翻六倍价格宰客!当行业里的某一品项火爆了,就会有很多商家蹭热度,装逼忽悠,最近火爆朋友圈的医用面膜,被沾上了污点,到底怎么回事呢? “比普通面膜安全、效果好!痘痘、痘印、敏感肌都能用…...

    2024/4/27 23:24:42
  21. 「发现」铁皮石斛仙草之神奇功效用于医用面膜

    原标题:「发现」铁皮石斛仙草之神奇功效用于医用面膜丽彦妆铁皮石斛医用面膜|石斛多糖无菌修护补水贴19大优势: 1、铁皮石斛:自唐宋以来,一直被列为皇室贡品,铁皮石斛生于海拔1600米的悬崖峭壁之上,繁殖力差,产量极低,所以古代仅供皇室、贵族享用 2、铁皮石斛自古民间…...

    2024/4/28 5:48:52
  22. 丽彦妆\医用面膜\冷敷贴轻奢医学护肤引导者

    原标题:丽彦妆\医用面膜\冷敷贴轻奢医学护肤引导者【公司简介】 广州华彬企业隶属香港华彬集团有限公司,专注美业21年,其旗下品牌: 「圣茵美」私密荷尔蒙抗衰,产后修复 「圣仪轩」私密荷尔蒙抗衰,产后修复 「花茵莳」私密荷尔蒙抗衰,产后修复 「丽彦妆」专注医学护…...

    2024/4/30 9:42:22
  23. 广州械字号面膜生产厂家OEM/ODM4项须知!

    原标题:广州械字号面膜生产厂家OEM/ODM4项须知!广州械字号面膜生产厂家OEM/ODM流程及注意事项解读: 械字号医用面膜,其实在我国并没有严格的定义,通常我们说的医美面膜指的应该是一种「医用敷料」,也就是说,医用面膜其实算作「医疗器械」的一种,又称「医用冷敷贴」。 …...

    2024/4/30 9:43:22
  24. 械字号医用眼膜缓解用眼过度到底有无作用?

    原标题:械字号医用眼膜缓解用眼过度到底有无作用?医用眼膜/械字号眼膜/医用冷敷眼贴 凝胶层为亲水高分子材料,含70%以上的水分。体表皮肤温度传导到本产品的凝胶层,热量被凝胶内水分子吸收,通过水分的蒸发带走大量的热量,可迅速地降低体表皮肤局部温度,减轻局部皮肤的灼…...

    2024/4/30 9:42:49
  25. 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...

    解析如下&#xff1a;1、长按电脑电源键直至关机&#xff0c;然后再按一次电源健重启电脑&#xff0c;按F8健进入安全模式2、安全模式下进入Windows系统桌面后&#xff0c;按住“winR”打开运行窗口&#xff0c;输入“services.msc”打开服务设置3、在服务界面&#xff0c;选中…...

    2022/11/19 21:17:18
  26. 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。

    %读入6幅图像&#xff08;每一幅图像的大小是564*564&#xff09; f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...

    2022/11/19 21:17:16
  27. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...

    win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面&#xff0c;在等待界面中我们需要等待操作结束才能关机&#xff0c;虽然这比较麻烦&#xff0c;但是对系统进行配置和升级…...

    2022/11/19 21:17:15
  28. 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...

    有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows&#xff0c;请勿关闭计算机”的提示&#xff0c;要过很久才能进入系统&#xff0c;有的用户甚至几个小时也无法进入&#xff0c;下面就教大家这个问题的解决方法。第一种方法&#xff1a;我们首先在左下角的“开始…...

    2022/11/19 21:17:14
  29. win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...

    置信有很多用户都跟小编一样遇到过这样的问题&#xff0c;电脑时发现开机屏幕显现“正在配置Windows Update&#xff0c;请勿关机”(如下图所示)&#xff0c;而且还需求等大约5分钟才干进入系统。这是怎样回事呢&#xff1f;一切都是正常操作的&#xff0c;为什么开时机呈现“正…...

    2022/11/19 21:17:13
  30. 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...

    Win7系统开机启动时总是出现“配置Windows请勿关机”的提示&#xff0c;没过几秒后电脑自动重启&#xff0c;每次开机都这样无法进入系统&#xff0c;此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一&#xff1a;开机按下F8&#xff0c;在出现的Windows高级启动选…...

    2022/11/19 21:17:12
  31. 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...

    有不少windows10系统用户反映说碰到这样一个情况&#xff0c;就是电脑提示正在准备windows请勿关闭计算机&#xff0c;碰到这样的问题该怎么解决呢&#xff0c;现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法&#xff1a;1、2、依次…...

    2022/11/19 21:17:11
  32. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...

    今天和大家分享一下win7系统重装了Win7旗舰版系统后&#xff0c;每次关机的时候桌面上都会显示一个“配置Windows Update的界面&#xff0c;提示请勿关闭计算机”&#xff0c;每次停留好几分钟才能正常关机&#xff0c;导致什么情况引起的呢&#xff1f;出现配置Windows Update…...

    2022/11/19 21:17:10
  33. 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...

    只能是等着&#xff0c;别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚&#xff0c;只能是考虑备份数据后重装系统了。解决来方案一&#xff1a;管理员运行cmd&#xff1a;net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...

    2022/11/19 21:17:09
  34. 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?

    原标题&#xff1a;电脑提示“配置Windows Update请勿关闭计算机”怎么办&#xff1f;win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢&#xff1f;一般的方…...

    2022/11/19 21:17:08
  35. 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...

    关机提示 windows7 正在配置windows 请勿关闭计算机 &#xff0c;然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;关机提示 windows7 正在配…...

    2022/11/19 21:17:05
  36. 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...

    钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...

    2022/11/19 21:17:05
  37. 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...

    前几天班里有位学生电脑(windows 7系统)出问题了&#xff0c;具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面&#xff0c;长时间没反应&#xff0c;无法进入系统。这个问题原来帮其他同学也解决过&#xff0c;网上搜了不少资料&#x…...

    2022/11/19 21:17:04
  38. 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...

    本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法&#xff0c;并在最后教给你1种保护系统安全的好方法&#xff0c;一起来看看&#xff01;电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中&#xff0c;添加了1个新功能在“磁…...

    2022/11/19 21:17:03
  39. 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...

    许多用户在长期不使用电脑的时候&#xff0c;开启电脑发现电脑显示&#xff1a;配置windows更新失败&#xff0c;正在还原更改&#xff0c;请勿关闭计算机。。.这要怎么办呢&#xff1f;下面小编就带着大家一起看看吧&#xff01;如果能够正常进入系统&#xff0c;建议您暂时移…...

    2022/11/19 21:17:02
  40. 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...

    配置windows update失败 还原更改 请勿关闭计算机&#xff0c;电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;配置windows update失败 还原更改 请勿关闭计算机&#x…...

    2022/11/19 21:17:01
  41. 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...

    不知道大家有没有遇到过这样的一个问题&#xff0c;就是我们的win7系统在关机的时候&#xff0c;总是喜欢显示“准备配置windows&#xff0c;请勿关机”这样的一个页面&#xff0c;没有什么大碍&#xff0c;但是如果一直等着的话就要两个小时甚至更久都关不了机&#xff0c;非常…...

    2022/11/19 21:17:00
  42. 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...

    当电脑出现正在准备配置windows请勿关闭计算机时&#xff0c;一般是您正对windows进行升级&#xff0c;但是这个要是长时间没有反应&#xff0c;我们不能再傻等下去了。可能是电脑出了别的问题了&#xff0c;来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...

    2022/11/19 21:16:59
  43. 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...

    我们使用电脑的过程中有时会遇到这种情况&#xff0c;当我们打开电脑之后&#xff0c;发现一直停留在一个界面&#xff1a;“配置Windows Update失败&#xff0c;还原更改请勿关闭计算机”&#xff0c;等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢&#xff0…...

    2022/11/19 21:16:58
  44. 如何在iPhone上关闭“请勿打扰”

    Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...

    2022/11/19 21:16:57