📄 decoder.cpp
字号:
/*****************************************************************************
******************************************************************************
** **
** Copyright (c) 2006 Videon Central, Inc. **
** All rights reserved. **
** **
** The computer program contained herein contains proprietary information **
** which is the property of Videon Central, Inc. The program may be used **
** and/or copied only with the written permission of Videon Central, Inc. **
** or in accordance with the terms and conditions stipulated in the **
** agreement/contract under which the programs have been supplied. **
** **
******************************************************************************
*****************************************************************************/
/**
* @file decoder.cpp
*
* $Revision: 1.16 $
*
* Decoder base class - provides a decoder API and decoder event notification
* services
*
*/
#include <string.h>
#include <time.h>
#include "decoder.h"
#include "dbgprint.h"
/********************************************************************************
Constants
********************************************************************************/
#define DEBUG_ERROR (1<<0)
#define DEBUG_TRACE (1<<1)
#define DEBUG_INFO (1<<2)
#define DEBUG_SETTINGS (DEBUG_ERROR | DEBUG_INFO | DEBUG_TRACE )
#define DEBUG_ON(x) (DEBUG_SETTINGS & x)
/**
*******************************************************************************
* DecodeEventTypeName returns name of event as string
*
* @param decodeEventType the type of decode event
*
* @return If the function succeeds, the return value is name, else NULL
*******************************************************************************/
const char* DecodeEventTypeName( DECODE_EVENT_TYPE decodeEventType )
{
switch ( decodeEventType )
{
case DECODE_EVENT_DECODE_DONE: return ("DECODE_EVENT_DECODE_DONE" );
case DECODE_EVENT_TIMESTAMPS: return ("DECODE_EVENT_TIMESTAMPS");
case DECODE_EVENT_PRESENTATION_START: return ("DECODE_EVENT_PRESENTATION_START");
}
return ( NULL );
}
/**
*******************************************************************************
* DecodeNotifyWaitTypeName returns name of notify type as string
*
* @param decodeNotifyWaitType the type of decode event
*
* @return If the function succeeds, the return value is name, else NULL
*******************************************************************************/
const char* DecodeNotifyWaitTypeName( DECODE_NOTIFY_WAIT_TYPE decodeNotifyWaitType )
{
switch ( decodeNotifyWaitType )
{
case DECODE_NOTIFY_ALWAYS: return ("DECODE_NOTIFY_ALWAYS" );
case DECODE_NOTIFY_ONCE: return ("DECODE_NOTIFY_ONCE" );
case DECODE_NOTIFY_CANCEL: return ("DECODE_NOTIFY_CANCEL" );
}
return ( NULL );
}
/**
*******************************************************************************
* Decoder::Decoder initialize members to known state
*
*******************************************************************************/
Decoder::Decoder ( void )
{
m_decoderName = NULL;
m_eventNotificationTableSize = 0;
m_notifyCallback = NULL;
m_notifyCallbackContext = NULL;
memset(&m_eventNotificationTable,0,sizeof(m_eventNotificationTable));
}
/**
*******************************************************************************
* Decoder::Create allocate resources needed
*
* @param decoderName string to identify the decoder
*
* @return If the function succeeds, the return value is SUCCESS.
*******************************************************************************/
VDVD_ERROR Decoder::Create ( const char* decoderName )
{
AutoMutex autoMutex(&m_mutex);
VDVD_RAISE_ERROR( ReferenceChecker::Create() );
m_decoderName = decoderName;
return ( VDVD_SUCCESS );
}
/**
*******************************************************************************
* Decoder::Destroy free allocated resources
*
*
* @return If the function succeeds, the return value is SUCCESS.
*******************************************************************************/
VDVD_ERROR Decoder::Destroy ( void )
{
AutoMutex autoMutex(&m_mutex);
VDVD_RAISE_ERROR( ReferenceChecker::Destroy() );
return ( VDVD_SUCCESS );
}
/**
*******************************************************************************
* Decoder::SetNotifyCallback sets notification callback
*
* @param notifyCallback callback routine for event notifications
* @param notifyCallbackContext callback routine optional parameter
*
* @return If the function succeeds, the return value is SUCCESS.
*******************************************************************************/
VDVD_ERROR Decoder::SetNotifyCallback( DECODE_NOTIFY_CALLBACK notifyCallback, void* notifyCallbackContext )
{
AutoMutex autoMutex(&m_mutex);
VDVD_ASSERT_ERROR( (notifyCallback==NULL), VDVD_ERROR_INVALID_PARAMETER );
m_notifyCallback = notifyCallback;
m_notifyCallbackContext = notifyCallbackContext;
return ( VDVD_SUCCESS );
}
/**
*******************************************************************************
* Decoder::RequestNotification processes a notification change request.
* RequestNotification will update the decoder's notification table.
*
* @param eventType the type of decode event notification to update
* @param decodeNotifyType the type of notification that should occur
* @param timeout notification timeout (not implemented)
*
* @return If the function succeeds, the return value is SUCCESS.
*******************************************************************************/
VDVD_ERROR Decoder::RequestNotification( DECODE_EVENT_TYPE decodeEventType, DECODE_NOTIFY_WAIT_TYPE decodeNotifyType )
{
AutoMutex autoMutex(&m_mutex);
uint32 index = 0;
// See if this eventType is already in the event table
for ( index = 0; index < m_eventNotificationTableSize; index++ )
{
if ( m_eventNotificationTable[index].eventType == decodeEventType )
{
// check if we should remove the event from the table
if ( decodeNotifyType == DECODE_NOTIFY_CANCEL )
{
memmove( &m_eventNotificationTable[index], &m_eventNotificationTable[index+1], sizeof(DECODER_EVENT_NOTIFICATION_TABLE_ENTRY) * ( m_eventNotificationTableSize - (index+1) ));
m_eventNotificationTableSize--;
return ( VDVD_SUCCESS );
}
else
{
// don't add or remove the event, just update the event's notification type
m_eventNotificationTable[index].eventType = decodeEventType;
m_eventNotificationTable[index].notifyType = decodeNotifyType;
m_eventNotificationTable[index].notifyRequestTime = (uint32)time(NULL);
return ( VDVD_SUCCESS );
}
}
}
// event was not found in the event table, add new event notification
VDVD_ASSERT_ERROR( (m_eventNotificationTableSize>=DECODER_EVENT_NOTIFICATION_TABLE_SIZE), VDVD_ERROR_OBJECT_FAILED );
m_eventNotificationTable[m_eventNotificationTableSize].eventType = decodeEventType;
m_eventNotificationTable[m_eventNotificationTableSize].notifyType = decodeNotifyType;
m_eventNotificationTable[m_eventNotificationTableSize].notifyRequestTime = (uint32)time(NULL);
m_eventNotificationTableSize++;
DBGPRINT(DEBUG_ON(DEBUG_TRACE),("Decoder::RequestNotification (%s,%s)",DecodeEventTypeName(decodeEventType), DecodeNotifyWaitTypeName(decodeNotifyType) ));
return ( VDVD_SUCCESS );
}
/**
*******************************************************************************
* Decoder::Notify Performs an event notification callback if previously requested
*
* @param eventType the type of decode event notification to notify
*
* @return If the function succeeds, the return value is SUCCESS.
*******************************************************************************/
VDVD_ERROR Decoder::Notify( DECODE_EVENT_TYPE eventType )
{
AutoMutex autoMutex(&m_mutex);
uint32 index = 0;
// search the event table for the event type
for ( index = 0; index < m_eventNotificationTableSize; index++ )
{
if ( m_eventNotificationTable[index].eventType == eventType )
{
// found event in table, if it is a one-shot, remove it
if ( m_eventNotificationTable[index].notifyType == DECODE_NOTIFY_ONCE )
{
memmove( &m_eventNotificationTable[index], &m_eventNotificationTable[index+1], sizeof(DECODER_EVENT_NOTIFICATION_TABLE_ENTRY) * ( m_eventNotificationTableSize - (index+1) ));
m_eventNotificationTableSize--;
}
if ( m_notifyCallback != NULL )
{
m_notifyCallback(this, eventType, NULL, m_notifyCallbackContext );
return ( VDVD_SUCCESS );
}
}
}
return ( VDVD_SUCCESS );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -