VoiSmart / pjsip-android

SIP Service for Android based on PJSIP
http://www.pjsip.org/
Apache License 2.0
290 stars 140 forks source link

Can not place a Video Call #113

Closed SachithKasthuriarachchi closed 2 years ago

SachithKasthuriarachchi commented 4 years ago

Hi, I am developing an android app based on this library and I have implemented SIP calling in my app using the library. Now I want my app to perform video calls also. Here I will provide my code below.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/vid"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical"
    android:weightSum="2">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@drawable/calling_background">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            android:layout_marginStart="20dp"
            android:layout_marginTop="20dp"
            android:layout_marginEnd="20dp"
            android:layout_marginBottom="20dp"
            android:src="@drawable/ic_phone_black_24dp" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <SurfaceView
            android:id="@+id/mySurface"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <TextView
            android:id="@+id/dialling_number"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textAlignment="center"
            android:textColor="@color/black"
            android:textSize="35sp" />

        <ImageView
            android:id="@+id/hangup"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/dialling_number"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="45dp"
            android:background="@color/white"
            android:clickable="true"
            android:focusable="true"
            android:src="@drawable/ic_call_end_black_24dp" />

    </RelativeLayout>

</LinearLayout>

In the above xml file I use the mySurface to start the video. The following code is related to the Outgoing video call activity.

package com.ptt_app.easytalk;


import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.ptt_app.easytalk.core.SipServiceCommand;

public class OutgoingCall extends AppCompatActivity implements SurfaceHolder.Callback,
        MediaPlayer.OnPreparedListener {

    private String accountID;
    private int callID;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_outgoing_call);
    }

    @Override
    public void onResume() {
        super.onResume();

        Intent intent = getIntent();
        accountID = intent.getStringExtra("accountID");
        callID = intent.getIntExtra("callID", 0);
        String number = intent.getStringExtra("number");

        final ImageView hangupButton = findViewById(R.id.hangup);
        TextView displayNumber = findViewById(R.id.dialling_number);

        SurfaceView surfaceView = findViewById(R.id.mySurface);
        SurfaceHolder holder = surfaceView.getHolder();
        holder.addCallback(this);

        displayNumber.setText(number);

        hangupButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hangupButton.setImageDrawable(getDrawable(R.drawable.ic_call_end_pressed_24dp));
                SipServiceCommand.hangUpCall(getApplicationContext(), accountID, callID);
                Intent intent = new Intent(getApplicationContext(), CallActivity.class);
                startActivity(intent);
            }
        });

    }

    @Override
    public void onPrepared(MediaPlayer mp) {

    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        SipServiceCommand.setupIncomingVideoFeed(this, accountID, callID, holder.getSurface());
        SipServiceCommand.startVideoPreview(this, accountID, callID, holder.getSurface());
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {

    }
}

I call setUpIncomingVideoFeed and startVideoPreview methods here. Is it alright how I have provided the required surface for video?

(This class is called when I called SipServiceCommand.makeCall(getActivity(), currentAccount, numberToCall, true, false); to place an video call)

But I always get this error.

E/SipCall: Error while toggling video transmission
    java.lang.Exception: Title:       pjsua_call_set_vid_strm(id, op, &prm)
    Code:        70006
    Description: Not found (PJ_ENOTFOUND)
    Location:    ../src/pjsua2/call.cpp:633

        at org.pjsip.pjsua2.pjsua2JNI.Call_vidSetStream(Native Method)
        at org.pjsip.pjsua2.Call.vidSetStream(Call.java:171)
        at com.ptt_app.easytalk.core.SipCall.setVideoMute(SipCall.java:543)
        at com.ptt_app.easytalk.core.SipCall.onCallState(SipCall.java:133)
        at org.pjsip.pjsua2.pjsua2JNI.SwigDirector_Call_onCallState(pjsua2JNI.java:2426)
E/SipCall: onCallState: error while getting call info
    java.lang.IllegalStateException: Must Initialize Fabric before using singleton()
        at io.fabric.sdk.android.Fabric.singleton(Fabric.java:301)
        at io.fabric.sdk.android.Fabric.getKit(Fabric.java:551)
        at com.crashlytics.android.Crashlytics.getInstance(Crashlytics.java:191)
        at com.crashlytics.android.Crashlytics.checkInitialized(Crashlytics.java:390)
        at com.crashlytics.android.Crashlytics.logException(Crashlytics.java:210)
        at com.ptt_app.easytalk.core.SipCall.setVideoMute(SipCall.java:550)
        at com.ptt_app.easytalk.core.SipCall.onCallState(SipCall.java:133)
        at org.pjsip.pjsua2.pjsua2JNI.SwigDirector_Call_onCallState(pjsua2JNI.java:2426)

Could you please show me where have I done wrong?

aenonGit commented 4 years ago

usually that happens when the other side do not negotiate a video codec. Is that the case? Can you post your sdp offer and the other party's answer?

SachithKasthuriarachchi commented 4 years ago

Thanks for replying @aenonGit! I am not using my own server and instead I am using my SIP accounts of "iptel.org" to check this video calling feature. Could you please instruct me how to post the sdp offer? Is my code ok?

aenonGit commented 4 years ago

Wireshark

aenonGit commented 2 years ago

closing due to inactivity