📄 mobiflvappview.cpp
字号:
/*
============================================================================
Name : MobiFLVAppView.cpp
Author :
Copyright : Copyright by Sittiphol Phanvilai
Description : Application view implementation
============================================================================
*/
// INCLUDE FILES
#include <coemain.h>
#include <hal.h>
#include "Player.h"
#include "YUVtoRGB.h"
#include "KeyFrameMan.h"
#include "MobiFLVAppView.h"
#define MAX_FRAME_SKIP 4
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CMobiFLVAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CMobiFLVAppView* CMobiFLVAppView::NewL( const TRect& aRect )
{
CMobiFLVAppView* self = CMobiFLVAppView::NewLC( aRect );
CleanupStack::Pop( self );
return self;
}
// -----------------------------------------------------------------------------
// CMobiFLVAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CMobiFLVAppView* CMobiFLVAppView::NewLC( const TRect& aRect )
{
CMobiFLVAppView* self = new ( ELeave ) CMobiFLVAppView;
CleanupStack::PushL( self );
self->ConstructL( aRect );
return self;
}
// -----------------------------------------------------------------------------
// CMobiFLVAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CMobiFLVAppView::ConstructL( const TRect& aRect )
{
InitConvertTable();
iOffScreenBitmap = new (ELeave) CFbsBitmap;
User::LeaveIfError(iOffScreenBitmap->Create(TSize(aRect.Width(), aRect.Height()), EColor16MU));
PlayerSetRect(aRect.Width(), aRect.Height());
// Create a window for this application view
CreateWindowL();
// Set the windows size
SetRect( aRect );
// Activate the window, which makes it ready to be drawn
ActivateL();
ActivateGc();
Window().BeginRedraw();
SystemGc().SetBrushColor(KRgbBlack);
SystemGc().Clear();
Window().EndRedraw();
DeactivateGc();
iNeoStreamPlayer = CNeoStreamPlayer::NewL();
// __UHEAP_MARK;
OpenFlvAndInit("C:\\Data\\Videos\\Test.flv", iNeoStreamPlayer);
iPts = 0;
iAudioCurrentFTell = CurrentFTell();
FetchCodecAndDecode(iPts, iNeoStreamPlayer);
iFirstFrameNum = iFrameNum;
iNowTime.HomeTime();
iFirstFrameTimeStamp = iNowTime.Int64();
iOffScreenBitmap->LockHeap();
DoWithDecoded((unsigned char*)iOffScreenBitmap->DataAddress(), EFalse, iFirstFrameNum, iFirstFrameTimeStamp, iFrameNum, iNowTime.Int64());
iOffScreenBitmap->UnlockHeap();
DrawNow();
// __UHEAP_MARKEND;
}
// -----------------------------------------------------------------------------
// CMobiFLVAppView::CMobiFLVAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CMobiFLVAppView::CMobiFLVAppView()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CMobiFLVAppView::~CMobiFLVAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CMobiFLVAppView::~CMobiFLVAppView()
{
ClearKeyFrame();
CloseFlvAndDestroy();
DestroyConvertTable();
if (iPeriodic)
{
delete iPeriodic;
iPeriodic = NULL;
}
if (iNeoStreamPlayer)
{
delete iNeoStreamPlayer;
iNeoStreamPlayer = NULL;
}
if (iOffScreenBitmap)
{
delete iOffScreenBitmap;
iOffScreenBitmap = NULL;
}
}
// -----------------------------------------------------------------------------
// CMobiFLVAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CMobiFLVAppView::Draw( const TRect& /*aRect*/ ) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();
// Gets the control's extent
TRect drawRect( Rect());
// Clears the screen
//gc.Clear( drawRect );
gc.BitBlt(TPoint(0, 0), iOffScreenBitmap);
}
// -----------------------------------------------------------------------------
// CMobiFLVAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CMobiFLVAppView::SizeChanged()
{
if (iOffScreenBitmap)
{
delete iOffScreenBitmap;
iOffScreenBitmap = NULL;
}
iOffScreenBitmap = new (ELeave) CFbsBitmap;
User::LeaveIfError(iOffScreenBitmap->Create(TSize(Rect().Width(), Rect().Height()), EColor16MU));
PlayerSetRect(Rect().Width(), Rect().Height());
DrawNow();
}
TKeyResponse CMobiFLVAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
if (aType == EEventKey)
{
if (aKeyEvent.iCode == EKeyLeftArrow)
{
SeekLeft();
return EKeyWasConsumed;
}
if (aKeyEvent.iCode == EKeyRightArrow)
{
SeekRight();
return EKeyWasConsumed;
}
if (aKeyEvent.iCode == EKeyDevice3)
{
if (iPeriodic)
{
delete iPeriodic;
iPeriodic = NULL;
}
else
{
iPeriodic = CPeriodic::NewL(0);
TInt tTickInterval = 1;
iPeriodic->Start(tTickInterval, tTickInterval, TCallBack(PlayLoopTick, this));
}
return EKeyWasConsumed;
}
if (aKeyEvent.iCode == EKeyUpArrow)
{
iNeoStreamPlayer->IncreaseVolume();
return EKeyWasConsumed;
}
if (aKeyEvent.iCode == EKeyDownArrow)
{
iNeoStreamPlayer->DecreaseVolume();
return EKeyWasConsumed;
}
}
return EKeyWasNotConsumed;
}
TInt CMobiFLVAppView::PlayLoopTick(TAny* aObject)
{
// cast, and call non-static function
((CMobiFLVAppView*)aObject)->PlayLoop();
return 1;
}
void CMobiFLVAppView::PlayLoop()
{
TInt result = FetchCodecAndDecode(iPts, iNeoStreamPlayer);
if (result == -3) // End
{
iPts = FLVGetDuration() * 1000;
delete iPeriodic;
iPeriodic = NULL;
}
iNowTime.HomeTime();
iOffScreenBitmap->LockHeap();
if (DoWithDecoded((unsigned char*)iOffScreenBitmap->DataAddress(), EFalse, iFirstFrameNum, iFirstFrameTimeStamp, iFrameNum, iNowTime.Int64()) > MAX_FRAME_SKIP)
{
iFirstFrameNum = iFrameNum;
iNowTime.HomeTime();
iFirstFrameTimeStamp = iNowTime.Int64();
DoWithDecoded((unsigned char*)iOffScreenBitmap->DataAddress(), EFalse, iFirstFrameNum, iFirstFrameTimeStamp, iFrameNum, iNowTime.Int64());
}
FetchCodecAndDecodeSoundOnly(iPts, iNeoStreamPlayer, iAudioCurrentFTell);
iOffScreenBitmap->UnlockHeap();
User::ResetInactivityTime();
DrawNow();
}
void CMobiFLVAppView::SeekLeft()
{
TInt tTargetPosition = GetFirstKeyFramePositionBefore();
if (tTargetPosition != -1)
{
SeekFileTo(tTargetPosition);
iAudioCurrentFTell = CurrentFTell();
FetchCodecAndDecode(iPts, iNeoStreamPlayer);
iFrameNum = 0;
iFirstFrameNum = iFrameNum;
iNowTime.HomeTime();
iFirstFrameTimeStamp = iNowTime.Int64();
iOffScreenBitmap->LockHeap();
DoWithDecoded((unsigned char*)iOffScreenBitmap->DataAddress(), EFalse, iFirstFrameNum, iFirstFrameTimeStamp, iFrameNum, iNowTime.Int64());
iOffScreenBitmap->UnlockHeap();
User::ResetInactivityTime();
DrawNow();
}
}
void CMobiFLVAppView::SeekRight()
{
TInt tTargetPosition = GetFirstKeyFramePositionAfter();
if (tTargetPosition != -1)
{
SeekFileTo(tTargetPosition);
iAudioCurrentFTell = CurrentFTell();
FetchCodecAndDecode(iPts, iNeoStreamPlayer);
iFrameNum = 0;
iFirstFrameNum = iFrameNum;
iNowTime.HomeTime();
iFirstFrameTimeStamp = iNowTime.Int64();
iOffScreenBitmap->LockHeap();
DoWithDecoded((unsigned char*)iOffScreenBitmap->DataAddress(), EFalse, iFirstFrameNum, iFirstFrameTimeStamp, iFrameNum, iNowTime.Int64());
iOffScreenBitmap->UnlockHeap();
User::ResetInactivityTime();
DrawNow();
}
}
TBool CMobiFLVAppView::IsE50()
{
#ifndef __WINS__
TInt mUid = 0;
HAL::Get(HALData::EMachineUid, mUid);
switch (mUid)
{
case 0x20002495:
case 0x20000604:
return ETrue;
default:
return EFalse;
}
#else
return EFalse;
#endif
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -