实例介绍
【实例简介】
有相关文档和测试demo,回音消除等处理,学习WebRTC、回音消除的同学可以好好参考
【实例截图】
【核心代码】
/* * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ package org.webrtc.webrtcdemo; import android.app.ActionBar.Tab; import android.app.ActionBar.TabListener; import android.app.ActionBar; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.pm.ActivityInfo; import android.media.AudioManager; import android.os.Bundle; import android.os.Handler; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.WindowManager; public class WebRTCDemo extends Activity implements MenuStateProvider { // From http://developer.android.com/guide/topics/ui/actionbar.html public static class TabListener<T extends Fragment> implements ActionBar.TabListener { private Fragment fragment; private final Activity activity; private final String tag; private final Class<T> instance; private final Bundle args; public TabListener(Activity activity, String tag, Class<T> clz) { this(activity, tag, clz, null); } public TabListener(Activity activity, String tag, Class<T> clz, Bundle args) { this.activity = activity; this.tag = tag; this.instance = clz; this.args = args; } public void onTabSelected(Tab tab, FragmentTransaction ft) { // Check if the fragment is already initialized if (fragment == null) { // If not, instantiate and add it to the activity fragment = Fragment.instantiate(activity, instance.getName(), args); ft.add(android.R.id.content, fragment, tag); } else { // If it exists, simply attach it in order to show it ft.attach(fragment); } } public void onTabUnselected(Tab tab, FragmentTransaction ft) { if (fragment != null) { // Detach the fragment, because another one is being attached ft.detach(fragment); } } public void onTabReselected(Tab tab, FragmentTransaction ft) { // User selected the already selected tab. Do nothing. } } private NativeWebRtcContextRegistry contextRegistry = null; private MediaEngine mediaEngine = null; private Handler handler; public MediaEngine getEngine() { return mediaEngine; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Global settings. getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // State. // Must be instantiated before MediaEngine. contextRegistry = new NativeWebRtcContextRegistry(); contextRegistry.register(this); // Load all settings dictated in xml. mediaEngine = new MediaEngine(this); mediaEngine.setRemoteIp(getResources().getString(R.string.loopbackIp)); mediaEngine.setTrace(getResources().getBoolean( R.bool.trace_enabled_default)); mediaEngine.setAudio(getResources().getBoolean( R.bool.audio_enabled_default)); mediaEngine.setAudioCodec(mediaEngine.getIsacIndex()); mediaEngine.setAudioRxPort(getResources().getInteger( R.integer.aRxPortDefault)); mediaEngine.setAudioTxPort(getResources().getInteger( R.integer.aTxPortDefault)); mediaEngine.setSpeaker(getResources().getBoolean( R.bool.speaker_enabled_default)); mediaEngine.setDebuging(getResources().getBoolean( R.bool.apm_debug_enabled_default)); mediaEngine.setReceiveVideo(getResources().getBoolean( R.bool.video_receive_enabled_default)); mediaEngine.setSendVideo(getResources().getBoolean( R.bool.video_send_enabled_default)); mediaEngine.setVideoCodec(getResources().getInteger( R.integer.video_codec_default)); // TODO(hellner): resolutions should probably be in the xml as well. mediaEngine.setResolutionIndex(MediaEngine.numberOfResolutions() - 2); mediaEngine.setVideoTxPort(getResources().getInteger( R.integer.vTxPortDefault)); mediaEngine.setVideoRxPort(getResources().getInteger( R.integer.vRxPortDefault)); mediaEngine.setNack(getResources().getBoolean(R.bool.nack_enabled_default)); mediaEngine.setViewSelection(getResources().getInteger( R.integer.defaultView)); // Create action bar with all tabs. ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayShowTitleEnabled(false); Tab tab = actionBar.newTab() .setText("Main") .setTabListener(new TabListener<MainMenuFragment>( this, "main", MainMenuFragment.class)); actionBar.addTab(tab); tab = actionBar.newTab() .setText("Settings") .setTabListener(new TabListener<SettingsMenuFragment>( this, "Settings", SettingsMenuFragment.class)); actionBar.addTab(tab); tab = actionBar.newTab() .setText("Video") .setTabListener(new TabListener<VideoMenuFragment>( this, "video", VideoMenuFragment.class)); actionBar.addTab(tab); tab = actionBar.newTab() .setText("Audio") .setTabListener(new TabListener<AudioMenuFragment>( this, "Audio", AudioMenuFragment.class)); actionBar.addTab(tab); enableTimedStartStop(); // Hint that voice call audio stream should be used for hardware volume // controls. setVolumeControlStream(AudioManager.STREAM_VOICE_CALL); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_activity_actions, menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_exit: MainMenuFragment main = (MainMenuFragment)getFragmentManager() .findFragmentByTag("main"); main.stopAll(); finish(); return true; default: return super.onOptionsItemSelected(item); } } @Override public void onDestroy() { disableTimedStartStop(); mediaEngine.dispose(); contextRegistry.unRegister(); super.onDestroy(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { // Prevent app from running in the background. MainMenuFragment main = (MainMenuFragment)getFragmentManager() .findFragmentByTag("main"); main.stopAll(); finish(); return true; } return super.onKeyDown(keyCode, event); } private int getCallRestartPeriodicity() { return getResources().getInteger(R.integer.call_restart_periodicity_ms); } // Thread repeatedly calling start/stop. void enableTimedStartStop() { if (getCallRestartPeriodicity() > 0) { // Periodicity == 0 <-> Disabled. handler = new Handler(); handler.postDelayed(startOrStopCallback, getCallRestartPeriodicity()); } } void disableTimedStartStop() { if (handler != null) { handler.removeCallbacks(startOrStopCallback); } } private Runnable startOrStopCallback = new Runnable() { public void run() { MainMenuFragment main = (MainMenuFragment)getFragmentManager() .findFragmentByTag("main"); main.toggleStart(); handler.postDelayed(startOrStopCallback, getCallRestartPeriodicity()); } }; }
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论