设为首页收藏本站

AnyChat技术支持论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 10436|回复: 17
打印 上一主题 下一主题

AnyChat视频通话Dialog无法显示对方视频问题

[复制链接]

24

主题

36

帖子

120

积分

注册会员

Rank: 2

积分
120
跳转到指定楼层
楼主
发表于 2014-5-15 11:59:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Anychat工程师你们好:
    之前已经在电话里沟通过该问题,将demo中VideoActivity中的代码移植到我的Dialog中发现可以取到自己的视频但拿不到对方的视频。现附上代码,盼尽快回复,谢谢!
  1. package com.skytech.isplatform.dialogs.messageschatdialog.instantvideodialog;

  2. import java.util.Timer;
  3. import java.util.TimerTask;

  4. import com.bairuitech.anychat.AnyChatCoreSDK;
  5. import com.bairuitech.anychat.AnyChatDefine;
  6. import com.skytech.anychat.AnyChatManager;
  7. import com.skytech.anychat.ConfigEntity;
  8. import com.skytech.anychat.ConfigService;
  9. import com.skytech.isplatform.R;

  10. import android.app.Dialog;
  11. import android.content.Context;
  12. import android.graphics.PixelFormat;
  13. import android.os.Bundle;
  14. import android.os.Handler;
  15. import android.os.Message;
  16. import android.view.Surface;
  17. import android.view.SurfaceHolder;
  18. import android.view.SurfaceView;
  19. import android.view.View;
  20. import android.view.Window;
  21. import android.view.ViewTreeObserver.OnGlobalLayoutListener;
  22. import android.widget.Button;
  23. import android.widget.FrameLayout;
  24. import android.widget.LinearLayout;
  25. import android.widget.RelativeLayout;
  26. import android.widget.TextView;

  27. public class InstantVideoDialog extends Dialog
  28. {
  29.         private Context context;
  30.         
  31.         private RelativeLayout relativeLayoutCalling;
  32.         private TextView textViewChatTarget;
  33.         private RelativeLayout relativeLayoutVideoShow;
  34.         private SurfaceView surfaceViewTarget;
  35.         private SurfaceView surfaceViewSelf;
  36.         private Button buttonCallOff;
  37.         
  38.         private static InstantVideoDialog ivd;
  39.         
  40.         private InstantVideoDialog(Context context)
  41.         {
  42.                 super(context, R.style.Dialog_Transparent);
  43.                 this.context = context;
  44.         }
  45.         
  46.         public static InstantVideoDialog getInstance(Context context)
  47.         {
  48.                 if(ivd == null)
  49.                 {
  50.                         ivd = new InstantVideoDialog(context);
  51.                 }
  52.                
  53.                 return ivd;
  54.         }
  55.         
  56.         @Override
  57.         protected void onCreate(Bundle savedInstanceState)
  58.         {
  59.                 super.onCreate(savedInstanceState);
  60.                 requestWindowFeature(Window.FEATURE_NO_TITLE);
  61.                 setContentView(R.layout.instant_video_dialog_layout);
  62.                
  63.                 initView();
  64.                
  65.         }
  66.         
  67.         @Override
  68.         protected void onStop()
  69.         {        
  70.                 relativeLayoutCalling.setVisibility(View.VISIBLE);
  71.                 relativeLayoutVideoShow.setVisibility(View.GONE);
  72.                
  73.                 if(mTimer != null)
  74.                 {
  75.                         mTimer.cancel();
  76.                 }
  77.                
  78.                 AnyChatManager.getInstance(context).logout();
  79.                 super.onStop();
  80.         }
  81.         
  82.         public void setChatTargetName(String targetName)
  83.         {
  84.                 textViewChatTarget.setText(targetName);
  85.         }

  86.         private void initView()
  87.         {
  88.                 relativeLayoutCalling = (RelativeLayout)findViewById(R.id.rl_instant_video_dialog_calling);
  89.                 textViewChatTarget = (TextView)findViewById(R.id.tv_instant_video_chat_target);
  90.                 relativeLayoutVideoShow = (RelativeLayout)findViewById(R.id.rl_instant_video_dialog_start_video_chat);
  91.                 surfaceViewTarget = (SurfaceView)findViewById(R.id.sv_instant_video_target_show);
  92.                 surfaceViewSelf = (SurfaceView)findViewById(R.id.sv_instant_video_self_show);
  93.                 buttonCallOff= (Button)findViewById(R.id.bt_instant_video_call_off);
  94.                
  95.                 buttonCallOff.setOnClickListener(new View.OnClickListener()
  96.                 {
  97.                         
  98.                         @Override
  99.                         public void onClick(View v)
  100.                         {
  101.                                 dismiss();
  102.                         }
  103.                 });

  104.         }
  105.         
  106.         private boolean bVideoAreaLoaded = false; // 视频区域大小是否加载
  107.         private int dwLocalVideoWidth = 0;
  108.         private int dwLocalVideoHeight = 0;
  109.         private int dwRemoteVideoHeight = 0;
  110.         private int dwRemoteVideoWidth = 0;
  111.         
  112.         @SuppressWarnings("deprecation")
  113.         public void startChat()
  114.         {
  115.                 bOtherVideoOpened = false;
  116.                 bSelfVideoOpened = false;
  117.                 bVideoAreaLoaded = false;
  118.                
  119.                 relativeLayoutCalling.setVisibility(View.GONE);
  120.                 relativeLayoutVideoShow.setVisibility(View.VISIBLE);
  121.                
  122.                 if(AnyChatCoreSDK.GetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_CAPDRIVER) == AnyChatDefine.VIDEOCAP_DRIVER_JAVA) {
  123.                         surfaceViewSelf.getHolder().addCallback(AnyChatCoreSDK.mCameraHelper);                        
  124.                 }
  125.                
  126.                 //如果是采用Java视频显示,则需要设置Surface的CallBack
  127.                 if(AnyChatCoreSDK.GetSDKOptionInt(AnyChatDefine.BRAC_SO_VIDEOSHOW_DRIVERCTRL) == AnyChatDefine.VIDEOSHOW_DRIVER_JAVA) {
  128.                         int index = AnyChatManager.getInstance(context).getAnyChatSDK().mVideoHelper.bindVideo(surfaceViewTarget.getHolder());
  129.                         AnyChatManager.getInstance(context).getAnyChatSDK().mVideoHelper.SetVideoUser(index, AnyChatManager.getInstance(context).getTargetUserId());
  130.                 }
  131.                
  132.                
  133.                 surfaceViewTarget.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
  134.                         
  135.                         @Override
  136.                         public void onGlobalLayout() {
  137.                                 if(!bVideoAreaLoaded)
  138.                                 {
  139.                                         adjuestVideoSize(surfaceViewTarget.getWidth(), surfaceViewTarget.getHeight());
  140.                                         bVideoAreaLoaded=true;
  141.                                 }
  142.                         }
  143.                 });
  144.                
  145.                 SurfaceHolder holder = surfaceViewTarget.getHolder();
  146.                 holder.setKeepScreenOn(true);
  147.                 AnyChatManager.getInstance(context).getAnyChatSDK().UserCameraControl(AnyChatManager.getInstance(context).getTargetUserId(), 1);
  148.                 AnyChatManager.getInstance(context).getAnyChatSDK().UserSpeakControl(AnyChatManager.getInstance(context).getTargetUserId(), 1);
  149.         
  150.                 ConfigEntity configEntity = ConfigService.LoadConfig(context);
  151.                 if (configEntity.videoOverlay != 0)
  152.                 {
  153.                         surfaceViewSelf.getHolder().setType(
  154.                                         SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  155.                 }
  156.                 // 判断是否显示本地摄像头切换图标
  157.                 if (AnyChatCoreSDK
  158.                                 .GetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_CAPDRIVER) == AnyChatDefine.VIDEOCAP_DRIVER_JAVA)
  159.                 {
  160.                         if (AnyChatCoreSDK.mCameraHelper.GetCameraNumber() > 1)
  161.                         {
  162.                                 // TODO mCameraSwitchImage.setVisibility(View.VISIBLE);
  163.                                 // 默认打开前置摄像头
  164.                                 AnyChatCoreSDK.mCameraHelper
  165.                                                 .SelectVideoCapture(AnyChatCoreSDK.mCameraHelper.CAMERA_FACING_FRONT);
  166.                         }
  167.                 }
  168.                 else
  169.                 {
  170.                         String[] strVideoCaptures = AnyChatManager.getInstance(context)
  171.                                         .getAnyChatSDK().EnumVideoCapture();
  172.                         if (strVideoCaptures != null && strVideoCaptures.length > 1)
  173.                         {
  174.                                 // TODO mCameraSwitchImage.setVisibility(View.VISIBLE);
  175.                                 // 默认打开前置摄像头
  176.                                 for (int i = 0; i < strVideoCaptures.length; i++)
  177.                                 {
  178.                                         String strDevices = strVideoCaptures[i];
  179.                                         if (strDevices.indexOf("Front") >= 0)
  180.                                         {
  181.                                                 AnyChatManager.getInstance(context).getAnyChatSDK().SelectVideoCapture(strDevices);
  182.                                                 break;
  183.                                         }
  184.                                 }
  185.                         }
  186.                 }
  187.                 // 打开本地音频、视频设备
  188.                 AnyChatManager.getInstance(context).getAnyChatSDK().UserCameraControl(-1, 1);
  189.                 AnyChatManager.getInstance(context).getAnyChatSDK().UserSpeakControl(-1, 1);
  190.                
  191.                 videoTrans();
  192.         }
  193.         
  194.         private Timer mTimer;
  195.         private TimerTask mTimerTask;
  196.         private Handler handler;
  197.         boolean bOnPaused = false;
  198.         private boolean bSelfVideoOpened = false; // 本地视频是否已打开
  199.         private boolean bOtherVideoOpened = false; // 对方视频是否已打开
  200.         
  201.         
  202.         private void videoTrans()
  203.         {
  204.                 mTimer = new Timer(true);
  205.                
  206.                 mTimerTask = new TimerTask() {
  207.                         public void run() {
  208.                                 if(handler == null)
  209.                                         return;
  210.                                 Message mesasge = new Message();
  211.                                 handler.sendMessage(mesasge);
  212.                         }
  213.                 };

  214.                 mTimer.schedule(mTimerTask, 1000, 100);

  215.                 handler = new Handler() {
  216.                         @Override
  217.                         public void handleMessage(Message msg) {
  218.                                 CheckVideoStatus();
  219. //                                SetVolum();
  220.                                 super.handleMessage(msg);
  221.                         }
  222.                 };
  223.         }
  224.         
  225.         // 判断视频是否已打开
  226.         private void CheckVideoStatus()
  227.         {
  228.                 if (bOnPaused)
  229.                         return;
  230.                 if (!bOtherVideoOpened)
  231.                 {
  232.                         if (AnyChatManager.getInstance(context).getAnyChatSDK()
  233.                                         .GetCameraState(AnyChatManager.getInstance(context).getTargetUserId()) == 2
  234.                                         && AnyChatManager.getInstance(context).getAnyChatSDK()
  235.                                                         .GetUserVideoWidth(AnyChatManager.getInstance(context).getTargetUserId()) != 0)
  236.                         {
  237.                                 SurfaceHolder holder = surfaceViewTarget.getHolder();
  238.                                 holder.setFormat(PixelFormat.RGB_565);
  239.                                 holder.setFixedSize(AnyChatManager.getInstance(context)
  240.                                                 .getAnyChatSDK().GetUserVideoWidth(AnyChatManager.getInstance(context).getTargetUserId()),
  241.                                                 AnyChatManager.getInstance(context).getAnyChatSDK()
  242.                                                                 .GetUserVideoHeight(AnyChatManager.getInstance(context).getTargetUserId()));
  243.                                 Surface s = holder.getSurface();
  244.                                 AnyChatManager.getInstance(context).getAnyChatSDK()
  245.                                                 .SetVideoPos(AnyChatManager.getInstance(context).getTargetUserId(), s, 0, 0, 0, 0);
  246.                                 bOtherVideoOpened = true;
  247.                         }
  248.                 }
  249.                 if (!bSelfVideoOpened)
  250.                 {
  251.                         if (AnyChatManager.getInstance(context).getAnyChatSDK()
  252.                                         .GetCameraState(-1) == 2
  253.                                         && AnyChatManager.getInstance(context).getAnyChatSDK()
  254.                                                         .GetUserVideoWidth(-1) != 0)
  255.                         {
  256.                                 SurfaceHolder holder = surfaceViewSelf.getHolder();
  257.                                 holder.setFormat(PixelFormat.RGB_565);
  258.                                 holder.setFixedSize(AnyChatManager.getInstance(context)
  259.                                                 .getAnyChatSDK().GetUserVideoWidth(-1), AnyChatManager
  260.                                                 .getInstance(context).getAnyChatSDK()
  261.                                                 .GetUserVideoHeight(-1));
  262.                                 Surface s = holder.getSurface();
  263.                                 AnyChatManager.getInstance(context).getAnyChatSDK()
  264.                                                 .SetVideoPos(-1, s, 0, 0, 0, 0);
  265.                                 bSelfVideoOpened = true;
  266.                         }
  267.                 }

  268.         }
  269.         
  270.         private void adjuestVideoSize(int width, int height) {

  271.                 if (3 * width > 4 * height) {

  272.                         dwRemoteVideoHeight = height;
  273.                         dwRemoteVideoWidth = (int) (4.0 / 3.0 * dwRemoteVideoHeight);
  274.                 } else {
  275.                         dwRemoteVideoWidth = width;
  276.                         dwRemoteVideoHeight = (int) (3.0 / 4.0 * dwRemoteVideoWidth);
  277.                 }
  278.                 dwLocalVideoWidth = dwRemoteVideoWidth;
  279.                 dwLocalVideoHeight = dwRemoteVideoHeight;
  280.                 FrameLayout.LayoutParams layoutParamSelf=new FrameLayout.LayoutParams(dwLocalVideoWidth, dwLocalVideoHeight);
  281.                 surfaceViewSelf.setLayoutParams(layoutParamSelf);
  282.                 LinearLayout.LayoutParams layoutPramOther=new LinearLayout.LayoutParams(dwLocalVideoWidth, dwLocalVideoHeight);
  283.                 surfaceViewTarget.setLayoutParams(layoutPramOther);
  284.                
  285.                
  286.         }
  287. }

复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

5

主题

1269

帖子

3677

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3677
沙发
发表于 2014-5-15 12:05:39 | 只看该作者
您好,这个代码里面没有看到登录、进入房间的过程,您是在进入房间成功后跳转到这个界面的吗?另外可以将一份双方通话结束后的anychat日志给我们吗?日志在sdcard的根目录下面,BRAnyChatCore.log文件
回复 支持 反对

使用道具 举报

24

主题

36

帖子

120

积分

注册会员

Rank: 2

积分
120
板凳
 楼主| 发表于 2014-5-15 13:10:06 | 只看该作者
是的 这个是在进入房间成功后跳转的,目前声音是OK的,两边都能收到,就是对方的视频拿不到。log如下:
[2014-05-15 12:50:39(715)]        ---------------------------BRAnyChatCore ActiveCallLog---------------------------
[2014-05-15 12:50:39(716)]        Load SDK Success, dwFuncMode:0x8a,V4.7(Build Time:Jun  4 2013 02:15:50)
[2014-05-15 12:50:39(716)]        Android OS SDK Version:18, Support ARMv7:2, Support Neon:4
[2014-05-15 12:50:39(729)]        Load libmediautil_v7.so success!(V4.7 Build Time:Jun  4 2013 02:17:26)
[2014-05-15 12:50:39(735)]        Load libmediashow_4.0.so failed,video display functions will fail!(dlopen failed: cannot locate symbol "_ZN7android7Surface4lockEPNS0_11SurfaceInfoEPNS_6RegionE" referenced by "libmediashow_4.0.so"...)
[2014-05-15 12:50:39(744)]        dlopen failed: cannot locate symbol "_ZN7android10AudioTrack3setE19audio_stream_type_tj14audio_format_tii20audio_output_flags_tPFviPvS4_ES4_iRKNS_2spINS_7IMemoryEEEbi" referenced by "libmediacore_4.1.so"...
[2014-05-15 12:50:39(745)]        Load libmediacore.so success!(V4.7 Build Time:Jun  4 2013 02:16:40)
[2014-05-15 12:50:39(750)]        CPU:1592.52 MIPS, Hardware:SMDK4x12
[2014-05-15 12:50:54(460)]        Invoke        BRAC_Connect(32.1.5.86,8906)=0
[2014-05-15 12:50:54(462)]        Invoke        LoginServer(username=admin4@kyleyang/Smack)
[2014-05-15 12:50:54(462)]        Invoke        EnterRoom(roomid=1)
[2014-05-15 12:50:54(497)]        CheckClientSocketLink         Connect(ip=32.1.5.86,port=8906)
[2014-05-15 12:50:54(659)]        Server version: V4.8(Build Time:2013-06-19 22:32:49)
[2014-05-15 12:50:54(659)]        Message        OnConnect(bSuccess:1, errorcode=0)
[2014-05-15 12:50:54(861)]        Message        OnLoginSystem(userid=-347,errorcode=0,username=admin4@kyleyang/Smack), msg deliver worked(0)
[2014-05-15 12:50:54(867)]        Load libmediashow_4.0.so failed,video display functions will fail!(dlopen failed: cannot locate symbol "_ZN7android7Surface4lockEPNS0_11SurfaceInfoEPNS_6RegionE" referenced by "libmediashow_4.0.so"...)
[2014-05-15 12:50:54(874)]        Connection to streaming media server successfully!(udp delay:2ms)
[2014-05-15 12:50:54(889)]        Message        OnEnterRoom(roomid=1,errorcode=0,siteindex=1)
[2014-05-15 12:50:54(890)]        Audio Playback Device Init(0, 1, 16000, 16), Default Playback Driver
[2014-05-15 12:50:54(891)]        Message        OnReceiveOnlineUser(count=2,roomid=1)
[2014-05-15 12:50:54(959)]        Invoke        UserCameraControl(userid=-346,bOpen=1)
[2014-05-15 12:50:54(960)]        Invoke        UserSpeakControl(userid=-346,bOpen=1)
[2014-05-15 12:50:54(961)]        Invoke        UserCameraControl(userid=-1,bOpen=1)
[2014-05-15 12:50:54(962)]        Invoke        UserSpeakControl(userid=-1,bOpen=1)
[2014-05-15 12:50:55(280)]        video init finish:320x240, NV21, fps:25
[2014-05-15 12:50:55(310)]        Audio Init, error:0, device:-1, 1, 16000, 16, capmode:0
[2014-05-15 12:50:55(311)]        Audio codec init, handle:1, 11, 1, 16000, 16, 15850
[2014-05-15 12:50:55(478)]        Audio FX Status: VAD:1, NS:2, AGC:8, AEC:4
[2014-05-15 12:50:55(510)]        video codec init:codec:1, 15fps, 320x240, bitrate:90000, quality:3, preset:3, gop:30, handle:2
[2014-05-15 12:50:55(651)]        Message        OnP2PConnectState(userid=-346, state=2)
[2014-05-15 12:50:55(722)]        Message        OnP2PConnectState(userid=-346, state=3)
[2014-05-15 12:50:55(882)]        userid(-346) video decode delay:4ms
[2014-05-15 12:51:01(969)]        Invoke        LeaveRoom(roomid=-1)        Elapse:106 ms
[2014-05-15 12:51:01(971)]        Invoke        LogoutServer(userid=-347)        Elapse:2 ms
回复 支持 反对

使用道具 举报

24

主题

36

帖子

120

积分

注册会员

Rank: 2

积分
120
地板
 楼主| 发表于 2014-5-15 13:11:37 | 只看该作者
有一个so库载入失败,不知道是不是这个原因
回复 支持 反对

使用道具 举报

24

主题

36

帖子

120

积分

注册会员

Rank: 2

积分
120
5#
 楼主| 发表于 2014-5-15 13:24:22 | 只看该作者
对了 视频发送也是成功的 用你们的demo也能收到视频 但就是我的dialog收不到视频
回复 支持 反对

使用道具 举报

249

主题

2967

帖子

9079

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
9079
6#
发表于 2014-5-15 13:37:00 | 只看该作者
Load SDK Success, dwFuncMode:0x8a,V4.7(Build Time:Jun  4 2013 02:15:50)

您好,从Log分析,您目前使用的SDK还是老版本,建议更新到最新版本(需要更新.so库,以及.java源代码)。

Server version: V4.8(Build Time:2013-06-19 22:32:49)
同时也建议一并更新服务器到最新版本,当然您目前所遇到的问题可能和服务器为旧版本没有关系。
回复 支持 反对

使用道具 举报

24

主题

36

帖子

120

积分

注册会员

Rank: 2

积分
120
7#
 楼主| 发表于 2014-5-15 16:31:03 | 只看该作者
经过调试后现在可以取到视频了(版本我没有更新,是我自己代码的问题),但是现在又发生从第二次开始,后面的发送者都拿不到对方视频,但接收者可以拿到发送者的视频,不知有无这样的先例大概是什么原因?谢谢!
回复 支持 反对

使用道具 举报

5

主题

1269

帖子

3677

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3677
8#
发表于 2014-5-15 16:44:14 | 只看该作者
amurocrash 发表于 2014-5-15 16:31
经过调试后现在可以取到视频了(版本我没有更新,是我自己代码的问题),但是现在又发生从第二次开始,后面的 ...

您好。这种情况有可能是下面的情况造成的
一、请求别人的视频一定要在确认对方进入房间之后,有两个回调消息可以确认OnAnyChatOnlineUserMessage和OnAnyChatUserAtRoomMessage;
二、也有可能是在程序运行过程中多次释放和初始化,一般程序开始和结束分别调用一次初始化和释放就行了。
三、也有可能是早期版本的bug造成的
可以发一份双方通话两次的日志过来看下,通话双方的日志都要发上来,我们分析下。另外建议您更新到最新版本,最新版本各方面都有优化,能兼容更多的android设备。
回复 支持 反对

使用道具 举报

24

主题

36

帖子

120

积分

注册会员

Rank: 2

积分
120
9#
 楼主| 发表于 2014-5-15 16:44:26 | 只看该作者
我dialog用的单例 是不是资源释放的问题?
回复 支持 反对

使用道具 举报

5

主题

1269

帖子

3677

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3677
10#
发表于 2014-5-15 16:52:48 | 只看该作者
amurocrash 发表于 2014-5-15 16:44
我dialog用的单例 是不是资源释放的问题?

可以发一份双方通话两次的日志过来看下,通话双方的日志都要发上来,我们分析下
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|AnyChat ( 粤ICP备13022410号-1 )  

GMT+8, 2024-5-5 13:52 , Processed in 0.184586 second(s), 21 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表