예제 #1
0
파일: signal.cpp 프로젝트: cgestes/libqi
 bool SignalBasePrivate::disconnect(const SignalLink& l)
 {
   SignalSubscriberPtr s;
   {
     // Acquire signal mutex
     boost::recursive_mutex::scoped_lock sigLock(mutex);
     SignalSubscriberMap::iterator it = subscriberMap.find(l);
     if (it == subscriberMap.end())
       return false;
     s = it->second;
     // Remove from map (but SignalSubscriber object still good)
     subscriberMap.erase(it);
     // Acquire subscriber mutex before releasing mutex
     boost::mutex::scoped_lock subLock(s->mutex);
     // Release signal mutex
     sigLock.release()->unlock();
     // Ensure no call on subscriber occurrs once this function returns
     s->enabled = false;
     if (subscriberMap.empty() && onSubscribers)
       onSubscribers(false);
     if ( s->activeThreads.empty()
          || (s->activeThreads.size() == 1
              && *s->activeThreads.begin() == boost::this_thread::get_id()))
     { // One active callback in this thread, means above us in call stack
       // So we cannot trash s right now
       return true;
     }
     // More than one active callback, or one in a state that prevent us
     // from knowing in which thread it will run
     subLock.release()->unlock();
   }
   s->waitForInactive();
   return true;
 }
예제 #2
0
파일: subbuf.c 프로젝트: codywon/bell-jpg
void ClearH264SubBuf( void )
{
    subLock();
    encbufs.firstflag = 0x00;
    encbufs.firstflag = 0x00;
    encbufs.prelen = 0x00;
    encbufs.preindex = 0x00;
    encbufs.totallen = 0x00;
    subUnlock();
}
예제 #3
0
파일: subbuf.c 프로젝트: codywon/bell-jpg
void PushVSencData( unsigned char* pbuf, char type, char size, int len, unsigned int frameno )
{  
    LIVEHEAD        	livehead;       //livestream head
    struct timeval  	tv;
    struct timezone 	tz;
    char				flag = 0x00;

    subLock();
    
    if ( encbufs.firstflag == 0x01 )
    {
        if ( encbufs.totallen + len + sizeof( LIVEHEAD )  > EBUF_MAX_SLEN )
        {
            printf( "sub len > maxlen total %d len %d\n", encbufs.totallen, len );
            flag = 0x01;
        }
    }

    else
    {
        if ( encbufs.totallen + len + sizeof( LIVEHEAD )  > EBUF_MAX_SLEN / 2 )
        {
            printf( "sub len > maxlen/2\n" );
            flag = 0x01;
        }
    }

    if ( ( type == 0x00 ) || ( flag == 0x01 ) )
    {
        if ( encbufs.firstflag == 0x01 )
        {
            encbufs.firstindex	= encbufs.index;
            encbufs.index     	= 0x00;
            encbufs.totallen  	= 0x00;
            encbufs.firstflag 	= 0x00;
            SetSubStreamFlag( 0x01 );
        }

        else
        {
            encbufs.firstindex	= encbufs.index;
            encbufs.index     	= 0x00;
            encbufs.totallen  	= EBUF_MAX_SLEN / 2;
            encbufs.firstflag 	= 0x01;
            SetSubStreamFlag( 0x02 );
        }
    }

    gettimeofday( &tv, &tz );
    livehead.type             = type;
    livehead.len               = len;
    livehead.streamid       = 0;
    livehead.frameno        = frameno;
    livehead.militime         = tv.tv_usec / 1000;
		
    livehead.sectime         = tv.tv_sec;
    livehead.startcode		= STARTCODE;
    livehead.size			= size;

    livehead.framerate = GetSubFrameRate();
    //push data
    memcpy( (char*)(pbufs + encbufs.totallen), &livehead, sizeof( LIVEHEAD ) ); //livestream head
    memcpy( (char*)(pbufs + encbufs.totallen + sizeof( LIVEHEAD )), pbuf, len ); //media data

    encbufs.prelen = encbufs.totallen;
    encbufs.preindex = encbufs.index;
    encbufs.totallen += len + sizeof( LIVEHEAD );
    encbufs.index++;

    subUnlock();
}