示例#1
0
文件: server.c 项目: raphui/rdb
/* void *arg is a argumentReceivingThread_t type */
void receivingThread( void *arg )
{
    TRACE_2( SERVER , "receivingThread()");

    char buff[BUFF_SIZE];
    char input[] = "rdb_remote~>";
    int ret;
    void *cliRet;

    argumentReceivingThread_t *arguments = ( argumentReceivingThread_t * )arg;

    TRACE_3( SERVER , "Thread argument: socket: %d , port: %d" , arguments->socket , arguments->port );

    TRACE_1( SERVER , "[!]Receiving thread create !");

    if( arguments->port == PORT_CLI )
        sendVoidSocket( arguments->socket , input , sizeof( input ) );
    else
		TRACE_1( SERVER , "Port not used at the moment.\n");

    while( 1 )
    {
        memset( buff , 0 , BUFF_SIZE );

        ret = recv( arguments->socket , buff , BUFF_SIZE , 0 );

        if( ret > 0 )
        {

            if( arguments->port == PORT_CLI )
            {
                TRACE_3( SERVER , "[+]Data: %s" , buff );

                cliRet = doCommand( buff );

                if( cliRet != NULL )
                {
                    sendVoidSocket( arguments->socket , cliRet , strlen( ( const char * )cliRet ) );

                    zfree( cliRet );

//                    sendVoidSocket( arguments->socket , input , sizeof( input ) );
                }
            }
        }

    }

    TRACE_3( SERVER , "[!]Quitting receiving thread !");

    releaseThread();

    pthread_exit( NULL );
}
// -----------------------------------------------------------------------------
// CXIMPSrvSessionAdapter::ServiceError()
// -----------------------------------------------------------------------------
//
EXPORT_C void CXIMPSrvSessionAdapter::ServiceError( const RMessage2& /*aMessage*/,
                                                    TInt aError )
    {
    //If assert below is triggered, it means that current message ownersip
    //is taken somewhere (to be completed asynchronously), but there has
    //happened a leave after ownership transfer

    //The place taking message ownership has to be fixed in this case
    //not to cause exeptions after ownership transfer
    __ASSERT_ALWAYS( iCurrentMsg,
                     User::Panic( NXIMPPrivPanic::KCategory,
                                  NXIMPPrivPanic::ECurrentMsgNotFoundInServiceError ) );


    //If assert below is triggered, it means that current message is already
    //completed, but there has happened a leave after completion

    //The place completing message has to be fixed in this case
    //not to cause exeptions after message completion
    __ASSERT_ALWAYS( !iCurrentMsg->IsCompleted(),
                     User::Panic( NXIMPPrivPanic::KCategory,
                                  NXIMPPrivPanic::ECurrentMsgNotValidInServiceError ) );


    TRACE_3( _L("CXIMPSrvSessionAdapter[%d]::ServiceError() in op[%d], code[%d]"),
                 this, iCurrentMsg->Function(), aError );


    iCurrentMsg->Complete( aError );
    delete iCurrentMsg;
    iCurrentMsg = NULL;
    }
示例#3
0
/**
 * Send discarded notifications to a lib which will be received by the
 * saNtfDiscarded callback function.
 *
 *   @param discardedInfo struct that contains a list of notification id's for
 *                        the notifications to be discarded.
 *
 *   @return          return value = 1 if ok -1 if failed
 */
int send_discard_notification_lib(ntfsv_discarded_info_t *discardedInfo, uns32 c_id, SaNtfSubscriptionIdT s_id, MDS_DEST mds_dest)
{
	uns32 rc = NCSCC_RC_SUCCESS;
	ntfsv_msg_t msg;
	TRACE_ENTER();
#if DISCARDED_TEST
	/* TODO REMOVE TEST */
	if ((disc_test_cntr % 20)) {
		TRACE_3("FAKE DISKARDED");
		return NCSCC_RC_FAILURE;
	}
	/* END TODO REMOVE TEST */
#endif
	memset(&msg, 0, sizeof(ntfsv_msg_t));
	msg.type = NTFSV_NTFS_CBK_MSG;
	msg.info.cbk_info.type = NTFSV_DISCARDED_CALLBACK;
	msg.info.cbk_info.ntfs_client_id = c_id;
	msg.info.cbk_info.subscriptionId = s_id;
	msg.info.cbk_info.param.discarded_cbk.notificationType = discardedInfo->notificationType;
	msg.info.cbk_info.param.discarded_cbk.numberDiscarded = discardedInfo->numberDiscarded;
	msg.info.cbk_info.param.discarded_cbk.discardedNotificationIdentifiers = discardedInfo->discardedNotificationIdentifiers;

	rc = ntfs_mds_msg_send(ntfs_cb, &msg, &mds_dest, NULL,	/* send regular msg */
					 MDS_SEND_PRIORITY_HIGH);
	if (rc != NCSCC_RC_SUCCESS) {
		TRACE_1("ntfs_mds_msg_send to ntfa failed rc: %d", (int)rc);
	} else {
		sendNotConfirmUpdate(c_id, s_id, 0, NTFS_NOTIFICATION_DISCARDED_LIST_SENT);
	}
	TRACE_LEAVE();
	return (rc);
}
示例#4
0
文件: cli.c 项目: medTheCoder/rdb
void *doCommand( char *cmd )
{
    TRACE_2( CLI , "doCommand( %s )." , cmd );

	int i = 0;	
    int idFuncptr;
    void *ret = NULL;
	char *ptr = NULL;

    /* Dynamic allocation, because after send the response throught the socket, free() is called. (If it's declare like -char errorMsg[]="zedze"- this will crash for sure.) */
    char *errorMsg = NULL; 

	ptr = strtok( cmd , " ");

	env->arg_count = 0;

	for( i = 0 ; i < MAX_GENERIC_VAL ; i++ )
	{
		ptr = strtok( NULL , " " );
		
		if( !ptr )
			break;

		env->genericVal[i] = ptr;
		env->arg_count++;
	}

	if( env->arg_count > 0 )
	{
		/* Remove '\n' character from the last argument */
		ptr = env->genericVal[env->arg_count - 1];
		*( ptr + strlen( ptr ) - 1 ) = 0;
	}


    if( ( idFuncptr = searchCliCmd( cmd ) ) >= 0 )
    {
        TRACE_3( CLI , "Execute function.");

        ret = ( void * )cliCmd[idFuncptr].func( env );

        TRACE_1( CLI , "Function return: %d" , ret );
    }
    else
    {
        TRACE_ERROR( CLI , "Command is not supported.");

		errorMsg = ( char * )zmalloc( 28 * sizeof( char ) );

		memset( errorMsg , 0 , 28 );

        sprintf( errorMsg , "Command is not supported.\n");

        ret = ( void * )errorMsg;
    }

    return ret;
}
示例#5
0
/****************************************************************************
  Name          : ava_hdl_cbk_dispatch_one
 
  Description   : This routine dispatches one pending callback.
 
  Arguments     : cb      - ptr to the AvA control block
                  hdl_rec - ptr to the handle record
 
  Return Values : SA_AIS_OK/SA_AIS_ERR_<CODE>
 
  Notes         : None.
******************************************************************************/
uint32_t ava_hdl_cbk_dispatch_one(AVA_CB **cb, AVA_HDL_REC **hdl_rec)
{
	AVA_PEND_RESP *list_resp = &(*hdl_rec)->pend_resp;
	AVA_PEND_CBK_REC *rec = 0;
	uint32_t hdl = (*hdl_rec)->hdl;
	SaAmfCallbacksT reg_cbk;
	uint32_t rc = SA_AIS_OK;
	TRACE_ENTER();

	memset(&reg_cbk, 0, sizeof(SaAmfCallbacksT));
	memcpy(&reg_cbk, &(*hdl_rec)->reg_cbk, sizeof(SaAmfCallbacksT));

	/* pop the rec from the mailbox queue */
	rec = (AVA_PEND_CBK_REC *)m_NCS_IPC_NON_BLK_RECEIVE(&(*hdl_rec)->callbk_mbx, NULL);

	if (rec) {

		if (rec->cbk_info->type != AVSV_AMF_PG_TRACK) {
			/* push this record into pending response list */
			m_AVA_HDL_PEND_RESP_PUSH(list_resp, (AVA_PEND_RESP_REC *)rec);
			m_AVA_HDL_CBK_REC_IN_DISPATCH_SET(rec);
		}

		/* release the cb lock & return the hdls to the hdl-mngr */
		m_NCS_UNLOCK(&(*cb)->lock, NCS_LOCK_WRITE);
		ncshm_give_hdl(hdl);

		/* process the callback list record */
		ava_hdl_cbk_rec_prc(rec->cbk_info, &reg_cbk);

		m_NCS_LOCK(&(*cb)->lock, NCS_LOCK_WRITE);

		if (0 == (*hdl_rec = ncshm_take_hdl(NCS_SERVICE_ID_AVA, hdl))) {
			/* hdl is already finalized */
			ava_hdl_cbk_rec_del(rec);
			TRACE_LEAVE2("Handle is already finalized");
			return rc;
		}

		/* if we are done with this rec, free it */
		if ((rec->cbk_info->type != AVSV_AMF_PG_TRACK) && m_AVA_HDL_IS_CBK_RESP_DONE(rec)) {
			m_AVA_HDL_PEND_RESP_POP(list_resp, rec, rec->cbk_info->inv);
			ava_hdl_cbk_rec_del(rec);
		} else if (rec->cbk_info->type == AVSV_AMF_PG_TRACK) {
			/* PG Track cbk do not have any response */
			ava_hdl_cbk_rec_del(rec);
		} else {
			m_AVA_HDL_CBK_REC_IN_DISPATCH_RESET(rec);
		}

	}
	else
		TRACE_3("No record to process the dispatch()");

	TRACE_LEAVE();
	return rc;
}
示例#6
0
文件: player.c 项目: raphui/wMusic
void end_of_track( sp_session *session )
{
    TRACE_2( PLAYERMANAGER , "end_of_track().");

    TRACE_3( PLAYERMANAGER , "End of track...");

//    LOCK_MUTEX( PLAYERMANAGER , &mutexSession );

    TRACE_3( PLAYERMANAGER , "Removing the track which have been played.");

    sp_track_release( currentTrack );

//    UNLOCK_MUTEX( PLAYERMANAGER , &mutexSession );

//    if( hasNextTrack() == TRUE )
//    {
//        TRACE_1( PLAYERMANAGER , "Load next music !");

//        playMusic( session , "" , currentStreamName );
//    }
    if( nextTrackInStream( currentStreamName ) == PC_SUCCESS )
    {
        TRACE_1( PLAYERMANAGER , "Load next music !");

    }
    else
    {
        TRACE_WARNING( PLAYERMANAGER , "No more music in the mainplaylist");

        audio_fifo_flush( &g_audiofifo );

        LOCK_MUTEX( PLAYERMANAGER , &mutexSession );

        sp_session_player_play( session , 0 );
        sp_session_player_unload( session );

        UNLOCK_MUTEX( PLAYERMANAGER , &mutexSession );

        playing = FALSE;
    }



}
示例#7
0
文件: player.c 项目: raphui/wMusic
int createTrackFromUri( char *uri , char *name )
{
    TRACE_2( PLAYERMANAGER , "createTrackFromUri( %s , __track__ )" , uri );

    sp_link *link;
    sp_error error;

    if( playing == FALSE && hasNextTrack() == FALSE )
        createFile( name );

    TRACE_1( PLAYERMANAGER , "Creating URI : %s" , uri );

    link = sp_link_create_from_string( uri );

    if( link == NULL )
    {
        TRACE_ERROR( PLAYERMANAGER , "Fail to create link.");

        return PC_ERROR;
    }
    else
    {
        TRACE_1( PLAYERMANAGER , "Success to create link.");
    }

    TRACE_3( PLAYERMANAGER , "Construct track...");

    currentTrack = sp_link_as_track( link );

    if( currentTrack == NULL )
    {
        TRACE_ERROR( PLAYERMANAGER , "Fail to create track.");

        return PC_ERROR;
    }
    else
    {
        TRACE_1( PLAYERMANAGER , "Success to create track.");
    }

    error = sp_track_add_ref( currentTrack );

    if( error != SP_ERROR_OK )
    {
        TRACE_ERROR( PLAYERMANAGER , "Cannot add ref track, reason: %s" , sp_error_message( error ) );

        return PC_ERROR;
    }

    sp_link_release( link );

    running = TRUE;
//    playing = FALSE;

    return PC_SUCCESS;
}
示例#8
0
/**
 * Sends and receives an unregister message using osaf_secutil
 * @param evt_type
 * @param mds_dest
 * @param version
 * @param out_evt
 * @param timeout max time to wait for a response in ms unit
 * @return 0 - OK, negated errno otherwise
 */
int mds_auth_server_disconnect(const char *name, MDS_DEST mds_dest, int svc_id, int timeout)
{
	uint32_t rc;
	uint8_t msg[32];
	uint8_t *p = msg;
	uint32_t sz;
	int n;

	sz = ncs_encode_32bit(&p, MDS_UNREGISTER_REQ);
	sz += ncs_encode_32bit(&p, svc_id);
	sz += ncs_encode_64bit(&p, mds_dest);

	n = osaf_auth_server_connect(name, msg, sz, msg,
			sizeof(msg), timeout);

	if (n < 0) {
		TRACE_3("err n:%d", n);
		rc = NCSCC_RC_FAILURE;
		goto fail;
	} else if (n == 0) {
		TRACE_3("tmo");
		rc = NCSCC_RC_REQ_TIMOUT;
		goto fail;
	} else if (n == 8) {
		p = msg;
		int type = ncs_decode_32bit(&p);
		if (type != MDS_UNREGISTER_RESP) {
			TRACE_3("wrong type %d", type);
			rc = NCSCC_RC_FAILURE;
			goto fail;
		}
		int status = ncs_decode_32bit(&p);
		TRACE("received type:%d, status:%d", type, status);
		status == 0 ? (rc = NCSCC_RC_SUCCESS) : (rc = NCSCC_RC_FAILURE);
	} else {
		TRACE_3("err n:%d", n);
		rc = NCSCC_RC_FAILURE;
		goto fail;
	}

fail:
	return rc;
 }
示例#9
0
/******************************************************************************
 * Utility functions for get_number_of_log_files_hdl
 */
static int check_oldest(char *line, char *fname_prefix, int fname_prefix_size, int *old_date, int *old_time)
{
	int date, time, c, d;
	date = time = c = d = 0;
	int len = 0;
	char name_format[SA_MAX_NAME_LENGTH];
	char time_stamps[] = "_%d_%d_%d_%d.log";

	len = strlen(time_stamps);
	len += fname_prefix_size;

	strncpy(name_format, fname_prefix, fname_prefix_size);
	name_format[fname_prefix_size] = '\0';
	TRACE_3("fname: %s", name_format);
	strncat(name_format, time_stamps, SA_MAX_NAME_LENGTH-1);
	if (sscanf(line, name_format, &date, &time, &c, &d) == 4) {
		TRACE_3("line: arg1: %d 2: %d 3: %d 4: %d ok", date, time, c, d);
		if (date < *old_date || *old_date == -1) {
			*old_date = date;
			*old_time = time;
			return 1;
		} else if ((date == *old_date) && (time < *old_time)) {
			*old_date = date;
			*old_time = time;
			return 1;
		}
	} else if (sscanf(line, name_format, &date, &time) == 2) {
		TRACE_3("line: arg1: %d 2: %d ok", date, time);
		if (date < *old_date || *old_date == -1) {
			*old_date = date;
			*old_time = time;
			return 1;
		} else if ((date == *old_date) && (time < *old_time)) {
			*old_date = date;
			*old_time = time;
			return 1;
		}
	} else {
		TRACE_3("no match");
	}
	return 0;
}
示例#10
0
文件: Frontend.cpp 项目: rgly/pinavm
void Frontend::inlineProcessFct()
{
	for (Process *proc : *(this->elab->getProcesses()) ) {
		Function *F = proc->getMainFct();
		TRACE_3("Parsing Function : " << F->getName().str() << "\n");

		bool restartInlining = true;
		while(restartInlining) {
			restartInlining = this->inlineForProcessFct(F);
		}
	}
}
示例#11
0
/**
 *   Send notification to a lib which will be received by the
 *   SaNtfNotificationCallbackT function.
 *
 *   @param dispatchInfo contains all information about the notification.
 *
 *   @return return value == NCSCC_RC_SUCCESS if ok
 */
int send_notification_lib(ntfsv_send_not_req_t *dispatchInfo, uns32 client_id, MDS_DEST mds_dest)
{
	uns32 rc = NCSCC_RC_SUCCESS;
	ntfsv_msg_t msg;
	SaNtfNotificationHeaderT *header;
	int discarded = 0;
	
	TRACE_ENTER();
	ntfsv_get_ntf_header(dispatchInfo, &header);
	TRACE_3("client id: %u, not_id: %llu", client_id, *header->notificationId);	
	
#if DISCARDED_TEST
	/* TODO REMOVE TEST */
	if ((disc_test_cntr % 20)) {
		TRACE_3("FAKE DISKARDED");
		/* Allways confirm if not success notification will be put in discarded list. */
		notificationSentConfirmed(client_id, dispatchInfo->subscriptionId, *header->notificationId, NTFS_NOTIFICATION_DISCARDED);
		return NCSCC_RC_FAILURE;
	}
	/* END TODO REMOVE TEST */
#endif
	memset(&msg, 0, sizeof(ntfsv_msg_t));
	msg.type = NTFSV_NTFS_CBK_MSG;
	msg.info.cbk_info.type = NTFSV_NOTIFICATION_CALLBACK;
	msg.info.cbk_info.ntfs_client_id = client_id;
	msg.info.cbk_info.subscriptionId = dispatchInfo->subscriptionId;
	msg.info.cbk_info.param.notification_cbk = dispatchInfo;
	rc = ntfs_mds_msg_send(ntfs_cb, &msg, &mds_dest, NULL,	/* send regular msg */
			       MDS_SEND_PRIORITY_HIGH);
	if (rc != NCSCC_RC_SUCCESS) {
		discarded = NTFS_NOTIFICATION_DISCARDED;
		LOG_ER("ntfs_mds_msg_send to ntfa failed rc: %d", (int)rc);
	} 
	/* Allways confirm if not success notification will be put in discarded list. */
	notificationSentConfirmed(client_id, dispatchInfo->subscriptionId, *header->notificationId, discarded);
	TRACE_LEAVE();
	return (rc);
};
示例#12
0
/*!
 * \brief parse_ebml_element
 * \note 'bitstr' pointer is not checked for performance reasons.
 *
 * https://matroska.org/technical/specs/index.html
 * https://matroska.org/technical/specs/rfc/index.html
 */
int parse_ebml_element(Bitstream_t *bitstr, EbmlElement_t *element)
{
    TRACE_3(MKV, "parse_ebml_element()");
    int retcode = SUCCESS;

    if (element == NULL)
    {
        TRACE_ERROR(MKV, "Invalid EbmlElement_t structure!");
        retcode = FAILURE;
    }
    else
    {
        // Set element offset
        element->offset_start = bitstream_get_absolute_byte_offset(bitstr);

        // Read element ID
        {
            uint32_t ebml_leadingZeroBits = 0;
            uint32_t ebml_size = 0;

            while (read_bit(bitstr) == 0 && ebml_leadingZeroBits < 4)
                ebml_leadingZeroBits++;

            ebml_size = (ebml_leadingZeroBits + 1) * 7;
            element->eid_size = (ebml_size + ebml_leadingZeroBits + 1) / 8;
            element->eid = read_bits_64(bitstr, ebml_size) + pow(2, ebml_size);
        }

        // Read element size
        {
            uint32_t ebml_leadingZeroBits = 0;
            uint32_t ebml_size = 0;

            while (read_bit(bitstr) == 0 && ebml_leadingZeroBits < 8)
                ebml_leadingZeroBits++;

            ebml_size = (ebml_leadingZeroBits + 1) * 7;
            element->size_size = (ebml_size + ebml_leadingZeroBits + 1) / 8;
            element->size = read_bits_64(bitstr, ebml_size);
        }

        // Set end offset
        element->offset_end = element->offset_start + (element->eid_size + element->size_size + element->size);
    }

    return retcode;
}
示例#13
0
/*!
 * \brief Read an EBML element size.
 * \param *bitstr The bitstream to read.
 * \return The element size.
 */
uint64_t read_ebml_size(Bitstream_t *bitstr)
{
    uint32_t leadingZeroBits = 0;
    uint32_t sizeSize = 0;
    uint64_t sizeValue = 0;

    while (read_bit(bitstr) == 0 && leadingZeroBits < 8)
        leadingZeroBits++;

    sizeSize = (leadingZeroBits + 1) * 7;
    sizeValue = read_bits_64(bitstr, sizeSize);

    TRACE_2(MKV, "read_ebml_size()");
    TRACE_3(MKV, "- leadingZeroBits = %u", leadingZeroBits);
    TRACE_2(MKV, "- sizeSize        = %u", sizeSize);
    TRACE_2(MKV, "- sizeValue       = %llu", sizeValue);

    return sizeValue;
}
示例#14
0
文件: Frontend.cpp 项目: rgly/pinavm
void Frontend::handleConstruct_and_GV()
{
	// Walk through call graph and build intermediate representation
	std::vector < Function * >*fctStack = new std::vector < Function * >();

	for (Process *proc : *(this->elab->getProcesses()) ) {
		fctStack->push_back(proc->getMainFct());
		proc->addUsedFunction(proc->getMainFct());
		this->scjit->setCurrentProcess(proc);
		TRACE_2("Process:" << proc->getName() << "\n");
		while (!fctStack->empty()) {
			Function* F = fctStack->back();
			fctStack->pop_back();
			TRACE_3("Parsing Function : " << F->getName().str() << "\n");
			PRINT_3(F->dump());
			this->handleFctConstruct_and_GV(proc, F, fctStack);
		}
	}
	delete fctStack;
}
示例#15
0
文件: player.c 项目: raphui/wMusic
int music_delivery( sp_session *session , const sp_audioformat *format , const void *frames , int num_frames )
{
    TRACE_2( PLAYERMANAGER , "music_delivery().");

    TRACE_3( PLAYERMANAGER , "Playing music...%d" , num_frames );

    audio_fifo_t *af = &g_audiofifo;
    audio_fifo_data_t *afd;
    size_t s;

    TRACE_3( PLAYERMANAGER , "###############################################");
    TRACE_3( PLAYERMANAGER , "Channels: %d" , format->channels );
    TRACE_3( PLAYERMANAGER , "Rate: %d" , format->sample_rate );
    TRACE_3( PLAYERMANAGER , "NSamples: %d" , num_frames );
    TRACE_3( PLAYERMANAGER , "###############################################");

    // audio discontinuity, do nothing
    if( num_frames == 0 )
    {
        pthread_mutex_unlock( &af->mutex );
        return 0;
    }

    // buffer one second of audio
    if( af->qlen > format->sample_rate )
        return 0;

    s = num_frames * sizeof( int16_t ) * format->channels;
    afd = zmalloc( sizeof( *afd ) + s );

    afd->channels = format->channels;

    afd->rate = format->sample_rate;

    afd->nsamples = num_frames;

    memcpy( afd->samples , frames , s );

    TAILQ_INSERT_TAIL( &af->q , afd , link );
    af->qlen += num_frames;

    pthread_cond_signal( &af->cond );
    pthread_mutex_unlock( &af->mutex );

    return num_frames;
}
示例#16
0
文件: player.c 项目: raphui/wMusic
int nextMusic( sp_session *session , char *uri )
{
    TRACE_2( PLAYERMANAGER , "nextMusic( __session__ , %s )." , uri );

    int status = PC_SUCCESS;

    TRACE_3( PLAYERMANAGER , "Getting next track from the playqueue.");

    if( hasNextTrack() == TRUE )
    {
        TRACE_1( PLAYERMANAGER , "Playing next track.");

//        playMusic( g_session , NULL );
    }
    else
    {
        TRACE_ERROR( PLAYERMANAGER , "No next track in the playqueue.");

        status = PC_ERROR;
    }

    return status;
}
示例#17
0
void MiniTraces_info(void)
{
    unsigned i = 0;

    printf(PID BLD_GREEN "\nMiniTraces_infos()" CLR_RESET " version 0.4\n");

    printf(PID "\n* TRACE LEVELS ENABLED:\n");
    TRACE_ERROR(MAIN, "ERROR traces enabled\n");
    TRACE_WARNING(MAIN, "WARNING traces enabled\n");
    TRACE_INFO(MAIN, "INFO traces enabled\n");
    TRACE_1(MAIN, "LVL 1 traces enabled\n");
    TRACE_2(MAIN, "LVL 2 traces enabled\n");
    TRACE_3(MAIN, "LVL 3 traces enabled\n");

    printf(PID "\n* TRACE MODULES CONFIGURATION:\n");
    for (i = 0; i < trace_module_count; i++)
    {
        printf(PID "[%02x][%5s] Trace Mask 0x%X: ", i,
               trace_modules_table[i].module_name,
               trace_modules_table[i].module_output_mask);

        print_trace_levels(trace_modules_table[i].module_output_mask);
    }
}
示例#18
0
/*!
 * \param *dc The current DecodingContext.
 * \param startIdx docme.
 * \param endIdx docme.
 *
 * Decode the chroma coefficients of the macroblock. There can only be 4x4 block size.
 * Start by decoding DC coefficients for Cr block, then Cb block.
 * Then decode 4 AC blocks of Cb and 4 AC blocks of Cr.
 */
static void residual_chroma(DecodingContext_t *dc, const int startIdx, const int endIdx)
{
    TRACE_INFO(MB, "<> " BLD_GREEN "residual_chroma()\n" CLR_RESET);

    // Shortcuts
    Macroblock_t *mb = dc->mb_array[dc->CurrMbAddr];
    sps_t *sps = dc->sps_array[dc->pps_array[dc->active_slice->pic_parameter_set_id]->seq_parameter_set_id];

    //
    if (dc->ChromaArrayType == 1 || dc->ChromaArrayType == 2)
    {
        int iCbCr = 0;
        int NumC8x8 = 4 / (sps->SubWidthC * sps->SubHeightC);

        for (iCbCr = 0; iCbCr < 2; iCbCr++)
        {
            if ((mb->CodedBlockPatternChroma & 3) && (startIdx == 0))
            {
                TRACE_2(MB, "---- residual_chroma 4x4 DC (mb %i - iCbCr %i - blk 0) ---------------- START\n", mb->mbAddr, iCbCr);

                if (dc->entropy_coding_mode_flag)
                    residual_block_cabac(dc, mb->ChromaDCLevel[iCbCr], 0, 4 * NumC8x8 - 1, 4 * NumC8x8, blk_CHROMA_DC_Cb + iCbCr, 0);
                else
                    residual_block_cavlc(dc, mb->ChromaDCLevel[iCbCr], 0, 4 * NumC8x8 - 1, 4 * NumC8x8, blk_CHROMA_DC_Cb + iCbCr, 0);
            }
            else
            {
                TRACE_2(MB, "---- residual_chroma 4x4 DC (mb %i - iCbCr %i - blk 0) ---------------- EMPTY\n\n", mb->mbAddr, iCbCr);

                int i = 0;
                for (i = 0; i < (4 * NumC8x8); i++)
                {
                    mb->ChromaDCLevel[iCbCr][i] = 0;
                }
            }
        }

        for (iCbCr = 0; iCbCr < 2; iCbCr++)
        {
            int blkIdx = 0;
            int i8x8 = 0;
            for (i8x8 = 0; i8x8 < NumC8x8; i8x8++)
            {
                int i4x4 = 0;
                for (i4x4 = 0; i4x4 < 4; i4x4++)
                {
                    blkIdx = i8x8*4 + i4x4;

                    if (mb->CodedBlockPatternChroma & 2)
                    {
                        TRACE_2(MB, "---- residual_chroma 4x4 AC (mb %i - iCbCr %i - blk %i/3) ---------------- START\n", mb->mbAddr, iCbCr, blkIdx);

                        if (dc->entropy_coding_mode_flag)
                            residual_block_cabac(dc, mb->ChromaACLevel[iCbCr][blkIdx], MAX(0, startIdx - 1), endIdx - 1, 15, blk_CHROMA_AC_Cb + iCbCr, blkIdx);
                        else
                            residual_block_cavlc(dc, mb->ChromaACLevel[iCbCr][blkIdx], MAX(0, startIdx - 1), endIdx - 1, 15, blk_CHROMA_AC_Cb + iCbCr, blkIdx);
                    }
                    else
                    {
                        TRACE_2(MB, "---- residual_chroma 4x4 AC (mb %i - iCbCr %i - blk %i/3) ---------------- EMPTY\n\n", mb->mbAddr, iCbCr, blkIdx);

                        int i = 0;
                        for (i = 0; i < 15; i++)
                        {
                            mb->ChromaACLevel[iCbCr][blkIdx][i] = 0;
                        }
                    }
                }
            }
        }
    }

    TRACE_3(MB, "---- residual_chroma - the end\n\n");
}
示例#19
0
/*!
 * \param *dc The current DecodingContext.
 * \param startIdx docme.
 * \param endIdx docme.
 *
 * 7.4.5.3.1 Residual luma data semantics.
 * Output of this syntax structure are the variables i16x16DClevel, i16x16AClevel, level, and level8x8.
 *
 * This function decode the luma coefficients contained in a macroblock. It can
 * handle 16x16 block (composed of one 4x4 DC block and 16 4x4 AC blocks)
 * 4x4 blocks (16 4x4 blocks) and 8x8 blocks (4 8x8 blocks).
 */
static void residual_luma(DecodingContext_t *dc, const int startIdx, const int endIdx)
{
    TRACE_INFO(MB, "<> " BLD_GREEN "residual_luma()\n" CLR_RESET);

    // Shortcut
    Macroblock_t *mb = dc->mb_array[dc->CurrMbAddr];

    //
    if (startIdx == 0 && mb->MbPartPredMode[0] == Intra_16x16)
    {
        TRACE_2(MB, "---- residual_luma 4x4 DC (mb %i - blk 0) ---------------- START - 16x16 DC\n", mb->mbAddr);

        if (dc->entropy_coding_mode_flag)
            residual_block_cabac(dc, mb->Intra16x16DCLevel, 0, 15, 16, blk_LUMA_16x16_DC, 0);
        else
            residual_block_cavlc(dc, mb->Intra16x16DCLevel, 0, 15, 16, blk_LUMA_16x16_DC, 0);
    }

    int blkIdx = 0;
    int i8x8 = 0;
    for (i8x8 = 0; i8x8 < 4; i8x8++)
    {
        if (mb->transform_size_8x8_flag == false || dc->entropy_coding_mode_flag == false)
        {
            int i4x4 = 0;
            for (i4x4 = 0; i4x4 < 4; i4x4++)
            {
                blkIdx = i8x8*4 + i4x4;

                if (mb->CodedBlockPatternLuma & (1 << i8x8))
                {
                    if (mb->MbPartPredMode[0] == Intra_16x16)
                    {
                        TRACE_2(MB, "---- residual_luma 16x16 AC (mb %i - blk %i/15) ---------------- START - 16x16 AC\n", mb->mbAddr, blkIdx);

                        if (dc->entropy_coding_mode_flag)
                            residual_block_cabac(dc, mb->Intra16x16ACLevel[blkIdx], MAX(0, startIdx - 1), endIdx - 1, 15, blk_LUMA_16x16_AC, blkIdx);
                        else
                            residual_block_cavlc(dc, mb->Intra16x16ACLevel[blkIdx], MAX(0, startIdx - 1), endIdx - 1, 15, blk_LUMA_16x16_AC, blkIdx);
                    }
                    else
                    {
                        TRACE_2(MB, "---- residual_luma 4x4 (mb %i - blk %i/15) ---------------- START\n", mb->mbAddr, blkIdx);

                        if (dc->entropy_coding_mode_flag)
                            residual_block_cabac(dc, mb->LumaLevel4x4[blkIdx], startIdx, endIdx, 16, blk_LUMA_4x4, blkIdx);
                        else
                            residual_block_cavlc(dc, mb->LumaLevel4x4[blkIdx], startIdx, endIdx, 16, blk_LUMA_4x4, blkIdx);
                    }
                }
                else if (mb->MbPartPredMode[0] == Intra_16x16)
                {
                    TRACE_2(MB, "---- residual_luma 16x16 AC (mb %i - blk %i/15) ---------------- EMPTY - no 16x16 AC coeff\n\n", mb->mbAddr, blkIdx);

                    int i = 0;
                    for (i = 0; i < 15; i++)
                    {
                        mb->Intra16x16ACLevel[blkIdx][i] = 0;
                        mb->TotalCoeffs_luma[blkIdx] = 0;
                    }
                }
                else
                {
                    TRACE_2(MB, "---- residual_luma 4x4 (mb %i - blk %i/15) ---------------- EMPTY\n\n", mb->mbAddr, blkIdx);

                    int i = 0;
                    for (i = 0; i < 16; i++)
                    {
                        mb->LumaLevel4x4[blkIdx][i] = 0;
                        mb->TotalCoeffs_luma[blkIdx] = 0;
                    }
                }

                if (!dc->entropy_coding_mode_flag && mb->transform_size_8x8_flag)
                {
                    TRACE_2(MB, "---- residual_luma 8x8 from 4x4 (mb %i) ----------------\n\n", mb->mbAddr, blkIdx);

                    int i = 0;
                    for (i = 0; i < 16; i++)
                    {
                        mb->LumaLevel8x8[i8x8][4 * i + i4x4] = mb->LumaLevel4x4[blkIdx][i];
                    }
                }
            }
        }
        else if (mb->CodedBlockPatternLuma & (1 << i8x8))
        {
            TRACE_2(MB, "---- residual_luma 8x8 (mb %i - blk %i/3) ---------------- START\n", mb->mbAddr, i8x8);

            if (dc->entropy_coding_mode_flag)
                residual_block_cabac(dc, mb->LumaLevel8x8[i8x8], 4 * startIdx, 4 * endIdx + 3, 64, blk_LUMA_8x8, i8x8);
            else
                residual_block_cavlc(dc, mb->LumaLevel8x8[i8x8], 4 * startIdx, 4 * endIdx + 3, 64, blk_LUMA_8x8, i8x8);
        }
        else
        {
            TRACE_2(MB, "---- residual_luma 8x8 (mb %i - blk %i/3) ---------------- EMPTY\n\n", mb->mbAddr, i8x8);

            int i = 0;
            for (i = 0; i < 64; i++)
            {
                mb->LumaLevel8x8[i8x8][i] = 0;
            }
        }
    }

    TRACE_3(MB, "---- residual_luma - the end\n\n");
}
示例#20
0
文件: mp3.cpp 项目: emericg/MiniVideo
int mp3_fileParse(MediaFile_t *media)
{
    int retcode = SUCCESS;

    TRACE_INFO(MP3, BLD_GREEN "mp3_fileParse()" CLR_RESET);

    // Init bitstream to parse container infos
    Bitstream_t *bitstr = init_bitstream(media, NULL);

    if (bitstr != NULL)
    {
        // Init a MediaStream_t to store samples
        retcode = init_bitstream_map(&media->tracks_audio[0], 0, 999999);

        // Init an MP3 structure
        mp3_t mp3;
        memset(&mp3, 0, sizeof(mp3_t));

        // A convenient way to stop the parser
        mp3.run = true;

        // stuff
        int64_t min_frame_size = 128;
        int64_t frame_offset = 0;
        uint32_t frame_header = 0;
        bool first_frame_parsed = false;

        // Loop on 1st level elements
        while (mp3.run == true &&
               retcode == SUCCESS &&
               bitstream_get_absolute_byte_offset(bitstr) < (media->file_size - min_frame_size))
        {
            // Seek to the next frame offset // Assume the MP3 frames will not be bigger than 4Gib
            uint32_t jump_bits = (uint32_t)(frame_offset - bitstream_get_absolute_byte_offset(bitstr)) * 8;
            if (jump_bits > 0)
                skip_bits(bitstr, jump_bits);

            // Read the next frame header
            frame_header = read_bits(bitstr, 32);

            // note: check frame header against 11 bits long instead of 12, to be compatible with MPEG-1/2/2.5
            if ((frame_header & 0xFFE00000) == 0xFFE00000)
            {
                TRACE_1(MP3, "> MP3 frame @ %lli", frame_offset);

                if (first_frame_parsed == false)
                {
                    frame_offset = parse_frame_full(bitstr, frame_header, &mp3, media);

                    if (frame_offset > 0)
                        first_frame_parsed = true;
                    else
                        retcode = FAILURE;
                }
                else
                {
                    frame_offset = parse_frame(bitstr, frame_header, &mp3, media);
                }
            }
            else if ((frame_header & 0xFFFFFF00) == 0x54414700)
            {
                TRACE_INFO(MP3, "> ID3v1 tag @ %lli", frame_offset);
                mp3.run = false;

                // Add the TAG to the track
                int sid = media->tracks_audio[0]->sample_count;
                if (sid < 999999)
                {
                    media->tracks_audio[0]->sample_type[sid] = sample_AUDIO_TAG;
                    media->tracks_audio[0]->sample_size[sid] = media->file_size - frame_offset;
                    media->tracks_audio[0]->sample_offset[sid] = frame_offset;
                    media->tracks_audio[0]->sample_pts[sid] = 0;
                    media->tracks_audio[0]->sample_dts[sid] = 0;
                    media->tracks_audio[0]->sample_count++;
                }
            }
            else if ((frame_header & 0xFFFFFF00) == 0x49443300)
            {
                int id3tag_version = ((frame_header & 0x000000FF) << 8) + read_bits(bitstr, 8);
                /*int id3tag_flag =*/ read_bits(bitstr, 8);

                TRACE_INFO(MP3, "> ID3v2.%i @ %lli", id3tag_version, frame_offset);

                uint32_t id3tag_size = read_bits(bitstr, 8) & 0x0000007F;
                id3tag_size <<= 7;
                id3tag_size += read_bits(bitstr, 8) & 0x0000007F;
                id3tag_size <<= 7;
                id3tag_size += read_bits(bitstr, 8) & 0x0000007F;
                id3tag_size <<= 7;
                id3tag_size += read_bits(bitstr, 8) & 0x0000007F;
                id3tag_size += 10; // bytes already read

                // Add the TAG to the track
                int sid = media->tracks_audio[0]->sample_count;
                if (sid < 999999)
                {
                    media->tracks_audio[0]->sample_type[sid] = sample_AUDIO_TAG;
                    media->tracks_audio[0]->sample_size[sid] = id3tag_size;
                    media->tracks_audio[0]->sample_offset[sid] = frame_offset;
                    media->tracks_audio[0]->sample_pts[sid] = 0;
                    media->tracks_audio[0]->sample_dts[sid] = 0;
                    media->tracks_audio[0]->sample_count++;
                }

                // Simulate TAG parsing
                frame_offset += id3tag_size;
            }
            else if (frame_header == 0x4C595249)
            {
                TRACE_INFO(MP3, "> Lyrics3 tag @ %lli", frame_offset);
                frame_offset += 32; // just restart MP3 frame detection 32 bytes later...

                // Add the TAG to the track
                int sid = media->tracks_audio[0]->sample_count;
                if (sid < 999999)
                {
                    media->tracks_audio[0]->sample_type[sid] = sample_AUDIO_TAG;
                    media->tracks_audio[0]->sample_size[sid] = 0;
                    media->tracks_audio[0]->sample_offset[sid] = frame_offset;
                    media->tracks_audio[0]->sample_pts[sid] = 0;
                    media->tracks_audio[0]->sample_dts[sid] = 0;
                    media->tracks_audio[0]->sample_count++;
                }
            }
            else if (frame_header == 0x58696E67)
            {
                TRACE_INFO(MP3, "> XING tag @ %lli", frame_offset);
                frame_offset += 32; // just restart MP3 frame detection 32 bytes later...

                // Add the TAG to the track
                int sid = media->tracks_audio[0]->sample_count;
                if (sid < 999999)
                {
                    media->tracks_audio[0]->sample_type[sid] = sample_AUDIO_TAG;
                    media->tracks_audio[0]->sample_size[sid] = 0;
                    media->tracks_audio[0]->sample_offset[sid] = frame_offset;
                    media->tracks_audio[0]->sample_pts[sid] = 0;
                    media->tracks_audio[0]->sample_dts[sid] = 0;
                    media->tracks_audio[0]->sample_count++;
                }
            }
            else if (frame_header == 0x56425249)
            {
                TRACE_INFO(MP3, "> VBRI tag @ %lli", frame_offset);
                frame_offset += 32; // just restart MP3 frame detection 32 bytes later...

                // Add the TAG to the track
                int sid = media->tracks_audio[0]->sample_count;
                if (sid < 999999)
                {
                    media->tracks_audio[0]->sample_type[sid] = sample_AUDIO_TAG;
                    media->tracks_audio[0]->sample_size[sid] = 0;
                    media->tracks_audio[0]->sample_offset[sid] = frame_offset;
                    media->tracks_audio[0]->sample_pts[sid] = 0;
                    media->tracks_audio[0]->sample_dts[sid] = 0;
                    media->tracks_audio[0]->sample_count++;
                }
            }
            else if (frame_header == 0x41504554)
            {
                TRACE_WARNING(MP3, "> APE tag @ %lli", frame_offset);

                /*uint32_t apetag_header =*/ read_bits(bitstr, 32); // 0x41474558, second part of the tag header
                /*uint32_t apetag_version =*/ read_bits(bitstr, 32);
                uint32_t apetag_size = 8 + read_bits(bitstr, 32); //  APE header size (8 bytes) + tag content size

                // Add the TAG to the track
                int sid = media->tracks_audio[0]->sample_count;
                if (sid < 999999)
                {
                    media->tracks_audio[0]->sample_type[sid] = sample_AUDIO_TAG;
                    media->tracks_audio[0]->sample_size[sid] = apetag_size;
                    media->tracks_audio[0]->sample_offset[sid] = frame_offset;
                    media->tracks_audio[0]->sample_pts[sid] = 0;
                    media->tracks_audio[0]->sample_dts[sid] = 0;
                    media->tracks_audio[0]->sample_count++;
                }

                // Simulate TAG parsing
                frame_offset = frame_offset + apetag_size;
            }
            else
            {
                // Try to find a new startcode closeby...
                frame_offset += 1;
                TRACE_3(MP3, "Unknown frame header @ %lli (startcode: 0x%X)",
                        frame_offset, frame_header);
            }
        }

        if (retcode == SUCCESS)
        {
            retcode = mp3_indexer_track(media, &mp3);
            if (retcode == SUCCESS)
            {
                retcode = mp3_indexer(media, &mp3);
            }
        }
    }
    else
    {
        retcode = FAILURE;
    }

    return retcode;
}
示例#21
0
/****************************************************************************
  Name          : eda_eds_msg_proc
 
  Description   : This routine is used to process the ASYNC incoming
                  EDS messages. 
 
  Arguments     : pointer to struct ncsmds_callback_info
 
  Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE
 
  Notes         : None.
******************************************************************************/
static uint32_t eda_eds_msg_proc(EDA_CB *eda_cb, EDSV_MSG *edsv_msg, MDS_SEND_PRIORITY_TYPE prio)
{

	switch (edsv_msg->type) {
	case EDSV_EDS_CBK_MSG:
		switch (edsv_msg->info.cbk_info.type) {
		case EDSV_EDS_CHAN_OPEN:
			{
				EDA_CLIENT_HDL_REC *eda_hdl_rec;
				EDA_CHANNEL_HDL_REC *channel_hdl_rec;
				EDSV_EDA_CHAN_OPEN_CBK_PARAM *cbk_param = &edsv_msg->info.cbk_info.param.chan_open_cbk;
	    /** Create the chan hdl record here before 
             ** queing this message onto the priority queue
             ** so that the dispatch by the application to fetch
             ** the callback is instantaneous.
             **/

	    /** Lookup the hdl rec by reg_id 
             **/
				if (NULL == (eda_hdl_rec = eda_find_hdl_rec_by_regid(eda_cb,
										     edsv_msg->info.cbk_info.
										     eds_reg_id))) {
					TRACE_4("client handle record for reg_id: %u not found",
										 edsv_msg->info.cbk_info.eds_reg_id);
					eda_msg_destroy(edsv_msg);
					return NCSCC_RC_FAILURE;
				}

	    /** Create/add a channel record to the hdl rec with 
             ** the information received in this message. 
             ** only if the return status was SA_AIS_OK.
             **/
				if (SA_AIS_OK == cbk_param->error) {
					if (NULL == (channel_hdl_rec = eda_channel_hdl_rec_add(&eda_hdl_rec,
											       cbk_param->chan_id,
											       cbk_param->chan_open_id,
											       cbk_param->
											       chan_open_flags,
											       &cbk_param->
											       chan_name))) {
						TRACE_4("channel add failed for chan_id: %u, chan_open_id: %u, \
							channelname: %s", cbk_param->chan_id, cbk_param->chan_open_id,
											cbk_param->chan_name.value);
						eda_msg_destroy(edsv_msg);
						return NCSCC_RC_FAILURE;
					}

	      /** pass on the channel_hdl to the application thru cbk
               **/
					cbk_param->eda_chan_hdl = channel_hdl_rec->channel_hdl;
				}

	    /** enqueue this message anyway
             **/
				if (NCSCC_RC_SUCCESS != m_NCS_IPC_SEND(&eda_hdl_rec->mbx, edsv_msg, prio)) {
					TRACE_4("IPC send failed failed for msg type: %u", edsv_msg->type);
					return NCSCC_RC_FAILURE;
				}
			}
			break;
		case EDSV_EDS_DELIVER_EVENT:
			{
				EDA_CLIENT_HDL_REC *eda_hdl_rec;
				EDA_CHANNEL_HDL_REC *chan_hdl_rec;
				EDA_EVENT_HDL_REC *evt_hdl_rec;
				EDSV_EDA_EVT_DELIVER_CBK_PARAM *evt_dlv_param =
				    &edsv_msg->info.cbk_info.param.evt_deliver_cbk;

	    /** Lookup the hdl rec 
             **/
				if (NULL == (eda_hdl_rec = eda_find_hdl_rec_by_regid(eda_cb,
										     edsv_msg->info.cbk_info.
										     eds_reg_id))) {
					TRACE_4("reg record not found reg_id: %u", edsv_msg->info.cbk_info.eds_reg_id);
					edsv_free_evt_pattern_array(evt_dlv_param->pattern_array);
					evt_dlv_param->pattern_array = NULL;
		/** free the event data if any **/
					if (evt_dlv_param->data) {
						m_MMGR_FREE_EDSV_EVENT_DATA(evt_dlv_param->data);
						evt_dlv_param->data = NULL;
					}
					eda_msg_destroy(edsv_msg);
					return NCSCC_RC_FAILURE;
				}

	    /** Lookup the channel record to which
             ** this event belongs
             **/
				if (NULL == (chan_hdl_rec = eda_find_chan_hdl_rec_by_chan_id(eda_hdl_rec,
											     evt_dlv_param->chan_id,
											     evt_dlv_param->
											     chan_open_id))) {
					TRACE_4("chan rec not found for chan_id: %u, chan_open_id: %u", 
						evt_dlv_param->chan_id, evt_dlv_param->chan_open_id);
					edsv_free_evt_pattern_array(evt_dlv_param->pattern_array);
					evt_dlv_param->pattern_array = NULL;
		/** free the event data if any **/
					if (evt_dlv_param->data) {
						m_MMGR_FREE_EDSV_EVENT_DATA(evt_dlv_param->data);
						evt_dlv_param->data = NULL;
					}
					eda_msg_destroy(edsv_msg);
					return NCSCC_RC_FAILURE;
				}

	    /** Create/Add the new event record.
             **/
				if (NULL == (evt_hdl_rec = eda_event_hdl_rec_add(&chan_hdl_rec)))
				{
					edsv_free_evt_pattern_array(evt_dlv_param->pattern_array);
					evt_dlv_param->pattern_array = NULL;
		/** free the event data if any **/
					if (evt_dlv_param->data) {
						m_MMGR_FREE_EDSV_EVENT_DATA(evt_dlv_param->data);
						evt_dlv_param->data = NULL;
					}
					eda_msg_destroy(edsv_msg);
					TRACE_4("event record add failed");
					return NCSCC_RC_FAILURE;
				}

	    /** Initialize the fields in the evt_hdl_rec with data
             ** received in the message.
             **/
				evt_hdl_rec->priority = evt_dlv_param->priority;
				evt_hdl_rec->publisher_name = evt_dlv_param->publisher_name;
				evt_hdl_rec->publish_time = evt_dlv_param->publish_time;
				evt_hdl_rec->retention_time = evt_dlv_param->retention_time;
				evt_hdl_rec->event_data_size = evt_dlv_param->data_len;

	    /** mark the event as rcvd.
             **/
				evt_hdl_rec->evt_type |= EDA_EVT_RECEIVED;

	    /** Create/Add the new event inst record.
             **/

	    /** The evt hdl rec will take ownership of the memory
             ** for the patterns & data to avoid too many copies
             ** and not that much use of these in the callback.
             **/
				evt_hdl_rec->del_evt_id = evt_dlv_param->eda_event_id;
				evt_hdl_rec->pattern_array = evt_dlv_param->pattern_array;
				evt_dlv_param->pattern_array = NULL;

				evt_hdl_rec->evt_data = evt_dlv_param->data;
				evt_dlv_param->data = NULL;

				/* assign the newly allocated hdl */
				evt_dlv_param->event_hdl = evt_hdl_rec->event_hdl;

	    /** enqueue this message. MDS & IPC priority match 1-1 
             **/
				if (NCSCC_RC_SUCCESS != m_NCS_IPC_SEND(&eda_hdl_rec->mbx, edsv_msg, prio)) {
					TRACE_4("IPC send failed for msg type: %u", edsv_msg->type);
					return NCSCC_RC_FAILURE;
				}

			}
			break;
		case EDSV_EDS_CLMNODE_STATUS:
			{
				EDSV_EDA_CLM_STATUS_CBK_PARAM *clm_status_param =
				    &edsv_msg->info.cbk_info.param.clm_status_cbk;

				eda_cb->node_status = (SaClmClusterChangesT)clm_status_param->node_status;
				TRACE_1("Local node membership changed to : %u", eda_cb->node_status);
			}
			break;
		default:
			 TRACE_3("unknown message type: %u", edsv_msg->info.cbk_info.type);
			return NCSCC_RC_FAILURE;
			break;
		}
		break;
	case EDSV_EDS_MISC_MSG:
      /** No messages conceived yet **/
		TRACE_1("Unsupported message type");
		return NCSCC_RC_FAILURE;
		break;
	default:
      /** Unexpected message **/
		TRACE_4("Wrong message type");
		return NCSCC_RC_FAILURE;
		break;
	}
示例#22
0
文件: player.c 项目: raphui/wMusic
int playMusic( sp_session *session , char *uri , char *name , playqueue_fifo_t *playqueue )
{
    TRACE_2( PLAYERMANAGER , "playMusic().");

    static int firstTime = 0;

    int status = PC_SUCCESS;

    char response[255] = { 0 };

    sp_error error;

    LOCK_MUTEX( PLAYERMANAGER , &mutexSession );

    TRACE_3( PLAYERMANAGER , "Test if a music is playing or not");

    if( currentTrack == NULL )
    {
        TRACE_WARNING( PLAYERMANAGER , "Cannot play track because no track has been loaded.");

        status = PC_ERROR;

        snprintf( response , 255 , "NOK: Cannot play track because no track has been loaded.");

        sendVoid( ( void * )response , strlen( response ) );
    }
    else
    {
        TRACE_1( PLAYERMANAGER , "Getting the track.");


        currentTrack = getNextTrackToPlayqueue( playqueue );

        loadTrack( session ,  currentTrack );

        error = sp_session_player_play( session , 1 );

        if( error != SP_ERROR_OK )
        {
            TRACE_ERROR( PLAYERMANAGER , "Cannot play track, reason: %s" , sp_error_message( error ) );

            status = PC_ERROR;
        }
        else
        {
           TRACE_1( PLAYERMANAGER , "Success to play track.");

           if( firstTime++ != 0 )
               playStream( name );

           playing = TRUE;

           snprintf( response , 255 , "OK");

           sendVoid( ( void * )response , strlen( response ) );
        }

        if( currentStreamName[0] == 0 )
        {
            strncpy( currentStreamName , name , strlen( name ) );
        }
        else if( strcmp( currentStreamName , name ) != 0 )
        {
            memset( currentStreamName , 0 , 255 );
            strncpy( currentStreamName , name , strlen( name ) );
        }
        else if( !strcmp( currentStreamName , name ) )
        {
            //Do nothing
        }


    }

    UNLOCK_MUTEX( PLAYERMANAGER , &mutexSession );


    return status;
}
示例#23
0
文件: file.c 项目: raphui/wMusic
int createFile( char *name )
{
    TRACE_2( FILEMANAGER , "createFile( %s )." , name );

    FILE *f = NULL;
    FILE *h = NULL;
    wavHeader_t wavH;

    size_t ret;

    int status = PC_SUCCESS;

    memset( filename , 0 , 255 );

    sprintf( filename , "%s%s.wav" , STREAM_FOLDER , name );

    TRACE_INFO( FILEMANAGER , "Creating stream filename : %s." , filename );

    f = fopen( filename , "wb+");
    h = fopen( REF_FILE , "rb");

    if( f == NULL || h == NULL )
    {
        TRACE_ERROR( FILEMANAGER , "f or h FILE is NULL");

        status = PC_ERROR;
    }
    else
    {
        ret = fread( &wavH , sizeof( wavH ) , 1 ,  h );

        if( ret != 1 )
        {
            TRACE_ERROR( FILEMANAGER , "Fail to read all data.");

            status = PC_ERROR;
        }
        else
        {

            TRACE_3( FILEMANAGER , "######################################");
            TRACE_3( FILEMANAGER , "RIFF: %s" , wavH.RIFF );
            TRACE_3( FILEMANAGER , "ChunkSize: %d" , wavH.ChunkSize );
            TRACE_3( FILEMANAGER , "WAVE: %s" , wavH.WAVE );
            TRACE_3( FILEMANAGER , "fmt: %s" , wavH.fmt );
            TRACE_3( FILEMANAGER , "Subchunk1Size: %d" , wavH.Subchunk1Size );
            TRACE_3( FILEMANAGER , "AudioFormat: %d" , wavH.AudioFormat );
            TRACE_3( FILEMANAGER , "NumOfchan: %d" , wavH.NumOfChan );
            TRACE_3( FILEMANAGER , "SamplesPerSec: %d" , wavH.SamplesPerSec );
            TRACE_3( FILEMANAGER , "bytesPerSec: %d" , wavH.bytesPerSec );
            TRACE_3( FILEMANAGER , "blockAlign: %d" , wavH.blockAlign );
            TRACE_3( FILEMANAGER , "bitsPerSample: %d" , wavH.bitsPerSample );
            TRACE_3( FILEMANAGER , "Subchunk2ID: %s" , wavH.Subchunk2ID );
            TRACE_3( FILEMANAGER , "Subchunk2Size: %d" , wavH.Subchunk2Size );
            TRACE_3( FILEMANAGER , "######################################");

            wavH.ChunkSize = 36 + wavH.Subchunk2Size;
            wavH.Subchunk1Size = 16;
            wavH.AudioFormat = 1;
            wavH.NumOfChan = 2;
            wavH.SamplesPerSec = 44100;
            wavH.bytesPerSec = wavH.SamplesPerSec * wavH.NumOfChan * 16 / 8;
            wavH.blockAlign = wavH.NumOfChan * 16 / 8;
            wavH.bitsPerSample = 16;
            memcpy( wavH.Subchunk2ID , "data" , 4 );


            ret = fwrite( &wavH , sizeof( wavH ) , 1 , f );

            if( ret != 1 )
            {
                TRACE_ERROR( FILEMANAGER , "Fail to write all data.");

                status = PC_ERROR;
            }
        }

        fclose( f );
        fclose( h );
    }

    return status;
}
示例#24
0
/*!
 * \param *dc The current DecodingContext.
 * \param CurrMbAddr The address of the current macroblock.
 * \return The address of the next macroclock.
 *
 * Because this decoder do not support interlaced mode or slice partitioning or
 * flexible macroblock ordering (FMO) the NextMbAddress returned by this function
 * is always CurrMbAddr + 1.
 */
unsigned int NextMbAddress(DecodingContext_t *dc, const unsigned int CurrMbAddr)
{
    TRACE_3(MB, "> " BLD_GREEN "NextMbAddress()" "= %i\n" CLR_RESET, CurrMbAddr + 1);

    return CurrMbAddr + 1;
}
示例#25
0
/*
 * wrapper for qi_putp entry in module ops vec.
 * implements asynchronous putnext().
 * Note, that unlike putnext(), this routine is NOT optimized for the
 * fastpath.  Calling this routine will grab whatever locks are necessary
 * to protect the stream head, q_next, and syncq's.
 * And since it is in the normal locks path, we do not use putlocks if
 * they exist (though this can be changed by swapping the value of
 * UseFastlocks).
 */
void
put(queue_t *qp, mblk_t *mp)
{
	queue_t		*fqp = qp; /* For strft tracing */
	syncq_t		*sq;
	uint16_t	flags;
	uint16_t	drain_mask;
	struct qinit	*qi;
	int		(*putproc)();
	int		ix;
	boolean_t	queued = B_FALSE;
	kmutex_t	*sqciplock = NULL;
	ushort_t	*sqcipcount = NULL;

	TRACE_2(TR_FAC_STREAMS_FR, TR_PUT_START,
		"put:(%X, %X)", qp, mp);
	ASSERT(mp->b_datap->db_ref != 0);
	ASSERT(mp->b_next == NULL && mp->b_prev == NULL);

	sq = qp->q_syncq;
	ASSERT(sq != NULL);
	qi = qp->q_qinfo;

	if (UseFastlocks && sq->sq_ciputctrl != NULL) {
		/* fastlock: */
		ASSERT(sq->sq_flags & SQ_CIPUT);
		ix = CPU->cpu_seqid & sq->sq_nciputctrl;
		sqciplock = &sq->sq_ciputctrl[ix].ciputctrl_lock;
		sqcipcount = &sq->sq_ciputctrl[ix].ciputctrl_count;
		mutex_enter(sqciplock);
		if (!((*sqcipcount) & SQ_FASTPUT) ||
		    (sq->sq_flags & (SQ_STAYAWAY|SQ_EXCL|SQ_EVENTS))) {
			mutex_exit(sqciplock);
			sqciplock = NULL;
			goto slowlock;
		}
		(*sqcipcount)++;
		ASSERT(*sqcipcount != 0);
		queued = qp->q_sqflags & Q_SQQUEUED;
		mutex_exit(sqciplock);
	} else {
	    slowlock:
		ASSERT(sqciplock == NULL);
		mutex_enter(SQLOCK(sq));
		flags = sq->sq_flags;
		/*
		 * We are going to drop SQLOCK, so make a claim to prevent syncq
		 * from closing.
		 */
		sq->sq_count++;
		ASSERT(sq->sq_count != 0);		/* Wraparound */
		/*
		 * If there are writers or exclusive waiters, there is not much
		 * we can do.  Place the message on the syncq and schedule a
		 * background thread to drain it.
		 *
		 * Also if we are approaching end of stack, fill the syncq and
		 * switch processing to a background thread - see comments on
		 * top.
		 */
		if ((flags & (SQ_STAYAWAY|SQ_EXCL|SQ_EVENTS)) ||
		    (sq->sq_needexcl != 0) || PUT_STACK_NOTENOUGH()) {

			TRACE_3(TR_FAC_STREAMS_FR, TR_PUTNEXT_END,
			    "putnext_end:(%p, %p, %p) SQ_EXCL fill",
			    qp, mp, sq);

			/*
			 * NOTE: qfill_syncq will need QLOCK. It is safe to drop
			 * SQLOCK because positive sq_count keeps the syncq from
			 * closing.
			 */
			mutex_exit(SQLOCK(sq));

			qfill_syncq(sq, qp, mp);
			/*
			 * NOTE: after the call to qfill_syncq() qp may be
			 * closed, both qp and sq should not be referenced at
			 * this point.
			 *
			 * This ASSERT is located here to prevent stack frame
			 * consumption in the DEBUG code.
			 */
			ASSERT(sqciplock == NULL);
			return;
		}

		queued = qp->q_sqflags & Q_SQQUEUED;
		/*
		 * If not a concurrent perimiter, we need to acquire
		 * it exclusively.  It could not have been previously
		 * set since we held the SQLOCK before testing
		 * SQ_GOAWAY above (which includes SQ_EXCL).
		 * We do this here because we hold the SQLOCK, and need
		 * to make this state change BEFORE dropping it.
		 */
		if (!(flags & SQ_CIPUT)) {
			ASSERT((sq->sq_flags & SQ_EXCL) == 0);
			ASSERT(!(sq->sq_type & SQ_CIPUT));
			sq->sq_flags |= SQ_EXCL;
		}
		mutex_exit(SQLOCK(sq));
	}

	ASSERT((sq->sq_flags & (SQ_EXCL|SQ_CIPUT)));
	ASSERT(MUTEX_NOT_HELD(SQLOCK(sq)));

	/*
	 * We now have a claim on the syncq, we are either going to
	 * put the message on the syncq and then drain it, or we are
	 * going to call the putproc().
	 */
	putproc = qi->qi_putp;
	if (!queued) {
		STR_FTEVENT_MSG(mp, fqp, FTEV_PUTNEXT, mp->b_rptr -
		    mp->b_datap->db_base);
		(*putproc)(qp, mp);
		ASSERT(MUTEX_NOT_HELD(SQLOCK(sq)));
		ASSERT(MUTEX_NOT_HELD(QLOCK(qp)));
	} else {
		mutex_enter(QLOCK(qp));
		/*
		 * If there are no messages in front of us, just call putproc(),
		 * otherwise enqueue the message and drain the queue.
		 */
		if (qp->q_syncqmsgs == 0) {
			mutex_exit(QLOCK(qp));
			STR_FTEVENT_MSG(mp, fqp, FTEV_PUTNEXT, mp->b_rptr -
			    mp->b_datap->db_base);
			(*putproc)(qp, mp);
			ASSERT(MUTEX_NOT_HELD(SQLOCK(sq)));
		} else {
			/*
			 * We are doing a fill with the intent to
			 * drain (meaning we are filling because
			 * there are messages in front of us ane we
			 * need to preserve message ordering)
			 * Therefore, put the message on the queue
			 * and call qdrain_syncq (must be done with
			 * the QLOCK held).
			 */
			STR_FTEVENT_MSG(mp, fqp, FTEV_PUTNEXT,
			    mp->b_rptr - mp->b_datap->db_base);

#ifdef DEBUG
			/*
			 * These two values were in the original code for
			 * all syncq messages.  This is unnecessary in
			 * the current implementation, but was retained
			 * in debug mode as it is usefull to know where
			 * problems occur.
			 */
			mp->b_queue = qp;
			mp->b_prev = (mblk_t *)putproc;
#endif
			SQPUT_MP(qp, mp);
			qdrain_syncq(sq, qp);
			ASSERT(MUTEX_NOT_HELD(QLOCK(qp)));
		}
	}
	/*
	 * Before we release our claim, we need to see if any
	 * events were posted. If the syncq is SQ_EXCL && SQ_QUEUED,
	 * we were responsible for going exclusive and, therefore,
	 * are resposible for draining.
	 */
	if (sq->sq_flags & (SQ_EXCL)) {
		drain_mask = 0;
	} else {
		drain_mask = SQ_QUEUED;
	}

	if (sqciplock != NULL) {
		mutex_enter(sqciplock);
		flags = sq->sq_flags;
		ASSERT(flags & SQ_CIPUT);
		/* SQ_EXCL could have been set by qwriter_inner */
		if ((flags & (SQ_EXCL|SQ_TAIL)) || sq->sq_needexcl) {
			/*
			 * we need SQLOCK to handle
			 * wakeups/drains/flags change.  sqciplock
			 * is needed to decrement sqcipcount.
			 * SQLOCK has to be grabbed before sqciplock
			 * for lock ordering purposes.
			 * after sqcipcount is decremented some lock
			 * still needs to be held to make sure
			 * syncq won't get freed on us.
			 *
			 * To prevent deadlocks we try to grab SQLOCK and if it
			 * is held already we drop sqciplock, acquire SQLOCK and
			 * reacqwire sqciplock again.
			 */
			if (mutex_tryenter(SQLOCK(sq)) == 0) {
				mutex_exit(sqciplock);
				mutex_enter(SQLOCK(sq));
				mutex_enter(sqciplock);
			}
			flags = sq->sq_flags;
			ASSERT(*sqcipcount != 0);
			(*sqcipcount)--;
			mutex_exit(sqciplock);
		} else {
			ASSERT(*sqcipcount != 0);
			(*sqcipcount)--;
			mutex_exit(sqciplock);
			TRACE_3(TR_FAC_STREAMS_FR, TR_PUTNEXT_END,
			"putnext_end:(%p, %p, %p) done", qp, mp, sq);
			return;
		}
	} else {
		mutex_enter(SQLOCK(sq));
		flags = sq->sq_flags;
		ASSERT(sq->sq_count != 0);
		sq->sq_count--;
	}
	if ((flags & (SQ_TAIL)) || sq->sq_needexcl) {
		putnext_tail(sq, qp, (flags & ~drain_mask));
		/*
		 * The only purpose of this ASSERT is to preserve calling stack
		 * in DEBUG kernel.
		 */
		ASSERT(sq != NULL);
		return;
	}
	ASSERT((sq->sq_flags & (SQ_EXCL|SQ_CIPUT)) || queued);
	ASSERT((flags & (SQ_EXCL|SQ_CIPUT)) || queued);
	/*
	 * Safe to always drop SQ_EXCL:
	 *	Not SQ_CIPUT means we set SQ_EXCL above
	 *	For SQ_CIPUT SQ_EXCL will only be set if the put
	 *	procedure did a qwriter(INNER) in which case
	 *	nobody else is in the inner perimeter and we
	 *	are exiting.
	 *
	 * I would like to make the following assertion:
	 *
	 * ASSERT((flags & (SQ_EXCL|SQ_CIPUT)) != (SQ_EXCL|SQ_CIPUT) ||
	 * 	sq->sq_count == 0);
	 *
	 * which indicates that if we are both putshared and exclusive,
	 * we became exclusive while executing the putproc, and the only
	 * claim on the syncq was the one we dropped a few lines above.
	 * But other threads that enter putnext while the syncq is exclusive
	 * need to make a claim as they may need to drop SQLOCK in the
	 * has_writers case to avoid deadlocks.  If these threads are
	 * delayed or preempted, it is possible that the writer thread can
	 * find out that there are other claims making the (sq_count == 0)
	 * test invalid.
	 */

	sq->sq_flags = flags & ~SQ_EXCL;
	mutex_exit(SQLOCK(sq));
	TRACE_3(TR_FAC_STREAMS_FR, TR_PUTNEXT_END,
	    "putnext_end:(%p, %p, %p) done", qp, mp, sq);
}
示例#26
0
/*!
 * \param *dc The current DecodingContext.
 * \param mbAddr The current macroblock address.
 * \return 0 if macroblock decoding fail, 1 otherwise.
 *
 * This function extract one macroblock from the bitstream, handle intra/inter
 * prediction for its blocks.
 */
int macroblock_layer(DecodingContext_t *dc, const int mbAddr)
{
    TRACE_INFO(MB, "<> " BLD_GREEN "macroblock_layer(" CLR_RESET "%i" BLD_GREEN ")\n" CLR_RESET, mbAddr);
    int retcode = FAILURE;

    // Macroblock allocation
    ////////////////////////////////////////////////////////////////////////////

    dc->mb_array[mbAddr] = (Macroblock_t*)calloc(1, sizeof(Macroblock_t));

    if (dc->mb_array[mbAddr] == NULL)
    {
        TRACE_ERROR(MB, "Unable to alloc new macroblock!\n");
    }
    else
    {
        // Set macroblock address
        dc->mb_array[mbAddr]->mbAddr = mbAddr;

        // Shortcuts
        pps_t *pps = dc->pps_array[dc->active_slice->pic_parameter_set_id];
        sps_t *sps = dc->sps_array[pps->seq_parameter_set_id];
        slice_t *slice = dc->active_slice;
        Macroblock_t *mb = dc->mb_array[mbAddr];

        // Macroblock decoding
        ////////////////////////////////////////////////////////////////////////

#if ENABLE_DEBUG
        mb->mbFileAddrStart = bitstream_get_absolute_bit_offset(dc->bitstr);
#endif // ENABLE_DEBUG

        deriv_macroblockneighbours_availability(dc, mbAddr);
        MbPosition(mb, sps);

        if (pps->entropy_coding_mode_flag)
            mb->mb_type = read_ae(dc, SE_mb_type);
        else
            mb->mb_type = read_ue(dc->bitstr);

        mb->MbPartPredMode[0] = MbPartPredMode(mb, slice->slice_type, 0);
        mb->NumMbPart = NumMbPart(slice->slice_type, mb->mb_type);

        if (mb->mb_type == I_PCM)
        {
#if ENABLE_IPCM
            TRACE_3(MB, "---- macroblock_layer - I PCM macroblock\n");

            while (bitstream_check_alignment(dc->bitstr) == false)
            {
                if (read_bit(dc->bitstr) != 0) // pcm_alignment_zero_bit
                {
                    TRACE_ERROR(MB, "  Error while reading pcm_alignment_zero_bit: must be 0!\n");
                    return FAILURE;
                }
            }

            // CABAC initialization process //FIXME needed? See 'ITU-T H.264' recommendation 9.3.1.2
            initCabacDecodingEngine(dc);

            int i = 0;
            for (i = 0; i < 256; i++)
            {
                mb->pcm_sample_luma[i] = (uint8_t)read_bits(dc->bitstr, sps->BitDepthY);
            }

            // CABAC initialization process //FIXME needed? See 'ITU-T H.264' recommendation 9.3.1.2
            initCabacDecodingEngine(dc);

            for (i = 0; i < 2 * sps->MbWidthC * sps->MbHeightC; i++)
            {
                mb->pcm_sample_chroma[i] = (uint8_t)read_bits(dc->bitstr, sps->BitDepthC);
            }

            // CABAC initialization process //FIXME needed? See 'ITU-T H.264' recommendation 9.3.1.2
            initCabacDecodingEngine(dc);
#else // ENABLE_IPCM
            TRACE_ERROR(MB, "I_PCM decoding is currently disabled!\n");
            return UNSUPPORTED;
#endif // ENABLE_IPCM
        }
        else
        {
#if ENABLE_INTER_PRED
            bool noSubMbPartSizeLessThan8x8Flag = true;

            if (mb->mb_type != I_NxN &&
                mb->MbPartPredMode[0] != Intra_16x16 &&
                mb->NumMbPart == 4)
            {
                TRACE_3(MB, "---- macroblock_layer - mb partition & related\n");

                int mbPartIdx = 0;
                for (mbPartIdx = 0; mbPartIdx < 4; mbPartIdx++)
                {
                    if (mb->sub_mb_type[mbPartIdx] != B_Direct_8x8)
                    {
                        if (NumSubMbPart(slice->slice_type, mb->sub_mb_type[mbPartIdx]) > 1)
                        {
                            noSubMbPartSizeLessThan8x8Flag = false;
                        }
                    }
                    else if (sps->direct_8x8_inference_flag == false)
                    {
                        noSubMbPartSizeLessThan8x8Flag = false;
                    }
                }

                // Read sub macroblock prediction mode
                sub_mb_pred(dc, mb->mb_type, mb->sub_mb_type);
            }
            else
#endif // ENABLE_INTER_PRED
            {
                TRACE_3(MB, "---- macroblock_layer - transform_size_8x8_flag & prediction modes\n");

                if (pps->transform_8x8_mode_flag == true && mb->mb_type == I_NxN)
                {
                    if (pps->entropy_coding_mode_flag)
                        mb->transform_size_8x8_flag = read_ae(dc, SE_transform_size_8x8_flag);
                    else
                        mb->transform_size_8x8_flag = read_bit(dc->bitstr);

                    // Need to update MbPartPredMode in order to detect I_8x8 prediction mode
                    mb->MbPartPredMode[0] = MbPartPredMode(mb, slice->slice_type, 0);
                }

                // Read macroblock prediction mode
                mb_pred(dc, mb);
            }

            if (mb->MbPartPredMode[0] != Intra_16x16)
            {
                TRACE_3(MB, "---- macroblock_layer - coded block pattern & transform_size_8x8_flag\n");

                if (pps->entropy_coding_mode_flag)
                    mb->coded_block_pattern = read_ae(dc, SE_coded_block_pattern);
                else
                    mb->coded_block_pattern = read_me(dc->bitstr, sps->ChromaArrayType, dc->IdrPicFlag);

                mb->CodedBlockPatternLuma = mb->coded_block_pattern % 16;
                mb->CodedBlockPatternChroma = mb->coded_block_pattern / 16;
#if ENABLE_INTER_PRED
                if (mb->CodedBlockPatternLuma > 0 &&
                    pps->transform_8x8_mode_flag == true &&
                    mb->mb_type != I_NxN &&
                    noSubMbPartSizeLessThan8x8Flag == true &&
                    (mb->mb_type != B_Direct_16x16 || sps->direct_8x8_inference_flag == true))
                {
                    if (pps->entropy_coding_mode_flag)
                        mb->transform_size_8x8_flag = read_ae(dc, SE_transform_size_8x8_flag);
                    else
                        mb->transform_size_8x8_flag = read_bit(dc->bitstr);

                    // Need to update MbPartPredMode in order to account for I_8x8 prediction mode
                    if (transform_size_8x8_flag)
                        mb->MbPartPredMode[0] = MbPartPredMode(mb, slice->slice_type, 0);
                }
#endif // ENABLE_INTER_PRED
            }

            if (mb->CodedBlockPatternLuma > 0 ||
                mb->CodedBlockPatternChroma > 0 ||
                mb->MbPartPredMode[0] == Intra_16x16)
            {
                TRACE_3(MB, "---- macroblock_layer - quantization parameter & residual datas\n");

                // Read QP delta
                if (pps->entropy_coding_mode_flag)
                    mb->mb_qp_delta = read_ae(dc, SE_mb_qp_delta);
                else
                    mb->mb_qp_delta = read_se(dc->bitstr);

                // Parse the residual coefficients
                ////////////////////////////////////////////////////////////////

                // Luma levels
                residual_luma(dc, 0, 15);

                // Chroma levels
                residual_chroma(dc, 0, 15);
            }
            else
            {
                TRACE_3(MB, "---- macroblock_layer - No residual datas to decode in this macroblock\n");
            }

            // Compute luma Quantization Parameters
            if (mb->mb_qp_delta)
                mb->QPY = ((slice->QPYprev + mb->mb_qp_delta + 52 + sps->QpBdOffsetY*2) % (52 + sps->QpBdOffsetY)) - sps->QpBdOffsetY;
            else
                mb->QPY = slice->QPYprev;

            mb->QPprimeY = mb->QPY + sps->QpBdOffsetY;
            slice->QPYprev = mb->QPY;

            // Set Transform Bypass Mode
            if (sps->qpprime_y_zero_transform_bypass_flag == true && mb->QPprimeY == 0)
                mb->TransformBypassModeFlag = true;

            // Prediction process (include quantization and transformation stages)
            ////////////////////////////////////////////////////////////////

            if (dc->IdrPicFlag)
            {
                retcode = intra_prediction_process(dc, mb);
            }
            else
            {
                retcode = inter_prediction_process(dc, mb);
            }

            // Print macroblock(s) header and block data ?
            ////////////////////////////////////////////////////////////////

#if ENABLE_DEBUG
            mb->mbFileAddrStop = bitstream_get_absolute_bit_offset(dc->bitstr) - 1;

            int frame_debug_range[2] = {-1, -1}; // Range of (idr) frame(s) to debug/analyse
            int mb_debug_range[2] = {-1, -1}; // Range of macroblock(s) to debug/analyse

            if (dc->idrCounter >= frame_debug_range[0] && dc->idrCounter <= frame_debug_range[1])
            {
                if (mb->mbAddr >= mb_debug_range[0] && mb->mbAddr <= mb_debug_range[1])
                {
                    print_macroblock_layer(dc, mb);
                    print_macroblock_pixel_residual(mb);
                    print_macroblock_pixel_predicted(mb);
                    print_macroblock_pixel_final(mb);
                }
            }
#endif // ENABLE_DEBUG
        }

        TRACE_3(MB, "---- macroblock_layer - the end\n\n");
    }

    return retcode;
}
示例#27
0
/**
 * Return number of log files in a dir and the name of the oldest file.
 * @param indata, see gnolfh_in_t
 * @param outdata, char *oldest_file
 * @param max_outsize, Max size for oldest_file string
 * 
 * @return int, number of logfiles or -1 if error
 */
int get_number_of_log_files_hdl(void *indata, void *outdata, size_t max_outsize)
{
	struct dirent **namelist;
	int n, old_date = -1, old_time = -1, old_ind = -1, files, i, failed = 0;
	char path[PATH_MAX];
	gnolfh_in_t *params_in;
	char *oldest_file;
	int rc = 0;
	
	TRACE_ENTER();
	
	params_in = (gnolfh_in_t *) indata;
	oldest_file = (char *) outdata;
	
	/* Initialize the filter */
	n = snprintf(file_prefix, SA_MAX_NAME_LENGTH, "%s", params_in->file_name);
	if (n >= SA_MAX_NAME_LENGTH) {
		rc = -1;
		LOG_WA("file_prefix > SA_MAX_NAME_LENGTH");
		goto done_exit;
	}

	n = snprintf(path, PATH_MAX, "%s/%s",
			params_in->logsv_root_dir, params_in->pathName);
	if (n >= PATH_MAX) {
		LOG_WA("path > PATH_MAX");
		rc = -1;
		goto done_exit;
	}

	files = n = scandir(path, &namelist, filter_func, alphasort);
	if (n == -1 && errno == ENOENT) {
		rc = 0;
		goto done_exit;
	}

	if (n < 0) {
		LOG_WA("scandir:%s - %s", strerror(errno), path);
		rc = -1;
		goto done_exit;
	}
	
	if (n == 0) {
		rc = files;
		goto done_exit;
	}

	while (n--) {
		TRACE_3("%s", namelist[n]->d_name);
		if (check_oldest(namelist[n]->d_name, params_in->file_name,
				 strlen(params_in->file_name), &old_date, &old_time)) {
			old_ind = n;
		} else {
			failed++;	/* wrong format */
		}
	}
	if (old_ind != -1) {
		TRACE_1("oldest: %s", namelist[old_ind]->d_name);
		n = snprintf(oldest_file, max_outsize, "%s/%s",
				path, namelist[old_ind]->d_name);
		if (n >= max_outsize) {
			LOG_WA("oldest_file > max_outsize");
			rc = -1;
			goto done_free;
		} else {
			rc = (files - failed);
		}
	} else {
		TRACE("Only file/files with wrong format found");
	}

done_free:
	/* Free scandir allocated memory */
	for (i = 0; i < files; i++)
		free(namelist[i]);
	free(namelist);

done_exit:	
	TRACE_LEAVE();
	return rc;
}
示例#28
0
文件: server.c 项目: raphui/wMusic
/* void *arg is a argumentReceivingThread_t type */
void receivingThread( void *arg )
{
    TRACE_2( SERVERMANAGER , "receivingThread()");

    char buff[BUFF_SIZE];
    char input[] = "wMusic~>";
    int ret;
    int info;
    void *cliRet;

    argumentReceivingThread_t *arguments = ( argumentReceivingThread_t * )arg;

    TRACE_3( SERVERMANAGER , "Thread argument: socket: %d , port: %d" , arguments->socket , arguments->port );

    TRACE_1( SERVERMANAGER , "[!]Receiving thread create !");

    if( arguments->port == PORT_CLI )
        sendVoidSocket( arguments->socket , input , sizeof( input ) );
    else //usleep( 2000 ) for WAN connection, usleep( 300 ) for LAN connection.
        usleep( 2000 ); info = IAMBRIDGE; sendVoidSocket( arguments->socket , ( void *)&info , sizeof( int ) );    //Sending info that the remote is connected to a bridge.

    while( 1 )
    {
        memset( buff , 0 , BUFF_SIZE );

        ret = recv( arguments->socket , buff , BUFF_SIZE , 0 );

        if( ret > 0 )
        {

            if( arguments->port == PORT_COMMANDER )
            {
                TRACE_3( SERVERMANAGER , "[+]Data: %s" , buff );

                if( strstr( buff , "DISC") != NULL )
                {
                    disconnectClient( &arguments->socket );

                    break;
                }

                lastRequester = arguments->socket;

                doAction( buff );
            }
            else if( arguments->port == PORT_CLI )
            {
                TRACE_3( SERVERMANAGER , "[+]Data: %s" , buff );

                cliRet = doCommand( buff );

                if( cliRet != NULL )
                {
                    sendVoidSocket( arguments->socket , cliRet , strlen( ( const char * )cliRet ) );

                    zfree( cliRet );

                    sendVoidSocket( arguments->socket , input , sizeof( input ) );
                }
            }
        }

    }

    TRACE_3( SERVERMANAGER , "[!]Quitting receiving thread !");

    releaseThread();

    pthread_exit( NULL );
}
示例#29
0
/*
 * Find the largest contiguous block which contains `addr' for file offset
 * `offset' in it while living within the file system block sizes (`vp_off'
 * and `vp_len') and the address space limits for which no pages currently
 * exist and which map to consecutive file offsets.
 */
page_t *
pvn_read_kluster(
    struct vnode *vp,
    u_offset_t off,
    struct seg *seg,
    caddr_t addr,
    u_offset_t *offp,			/* return values */
    size_t *lenp,				/* return values */
    u_offset_t vp_off,
    size_t vp_len,
    int isra)
{
    ssize_t deltaf, deltab;
    page_t *pp;
    page_t *plist = NULL;
    spgcnt_t pagesavail;
    u_offset_t vp_end;

    ASSERT(off >= vp_off && off < vp_off + vp_len);

    /*
     * We only want to do klustering/read ahead if there
     * is more than minfree pages currently available.
     */
    pagesavail = freemem - minfree;

    if (pagesavail <= 0)
        if (isra)
            return ((page_t *)NULL);    /* ra case - give up */
        else
            pagesavail = 1;		    /* must return a page */

    /* We calculate in pages instead of bytes due to 32-bit overflows */
    if (pagesavail < (spgcnt_t)btopr(vp_len)) {
        /*
         * Don't have enough free memory for the
         * max request, try sizing down vp request.
         */
        deltab = (ssize_t)(off - vp_off);
        vp_len -= deltab;
        vp_off += deltab;
        if (pagesavail < btopr(vp_len)) {
            /*
             * Still not enough memory, just settle for
             * pagesavail which is at least 1.
             */
            vp_len = ptob(pagesavail);
        }
    }

    vp_end = vp_off + vp_len;
    ASSERT(off >= vp_off && off < vp_end);

    if (isra && SEGOP_KLUSTER(seg, addr, 0))
        return ((page_t *)NULL);	/* segment driver says no */

    if ((plist = page_create_va(vp, off,
                                PAGESIZE, PG_EXCL | PG_WAIT, seg, addr)) == NULL)
        return ((page_t *)NULL);

    if (vp_len <= PAGESIZE || pvn_nofodklust) {
        *offp = off;
        *lenp = MIN(vp_len, PAGESIZE);
    } else {
        /*
         * Scan back from front by incrementing "deltab" and
         * comparing "off" with "vp_off + deltab" to avoid
         * "signed" versus "unsigned" conversion problems.
         */
        for (deltab = PAGESIZE; off >= vp_off + deltab;
                deltab += PAGESIZE) {
            /*
             * Call back to the segment driver to verify that
             * the klustering/read ahead operation makes sense.
             */
            if (SEGOP_KLUSTER(seg, addr, -deltab))
                break;		/* page not eligible */
            if ((pp = page_create_va(vp, off - deltab,
                                     PAGESIZE, PG_EXCL, seg, addr - deltab))
                    == NULL)
                break;		/* already have the page */
            /*
             * Add page to front of page list.
             */
            page_add(&plist, pp);
        }
        deltab -= PAGESIZE;

        /* scan forward from front */
        for (deltaf = PAGESIZE; off + deltaf < vp_end;
                deltaf += PAGESIZE) {
            /*
             * Call back to the segment driver to verify that
             * the klustering/read ahead operation makes sense.
             */
            if (SEGOP_KLUSTER(seg, addr, deltaf))
                break;		/* page not file extension */
            if ((pp = page_create_va(vp, off + deltaf,
                                     PAGESIZE, PG_EXCL, seg, addr + deltaf))
                    == NULL)
                break;		/* already have page */

            /*
             * Add page to end of page list.
             */
            page_add(&plist, pp);
            plist = plist->p_next;
        }
        *offp = off = off - deltab;
        *lenp = deltab + deltaf;
        ASSERT(off >= vp_off);

        /*
         * If we ended up getting more than was actually
         * requested, retract the returned length to only
         * reflect what was requested.  This might happen
         * if we were allowed to kluster pages across a
         * span of (say) 5 frags, and frag size is less
         * than PAGESIZE.  We need a whole number of
         * pages to contain those frags, but the returned
         * size should only allow the returned range to
         * extend as far as the end of the frags.
         */
        if ((vp_off + vp_len) < (off + *lenp)) {
            ASSERT(vp_end > off);
            *lenp = vp_end - off;
        }
    }
    TRACE_3(TR_FAC_VM, TR_PVN_READ_KLUSTER,
            "pvn_read_kluster:seg %p addr %x isra %x",
            seg, addr, isra);
    return (plist);
}