8

I want to add sip calls to my quiz game. So, I've built SipHome project by this way:

http://code.google.com/p/csipsimple/wiki/HowToBuild#Without_building_the_native_library

It's Ok. Application compiled and launched. Now I want to add video-call ability on my app. After checkout (http://csipsimple.googlecode.com/svn/trunk/) I have also this SVN dependencies:

CSipSimpleBranded
CSipSimpleCodecG729
CSipSimpleCodecPack
CSipSimpleVideoPlugin 

I've put classes PluginReceiver, CaptureReceiver, PluginReceiverFfmpeg and PluginReceiverVpx from CSipSimpleVideoPlugin project to SipHome project. And also I've put descriptions of receivers to SipHome manifest project:

    <receiver android:name=".plugins.video.PluginReceiver" >
        <intent-filter>
            <action android:name="com.csipsimple.plugins.action.REGISTER_VIDEO" />
        </intent-filter>

        <meta-data
            android:name="lib_name"
            android:value="libpj_video_android.so" />
        <!-- For now it does not matter in the future we should have one per device, codec, and converter (if needed) -->
        <meta-data
            android:name="init_factory"
            android:value="pjmedia_webrtc_vid_render_factory" />
    </receiver>

    <!--
    Receiver for video capture
    <receiver android:name=".plugins.video.CaptureReceiver" >
        <intent-filter>
            <action android:name="com.csipsimple.plugins.action.REGISTER_CAPTURE_VIDEO" />
        </intent-filter>

        <meta-data
            android:name="lib_name"
            android:value="libpj_screen_capture_android.so" />
        <meta-data
            android:name="init_factory"
            android:value="pjmedia_webrtc_vid_capture_factory" />
    </receiver>
    -->
    <receiver android:name=".plugins.video.PluginReceiverFfmpeg" >
        <intent-filter>
            <action android:name="com.csipsimple.codecs.action.REGISTER_VIDEO_CODEC" />
        </intent-filter>

        <meta-data
            android:name="lib_name"
            android:value="libpj_video_android.so" />
        <meta-data
            android:name="init_factory"
            android:value="pjmedia_codec_ffmpeg_vid_init" />
        <meta-data
            android:name="deinit_factory"
            android:value="pjmedia_codec_ffmpeg_vid_deinit" />
    </receiver>
    <receiver android:name=".plugins.video.PluginReceiverVpx" >
        <intent-filter>
            <action android:name="com.csipsimple.codecs.action.REGISTER_VIDEO_CODEC" />
        </intent-filter>

        <meta-data
            android:name="lib_name"
            android:value="libpj_vpx.so" />
        <meta-data
            android:name="init_factory"
            android:value="pjmedia_codec_vpx_init" />
        <meta-data
            android:name="deinit_factory"
            android:value="pjmedia_codec_vpx_deinit" />
    </receiver>

I've set USE_VIDEO=true flag after login:

prefProviderWrapper.setPreferenceBooleanValue(SipConfigManager.USE_VIDEO, true);

When I call in InCallActivity I see VideoButton, but after press it I have this in logcat:

pjsua_vid.c .Unable to create re-INVITE: No SDP payload format in the media line (PJMEDIA_SDP_ENOFMT) [status=220032]

and video doesn't show.

Thanks.

valerybodak
  • 4,195
  • 2
  • 42
  • 53
  • 2
    Adding a bounty to the question will not change the fact that nobody will write your code for you. – Xaver Kapeller Mar 13 '14 at 10:51
  • Sorry, but I don't need code. I want description what I need to do next? How to add video-plugin to my project? Thanks. – valerybodak Mar 13 '14 at 11:07
  • Well it's basically the same thing. On this site you are supposed to show your own effort, you are supposed to try to do it yourself and when you encounter a specific problem, we can help you with that. Have you tried to add it to your app yourself? What problems did you encounter while trying to add it? Have you tried searching for the answer on google and on Stackoverflow? Or in your case you already found the perfect source of information. The project your are linking to is an app that already integrates this feature and it's open source. Why don't you look for your answer there? – Xaver Kapeller Mar 13 '14 at 11:21

1 Answers1

-1

You don't need to add any of those Receivers to the main manifest, they are only used to check if the plugin is installed.

Here is a guide to using CSipSimple for video calls without the VideoPLugin :D

Modify the CSipSimpleVideoPlugin build script so it copies the libpj_video_android.so to the CSipSimple libs directory. (Or just copy it over manually every time you build).

Finally to include the video library you need to modify the PjsipService, replace lines 273 to 307 with something like;

String videoLibraryPath = NativeLibManager.getLibraryPath(mContext, "libpj_video_android.so");

if (!videoLibraryPath.isEmpty()) {

pj_str_t pjVideoFile = pjsua.pj_str_copy(videoLibraryPath);

// Render
dynamic_factory videoRenderFactory = csipSimpleConfig.getVideo_render_implementation();
videoRenderFactory.setInit_factory_name(pjsua.pj_str_copy("pjmedia_webrtc_vid_render_factory"));
videoRenderFactory.setShared_lib_path(pjVideoFile);

// Capture
dynamic_factory videoCaptureFactory = csipSimpleConfig.getVideo_capture_implementation();
videoCaptureFactory.setInit_factory_name(pjsua.pj_str_copy("pjmedia_webrtc_vid_capture_factory"));
videoCaptureFactory.setShared_lib_path(pjVideoFile);

// Video codecs
List<CodecInfo> availableCodecs = Lists.newArrayList(
        new CodecInfo(NativeLibManager.getLibraryPath(mContext, "libpj_video_android.so"),
                "pjmedia_codec_ffmpeg_vid_init", "pjmedia_codec_ffmpeg_vid_deinit"),

        new CodecInfo(NativeLibManager.getLibraryPath(mContext, "libpj_vpx.so"),
                "pjmedia_codec_vpx_init", "pjmedia_codec_vpx_deinit")
);

dynamic_factory[] cssCodecs = csipSimpleConfig.getExtra_vid_codecs();
dynamic_factory[] cssCodecsDestroy = csipSimpleConfig.getExtra_vid_codecs_destroy();

int videoCodecIndex = 0;
for (CodecInfo codecInfo : availableCodecs) {
    if (!TextUtils.isEmpty(codecInfo.mLibraryPath)) {
        // Create
        cssCodecs[videoCodecIndex].setShared_lib_path(pjsua.pj_str_copy(codecInfo.mLibraryPath));
        cssCodecs[videoCodecIndex].setInit_factory_name(pjsua.pj_str_copy(codecInfo.mFactoryInitFunction));
        // Destroy
        cssCodecsDestroy[videoCodecIndex].setShared_lib_path(pjsua.pj_str_copy(codecInfo.mLibraryPath));
        cssCodecsDestroy[videoCodecIndex].setInit_factory_name(pjsua.pj_str_copy(codecInfo.mFactoryDeinitFunction));
    }
    videoCodecIndex++;
}

csipSimpleConfig.setExtra_vid_codecs_cnt(videoCodecIndex);

// Converter
dynamic_factory convertImpl = csipSimpleConfig.getVid_converter();
convertImpl.setShared_lib_path(pjVideoFile);
convertImpl.setInit_factory_name(pjsua.pj_str_copy("pjmedia_libswscale_converter_init"));

NativeLibManager:

public static String getLibraryPath(Context context, String libraryName) {
    String libraryPath = "";

    PackageManager packageManager = context.getPackageManager();

    PackageInfo packageInfo = null;

    if (packageManager != null) {
        try {
            packageInfo = packageManager.getPackageInfo(context.getPackageName(), PackageManager.GET_SHARED_LIBRARY_FILES);
        } catch (NameNotFoundException e) {
            logger.error(e.getMessage());
        }
    }

    File libFile = getLibFileFromPackage(packageInfo.applicationInfo, libraryName);

    if (libFile != null) {
        libraryPath = libFile.getAbsolutePath();
    }

        return libraryPath;
    }

To modify the build script you need to look at dispatch_shared_libs.sh, possible something along the lines of; (where "sipstack" is your csipsimple directory...)

move_generic_lib() {
    echo -n "Moving $1.so to $2 project ... "
    libs_files=$(ls libs/*/${1}.so 2> /dev/null | wc -l | sed -e 's/^[ \t]*//')
    if [ "$libs_files" != "0" ]; then
        for lib_folder in libs/*; do
            if [ -d ${lib_folder} ]; then
                mkdir -p ../${2}/${lib_folder};
                mv ${lib_folder}/${1}.so ../${2}/${lib_folder}/${1}.so;
            fi
        done
        echo "[OK]";
    else
        echo "[--] - plugin not built"
    fi
}

move_lib() {
    move_generic_lib libpj_${1}_codec CSipSimpleCodec${2}
}

move_lib "g7221" "Pack"
move_lib "codec2" "Pack"
move_lib "opus" "Pack"
move_lib "g726" "Pack"
move_lib "aac" "Pack"
move_lib "g729" "G729"
move_generic_lib "libcrypto" "sipstack"
move_generic_lib "libssl" "sipstack"
move_generic_lib "libpj_video_android" "sipstack"

move_generic_lib "libpj_screen_capture_android" "sipstack"
move_generic_lib "libpj_vpx" "sipstack"
Lunar
  • 4,663
  • 7
  • 43
  • 51
  • Thanks for your help, Lunar. But where can I get libpj_video_android.so file? – valerybodak Mar 19 '14 at 12:32
  • You will need to build that file, so do "make VideoLibs". – Lunar Mar 19 '14 at 13:54
  • Wow, I thought that this two alternative ways: 1. http://code.google.com/p/csipsimple/wiki/HowToBuild#Build_native_library 2. http://code.google.com/p/csipsimple/wiki/HowToBuild#Without_building_the_native_library – valerybodak Mar 19 '14 at 14:04
  • I have some prebuilt ones here ... http://snk.to/f-cdhps1cd but you really need to learn how to built them. – Lunar Mar 19 '14 at 14:05
  • The "Without building the native library" requires you to pull out the.so files from the Nightly Build APK... however video is not in the nightly build. – Lunar Mar 19 '14 at 14:07
  • Lunar, thanks, but your archive is either in unknown format or damaged. Also I will try do this yourself. – valerybodak Mar 19 '14 at 14:15
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/50043/discussion-between-anivaler-and-lunar) – valerybodak Mar 19 '14 at 14:15
  • 1
    Hi @Lunar I am trying to use your code.. but I got error on CodecInfo as "CodecInfo cannot be resolved to a type". Please tell me what is missing and from where I can import is this call in to PjsipService.java – Karan Nagpal May 10 '15 at 10:13
  • 1
    Hi @Lunar I am trying to use your code.. but I got error on csipSimpleConfig as "csipSimpleConfig cannot be resolved to a type". Please tell me what is missing and from where I can import is this call in to PjsipService.java – osimer pothe Dec 28 '15 at 09:09
  • @Lunar, from where to find "CodecInfo" class? And also what is "Lists" in Lists.newArrayList(...) line? – Rahul Patidar Aug 30 '17 at 10:59