编译webrtc到pjsip中的方法

网络上编译webrtc的方法很多,大都直接使用GOOGLE的本身提供的编译webrtc的方法。实际上webrtc本身就是支持夸平台的代码,因此理论上说,可以将WEBRTC中对你有用代码提出来,编译到任何的平台中。

下面就是这两天折腾的将webrtc的audio_processing模块编译整合到了pjsip中去的编译过程:


         pjsip库是一个跨平台的VOIP库,支持语音和视频,在android平台编译是通过makefile的方式来进行的。使用编译工具链是ndk提供的。比如当前我们使用的就是android-ndk-r10e版本中提供的工具链,具体到编译工具,主要分为三大类,一个是编译C语言的工具。使用的是: android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc

编译C++的工具是:

android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++

这两个编译器是我的linux中配置的android相应的版本所采用的工具链,具体的不同版本采用的只是版本不同的GCC和G++。

编译框架

         PJSIP的主要编译原理是将所有的生成动作的makefile文件放置在根目录下的build/rules.mak 中,这个文件主要是定义的通用的生成规则,根目录下build.mak由build.mak.in生成,主要是用于环境检查以及生成各个脚本中的宏定义。然后再各个子模块的build目录下均有一个Makefile文件用于生成该子模块。

集成WEBRTC方式

对于WEBRTC,我们采用的集成方式是,将WEBRTC作为一个第三方的静态库集成到PJSIP中去,具体就是将WEBRTC的代码放到pjsip库目录下的third_party/webrtc/目录下,同时将编译脚本放置到/third_party/build/webrtc目录下。

脚本准备:

         1.在跟目录下的build.mak中加入如下代码:

        

 #add for webrtc audio module compile
ifneq (,1)
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libwebrtc-$(LIB_SUFFIX)
ifeq ($(PJ_SHARED_LIBRARIES),)
APP_THIRD_PARTY_LIBS += -lwebrtc-$(TARGET_NAME)
else
APP_THIRD_PARTY_LIBS += -lwebrtc
APP_THIRD_PARTY_LIB_FILES +=$(PJ_DIR)/third_party/lib/libwebrtc.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR)$(PJ_DIR)/third_party/lib/libwebrtc.$(SHLIB_SUFFIX)
endif
endif

参考:

2. 将build/rules.mak文件拷贝一份,修改名字为rules-webrtc.mak,

将$(OBJDIR)/%$(OBJEXT):$(SRCDIR)/%.m 改为$(OBJDIR)/%$(OBJEXT):$(SRCDIR)/%.cc

将$(SRCDIR)/$(basename$(file)).m 改为$(SRCDIR)/$(basename$(file)).cc

参考:

3. 将third_party/build/webrtc/目录中新建一个Makefile文件。内容如下:

$(warning Makefile begin)
include ../../../build.mak
include ../../../build/common.mak
$(warning  include build.mak common.mak end)
export LIBDIR := ../../lib

RULES_MAK := $(PJDIR)/build/rules-webrtc.mak

export WEBRTC_LIB := libwebrtc-$(TARGET_NAME)$(LIBEXT)

ifeq ($(PJ_SHARED_LIBRARIES),)
else
export WEBRTC_SONAME := libwebrtc.$(SHLIB_SUFFIX)
export WEBRTC_SHLIB := $(WEBRTC_SONAME).$(PJ_VERSION_MAJOR)
endif

###############################################################################
# Gather all flags.
#
WEBRTC_EXTRA_CFLAGS :=  -DNDEBUG -DWEBRTC_NO_LOG -DWEBRTC_ANDROID -DWEBRTC_POSIX -DWEBRTC_LINUX -DWEBRTC_NS_FIXED -DWEBRTC_CLOCK_TYPE_REALTIME -mfloat-abi=softfp -mfpu=neon
export _CFLAGS 	:= $(CC_CFLAGS) $(OS_CFLAGS) $(HOST_CFLAGS) $(M_CFLAGS) $(WEBRTC_EXTRA_CFLAGS) \
		   $(CFLAGS) $(CC_INC). $(CC_INC)../../webrtc \
		   $(CC_INC)../../webrtc/webrtc/common_audio/include \
		   $(CC_INC)../../webrtc/webrtc/common_audio/signal_processing/include

           #$(CC_INC)/root/android-ndk-r10e/platforms/android-19/arch-arm/usr/include
           #$(CC_INC)/root/android-ndk-r10e/platforms/android-19/arch-arm/usr/include/machine/\
           #$(CC_INC)/root/android-ndk-r10e//platforms/android-19/arch-arm/usr/include/

export _CXXFLAGS:= $(_CFLAGS) $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
		   $(HOST_CXXFLAGS) $(CXXFLAGS) $(WEBRTC_EXTRA_CFLAGS) -std=c++11 
export _LDFLAGS := $(CC_LDFLAGS) $(OS_LDFLAGS) $(M_LDFLAGS) $(HOST_LDFLAGS) \
		   $(APP_LDFLAGS) $(LDFLAGS) 

export WEBRTC_SRCDIR = ../../webrtc/webrtc
export WEBRTC_OBJS =base/checks.o base/criticalsection.o base/platform_file.o base/platform_thread.o\
    common_audio/audio_converter.o  common_audio/audio_ring_buffer.o  common_audio/audio_util.o  common_audio/blocker.o\
	common_audio/channel_buffer.o common_audio/fft4g.o common_audio/fir_filter.o\
    common_audio/fir_filter_neon.o common_audio/lapped_transform.o common_audio/real_fourier.o common_audio/real_fourier_ooura.o\
    common_audio/resampler/push_resampler.o common_audio/resampler/push_sinc_resampler.o common_audio/resampler/resampler.o\
    common_audio/resampler/sinc_resampler.o common_audio/resampler/sinusoidal_linear_chirp_source.o\
    common_audio/ring_buffer.o common_audio/signal_processing/auto_correlation.o common_audio/signal_processing/auto_corr_to_refl_coef.o\
    common_audio/signal_processing/complex_bit_reverse.o common_audio/signal_processing/complex_fft.o \
    common_audio/signal_processing/copy_set_operations.o common_audio/signal_processing/cross_correlation.o \
    common_audio/signal_processing/division_operations.o common_audio/signal_processing/dot_product_with_scale.o common_audio/signal_processing/downsample_fast.o \
    common_audio/signal_processing/energy.o common_audio/signal_processing/filter_ar.o common_audio/signal_processing/filter_ar_fast_q12.o\
    common_audio/signal_processing/filter_ma_fast_q12.o common_audio/signal_processing/get_hanning_window.o common_audio/signal_processing/get_scaling_square.o \
    common_audio/signal_processing/levinson_durbin.o common_audio/signal_processing/lpc_to_refl_coef.o  common_audio/signal_processing/min_max_operations.o\
    common_audio/signal_processing/randomization_functions.o common_audio/signal_processing/real_fft.o \
    common_audio/signal_processing/refl_coef_to_lpc.o common_audio/signal_processing/resample.o common_audio/signal_processing/resample_48khz.o\
    common_audio/signal_processing/resample_by_2.o common_audio/signal_processing/resample_by_2_internal.o common_audio/signal_processing/resample_by_2_mips.o \
    common_audio/signal_processing/resample_fractional.o common_audio/signal_processing/splitting_filter.o common_audio/signal_processing/spl_init.o\
    common_audio/signal_processing/spl_sqrt.o common_audio/signal_processing/spl_sqrt_floor.o common_audio/signal_processing/sqrt_of_one_minus_x_squared.o \
    common_audio/signal_processing/vector_scaling_operations.o common_audio/sparse_fir_filter.o common_audio/vad/vad.o common_audio/vad/vad_core.o\
    common_audio/vad/vad_filterbank.o common_audio/vad/vad_gmm.o common_audio/vad/vad_sp.o \
    common_audio/vad/webrtc_vad.o common_audio/wav_file.o common_audio/wav_header.o \
    common_audio/window_generator.o modules/audio_coding/codecs/audio_decoder.o modules/audio_coding/codecs/audio_encoder.o modules/audio_coding/codecs/cng/audio_encoder_cng.o \
    modules/audio_coding/codecs/g711/audio_encoder_pcm.o modules/audio_coding/codecs/g722/audio_decoder_g722.o modules/audio_coding/codecs/g722/audio_encoder_g722.o\
    modules/audio_coding/codecs/ilbc/abs_quant.o modules/audio_coding/codecs/ilbc/abs_quant_loop.o  modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.o \
    modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.o modules/audio_coding/codecs/ilbc/augmented_cb_corr.o modules/audio_coding/codecs/ilbc/cb_construct.o\
    modules/audio_coding/codecs/ilbc/cb_mem_energy.o  modules/audio_coding/codecs/ilbc/cb_mem_energy_augmentation.o \
    modules/audio_coding/codecs/ilbc/cb_mem_energy_calc.o modules/audio_coding/codecs/ilbc/cb_search.o modules/audio_coding/codecs/ilbc/cb_search_core.o\
    modules/audio_coding/codecs/ilbc/cb_update_best_index.o modules/audio_coding/codecs/ilbc/chebyshev.o modules/audio_coding/codecs/ilbc/comp_corr.o\
    modules/audio_coding/codecs/ilbc/constants.o \
    modules/audio_coding/codecs/ilbc/create_augmented_vec.o modules/audio_coding/codecs/ilbc/decoder_interpolate_lsf.o\
    modules/audio_coding/codecs/ilbc/decode_residual.o modules/audio_coding/codecs/ilbc/do_plc.o modules/audio_coding/codecs/ilbc/encode.o\
    modules/audio_coding/codecs/ilbc/energy_inverse.o modules/audio_coding/codecs/ilbc/enhancer.o \
    modules/audio_coding/codecs/ilbc/enhancer_interface.o modules/audio_coding/codecs/ilbc/enh_upsample.o modules/audio_coding/codecs/ilbc/filtered_cb_vecs.o\
    modules/audio_coding/codecs/ilbc/frame_classify.o modules/audio_coding/codecs/ilbc/gain_dequant.o modules/audio_coding/codecs/ilbc/gain_quant.o modules/audio_coding/codecs/ilbc/get_cd_vec.o \
    modules/audio_coding/codecs/ilbc/get_lsp_poly.o modules/audio_coding/codecs/ilbc/get_sync_seq.o modules/audio_coding/codecs/ilbc/hp_input.o\
    modules/audio_coding/codecs/ilbc/hp_output.o modules/audio_coding/codecs/ilbc/index_conv_dec.o modules/audio_coding/codecs/ilbc/index_conv_enc.o\
    modules/audio_coding/codecs/ilbc/init_decode.o modules/audio_coding/codecs/ilbc/init_encode.o \
    modules/audio_coding/codecs/ilbc/interpolate.o modules/audio_coding/codecs/ilbc/interpolate_samples.o modules/audio_coding/codecs/ilbc/lpc_encode.o\
    modules/audio_coding/codecs/ilbc/lsf_check.o modules/audio_coding/codecs/ilbc/lsf_interpolate_to_poly_dec.o modules/audio_coding/codecs/ilbc/lsf_interpolate_to_poly_enc.o\
    modules/audio_coding/codecs/ilbc/lsf_to_lsp.o modules/audio_coding/codecs/ilbc/lsf_to_poly.o modules/audio_coding/codecs/ilbc/lsp_to_lsf.o\
    modules/audio_coding/codecs/ilbc/my_corr.o modules/audio_coding/codecs/ilbc/nearest_neighbor.o modules/audio_coding/codecs/ilbc/pack_bits.o\
    modules/audio_coding/codecs/ilbc/poly_to_lsf.o modules/audio_coding/codecs/ilbc/poly_to_lsp.o modules/audio_coding/codecs/ilbc/refiner.o \
    modules/audio_coding/codecs/ilbc/simple_interpolate_lsf.o modules/audio_coding/codecs/ilbc/simple_lpc_analysis.o\
    modules/audio_coding/codecs/ilbc/simple_lsf_dequant.o modules/audio_coding/codecs/ilbc/simple_lsf_quant.o modules/audio_coding/codecs/ilbc/smooth.o\
    modules/audio_coding/codecs/ilbc/smooth_out_data.o modules/audio_coding/codecs/ilbc/sort_sq.o \
    modules/audio_coding/codecs/ilbc/split_vq.o modules/audio_coding/codecs/ilbc/state_construct.o modules/audio_coding/codecs/ilbc/state_search.o\
    modules/audio_coding/codecs/ilbc/swap_bytes.o modules/audio_coding/codecs/ilbc/vq3.o modules/audio_coding/codecs/ilbc/vq4.o\
    modules/audio_coding/codecs/isac/fix/source/audio_encoder_isacfix.o modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.o \
    modules/audio_coding/codecs/isac/fix/source/decode_plc.o modules/audio_coding/codecs/isac/fix/source/filters.o modules/audio_coding/codecs/isac/fix/source/initialize.o\
    modules/audio_coding/codecs/isac/fix/source/isacfix.o modules/audio_coding/codecs/isac/fix/source/lpc_masking_model.o\
    modules/audio_coding/codecs/isac/fix/source/pitch_estimator_c.o modules/audio_coding/codecs/isac/fix/source/pitch_filter_c.o modules/audio_coding/codecs/isac/fix/source/transform_tables.o \
    modules/audio_coding/codecs/isac/locked_bandwidth_info.o  modules/audio_coding/codecs/isac/fix/source/arith_routines_hist.o\
    modules/audio_coding/codecs/isac/fix/source/arith_routines_logist.o modules/audio_coding/codecs/isac/main/source/audio_encoder_isac.o\
    modules/audio_coding/codecs/isac/fix/source/decode.o modules/audio_coding/codecs/isac/fix/source/decode_bwe.o modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.o \
    modules/audio_coding/codecs/isac/main/source/entropy_coding.o modules/audio_coding/codecs/isac/main/source/fft.o \
    modules/audio_coding/codecs/isac/main/source/filterbanks.o modules/audio_coding/codecs/isac/main/source/filterbank_tables.o\
    modules/audio_coding/codecs/isac/main/source/filter_functions.o modules/audio_coding/codecs/isac/main/source/intialize.o\
    modules/audio_coding/codecs/isac/main/source/isac.o modules/audio_coding/codecs/isac/main/source/lattice.o\
    modules/audio_coding/codecs/isac/main/source/lpc_analysis.o \
    modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.o modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.o\
    modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.o modules/audio_coding/codecs/isac/main/source/lpc_tables.o\
    modules/audio_coding/codecs/isac/main/source/pitch_estimator.o modules/audio_coding/codecs/isac/main/source/pitch_filter.o\
    modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.o \
    modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.o modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.o\
    modules/audio_coding/codecs/isac/main/source/transform.o modules/audio_coding/codecs/opus/audio_decoder_opus.o\
    modules/audio_coding/codecs/opus/audio_encoder_opus.o modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.o \
    modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.o modules/audio_coding/codecs/red/audio_encoder_copy_red.o\
    modules/audio_coding/main/acm2/acm_resampler.o  modules/audio_coding/main/acm2/call_statistics.o modules/audio_coding/main/acm2/initial_delay_manager.o\
    modules/audio_coding/main/acm2/nack.o modules/audio_coding/main/test/TimedTrace.o \
    modules/audio_coding/neteq/audio_multi_vector.o modules/audio_coding/neteq/audio_vector.o modules/audio_coding/neteq/buffer_level_filter.o\
    modules/audio_coding/neteq/delay_peak_detector.o modules/audio_coding/neteq/dsp_helper.o modules/audio_coding/neteq/dtmf_tone_generator.o \
    modules/audio_coding/neteq/merge.o modules/audio_coding/neteq/post_decode_vad.o \
    modules/audio_coding/neteq/preemptive_expand.o modules/audio_coding/neteq/random_vector.o\
    modules/audio_coding/neteq/sync_buffer.o modules/audio_coding/neteq/tools/audio_loop.o modules/audio_coding/neteq/tools/constant_pcm_packet_source.o \
    modules/audio_coding/neteq/tools/input_audio_file.o modules/audio_coding/neteq/tools/resample_input_audio_file.o\
    modules/audio_conference_mixer/source/audio_frame_manipulator.o modules/audio_conference_mixer/source/time_scheduler.o modules/audio_processing/aecm/aecm_core.o \
    modules/audio_processing/aecm/aecm_core_c.o modules/audio_processing/aecm/echo_control_mobile.o modules/audio_processing/aec/aec_core.o\
    modules/audio_processing/aec/aec_core_neon.o modules/audio_processing/aec/aec_rdft.o modules/audio_processing/aec/aec_rdft_neon.o modules/audio_processing/aec/aec_resampler.o \
    modules/audio_processing/aec/echo_cancellation.o modules/audio_processing/agc/agc.o modules/audio_processing/agc/agc_manager_direct.o\
    modules/audio_processing/agc/histogram.o modules/audio_processing/agc/legacy/analog_agc.o modules/audio_processing/agc/legacy/digital_agc.o modules/audio_processing/agc/utility.o \
    modules/audio_processing/audio_buffer.o modules/audio_processing/audio_processing_impl.o modules/audio_processing/beamformer/covariance_matrix_generator.o\
    modules/audio_processing/beamformer/nonlinear_beamformer.o \
    modules/audio_processing/echo_cancellation_impl.o modules/audio_processing/echo_control_mobile_impl.o\
    modules/audio_processing/gain_control_impl.o modules/audio_processing/high_pass_filter_impl.o\
    modules/audio_processing/intelligibility/intelligibility_enhancer.o \
    modules/audio_processing/intelligibility/intelligibility_utils.o modules/audio_processing/level_estimator_impl.o modules/audio_processing/logging/aec_logging_file_handling.o\
    modules/audio_processing/noise_suppression_impl.o\
    modules/audio_processing/ns/noise_suppression.o modules/audio_processing/ns/noise_suppression_x.o modules/audio_processing/ns/nsx_core.o\
    modules/audio_processing/ns/nsx_core_c.o modules/audio_processing/ns/ns_core.o modules/audio_processing/processing_component.o\
    modules/audio_processing/rms_level.o modules/audio_processing/splitting_filter_cc.o modules/audio_processing/three_band_filter_bank.o\
    modules/audio_processing/transient/click_annotate.o modules/audio_processing/transient/file_utils.o \
    modules/audio_processing/transient/moving_moments.o modules/audio_processing/transient/transient_detector.o modules/audio_processing/transient/transient_suppressor.o\
    modules/audio_processing/transient/wpd_node.o \
    modules/audio_processing/transient/wpd_tree.o modules/audio_processing/typing_detection.o\
    modules/audio_processing/utility/delay_estimator.o modules/audio_processing/utility/delay_estimator_wrapper.o modules/audio_processing/vad/gmm.o \
    modules/audio_processing/vad/pitch_based_vad.o modules/audio_processing/vad/pitch_internal.o modules/audio_processing/vad/pole_zero_filter.o\
    modules/audio_processing/vad/standalone_vad.o modules/audio_processing/vad/vad_audio_proc.o modules/audio_processing/vad/vad_circular_buffer.o \
    modules/audio_processing/vad/voice_activity_detector.o modules/audio_processing/voice_detection_impl.o modules/pacing/paced_sender.o\
    modules/remote_bitrate_estimator/aimd_rate_control.o \
    modules/remote_bitrate_estimator/inter_arrival.o modules/remote_bitrate_estimator/overuse_estimator.o modules/remote_bitrate_estimator/rate_statistics.o \
    modules/remote_bitrate_estimator/test/random.o modules/utility/source/audio_frame_operations.o modules/utility/source/process_thread_impl.o \
    system_wrappers/source/aligned_malloc.o system_wrappers/source/atomic32_posix.o system_wrappers/source/clock.o system_wrappers/source/condition_variable.o  \
    system_wrappers/source/cpu_info.o system_wrappers/source/critical_section.o system_wrappers/source/critical_section_posix.o \
    system_wrappers/source/data_log.o system_wrappers/source/data_log_c.o  system_wrappers/source/event.o\
    system_wrappers/source/event_timer_posix.o system_wrappers/source/event_tracer.o system_wrappers/source/field_trial_default.o \
    system_wrappers/source/metrics_default.o system_wrappers/source/rw_lock.o system_wrappers/source/rw_lock_generic.o system_wrappers/source/rw_lock_posix.o system_wrappers/source/sleep.o system_wrappers/source/sort.o system_wrappers/source/thread.o \
    system_wrappers/source/thread_posix.o system_wrappers/source/tick_util.o system_wrappers/source/timestamp_extrapolator.o system_wrappers/source/trace_posix.o webrtc_interface.o

export WEBRTC_CFLAGS := -DHAVE_CONFIG_H $(_CFLAGS) -std=c99
export WEBRTC_CXXFLAGS := $(_CXXFLAGS) 
export WEBRTC_LDFLAGS := $(PJLIB_LDLIB) $(_LDFLAGS)

export CC_OUT CC AR RANLIB HOST_MV HOST_RM HOST_RMDIR HOST_MKDIR OBJEXT LD LDOUT 
###############################################################################
# Main entry
#
# $(TARGET) is defined in os-$(OS_NAME).mak file in current directory.
#
TARGETS := $(WEBRTC_LIB) $(WEBRTC_SONAME)

all: $(TARGETS)

doc:
	cd .. && doxygen docs/doxygen.cfg

dep: depend
distclean: realclean

.PHONY: all dep depend clean realclean distclean
.PHONY: $(TARGETS)
.PHONY: $(WEBRTC_LIB) $(WEBRTC_SONAME)

libwebrtc: $(WEBRTC_LIB)
$(WEBRTC_SONAME): $(WEBRTC_LIB)
$(WEBRTC_LIB) $(WEBRTC_SONAME):
	$(MAKE) -f $(RULES_MAK) APP=WEBRTC app=libwebrtc $(subst /,$(HOST_PSEP),$(LIBDIR)/$@)

clean print_lib:
	$(MAKE) -f $(RULES_MAK) APP=WEBRTC app=libwebrtc $@

realclean:
	$(subst @@,$(subst /,$(HOST_PSEP),.ilbc-$(TARGET_NAME).depend),$(HOST_RMR))
	
	$(MAKE) -f $(RULES_MAK) APP=WEBRTC app=libwebrtc $@

depend:
	$(MAKE) -f $(RULES_MAK) APP=WEBRTC app=libwebrtc $@




WEBRTC目录以及文件:



4.替换pjmedia中的sound_port.c文件为下面这个:

(~~)自己去按自己的需求修改。。。。。


编译的方式:

1.       进入到third_party/build/webrtc/目录下,键入命令:make即可将webrtc模块的静态库生成,生成的具体位置:third_party/lib/libwebrtc-arm-unknown-linux-androideabi.a

2.       进入到pjsip的根目录下,直接make,即可生成对应的PJSIP库

3.       进入到pjsip-apps/src/swig 目录下make,就可以生成对应开发需要使用的PJSIP库(至于PJSIP的配置方法,请参见: http://trac.pjsip.org/repos/wiki/Getting-Started/Android)

4.       pjsip库的文件生成于:pjsip-apps/src/swig/java/android/libs/armeabi/libpjsua2.so

 

 

 

 



你可能感兴趣的:(谷歌,WebRTC,pjsip)