【NDK】移植Live555到Android

文章目录

    • 一、Live555简绍
    • 二、编译live555
    • 三、解决报错
    • 四、总结

有个IPC的项目有用到live555,简单编译了一下live555的动态库,作为笔记存用,因为也没碰到什么难点,有问题可以联系我

一、Live555简绍

  • Live555作为一个经典的流媒体开源框架,相信如果你要用到,肯定也有初步了解,我的项目中用到他的RTSP Server。一起来看看它的支持:

    The “LIVE555 Media Server” is a complete RTSP server application. It can stream several kinds of media file (which must be stored in the current working directory - i.e., the directory from which you launch the application - or a subdirectory.):

    • A MPEG Transport Stream file (with file name suffix “.ts”)
    • A Matroska or WebM file (with filename suffix “.mkv” or “.webm”)
    • An Ogg file (with filename suffix “.ogg”, “ogv”, or “.opus”)
    • A MPEG-1 or 2 Program Stream file (with file name suffix “.mpg”)
    • A MPEG-4 Video Elementary Stream file (with file name suffix “.m4e”)
    • A H.264 Video Elementary Stream file (with file name suffix “.264”)
    • A H.265 Video Elementary Stream file (with file name suffix “.265”)
    • A VOB video+audio file (with file name suffix “.vob”)
    • A DV video file (with file name suffix “.dv”)
    • A MPEG-1 or 2 (including layer III - i.e., ‘MP3’) audio file (with file name suffix “.mp3”)
    • A WAV (PCM) audio file (with file name suffix “.wav”)
    • An AMR audio file (with file name suffix “.amr”)
    • An AC-3 audio file (with file name suffix “.ac3”)
    • An AAC (ADTS format) audio file (with file name suffix “.aac”)
      上面死它支持流的类型,它能同时传输多路流,支持VLC和RTSP Client预览流媒体
  • 它对应的目录(中间还包含其他目录,包括win和linux编译环境和脚本,我们用不到删除即可):

    • BasicUsageEnvironment UsageEnvironment define
    • groupsock 包含网络和socket相关
    • liveMedia 核心功能,对接流媒体编码器等
    • mediaServer 媒体server
    • proxyServer 代理server
    • UsageEnvironment 都是些待实现的抽象基础类,构成一些基础架构
    • testProgs 列举使用UsageEnvironment实现的一些简单程序

二、编译live555

  1. 下载:http://www.live555.com/liveMedia/public/

     选择live555-latest.tar.gz
    
  2. 删除用不到的文件,如win和linux编译环境和脚本

  3. Android.mk

     LOCAL_PATH := $(call my-dir)
    
     include $(CLEAR_VARS)
     
     LOCAL_MODULE := live555
     
     #include header
     LOCAL_C_INCLUDES := \
     	$(LOCAL_PATH) \
     	$(LOCAL_PATH)/BasicUsageEnvironment \
     	$(LOCAL_PATH)/BasicUsageEnvironment/include \
     	$(LOCAL_PATH)/groupsock \
     	$(LOCAL_PATH)/groupsock/include \
     	$(LOCAL_PATH)/liveMedia \
     	$(LOCAL_PATH)/liveMedia/include \
     	$(LOCAL_PATH)/UsageEnvironment \
     	$(LOCAL_PATH)/UsageEnvironment/include \
     	$(LOCAL_PATH)/mediaServer \
     
     LOCAL_MODULE_TAGS := optional
     
     #build the needed source file
     LOCAL_SRC_FILES := \
     BasicUsageEnvironment/BasicHashTable.cpp \
     BasicUsageEnvironment/BasicTaskScheduler.cpp \
     BasicUsageEnvironment/BasicTaskScheduler0.cpp \
     BasicUsageEnvironment/BasicUsageEnvironment.cpp \
     BasicUsageEnvironment/BasicUsageEnvironment0.cpp \
     BasicUsageEnvironment/DelayQueue.cpp \
     groupsock/GroupEId.cpp \
     groupsock/Groupsock.cpp \
     groupsock/GroupsockHelper.cpp \
     groupsock/inet.c \
     groupsock/IOHandlers.cpp \
     groupsock/NetAddress.cpp \
     groupsock/NetInterface.cpp \
     UsageEnvironment/HashTable.cpp \
     UsageEnvironment/strDup.cpp \
     UsageEnvironment/UsageEnvironment.cpp \
     liveMedia/QuickTimeFileSink.cpp  \
     liveMedia/QuickTimeGenericRTPSource.cpp \
     liveMedia/RawVideoRTPSink.cpp \
     liveMedia/RawVideoRTPSource.cpp \
     liveMedia/RTCP.cpp \
     liveMedia/rtcp_from_spec.c \
     liveMedia/RTPInterface.cpp \
     liveMedia/RTPSink.cpp \
     liveMedia/RTPSource.cpp \
     liveMedia/RTSPClient.cpp \
     liveMedia/RTSPCommon.cpp \
     liveMedia/RTSPRegisterSender.cpp \
     liveMedia/RTSPServer.cpp \
     liveMedia/RTSPServerRegister.cpp \
     liveMedia/RTSPServerSupportingHTTPStreaming.cpp \
     liveMedia/ServerMediaSession.cpp \
     liveMedia/SimpleRTPSink.cpp \
     liveMedia/SimpleRTPSource.cpp \
     liveMedia/SIPClient.cpp \
     liveMedia/StreamParser.cpp \
     liveMedia/StreamReplicator.cpp \
     liveMedia/T140TextRTPSink.cpp \
     liveMedia/TCPStreamSink.cpp \
     liveMedia/TextRTPSink.cpp \
     liveMedia/TheoraVideoRTPSink.cpp \
     liveMedia/TheoraVideoRTPSource.cpp \
     liveMedia/uLawAudioFilter.cpp \
     liveMedia/VideoRTPSink.cpp \
     liveMedia/VorbisAudioRTPSink.cpp \
     liveMedia/VorbisAudioRTPSource.cpp \
     liveMedia/VP8VideoRTPSink.cpp \
     liveMedia/VP8VideoRTPSource.cpp \
     liveMedia/VP9VideoRTPSink.cpp \
     liveMedia/VP9VideoRTPSource.cpp \
     liveMedia/WAVAudioFileServerMediaSubsession.cpp \
     liveMedia/WAVAudioFileSource.cpp \
     liveMedia/MPEG2TransportFileServerMediaSubsession.cpp \
     liveMedia/MPEG2TransportStreamAccumulator.cpp \
     liveMedia/MPEG2TransportStreamFramer.cpp \
     liveMedia/MPEG2TransportStreamFromESSource.cpp \
     liveMedia/MPEG2TransportStreamFromPESSource.cpp \
     liveMedia/MPEG2TransportStreamIndexFile.cpp \
     liveMedia/MPEG2TransportStreamMultiplexor.cpp \
     liveMedia/MPEG2TransportStreamTrickModeFilter.cpp \
     liveMedia/MPEG2TransportUDPServerMediaSubsession.cpp \
     liveMedia/MPEG4ESVideoRTPSink.cpp  \
     liveMedia/MPEG4ESVideoRTPSource.cpp \
     liveMedia/MPEG4GenericRTPSink.cpp \
     liveMedia/MPEG4GenericRTPSource.cpp \
     liveMedia/MPEG4LATMAudioRTPSink.cpp \
     liveMedia/MPEG4LATMAudioRTPSource.cpp \
     liveMedia/MPEG4VideoFileServerMediaSubsession.cpp \
     liveMedia/MPEG4VideoStreamDiscreteFramer.cpp \
     liveMedia/MPEG4VideoStreamFramer.cpp \
     liveMedia/MPEGVideoStreamFramer.cpp \
     liveMedia/MPEGVideoStreamParser.cpp \
     liveMedia/MultiFramedRTPSink.cpp \
     liveMedia/MultiFramedRTPSource.cpp \
     liveMedia/OggDemuxedTrack.cpp \
     liveMedia/OggFile.cpp \
     liveMedia/OggFileParser.cpp \
     liveMedia/OggFileServerDemux.cpp \
     liveMedia/OggFileServerMediaSubsession.cpp \
     liveMedia/OggFileSink.cpp \
     liveMedia/OnDemandServerMediaSubsession.cpp \
     liveMedia/ourMD5.cpp \
     liveMedia/OutputFile.cpp \
     liveMedia/MatroskaFileServerMediaSubsession.cpp \
     liveMedia/Media.cpp \
     liveMedia/MediaSession.cpp \
     liveMedia/MediaSink.cpp \
     liveMedia/MediaSource.cpp \
     liveMedia/MP3ADU.cpp \
     liveMedia/MP3ADUdescriptor.cpp \
     liveMedia/MP3ADUinterleaving.cpp \
     liveMedia/MP3ADURTPSink.cpp \
     liveMedia/MP3ADURTPSource.cpp \
     liveMedia/MP3ADUTranscoder.cpp \
     liveMedia/MP3AudioFileServerMediaSubsession.cpp \
     liveMedia/MP3AudioMatroskaFileServerMediaSubsession.cpp \
     liveMedia/MP3FileSource.cpp \
     liveMedia/MP3Internals.cpp \
     liveMedia/MP3InternalsHuffman.cpp \
     liveMedia/MP3InternalsHuffmanTable.cpp \
     liveMedia/MP3StreamState.cpp \
     liveMedia/MP3Transcoder.cpp \
     liveMedia/MPEG1or2AudioRTPSink.cpp \
     liveMedia/MPEG1or2AudioRTPSource.cpp \
     liveMedia/MPEG1or2AudioStreamFramer.cpp \
     liveMedia/MPEG1or2Demux.cpp \
     liveMedia/MPEG1or2DemuxedElementaryStream.cpp \
     liveMedia/MPEG1or2DemuxedServerMediaSubsession.cpp \
     liveMedia/GSMAudioRTPSink.cpp \
     liveMedia/H261VideoRTPSource.cpp \
     liveMedia/H263plusVideoFileServerMediaSubsession.cpp \
     liveMedia/H263plusVideoRTPSink.cpp \
     liveMedia/H263plusVideoRTPSource.cpp \
     liveMedia/H263plusVideoStreamFramer.cpp \
     liveMedia/H263plusVideoStreamParser.cpp \
     liveMedia/H264or5VideoFileSink.cpp \
     liveMedia/H264or5VideoRTPSink.cpp \
     liveMedia/H264or5VideoStreamDiscreteFramer.cpp \
     liveMedia/H264or5VideoStreamFramer.cpp \
     liveMedia/H264VideoFileServerMediaSubsession.cpp \
     liveMedia/H264VideoFileSink.cpp \
     liveMedia/H264VideoRTPSink.cpp \
     liveMedia/H264VideoRTPSource.cpp \
     liveMedia/H264VideoStreamDiscreteFramer.cpp \
     liveMedia/H264VideoStreamFramer.cpp \
     liveMedia/H265VideoFileServerMediaSubsession.cpp \
     liveMedia/H265VideoFileSink.cpp \
     liveMedia/H265VideoRTPSink.cpp \
     liveMedia/H265VideoRTPSource.cpp \
     liveMedia/H265VideoStreamDiscreteFramer.cpp \
     liveMedia/H265VideoStreamFramer.cpp \
     liveMedia/InputFile.cpp \
     liveMedia/JPEGVideoRTPSink.cpp \
     liveMedia/JPEGVideoRTPSource.cpp \
     liveMedia/JPEGVideoSource.cpp \
     liveMedia/Locale.cpp \
     liveMedia/MatroskaDemuxedTrack.cpp \
     liveMedia/MatroskaFile.cpp \
     liveMedia/MatroskaFileParser.cpp \
     liveMedia/AC3AudioFileServerMediaSubsession.cpp \
     liveMedia/AC3AudioRTPSink.cpp \
     liveMedia/AC3AudioRTPSource.cpp \
     liveMedia/AC3AudioStreamFramer.cpp \
     liveMedia/ADTSAudioFileServerMediaSubsession.cpp \
     liveMedia/ADTSAudioFileSource.cpp \
     liveMedia/AMRAudioFileServerMediaSubsession.cpp  \
     liveMedia/AMRAudioFileSink.cpp \
     liveMedia/AMRAudioFileSource.cpp \
     liveMedia/AMRAudioRTPSink.cpp \
     liveMedia/AMRAudioRTPSource.cpp \
     liveMedia/AMRAudioSource.cpp \
     liveMedia/AudioInputDevice.cpp \
     liveMedia/AudioRTPSink.cpp \
     liveMedia/AVIFileSink.cpp \
     liveMedia/Base64.cpp \
     liveMedia/BasicUDPSink.cpp \
     liveMedia/BasicUDPSource.cpp \
     liveMedia/BitVector.cpp \
     liveMedia/ByteStreamFileSource.cpp \
     liveMedia/ByteStreamMemoryBufferSource.cpp \
     liveMedia/ByteStreamMultiFileSource.cpp \
     liveMedia/DeviceSource.cpp \
     liveMedia/DigestAuthentication.cpp \
     liveMedia/DVVideoFileServerMediaSubsession.cpp \
     liveMedia/DVVideoRTPSink.cpp \
     liveMedia/DVVideoRTPSource.cpp \
     liveMedia/DVVideoStreamFramer.cpp \
     liveMedia/EBMLNumber.cpp \
     liveMedia/FileServerMediaSubsession.cpp \
     liveMedia/MatroskaFileServerDemux.cpp \
     liveMedia/FileSink.cpp \
     liveMedia/FramedSource.cpp \
     liveMedia/FramedFileSource.cpp \
     liveMedia/QCELPAudioRTPSource.cpp \
     liveMedia/MPEG1or2FileServerDemux.cpp \
     liveMedia/MPEG1or2VideoRTPSink.cpp \
     liveMedia/ProxyServerMediaSession.cpp \
     liveMedia/MPEG1or2VideoStreamFramer.cpp \
     liveMedia/MPEG1or2VideoStreamDiscreteFramer.cpp \
     liveMedia/MPEG1or2VideoRTPSource.cpp \
     liveMedia/FramedFilter.cpp \
     liveMedia/GenericMediaServer.cpp \
     mediaServer/DynamicRTSPServer.cpp \
     mediaServer/live555MediaServer.cpp \
     
     
     LOCAL_LDLIBS    := -lm -llog
     
     
     LOCAL_CPPFLAGS := \
     -fexceptions -DLOCALE_NOT_USED -DNULL=0 -DNO_SSTREAM=1 -UIP_ADD_SOURCE_MEMBERSHIP
     
     include $(BUILD_SHARED_LIBRARY)
    
  4. Application.mk

     APP_STL := gnustl_static
     APP_ABI := armeabi armeabi-v7a
     APP_PLATFORM := android-8
    

三、解决报错

  • 错误:

    GroupsockHelper.cpp:575:23: error: request for member ‘s_addr’ in ‘imr.ip_mreq_source::imr_multiaddr’, which is of non-class type ‘__be32 {aka unsigned int}’
    imr.imr_multiaddr.s_addr = groupAddress;

    • 查看代码:

        ----------->其中定义的NDK版本
        #define ANDROID_OLD_NDK __NDK_MAJOR__ < 17
      
      
        ----------->575报错的代码:其中判断了NDK编版本。我关注自己版本以下即可,注释即可,后面的错误同理
      
        Boolean socketJoinGroupSSM(UsageEnvironment& env, int socket,
        	   netAddressBits groupAddress,
        	   netAddressBits sourceFilterAddr) {
        	  if (!IsMulticastAddress(groupAddress)) return True; // ignore this case
        	
        	  struct ip_mreq_source imr;
        	#if ANDROID_OLD_NDK
        	    imr.imr_multiaddr = groupAddress;
        	    imr.imr_sourceaddr = sourceFilterAddr;
        	    imr.imr_interface = ReceivingInterfaceAddr;
        	#else
        	   // imr.imr_multiaddr.s_addr = groupAddress;
        	   // imr.imr_sourceaddr.s_addr = sourceFilterAddr;
        	   // imr.imr_interface.s_addr = ReceivingInterfaceAddr;
        	#endif
        	  if (setsockopt(socket, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP,
        			 (const char*)&imr, sizeof (struct ip_mreq_source)) < 0) {
        	    socketErr(env, "setsockopt(IP_ADD_SOURCE_MEMBERSHIP) error: ");
        	    return False;
        	  }
        	
        	  clearMulticastAllSocketOption(socket);
        	
        	  return True;
        	}
      

四、总结

我的NDK版本是r14b,android api=8,顺利编译完成了,live555是个很成熟的库,网上也有许多的博客和代码,基本不存在很多编译难题,如果碰到问题,可以从源码中找答案,大多数是编译环境或者宏定义判断导致。只有认真排查,很快就能解决

你可能感兴趣的:(NDK-JNI,Android音视频)