⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vrexrecorderadapter.cpp

📁 symbian s60 有关音频的代码实例,供参考
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CVideoRecorderAdapter from VRexRecorderAdapter.cpp
*  Part of  : Video Example
*  Created  : 30/08/2006 by Forum  Nokia
*  Implementation notes:
*  Version  : 2.0
*  Copyright: Nokia Corporation, 2006
* ============================================================================
*/

// INCLUDE FILES
#include <eikenv.h> // CEikonEnv
#include <ecam.h> // CCamera
#include <PathInfo.h> // for PathInfo

#include "VRexRecorderAdapter.h"
#include "VRexPlayerAdapter.h"
#include "VRex.hrh"

_LIT(KNewVideoFileName, "NewVideo.3gp");
const TInt KMaxClipSize = 64 * 1024;

/*
-----------------------------------------------------------------------------

	CVideoRecorderAdapter* CVideoRecorderAdapter::NewL()

	Description: Two-phased construtor
	Comments   :

    Return values: CVideoRecorderAdapter object pointer

-----------------------------------------------------------------------------
*/
CVideoRecorderAdapter* CVideoRecorderAdapter::NewL(CVRexEngine* aEngine)
	{
	CVideoRecorderAdapter* self = CVideoRecorderAdapter::NewLC(aEngine);
	CleanupStack::Pop(self);
    return self;
	}

/*
-----------------------------------------------------------------------------

	CVideoRecorderAdapter* CVideoRecorderAdapter::NewLC()

	Description: Two-phased construtor
	Comments   : Leaves object in top of cleanup stack

    Return values: CVideoRecorderAdapter object pointer

-----------------------------------------------------------------------------
*/
CVideoRecorderAdapter* CVideoRecorderAdapter::NewLC(CVRexEngine* aEngine)
	{
    CVideoRecorderAdapter* self = new (ELeave) CVideoRecorderAdapter(aEngine);
    CleanupStack::PushL(self);
    self->ConstructL();
	return self;
	}

/*
-----------------------------------------------------------------------------

	void CVideoRecorderAdapter::ConstructL()

	Description: Second phase construtor
	Comments   : Method leaves with KErrNotSupported if necessary codecs are
	 			 not present.

    Return values:

-----------------------------------------------------------------------------
*/
void CVideoRecorderAdapter::ConstructL()
	{
	// Construct the actual utility class
	iUtility = CVideoRecorderUtility::NewL(*this);

	// Resolve the supported video format and retrieve a list of controllers
	CMMFControllerPluginSelectionParameters* cSelect =
		CMMFControllerPluginSelectionParameters::NewLC();
	CMMFFormatSelectionParameters* fSelect =
		CMMFFormatSelectionParameters::NewLC();

	// Set the play and record format selection parameters to be blank.
	// Format support is only retrieved if requested.
	cSelect->SetRequiredPlayFormatSupportL(*fSelect);
	cSelect->SetRequiredRecordFormatSupportL(*fSelect);

	// Set the media ids
	RArray<TUid> mediaIds;
	CleanupClosePushL(mediaIds);
	User::LeaveIfError(mediaIds.Append(KUidMediaTypeVideo));
	// Get plugins that support at least video
	cSelect->SetMediaIdsL(mediaIds,
		CMMFPluginSelectionParameters::EAllowOtherMediaIds);
	cSelect->SetPreferredSupplierL(KNullDesC,
		CMMFPluginSelectionParameters::EPreferredSupplierPluginsFirstInList);

	// Array to hold all the controllers support the match data
	RMMFControllerImplInfoArray controllers;
	CleanupResetAndDestroyPushL(controllers);
	cSelect->ListImplementationsL(controllers);

	TBool recordingSupported = EFalse;

	// Find the first controller with at least one record format available
	for(TInt i = 0; i < controllers.Count(); ++i)
		{
		RMMFFormatImplInfoArray recordFormats = controllers[i]->RecordFormats();

		if(recordFormats.Count() > 0)
			{
			iControllerUid = controllers[i]->Uid();
			iFormatUid = recordFormats[0]->Uid();
			recordingSupported = ETrue;
			break;
			}
		}

	CleanupStack::PopAndDestroy(&controllers);
	CleanupStack::PopAndDestroy(&mediaIds);
	CleanupStack::PopAndDestroy(fSelect);
	CleanupStack::PopAndDestroy(cSelect);

	// Leave if recording is not supported
	if(!recordingSupported)
		{
		User::Leave(KErrNotSupported);
		}

	// Create a progress updater
    iProgressUpdater = CHeartbeat::NewL(0);
	}

/*
-----------------------------------------------------------------------------

	CVideoRecorderAdapter::CVideoRecorderAdapter()

	Description: Constructor.
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
CVideoRecorderAdapter::CVideoRecorderAdapter(CVRexEngine* aEngine) :
	iEngine(aEngine) ,
	iState(ENotInitialized)
	{
	}

/*
-----------------------------------------------------------------------------

	CVideoRecorderAdapter::~CVideoRecorderAdapter()

	Description: Destructor.
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
CVideoRecorderAdapter::~CVideoRecorderAdapter()
	{
	delete iUtility;
	iUtility = NULL;

	delete iProgressUpdater;
	iProgressUpdater = NULL;
	}

/*
-----------------------------------------------------------------------------

	void CVideoRecorderAdapter::StartL()

	Description: This method initiates recording sequence.
	Comments   : Recording will start asynchronously after recording utility
				 is prepared.

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CVideoRecorderAdapter::StartL(MPlayerUIControllerListener* aCallback, TInt aCameraHandle)
	{
	// Set callbacks for UI updates
	iCtrlrListener = aCallback;
	TFileName filePath = PathInfo::PhoneMemoryRootPath();
	filePath.Append(PathInfo::VideosPath());
	filePath.Append(KNewVideoFileName);
	// Open file
	// On completion, MvruoOpenComplete will be called, and it will initiate
	// the recording process by calling iUtility->Prepare
	iUtility->OpenFileL(filePath, aCameraHandle, iControllerUid, iFormatUid);
	}

/*
-----------------------------------------------------------------------------

	void CVideoRecorderAdapter::Stop()

	Description: This method stops recording.
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CVideoRecorderAdapter::StopL()
	{
	if(iState != ERecording)
		return;
	
	iUtility->Stop();
	iUtility->Close();

	iState = ERecordComplete;
	
	
 	if (iCtrlrListener)
		{	
		iCtrlrListener->RecordCompletedL(KErrNone);
		}
	}

/*
-----------------------------------------------------------------------------

	void CVideoRecorderAdapter::Record()

	Description: This method starts recording.
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CVideoRecorderAdapter::Record()
	{
	if(!iProgressUpdater->IsActive())
        {
        iProgressUpdater->Start(ETwelveOClock,this);
        iRecPosition = 0;
        }
	iUtility->Record();
	}

/*
-----------------------------------------------------------------------------

	void CVideoRecorderAdapter::MvruoOpenComplete(TInt aError)

	Description: This method notifies that the opening of the video clip
    			 has completed, successfully, or otherwise.
	Comments   : This callback is generated in response to a call to OpenFile
				 in CVideoRecorderUtility

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CVideoRecorderAdapter::MvruoOpenComplete(TInt aError)
	{
	if(aError==KErrNone)
		{
		TRAPD(err, iUtility->SetMaxClipSizeL(KMaxClipSize));
		if(err==KErrNone)
			{
			iUtility->Prepare();
			iState = EOpenCompelete;
			}
		else
			{
			iState = ENotInitialized;
			}
		}
	else
		{
		iState = ENotInitialized;
		}
	}

/*
-----------------------------------------------------------------------------

	void CVideoRecorderAdapter::MvruoPrepareComplete(TInt aError)

	Description: This method notifies that video recorder is ready to begin recording.
	Comments   : This callback is generated in response to a call to Prepare
				 in CVideoRecorderUtility

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CVideoRecorderAdapter::MvruoPrepareComplete(TInt aError)
	{
	if(aError==KErrNone)
		{
		Record();
		iState = ERecording;
		}
	}

/*
-----------------------------------------------------------------------------

	void CVideoRecorderAdapter::MvruoRecordingComplete(TInt aError)

	Description: This method notifies that video recording has completed. This method
				 is not called if recording is explicitly stopped by calling Stop.
	Comments   : aError is KErrNone of KErrCompletion if recording was completed
				 successfully

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CVideoRecorderAdapter::MvruoRecordComplete(TInt aError)
	{
	if((aError==KErrNone) || (aError==KErrCompletion))
		{
		iUtility->Stop();
		iUtility->Close();

		iState = ERecordComplete;
		if (iCtrlrListener)
			{
			TRAPD(ignored, iCtrlrListener->RecordCompletedL(aError));
			}
		}
	}

/*
-----------------------------------------------------------------------------

	void CVideoRecorderAdapter::MvruoEvent(const TMMFEvent& aEvent)

	Description:  General event notification from controller. These events are
				  specified by the supplier of the controller
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CVideoRecorderAdapter::MvruoEvent(const TMMFEvent& /*aEvent*/)
	{
	}


/*
-----------------------------------------------------------------------------

	void CVideoRecorderAdapter::Beat()

	Description: This method handles a regular heartbeat timer event. This type of
				 event is one where the timer completes in synchronisation with the
				 system clock.
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CVideoRecorderAdapter::Beat()
{
    // Keep the backlight on while recording
    User::ResetInactivityTime();

	if (iState != ERecording)
		return;

    TInt64 ret = iRecPosition%2;

#ifndef __SERIES60_3X__
    if(ret.GetTInt())
#else
    if((TInt)ret)
#endif
    {
        iRecPosition++;
        if (iCtrlrListener)
			{
			TRAPD(ignored,iCtrlrListener->PlaybackPositionChangedL(iRecPosition, 0));
			}
	}
    else
    {
        Synchronize();
    }
}

/*
-----------------------------------------------------------------------------

	void CVideoRecorderAdapter::Synchronize()

	Description: This method synchronises the heartbeat timer with system clock.
	Comments   : This function handles a heartbeat timer event where the
				 timer completes out of synchronisation with the system clock,
				 (i.e. one or more heartbeats have been missed).

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CVideoRecorderAdapter::Synchronize()
    {
	if(iState != ERecording)
		return;

    TRAPD(ignored,
		// If live stream, fake progress
        iRecPosition = iUtility->DurationL().Int64() / KMPOneSecond;

        if (iCtrlrListener)
			{
            iCtrlrListener->PlaybackPositionChangedL(iRecPosition,0);
            }
        );
    }

// End of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -