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

📄 mpeg4decodercontainerview.cpp

📁 symbian上的yuv视频文件处理程序 可对yuv的每一帧数据进行读取 处理 显示
💻 CPP
字号:
/*
========================================================================
 Name        : Mpeg4DecoderContainerView.cpp
 Author      : Jin
 Copyright   : Copyright (C) 2005-2008 Cyansoft Studio, All rights Reserved.
 Description : 
========================================================================
*/
// [[[ begin generated region: do not modify [Generated System Includes]
#include <aknviewappui.h>
#include <eikmenub.h>
#include <avkon.hrh>
#include <akncontext.h>
#include <akntitle.h>
#include <stringloader.h>
#include <barsread.h>
#include <eikbtgpc.h>
#include <Mpeg4Decoder.rsg>
// ]]] end generated region [Generated System Includes]
#include <aknnotewrappers.h>
#include <akncommondialogs.h>
#include "mpg4dec.h"
#include "yuv2rgb.h"
#include "scale.h"
#include "DirectDraw.h"
#include "DecoderEngine.h"
// [[[ begin generated region: do not modify [Generated User Includes]

#include "Mpeg4Decoder.hrh"
#include "Mpeg4DecoderContainerView.h"
#include "Mpeg4DecoderContainer.hrh"
#include "Mpeg4DecoderContainer.h"
// ]]] end generated region [Generated User Includes]

// [[[ begin generated region: do not modify [Generated Constants]
// ]]] end generated region [Generated Constants]

/**
 * First phase of Symbian two-phase construction. Should not contain any
 * code that could leave.
 */
CMpeg4DecoderContainerView::CMpeg4DecoderContainerView()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	iMpeg4DecoderContainer = NULL;
	// ]]] end generated region [Generated Contents]
	
	}

/** 
 * The view's destructor removes the container from the control
 * stack and destroys it.
 */
CMpeg4DecoderContainerView::~CMpeg4DecoderContainerView()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	delete iMpeg4DecoderContainer;
	iMpeg4DecoderContainer = NULL;
	// ]]] end generated region [Generated Contents]
	if( iEngine )
		{
		iEngine->StopL( ETrue );
		delete iEngine;
		iEngine = NULL;
		}
	
	if( iDDraw )
		{
		delete iDDraw;
		iDDraw = NULL;
		}	
		
	if( iYuvbuf )
		{
		delete iYuvbuf;
		iYuvbuf = NULL;
		}
	
	if( iInputbuf )
		{
		delete iInputbuf;
		iInputbuf = NULL;
		}
		
	if( iRgbbuf )
		{
		delete iRgbbuf;
		iRgbbuf = NULL;
		}
	
	if( iDecoder )
		{
		delete iDecoder;
		iDecoder = NULL;
		}
	
	if( iYuv2Rgb )
		{
		delete iYuv2Rgb;
		iYuv2Rgb = NULL;
		}
	
	if( iScale )
		{
		delete iScale;
		iScale = NULL;
		}
	}

/**
 * Symbian two-phase constructor.
 * This creates an instance then calls the second-phase constructor
 * without leaving the instance on the cleanup stack.
 * @return new instance of CMpeg4DecoderContainerView
 */
CMpeg4DecoderContainerView* CMpeg4DecoderContainerView::NewL()
	{
	CMpeg4DecoderContainerView* self = CMpeg4DecoderContainerView::NewLC();
	CleanupStack::Pop( self );
	return self;
	}

/**
 * Symbian two-phase constructor.
 * This creates an instance, pushes it on the cleanup stack,
 * then calls the second-phase constructor.
 * @return new instance of CMpeg4DecoderContainerView
 */
CMpeg4DecoderContainerView* CMpeg4DecoderContainerView::NewLC()
	{
	CMpeg4DecoderContainerView* self = new ( ELeave ) CMpeg4DecoderContainerView();
	CleanupStack::PushL( self );
	self->ConstructL();
	return self;
	}


/**
 * Second-phase constructor for view.  
 * Initialize contents from resource.
 */ 
void CMpeg4DecoderContainerView::ConstructL()
	{
	// [[[ begin generated region: do not modify [Generated Code]
	BaseConstructL( R_MPEG4_DECODER_CONTAINER_MPEG4_DECODER_CONTAINER_VIEW );
				
	// ]]] end generated region [Generated Code]
	
	// add your own initialization code here
	iDisplayMode = iEikonEnv->ScreenDevice()->DisplayMode();
	iBytesPixel = 0;
	
	if(EColor64K == iDisplayMode)
		{
		iBytesPixel = 16>>3;
		}
	else if(EColor16M == iDisplayMode)
		{
		iBytesPixel = 24>>3;
		}
	else if(EColor16MU == iDisplayMode)
		{
		iBytesPixel = 32>>3;
		}
	else
		{
		User::Leave( -1 );
		}
	
	iYuv2Rgb = CYuv2Rgb::NewL( iDisplayMode );
	
	iWidth = 352; iHeight = 288;
		
	TRect aClientRc = ClientRect();	
	TInt aWidth = aClientRc.Width();
	TInt aHeight = aClientRc.Width() * iHeight / iWidth;
	TInt aPosX = 0;
	TInt aPosY = ((aClientRc.Height() - aHeight)>>1);
	
	iPtVideo = TPoint( aPosX, aPosY );
	iRcVideo = TRect( iPtVideo, TSize(aWidth, aHeight) );
	
	iScale = CScale::NewL( iWidth, iHeight, iRcVideo.Width(), iRcVideo.Height(), iBytesPixel );
	
	iInputSize = 4096;
	iYuvSize = iWidth * iHeight * 3 >> 1; /* YUV420P */
	iDecoder = CMPEG4Decoder::NewL( iWidth, iHeight );
	User::LeaveIfNull( iDecoder );
	iYuvbuf = HBufC8::NewL( iYuvSize );
	iInputbuf = HBufC8::NewL( iInputSize );
	iRgbbuf = HBufC8::NewL( iWidth * iHeight * iBytesPixel );
	iDDraw = NULL;
	iEngine = NULL;
	}

/**
 * @return The UID for this view
 */
TUid CMpeg4DecoderContainerView::Id() const
	{
	return TUid::Uid( EMpeg4DecoderContainerViewId );
	}

/**
 * Handle a command for this view (override)
 * @param aCommand command id to be handled
 */
void CMpeg4DecoderContainerView::HandleCommandL( TInt aCommand )
	{
	// [[[ begin generated region: do not modify [Generated Code]
	TBool commandHandled = EFalse;
	switch ( aCommand )
		{	// code to dispatch to the AknView's menu and CBA commands is generated here
		case EMpeg4DecoderContainerViewOpenMenuItemCommand:
			commandHandled = HandleOpenMenuItemSelectedL( aCommand );
			break;
		case EMpeg4DecoderContainerViewAboutMenuItemCommand:
			commandHandled = HandleAboutMenuItemSelectedL( aCommand );
			break;
		default:
			break;
		}
	
		
	if ( !commandHandled ) 
		{
	
		if ( aCommand == EAknSoftkeyExit )
			{
			AppUi()->HandleCommandL( EEikCmdExit );
			}
	
		}
	// ]]] end generated region [Generated Code]
	
	}

/**
 *	Handles user actions during activation of the view, 
 *	such as initializing the content.
 */
void CMpeg4DecoderContainerView::DoActivateL( 
		const TVwsViewId& /*aPrevViewId*/,
		TUid /*aCustomMessageId*/,
		const TDesC8& /*aCustomMessage*/ )
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	SetupStatusPaneL();
	
				
	if ( iMpeg4DecoderContainer == NULL )
		{
		iMpeg4DecoderContainer = CreateContainerL();
		iMpeg4DecoderContainer->SetMopParent( this );
		AppUi()->AddToStackL( *this, iMpeg4DecoderContainer );
		} 
	// ]]] end generated region [Generated Contents]
	
	}

/**
 */
void CMpeg4DecoderContainerView::DoDeactivate()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	CleanupStatusPane();
	
	if ( iMpeg4DecoderContainer != NULL )
		{
		AppUi()->RemoveFromViewStack( *this, iMpeg4DecoderContainer );
		delete iMpeg4DecoderContainer;
		iMpeg4DecoderContainer = NULL;
		}
	// ]]] end generated region [Generated Contents]
	
	}

/** 
 * Handle status pane size change for this view (override)
 */
void CMpeg4DecoderContainerView::HandleStatusPaneSizeChange()
	{
	CAknView::HandleStatusPaneSizeChange();
	
	// this may fail, but we're not able to propagate exceptions here
	TInt result;
	TRAP( result, SetupStatusPaneL() ); 
	
	// [[[ begin generated region: do not modify [Generated Code]
	// ]]] end generated region [Generated Code]
	
	}

// [[[ begin generated function: do not modify
void CMpeg4DecoderContainerView::SetupStatusPaneL()
	{
	// reset the context pane
	TUid contextPaneUid = TUid::Uid( EEikStatusPaneUidContext );
	CEikStatusPaneBase::TPaneCapabilities subPaneContext = 
		StatusPane()->PaneCapabilities( contextPaneUid );
	if ( subPaneContext.IsPresent() && subPaneContext.IsAppOwned() )
		{
		CAknContextPane* context = static_cast< CAknContextPane* > ( 
			StatusPane()->ControlL( contextPaneUid ) );
		context->SetPictureToDefaultL();
		}
	
	// setup the title pane
	TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
	CEikStatusPaneBase::TPaneCapabilities subPaneTitle = 
		StatusPane()->PaneCapabilities( titlePaneUid );
	if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
		{
		CAknTitlePane* title = static_cast< CAknTitlePane* >( 
			StatusPane()->ControlL( titlePaneUid ) );
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_MPEG4_DECODER_CONTAINER_TITLE_RESOURCE );
		title->SetFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
				
	}

// ]]] end generated function

// [[[ begin generated function: do not modify
void CMpeg4DecoderContainerView::CleanupStatusPane()
	{
	}

// ]]] end generated function

/**
 *	Creates the top-level container for the view.  You may modify this method's
 *	contents and the CMpeg4DecoderContainer::NewL() signature as needed to initialize the
 *	container, but the signature for this method is fixed.
 *	@return new initialized instance of CMpeg4DecoderContainer
 */
CMpeg4DecoderContainer* CMpeg4DecoderContainerView::CreateContainerL()
	{
	return CMpeg4DecoderContainer::NewL( ClientRect(), NULL, this );
	}

/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CMpeg4DecoderContainerView::HandleAboutMenuItemSelectedL( TInt aCommand )
	{
	// TODO: implement selected event handler
	_LIT(KMsgAbout1, "MPEG4 Decoder for Symbian S60 3rd");
	_LIT(KMsgAbout2, "Copyright (C) 2008 Cyansoft Studio");
	
	iEikonEnv->InfoWinL( KMsgAbout1, KMsgAbout2 );
	return ETrue;
	}
				
/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CMpeg4DecoderContainerView::HandleOpenMenuItemSelectedL( TInt aCommand )
	{
	// TODO: implement selected event handler	
	if( iEngine )
		iEngine->PauseL( ETrue );
	
	if( AknCommonDialogs::RunSelectDlgLD( iFileToOpen, R_MEMORY_SELECTION_DIALOG, R_FILE_SELECTION_DIALOG ) )
		{
		if(iEngine)
			{
			iEngine->StopL( ETrue );
			delete iEngine;
			iEngine = NULL;
			}
		
		if(iDDraw)
			{
			delete iDDraw;
			iDDraw = NULL;
			}
		
		iDDraw = CDirectDraw::NewL( iEikonEnv->WsSession(), *iEikonEnv->ScreenDevice(), iMpeg4DecoderContainer->GetWindow(), iPtVideo, iRcVideo );
		iEngine = CDecoderEngine::NewL( iDDraw );
		User::LeaveIfError( iEngine->CreateL( iFileToOpen, 
				iWidth, iHeight, iBytesPixel, iYuv2Rgb, iScale, iInputbuf, iInputSize, iYuvbuf, iYuvSize, iRgbbuf, iDecoder ) );
		iEngine->StartL();
		}
	else
		{
		if( iEngine )
				iEngine->PauseL( EFalse );
		}
	
	return ETrue;
	}
				

⌨️ 快捷键说明

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