javauis/mmapi_akn/animated_gif/src/cmmaanimationframepositioningcontrol.cpp
author Fionntina Carville <fionntinac@symbian.org>
Thu, 28 Oct 2010 16:07:36 +0100
branchRCL_3
changeset 86 be12440571b9
parent 19 04becd199f91
permissions -rw-r--r--
Reapply changes for bug 2896 and tweak for generatej9zips.py

/*
* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  This class implements FramePositioningControl for animation
*
*/


//  INCLUDE FILES
#include <jdebug.h>
#include <e32base.h>

#include "MIHLImageViewer.h"
#include "cmmaanimationframepositioningcontrol.h"

CMMAAnimationFramePositioningControl*
CMMAAnimationFramePositioningControl::NewL(CMMAAnimationPlayer* aPlayer)
{
    CMMAAnimationFramePositioningControl* self =
        new(ELeave) CMMAAnimationFramePositioningControl(aPlayer);
    return self;
}

CMMAAnimationFramePositioningControl::
CMMAAnimationFramePositioningControl(CMMAAnimationPlayer* aPlayer)
        : CMMAFramePositioningControl(aPlayer), iPlayer(aPlayer)
{
    DEBUG("MMA:CMMAAnimationFramePositioningControl::CMMAAnimationFramePositioningControl");
}

CMMAAnimationFramePositioningControl::~CMMAAnimationFramePositioningControl()
{
    DEBUG("MMA:CMMAAnimationFramePositioningControl::~CMMAAnimationFramePositioningControl");
}

TInt CMMAAnimationFramePositioningControl::SeekL(TInt aFrameNumber)
{
    DEBUG("CMMAAnimationFramePositioningControl::SeekL");
    MIHLImageViewer* viewer = iPlayer->Viewer();
    if (!viewer)
    {
        return KErrNotFound;
    }
    TInt frameNumber = FindFrame(viewer, aFrameNumber);
    TInt64 mediaTime = iPlayer->MediaTimeForFrame(frameNumber);
    // adjust wanted media time to get right frame (equal value returns one too small)
    mediaTime++;
    iPlayer->SetMediaTimeL(&mediaTime);
    frameNumber = viewer->AnimationFrame();
    return frameNumber;
}

TInt CMMAAnimationFramePositioningControl::SkipL(TInt aFramesToSkip)
{
    DEBUG("CMMAAnimationFramePositioningControl::SkipL");
    MIHLImageViewer* viewer = iPlayer->Viewer();
    if (!viewer)
    {
        return KErrNotFound;
    }

    TInt frameNumber = viewer->AnimationFrame();

    SeekL(frameNumber + aFramesToSkip);

    // Calculate number of frames skipped
    return viewer->AnimationFrame() - frameNumber;
}

void CMMAAnimationFramePositioningControl::MapFrameToTimeL(
    TInt aFrameNumber,
    TInt64* aMediaTime)
{
    DEBUG("CMMAAnimationFramePositioningControl::MapFrameToTimeL");
    MIHLImageViewer* viewer = iPlayer->Viewer();
    if (!viewer || (aFrameNumber < 0) ||
            (aFrameNumber >= viewer->AnimationFrameCount()))
    {
        *aMediaTime = KErrNotFound;
    }
    else
    {
        *aMediaTime = iPlayer->MediaTimeForFrame(aFrameNumber);
    }
}
TInt CMMAAnimationFramePositioningControl::MapTimeToFrameL(
    TInt64* aMediaTime)
{
    DEBUG("CMMAAnimationFramePositioningControl::MapTimeToFrameL");
    MIHLImageViewer* viewer = iPlayer->Viewer();
    TInt64 duration;
    iPlayer->GetDuration(&duration);
    if (!viewer || (*aMediaTime < 0) ||
            (duration == KErrNotFound))
    {
        return KErrNotFound;
    }
    return iPlayer->FindFrame(*aMediaTime);
}

TInt CMMAAnimationFramePositioningControl::FindFrame(MIHLImageViewer* aViewer, TInt aFrameNumber)
{
    TInt frame = 0;
    TInt count = aViewer->AnimationFrameCount();
    if (aFrameNumber >= count)
    {
        frame = count - 1;
    }
    else if (aFrameNumber > 0)
    {
        frame = aFrameNumber;
    }
    return frame;
}

//  END OF FILE