mmplugins/cameraplugins/source/webcamera/ecamwebcameravfactive.cpp
author Shimizu Satoshi <s_shimizu@isb.co.jp>
Tue, 19 Oct 2010 11:48:59 +0900
branchRCL_3
changeset 64 92a82bc706f7
parent 9 9ae0fe04e757
permissions -rw-r--r--
Obtain an image of Webcamera from QEMU and add the Bitmap change display function.

/*
* Copyright (c) 2010 ISB.
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of the "Symbian Foundation License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
*
* Initial Contributors:
* ISB - Initial contribution
*
* Contributors:
*
* Description:
*
*/

#include "ecamwebcameravfactive.h"


//
// CWebCameraVfActive
//
CWebCameraVfActive* CWebCameraVfActive::NewL(MWebCameraVfActiveCallBack* aOwner, RWebcameraDevice& aDriver)
	{
	CWebCameraVfActive* self = new(ELeave) CWebCameraVfActive(aOwner, aDriver);
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop(self);

	return self;
	}

CWebCameraVfActive::CWebCameraVfActive(MWebCameraVfActiveCallBack* aOwner, RWebcameraDevice& aDriver)
				   :CActive(CActive::EPriorityStandard),
				    iOwner(aOwner),
				    iDriver(aDriver),
				    iVfBufPtr(NULL, 0)
	{
	CActiveScheduler::Add(this);
	}

CWebCameraVfActive::~CWebCameraVfActive()
	{
	delete iVfBitmap;
	delete iDSA;
	delete iVfBuf;
	}

void CWebCameraVfActive::ConstructL()
	{
	}

/**
* RunL.
*/
void CWebCameraVfActive::RunL()
	{
	TInt wError = iStatus.Int();

	if (iViewFinderActive)
		{
		//The whole view finder start repeats screen update and the data acquisition.
		UpdateViewL();
		Start();
		}
	}

void CWebCameraVfActive::DoCancel()
	{
	iDriver.StopViewFinder();
	}

	/** 
	*/
TInt CWebCameraVfActive::InitViewFinder()
	{
	return iDriver.InitViewFinder();
	}

/** 
Starts transfer of view finder data to the given portion of the screen using
direct screen access.

The aScreenRect parameter is in screen co-ordinates and may be modified if,
eg, the camera requires the destination to have a certain byte alignment, etc.

@param  aWs 
        Window server session.
@param  aScreenDevice 
        Screen device.
@param  aWindow 
        Displayable window.
@param  aScreenRect 
        Portion of the screen to which view finder data is to be
        transferred. This is in screen co-ordinates and may be modified if, for example,
        the camera requires the destination to have a certain byte alignment.
@leave  KErrGeneral Init error.
*/
void CWebCameraVfActive::StartViewFinderDirectL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindowBase& aWindow, TRect& aScreenRect, TRect& aClipRect, TUint8* aChunkBase, TInt& aChunkSize)
	{

	iScreenRect = aScreenRect;
	iClipRect = aClipRect;
	iChuckBase = aChunkBase;
	
	// create buffer for view finder data
	iVfBuf = HBufC8::NewL(KMaxBufSize);
	
	// create DirectScreenAccess
	delete iDSA;
	iDSA = NULL;
	iViewFinderActive = EFalse;
	iDSA = CDirectScreenAccess::NewL(aWs, aScreenDevice, aWindow, *this);
	iDSA->StartL();
	iViewFinderActive = ETrue;

	iDSA->Gc()->SetOrigin();
	if (!iClipRect.IsEmpty())
		{
		iDSA->Gc()->SetClippingRect(iClipRect);
		}

	// init camera device.
	if (InitViewFinder() != KErrNone)
		{
		//TODO The error value is examined.
		User::Leave(KErrGeneral);
		}
	delete iVfBitmap;
	iVfBitmap = NULL;

	CFbsBitmap* image = new (ELeave) CFbsBitmap();
	CleanupStack::PushL(image);
	User::LeaveIfError(image->Create(TSize(KVfWidth, KVfHeight), EColor16M));
	CleanupStack::Pop(image);

	iVfBitmap = image;

	// start view finder
	// The division transfer is going to support in the next version. 
	Start();
	}

/** 
Stops transfer of view finder data to the screen. 
*/
void CWebCameraVfActive::StopViewFinder()
	{
	if (!iViewFinderActive)
		{
		return;
		}

	iViewFinderActive = EFalse;

	delete iDSA;
	iDSA = NULL;

	delete iVfBuf;
	iVfBuf = NULL;

	//Stop view finder
	iDriver.StopViewFinder();
	Cancel();
	}

/** 
Queries whether the view finder is active.

@return  ETrue if the view finder is active. EFalse if the view finder is not
         active. 
*/
TBool CWebCameraVfActive::ViewFinderActive()
	{
	return iViewFinderActive;
	}

/** 
Start viewfinder process.
*/
void CWebCameraVfActive::Start()
	{
	iDriver.StartViewFinder(iStatus, iChuckRemSize);

	SetActive();
	}

/** 
Draw the image of the view finder on screen.
*/
void CWebCameraVfActive::UpdateViewL()
	{
	iVfBufPtr.Set(iVfBuf->Des());
	iVfBufPtr.SetLength(0);
	iVfBufPtr.Copy(iChuckBase,iChuckRemSize);
	BitmapDataSet(iVfBufPtr, *iVfBitmap);

	// view position setting for test application
	iScreenRect.iTl.iY = 50;
	iScreenRect.iBr.iY = 169;
	// update view
	iDSA->Gc()->DrawBitmap(iScreenRect, iVfBitmap);
	iDSA->ScreenDevice()->Update();
	}

/**
Bitmap data is set in CFbsBitmap.

@param	aBitmap		[in]	Bitmap data.
		aVfBitmap	[out]	After Bitmap data is set in CFbsBitmap.
@return	KErrNone.
*/
TInt CWebCameraVfActive::BitmapDataSet(TDes8& aBitmap, CFbsBitmap& aVfBitmap)
	{
	TUint32 *wData = aVfBitmap.DataAddress();
	Mem::Copy(wData, aBitmap.Ptr(), (KVfHeight * KVfLineBytes));
	return KErrNone;
	}

/** 
from MAbortDirectScreenAccess

This function is called by the window server when direct screen access must stop
(for example because a dialogue is moved in front of the area where direct screen access is taking place).

@param  aScreenDevice 
		The reason why direct screen access was terminated. 
*/
void CWebCameraVfActive::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
	{
	}

/** 
from 	from MDirectScreenAccess

This function is called by the window server as soon as direct screen access can resume.

@param  aScreenDevice 
		Provides the reason why direct screen access was terminated. 
*/
void CWebCameraVfActive::Restart(RDirectScreenAccess::TTerminationReasons /*aReason*/)
	{
	}