Recording of a conversation in another thread - why does it work this way?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello.
I create a *. wav file recording of the conversation. I use Pjsip code
in version
1.0. The project I compile to DLL, and issuance of the method provide by
__declspec (dllexport). These methods it calls later in C #. The above
described solution downloaded from
http://sites.google.com/site/sipekvoip/sipeksdk.

Today I added the method by which I start recording conversations. Below is
the code for the recording.

When calling the method start recording I get an exception: "attempted to
read or write protected memory. This is an indication That Often other
memory is corrupt." The problem disappears when I start recording, in
another thread.

WHY?



/*******************************************************************************/
/******************** TEO VINCENT RECORDING
************************************/
/*******************************************************************************/
struct RecordingCallData
{
    pjsua_call_id       m_callId;
    //pj_str_t            m_recFile;
    pjsua_recorder_id    m_recId;
    pjsua_conf_port_id    m_recPort;
    pjsua_conf_port_id    m_confSlot;
    pj_bool_t            m_inUse;
};

static struct RecordingCalls
{
    struct RecordingCallData        m_arrRec[32];
} s_recordingCalls;

static void PrintMessageAboutRecordingCall(int a_recordIndex)
{
    PJ_LOG(3,(THIS_FILE, "[i=%d] InUse=%d CallId=%d RecFile=__ ConfSlot=%d
RecId=%d RecPort=%d"
                ,a_recordIndex
                ,s_recordingCalls.m_arrRec[a_recordIndex].m_inUse
                ,s_recordingCalls.m_arrRec[a_recordIndex].m_callId
                //,s_recordingCalls.m_arrRec[a_recordIndex].m_recFile
                ,s_recordingCalls.m_arrRec[a_recordIndex].m_confSlot
                ,s_recordingCalls.m_arrRec[a_recordIndex].m_recId
                ,s_recordingCalls.m_arrRec[a_recordIndex].m_recPort));
}

static void PrintAllRecordingCallsArrayInfo()
{
    int i;
    PJ_LOG(3,(THIS_FILE, "PrintAllRecordingCallsArrayInfo"));
    for(i = 0; i < 32; i++)
        PrintMessageAboutRecordingCall(i);
}

static void CleanRecordingOneCallInArray(int a_recordIndex)
{
    s_recordingCalls.m_arrRec[a_recordIndex].m_inUse = PJ_FALSE;
    s_recordingCalls.m_arrRec[a_recordIndex].m_callId = -100;
    //s_recordingCalls.m_arrRec[a_recordIndex].m_recFile = "";
    s_recordingCalls.m_arrRec[a_recordIndex].m_confSlot = -100;
    s_recordingCalls.m_arrRec[a_recordIndex].m_recId = -100;
    s_recordingCalls.m_arrRec[a_recordIndex].m_recPort = -100;
}

static void CleanRecordingCallsArray()
{
    unsigned i;
    for(i = 0; i < 32; i++)
        CleanRecordingOneCallInArray(i);
}

void StartRecording(pjsua_call_id a_callID, pj_str_t a_fileName, pj_bool_t
a_isRecFromSlot, pj_bool_t a_isRecFormMicrophone)
{
    unsigned freeItemIndex;
    pj_bool_t isFindEmptyPlace;
    pjsua_call_info callInfo;
    pj_status_t status;

    freeItemIndex = -1;

    PJ_LOG(3,(THIS_FILE, "StartRecording(CallID=%d FileName=%s
IsRecFromSlot=%d IsRecFromMicrophone=%d)", a_callID, a_fileName,
a_isRecFromSlot, a_isRecFormMicrophone));

    status = pjsua_call_get_info(a_callID, &callInfo);
    if (status != PJ_SUCCESS)
    {
        PJ_LOG(3,(THIS_FILE, "Blad w metodzie pjsua_call_get_info(..) i
nagrywania NIE BEDZIE"));
        return;
    }

    {
        unsigned i;
        // Odszukanie pierwszego wolnego mijesca w tablicy gdzie b?dzie
mo?na przechowa? info po??czeniu
        for(i = 0; i < 32; i++)
            if(s_recordingCalls.m_arrRec[i].m_inUse == PJ_FALSE)
            {
                freeItemIndex = i;
                PJ_LOG(3,(THIS_FILE, "Pierwsze wolne miejsce w tablicy info
o nagraniach to = %d", freeItemIndex));
                break;
            }
    }

    if(freeItemIndex == -1)
    {
        PJ_LOG(3,(THIS_FILE, "Brak miejsca w tablic
s_recordingCalls.m_arrRec i nagrywania NIE BEDZIE"));
        return;
    }

    s_recordingCalls.m_arrRec[freeItemIndex].m_inUse = PJ_TRUE;
    s_recordingCalls.m_arrRec[freeItemIndex].m_callId = a_callID;
    //s_recordingCalls.m_arrRec[freeItemIndex].m_recFile = a_fileName;
    s_recordingCalls.m_arrRec[freeItemIndex].m_confSlot =
callInfo.conf_slot;

    status = pjsua_recorder_create(&a_fileName, 0, NULL, 0, 0,
&s_recordingCalls.m_arrRec[freeItemIndex].m_recId);
    if (status != PJ_SUCCESS)
    {
        CleanRecordingOneCallInArray(freeItemIndex);
        PJ_LOG(3,(THIS_FILE, "Blad w metodzie pjsua_recorder_create(..) i
nagrywania NIE BEDZIE"));
        return;
    }

    s_recordingCalls.m_arrRec[freeItemIndex].m_recPort =
pjsua_recorder_get_conf_port(s_recordingCalls.m_arrRec[freeItemIndex].m_recId);

    PJ_LOG(3,(THIS_FILE, "ROZPOCZETE nagranie"));
    PrintMessageAboutRecordingCall(freeItemIndex);

    // Dokladam porty z ktorych bedzie nagrywany dzwiek
    if(s_recordingCalls.m_arrRec[freeItemIndex].m_recPort !=
PJSUA_INVALID_ID)
    {
        if (a_isRecFromSlot == PJ_TRUE)
        {
            status =
pjsua_conf_connect(s_recordingCalls.m_arrRec[freeItemIndex].m_confSlot,
s_recordingCalls.m_arrRec[freeItemIndex].m_recPort); //rtp to pliku
            if (status != PJ_SUCCESS)
            {
                CleanRecordingOneCallInArray(freeItemIndex);
                PJ_LOG(3,(THIS_FILE, "Blad w metodzie
pjsua_conf_connect(rtp -> file.wav) i nagrywania NIE BEDZIE"));
                return;
            }
        }
        else
        {
            PJ_LOG(3,(THIS_FILE, "NIE BEDZIE NAGRYWANE Z SLOTA"));
            PrintMessageAboutRecordingCall(freeItemIndex);
        }

        if (a_isRecFormMicrophone == PJ_TRUE)
        {
            status = pjsua_conf_connect(0,
s_recordingCalls.m_arrRec[freeItemIndex].m_recPort); //microphone to pliku
            if (status != PJ_SUCCESS)
            {
                CleanRecordingOneCallInArray(freeItemIndex);
                PJ_LOG(3,(THIS_FILE, "Blad w metodzie
pjsua_conf_connect(microphone -> file.wav) i nagrywania NIE BEDZIE"));
                return;
            }
        }
        else
        {
            PJ_LOG(3,(THIS_FILE, "NIE BEDZIE NAGRYWANE Z MIKROFONA"));
            PrintMessageAboutRecordingCall(freeItemIndex);
        }
    }

    PrintAllRecordingCallsArrayInfo();
}

void StopRecording(pjsua_call_id a_callID)
{
    int findItemIndex;
    pj_status_t status;

    findItemIndex = -1;

    {
        unsigned i;
        for(i = 0; i < 32; i++)
            if(s_recordingCalls.m_arrRec[i].m_inUse == PJ_TRUE &&
s_recordingCalls.m_arrRec[i].m_callId == a_callID)
            {
                findItemIndex = i;
                PJ_LOG(3,(THIS_FILE, "Znalazlem info o nagraniu na pozycji
= %d", findItemIndex));
                break;
            }
    }

    if(findItemIndex == -1)
    {
        PJ_LOG(3,(THIS_FILE, "Nie znalazlem nagrania - nie mozna go
zakonczyc wiec."));
    }
    else
    {
        PJ_LOG(3,(THIS_FILE, "Znalazlem nagranie by ZAKONCZYC"));
        PrintMessageAboutRecordingCall(findItemIndex);
        status =
pjsua_recorder_destroy(s_recordingCalls.m_arrRec[findItemIndex].m_recId);
        if (status != PJ_SUCCESS)
        {
                PJ_LOG(3,(THIS_FILE, "Blad w metodzie
pjsua_recorder_destroy(..)"));
                return;
        }
        CleanRecordingOneCallInArray(findItemIndex);
    }

    PrintAllRecordingCallsArrayInfo();
}
int dll_startRecording(int a_sessionId, char* a_fileName, bool
a_recFromRtp, bool a_recFormMicrophone)
{
    StartRecording(a_sessionId, pj_str(a_fileName), a_recFromRtp,
a_recFormMicrophone);
    return 123456;
}

int dll_stopRecording(int a_sessionId)
{
    StopRecording(a_sessionId);
    return 654321;
}




Pozdrawiam:
Artur Wincenciak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20120202/fbac5531/attachment.html>


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux