Tuesday, April 24, 2012

[SKYPEKIT][DM368][IPNC] H.264 QQVGA Encoding with DM36x

    According to Skypekit Video RTP host requirement, "Skype requires that all video endpoints support 160x120 video (QQVGA) to ensure a minimum level of interoperability." Thus, the first job is to ask DM368 to do QQVGA encoding (in H.264).

It seemed to be an easy job since in UI_setConfig( )@avServerUi.c, we can set
config->encodeConfig[i].cropWidth and
config->encodeConfig[i].cropHeight
to desired resolution and let the framework to do the rest.

However, it's not easy as dummy thought (代誌不是像憨人想的那麼簡單). you will find that the change will result in VIDEO_encodeTskRun error because the alg framework ALG_vidEncRun( )@alg_vidEnc.c returns error with message


CODEC RUN FAIL ERROR CODE: -1 32784 12206
 ERROR  (videoEncodeThr.c|VIDEO_encodeTskRun|292): ALG_vidEncRun()

because of the print statement 

OSA_printf("CODEC RUN FAIL ERROR CODE: %d %d %d\n", status, 264OutArgs.videncOutArgs.extendedError, h264OutArgs.videncOutArgs.bytesGenerated);




the 2nd returned error code (extendedError, 0x8010 in hex)  means IH264VENC_ERR_PROCESS_CALL

It's quite annoyed because there is not other detail information describing this error and the user's guide "H.264 Base/Main/High Profile Encoder on DM365/DM368" doesn't either. Thankfully by searching e2e forum, I found someone had the same problem, in post

DM36x H.264 encoder error 0x8010 at relatively high bitrates+low resolutions

Although it doesn't provide the exact solution, the hint is to reduce desired bitrate, which is a parameter of av_server.out if you are using IPNC platform.

for QQVGA, you can set the bitrate as low as 320k, or even set 0. rather than 5M in original, and the error is gone and I am able to get streamed QQVGA H264 video successfully.

Tuesday, April 10, 2012

[SKYPEKIT][DM368][IPNC] Revised: the Reason of "Account::LOGOUTREASON Unknown:673000" in Tutorials

In  Starting Skypekit on DM368-IPNC - setup environment and build the 1st tutorial example, we discussed  "Account::LOGOUTREASON<Unknown:673000>" problem in end of the article.  There we introduced a workaround to reduce the chance generating this error message.


After digging into skypekit examples a little bit deeper, the root cause *might be* found because improperly trying to get "GetPropLogoutreason", in MyAccount::OnChange@tutorial_common.h.


The original implementation imply that after Account::P_STATUS fired, the Account::LOGOUTREASON has already prepared, which *might* not be true. It can only be sure after Account::P_LOGOUTREASON is fired.


To fix this, try to catch Account::P_LOGOUTREASON at MyAccount::OnChange, Then you are safe to invoke 
this->GetPropLogoutreason for the logout reason.


Note:
Sorry I cannot put the code piece here because of skypekit legal term. but it's easy to patch by yourselves even with even little of experience of skypekit.

Monday, March 26, 2012

[SKYPEKIT][DM368][IPNC] Starting Skypekit on DM368-IPNC - setup environment and build the 1st tutorial example

It's interesting to have this project to enable Skype on DM368 device, specifically, Appro's IPNC. I got support from boss to initiate this trial project, after requesting funding for more than 6 months.

First of all, I registered "SkypeKit for Embedded", a $5 cost. According to the instruction, I did

1. register a (test) application and version at https://developer.skype.com/
2. download a runtime and an application token (key pair).
    (and sdk. I got skypekit-sdk_sdk-3.7.0.20_xxxxxxx.tar.gz for sdk, linux-armv5-skypekit-voicepcm-videortp_3.7.0.103_xxxxxxx.tar.gz for runtime, and a keypair.pem)
3. save the key pair as keypair.pem file in examples/cpp/tutorial/keypair
4. re-build C++ wrapper from project files located in interfaces/skype/cpp_embedded/build directory.
5. build tutorials from project files located in examples/cpp/tutorial/build

As a dm368-ipnc user, life is not that easy since you won't get it compiled or worked just follow the instructions above.

Note: this article includes sdk 3.7 and 4.1.2. Although 3.7 is stable, officially, I found that 4.1.2(beta) is actually more stable than 3.7.

[This Section is for SDK 3.7]

To make tutorial_1 running, the steps are:

1. Prepare the build environment. 
here I used Rules.make to setup parameters so the only thing to be patched is including "Rules.make" in Makefile.

Rules.make example:


TARGET_ARCH := armv5le-eabi
MVTOOL_PREFIX := arm_v5t_le-
TOOLCHAIN_PREFIX := /opt/mv_pro_5.0.0/montavista/pro/devkit/arm/v5t_le/bin/$(MVTOOL_PREFIX)
CC := $(MVTOOL_PREFIX)gcc
CXX := $(MVTOOL_PREFIX)g++
AR := $(MVTOOL_PREFIX)ar
LD := $(MVTOOL_PREFIX)ld
export CC
export CXX
export AR
you could also want to install utility "premake" from industriousone


2. Build skypekit-cyassl_lib and skypekit-cppwrapper_2_lib.
this is required before build tutorial example!
run make at [skypekit-sdk-dir]/interfaces/skype/cpp_embedded/build/gmake/

3. Build target tutorial 
before building, I had to copy keypair.pem to  [skypekit-sdk-dir]/examples/cpp/tutorial/keypair/
enter [skypekit-sdk-dir]/examples/cpp/tutorial/build/gmake/
make tutorial_1

now I have executable tutorial_1 and skypekit runtime linux-armv5-skypekit-voicepcm-videortp in hand. Per instruction, execute runtime as daemon and run tutorial_1 should demonstrate skype login and logout process.

./linux-armv5-skypekit-voicepcm-videortp &
it will show some information like below

SkypeRuntime Copyright (C) 2003-2012 Skype Technologies S.A.
SkypeRuntime Version: 3.7/linux-armv5-skypekit-voicepcm-videortp_3.7.0.103_xxxxxxx
Proprietary and confidential, do not share this application.


./tutorial_1 [skypename] [password]
Unfortunately, this test failed with messages below


*****************************************************************
 SkypeKit Tutorial, Step 1 - Login with skypename and password.
*****************************************************************
Creating skype ..
Getting account ..
Logging in..
UnixSocket.cpp:101(Connect): /tmp/vidrtp_from_skypekit_key: failed to connect: error #111
UnixSocket.cpp:101(Connect): /tmp/pcm_from_skypekit_key: failed to connect: error #111
PCM client connection was not established.
SidPCMClient.cpp:43(SkypePCMInterfaceGet): Skypekit will exit.
there are several discussions at skypekit forum but no explicitly answer as far. Mostly "Account::LOGOUTREASON<Unknown:0>" problem instead. After digging a little bit deeper, I found that the answer is simple - we need not only  C++ wrapper from project files located in interfaces/skype/cpp_embedded/build directory, but also video/voice host to hook with SkypeKit API. Of course, it is not necessary if your skypekit runtime is chat only (i.e. no video and voice post fix)

4. Build (loopback) video and voice host engines
since my runtime is of videortp and voicepcm option, run make at
[skypekit-sdk-dir]/reference/videortphost-loopback
[skypekit-sdk-dir]/reference/voicepcmhost-loopback
the executables can be found under ./build respectively.

5. Test tutorial 1 again

./linux-armv5-skypekit-voicepcm-videortp &
./videortphost-loopback &
./voicepcmhost-loopback &
./tutorial_1 [skypename] [password]

and the terminal shows

*****************************************************************
 SkypeKit Tutorial, Step 1 - Login with skypename and password.
*****************************************************************
Creating skype ..
Getting account ..
Logging in..
AVTransportWrapper (/tmp/pcm_from_skypekit_key): connected!
AVTransportWrapper (/tmp/pcm_from_skypekit_key): connected!
AVTransportWrapper (/tmp/pcm_to_skypekit_key): connected!
AVTransportWrapper (/tmp/pcm_to_skypekit_key): connected!
Init
UseDefaultDevice: INPUT_DEVICE
UseDefaultDevice: OUTPUT_DEVICE
UseDefaultDevice: NOTIFICATION_DEVICE
GetCurrentDevice: INPUT_DEVICE, guid0
UseDevice: INPUT_DEVICE, guid0
UseDevice: OUTPUT_DEVICE, guid0
UseDefaultDevice: NOTIFICATION_DEVICE
GetCurrentDevice: INPUT_DEVICE, guid0
GetDevices: INPUT_DEVICE
GetDevices: OUTPUT_DEVICE
Stop: INPUT_DEVICE
Stop: OUTPUT_DEVICE
Stop: NOTIFICATION_DEVICE
UseDevice: INPUT_DEVICE, guid0
UseDevice: OUTPUT_DEVICE, guid0
UseDefaultDevice: NOTIFICATION_DEVICE
GetCurrentDevice: INPUT_DEVICE, guid0
UseDevice: INPUT_DEVICE, guid0
UseDevice: OUTPUT_DEVICE, guid0
UseDefaultDevice: NOTIFICATION_DEVICE
GetCurrentDevice: INPUT_DEVICE, guid0
GetCurrentDevice: INPUT_DEVICE, guid0
Start: INPUT_DEVICE
Stop: INPUT_DEVICE
GetCurrentDevice: OUTPUT_DEVICE, guid0
GetCurrentDevice: NOTIFICATION_DEVICE, guid0
Start: OUTPUT_DEVICE
Stop: OUTPUT_DEVICE
Stop: INPUT_DEVICE
Stop: OUTPUT_DEVICE
Stop: NOTIFICATION_DEVICE
Login complete.
Press ENTER to log out...

Note:
if there is segmentation fault or Account::LOGOUTREASON.SERVER_CONNECT_FAILED, try to run ./killall and stop av_server.out. your system memory maybe limited to run this tutorial


[This Section is for SDK 4.1.2(Beta 4.1)]

The C++ wrapper library no longer ships with pre-made project files. Instead, the SDK now comes with CMake scripts. Thus, I had to change [skypekit_sdk]/interfaces/skype/cpp_embedded/cmake-build/CMakeCache.txt which was generated by running [skype_sdk]/interfaces/skype/cpp_embedded/BuildWithCmake.sh.

the change example including:
CMAKE_AR:FILEPATH
CMAKE_CXX_COMPILER:FILEPATH
CMAKE_C_COMPILER:FILEPATH
CMAKE_LINKER:FILEPATH
CMAKE_MAKE_PROGRAM:FILEPATH
CMAKE_OBJCOPY:FILEPATH
CMAKE_OBJDUMP:FILEPATH
CMAKE_STRIP:FILEPATH
the others are similar to SDK 3.7

Note2: Sometime there is login error with message "Account::LOGOUTREASON.SERVER_CONNECT_FAILED" or "Account::LOGOUTREASON<Unknown:673000>" or 
"Account::LOGOUTREASON<Unknown:0>"
The reason is not clarified as far (MAR2012) but it should be skypekit runtime problem. I added a delay before invoking "LoginWithPassword" (i.e. Delay(50)), and tried certain times if failed, to remedy this problem. The insertion of Delay can reduce the chance to be forced logout anyway.