javauis/mmapi_qt/baseline/src/cmmacameraplayer.cpp
branchRCL_3
changeset 24 0fd27995241b
child 26 dc7c549001d5
equal deleted inserted replaced
20:f9bb0fca356a 24:0fd27995241b
       
     1 /*
       
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class is used for playing camera.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <logger.h>
       
    21 #include <fbs.h>
       
    22 #include "cmmacameraplayer.h"
       
    23 #include "tmmaparametervalidator.h"
       
    24 #include "mmmadisplay.h"
       
    25 #include "cmmacamerasound.h"
       
    26 
       
    27 #if defined( __WINS__ )
       
    28 #include <w32std.h>
       
    29 #endif
       
    30 
       
    31 // CONSTANTS
       
    32 _LIT8(KImageJpegMime, "image/jpeg");
       
    33 _LIT8(KJpegMime, "jpeg");
       
    34 _LIT(KVideoControlName, "VideoControl");
       
    35 
       
    36 CMMACameraPlayer* CMMACameraPlayer::NewLC(TInt aCameraIndex)
       
    37 {
       
    38     CMMACameraPlayer* self = new(ELeave) CMMACameraPlayer;
       
    39     CleanupStack::PushL(self);
       
    40     self->ConstructL(aCameraIndex);
       
    41     return self;
       
    42 }
       
    43 
       
    44 CMMACameraPlayer::~CMMACameraPlayer()
       
    45 {
       
    46     LOG( EJavaMMAPI, EInfo, "CMMACameraPlayer::~CMMACameraPlayer");
       
    47 
       
    48     // Free (duplicated) UI camera resources first.
       
    49     // Window is not able to send any
       
    50     // callback requests to UI from now.
       
    51     if (iWindow)
       
    52     {
       
    53         iWindow->SetDisplay(NULL);
       
    54     }
       
    55 
       
    56     if (iCamera)
       
    57     {
       
    58         iCamera->CancelCaptureImage();
       
    59         iCamera->Release();
       
    60         delete iCamera;
       
    61     }
       
    62 
       
    63     delete iSnapshotEncoded;
       
    64     delete iSnapshotBitmap;
       
    65     delete iRealizeWait;
       
    66 
       
    67     if (iDisplay && iDisplay->HasContainer())
       
    68     {
       
    69         // Window will delete itself
       
    70         // after all pending events are processed
       
    71         // (lazy delete)
       
    72        // iDisplay->UIGetCallback(
       
    73        //     *iWindow, CMMACameraWindow::EDestroyWindow);
       
    74     }
       
    75     else
       
    76     {
       
    77         delete iWindow;
       
    78     }
       
    79     iWindow = NULL;
       
    80 }
       
    81 
       
    82 
       
    83 CMMACameraPlayer::CMMACameraPlayer():
       
    84         iDisplay(NULL),
       
    85         iSourceSizeIndex(KErrNotFound),
       
    86         iStartTime(KErrNotFound)
       
    87 {
       
    88     iStopViewFinder = ETrue;
       
    89 }
       
    90 
       
    91 
       
    92 void CMMACameraPlayer::ConstructL(TInt aCameraIndex)
       
    93 {
       
    94     CMMAPlayer::ConstructL();
       
    95 
       
    96     if (aCameraIndex >= CCamera::CamerasAvailable())
       
    97     {
       
    98         // image capture is not supported
       
    99         User::Leave(KErrNotFound);
       
   100     }
       
   101 
       
   102     iCamera = CCamera::NewL(*this, aCameraIndex);
       
   103 
       
   104     iWindow = CMMACameraWindow::NewL(iCamera->Handle());
       
   105 
       
   106     TCameraInfo cameraInfo;
       
   107     iCamera->CameraInfo(cameraInfo);
       
   108 
       
   109     if (cameraInfo.iNumImageSizesSupported < 1)
       
   110     {
       
   111         // image capture is not supported
       
   112         User::Leave(KErrNotFound);
       
   113     }
       
   114 
       
   115     // default snapshot size
       
   116     iSourceSizeIndex = cameraInfo.iNumImageSizesSupported - 1;
       
   117 
       
   118     iRealizeWait = new(ELeave)CRealizeWait;
       
   119 }
       
   120 
       
   121 TInt64 CMMACameraPlayer::CurrentTime()
       
   122 {
       
   123     TTime time;
       
   124     time.HomeTime();
       
   125     return time.Int64();
       
   126 }
       
   127 
       
   128 void CMMACameraPlayer::ResolveViewFinderSizeL(TSize& aSize)
       
   129 {
       
   130     LOG( EJavaMMAPI, EInfo, "CMMACameraPlayer::ResolveViewFinderSizeL");
       
   131 
       
   132     TSize resultSize;
       
   133 
       
   134     // The only way to find out the size is to start the view finder
       
   135     // with a proper size (screen size).
       
   136 
       
   137     ResolveScreenSizeL(resultSize);
       
   138 
       
   139     // StartViewFinderBitmapsL changes resultSize to
       
   140     // the used view finder size.
       
   141     // Used to get the source size only.
       
   142     iCamera->StartViewFinderBitmapsL(resultSize);
       
   143 
       
   144     // Bitmap viewfinder is not used anymore.
       
   145     iCamera->StopViewFinder();
       
   146 
       
   147     aSize = resultSize;
       
   148 }
       
   149 
       
   150 void CMMACameraPlayer::ResolveScreenSizeL(TSize& aSize)
       
   151 {
       
   152     LOG( EJavaMMAPI, EInfo, "CMMACameraPlayer::ResolveScreenSizeL");
       
   153 
       
   154 #if defined( __WINS__ )
       
   155     TSize size(0,0);
       
   156     RWsSession ws;
       
   157 
       
   158     if (ws.Connect() == KErrNone)
       
   159     {
       
   160         CleanupClosePushL(ws);
       
   161 
       
   162         CWsScreenDevice* wsScreenDevice = new(ELeave)CWsScreenDevice(ws);
       
   163         CleanupStack::PushL(wsScreenDevice);
       
   164 
       
   165         User::LeaveIfError(wsScreenDevice->Construct());
       
   166 
       
   167         size = wsScreenDevice->SizeInPixels();
       
   168 
       
   169         CleanupStack::PopAndDestroy(2);    // wsScreenDevice, ws.Close()
       
   170     }
       
   171 
       
   172     aSize = size;
       
   173 
       
   174 #else
       
   175     TScreenInfoV01 info;
       
   176     TPckgBuf< TScreenInfoV01 > buf(info);
       
   177 
       
   178     UserSvr::ScreenInfo(buf);
       
   179     info = buf();
       
   180 
       
   181     aSize = info.iScreenSize;
       
   182 #endif
       
   183 }
       
   184 
       
   185 void CMMACameraPlayer::ResolveCaptureSizes(const CCamera::TFormat aFormat,
       
   186         const TInt aNumImageSizesSupported,
       
   187         const TSize& aRequestSize,
       
   188         TSize& aSourceSize,
       
   189         TInt& aSourceIndex,
       
   190         TInt& aLargestIndex)
       
   191 {
       
   192     // Largest image size
       
   193     TSize largestSize;
       
   194     // Index to largest image size
       
   195     TInt largestSizeIndex = 0;
       
   196     // Source size
       
   197     TSize sourceSize;
       
   198     // Default source size index not set
       
   199     TInt sourceSizeIndex = KErrNotFound;
       
   200     // Temporary size for iterating capture sizes
       
   201     TSize tmpSize;
       
   202 
       
   203     LOG1( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::ResolveCaptureSizes: aFormat = 0x%x", aFormat);
       
   204 
       
   205     // go through all supported sizes.
       
   206     // Notice: Capture sizes are assumed to be in order from smaller to larger sizes
       
   207     for (TInt i = 0; i < aNumImageSizesSupported; i++)
       
   208     {
       
   209         iCamera->EnumerateCaptureSizes(tmpSize,
       
   210                                        i,
       
   211                                        aFormat);
       
   212 
       
   213         LOG1( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::ResolveCaptureSizes: tmpSize.iWidth = %d", tmpSize.iWidth);
       
   214         LOG1( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::ResolveCaptureSizes: tmpSize.iHeight = %d", tmpSize.iHeight);
       
   215 
       
   216         // Check if current is the largest
       
   217         if ((largestSize.iWidth < tmpSize.iWidth) &&
       
   218                 (largestSize.iHeight < tmpSize.iHeight))
       
   219         {
       
   220             largestSize = tmpSize;
       
   221             largestSizeIndex = i;
       
   222         }
       
   223 
       
   224         // If wanted size is smaller than tmpSize we can use it
       
   225         if ((aRequestSize.iWidth <= tmpSize.iWidth) &&
       
   226                 (aRequestSize.iHeight <= tmpSize.iHeight))
       
   227         {
       
   228             sourceSize = tmpSize;
       
   229             sourceSizeIndex = i;
       
   230         }
       
   231     }
       
   232 
       
   233     LOG1( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::ResolveCaptureSizes: sourceSizeIndex = %d", sourceSizeIndex);
       
   234     LOG1( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::ResolveCaptureSizes: largestSizeIndex = %d", largestSizeIndex);
       
   235 
       
   236     aSourceSize = sourceSize;
       
   237     aSourceIndex = sourceSizeIndex;
       
   238     aLargestIndex = largestSizeIndex;
       
   239 }
       
   240 
       
   241 void CMMACameraPlayer::StartL()
       
   242 {
       
   243     LOG1( EJavaMMAPI, EInfo, "CMMACameraPlayer:StartL iState %d", iState);
       
   244 
       
   245     // start can't be called to not ready player
       
   246     if (iState == EPrefetched)
       
   247     {
       
   248         // camera passes ready images through
       
   249         // ViewFinderFrameReady method
       
   250 
       
   251         // set time when started
       
   252         iStartTime = CurrentTime();
       
   253 
       
   254         // inform java side
       
   255         ChangeState(EStarted);
       
   256 
       
   257         TInt64 time;
       
   258         GetMediaTime(&time);
       
   259 
       
   260         // Notify the camera window
       
   261         // about the status change
       
   262         iWindow->SetStarted(ETrue);
       
   263 
       
   264         // inform java side
       
   265         PostLongEvent(CMMAPlayerEvent::EStarted, time);
       
   266     }
       
   267     PostActionCompletedStart();    
       
   268     PostActionCompleted(KErrNone);   // java start return
       
   269 }
       
   270 
       
   271 void CMMACameraPlayer::StopL(TBool aPostEvent)
       
   272 {
       
   273     LOG1( EJavaMMAPI, EInfo, "CMMACameraPlayer::StopL", iState);
       
   274     if (iState == EStarted)
       
   275     {
       
   276         TInt64 time;
       
   277         GetMediaTime(&time);   // add played time to media time
       
   278 
       
   279         if (iStopViewFinder && iWindow->ViewFinderActive())
       
   280         {
       
   281             iWindow->SetStarted(EFalse);
       
   282         }
       
   283         iStartTime = KErrNotFound;
       
   284 
       
   285         if (aPostEvent)
       
   286         {
       
   287             PostLongEvent(CMMAPlayerEvent::EStopped, time);
       
   288         }
       
   289 
       
   290         // go back to prefetched state
       
   291         ChangeState(EPrefetched);
       
   292     }
       
   293 }
       
   294 
       
   295 void CMMACameraPlayer::DeallocateL()
       
   296 {
       
   297     // If player is started when deallocate is called,
       
   298     // player is stopped from java side -> state is changed to
       
   299     // prefetched.
       
   300     // In prefetched state only reserved resource is
       
   301     // camera reserve( released with iCamera->Release() )
       
   302     // In realized state no resources have been reserved.
       
   303     // CHANGED: not releasing camera anymore, since it is already
       
   304     // done in realized state
       
   305     if (iState == EPrefetched)
       
   306     {
       
   307         ChangeState(ERealized);
       
   308     }
       
   309 }
       
   310 
       
   311 
       
   312 void CMMACameraPlayer::RealizeL()
       
   313 {
       
   314     iCamera->Reserve();
       
   315     // this lock will be released when power on is completed (or error)
       
   316     if (!iRealizeWait->IsStarted())
       
   317     {
       
   318         iRealizeWait->Start();
       
   319     }
       
   320     User::LeaveIfError(iRealizeWait->iError);
       
   321     CMMAPlayer::RealizeL();
       
   322 }
       
   323 
       
   324 
       
   325 void CMMACameraPlayer::PrefetchL()
       
   326 {
       
   327     LOG( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::PrefetchL");
       
   328     // nothing to do here
       
   329     ChangeState(EPrefetched);
       
   330     PostActionCompleted(KErrNone);
       
   331 }
       
   332 
       
   333 
       
   334 void CMMACameraPlayer::GetDuration(TInt64* aDuration)
       
   335 {
       
   336     // camera viewer has no duration.
       
   337     *aDuration = KTimeUnknown;
       
   338 }
       
   339 
       
   340 
       
   341 void CMMACameraPlayer::SetMediaTimeL(TInt64* /*aTime*/)
       
   342 {
       
   343     LOG( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::SetMediaTimeL ");
       
   344     // with camera media time is not supported.
       
   345 }
       
   346 
       
   347 
       
   348 void CMMACameraPlayer::GetMediaTime(TInt64* aMediaTime)
       
   349 {
       
   350     if (iState == EStarted)
       
   351     {
       
   352         // add play time to media time
       
   353         iMediaTime += CurrentTime() - iStartTime;
       
   354         // set new start time
       
   355         iStartTime = CurrentTime();
       
   356     }
       
   357 
       
   358     // set value to parameter
       
   359     (*aMediaTime) = iMediaTime;
       
   360 }
       
   361 
       
   362 void CMMACameraPlayer::CloseL()
       
   363 {
       
   364     LOG( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::CloseL()");
       
   365 
       
   366     // cancel all activity
       
   367     iCamera->CancelCaptureImage();
       
   368 
       
   369     // Stop and release UI Camera instance
       
   370     iWindow->SetDisplay(NULL);
       
   371 
       
   372     // we don't need reserve camera anymore
       
   373     iCamera->Release();
       
   374 
       
   375     CMMAPlayer::CloseL();
       
   376 }
       
   377 
       
   378 const TDesC& CMMACameraPlayer::Type()
       
   379 {
       
   380     return KMMACameraPlayer;
       
   381 }
       
   382 
       
   383 // MCameraObserver
       
   384 void CMMACameraPlayer::ReserveComplete(TInt aError)
       
   385 {
       
   386     ELOG1( EJavaMMAPI, "MMA::CMMACameraPlayer::ReserveComplete %d", aError);
       
   387     if (aError == KErrNone)
       
   388     {
       
   389         // camera will notify completion with PowerOnComplete method.
       
   390         iCamera->PowerOn();
       
   391     }
       
   392     else
       
   393     {
       
   394         // release lock and store error. State doesn't change.
       
   395         iRealizeWait->iError = aError;
       
   396         iRealizeWait->AsyncStop();
       
   397     }
       
   398 
       
   399 }
       
   400 
       
   401 void CMMACameraPlayer::PowerOnComplete(TInt aError)
       
   402 {
       
   403     ELOG1( EJavaMMAPI, "MMA::CMMACameraPlayer::PowerOnComplete %d", aError);
       
   404 
       
   405     TSize viewFinderSize;
       
   406     TInt error = aError;
       
   407 
       
   408     if (error == KErrNone)
       
   409     {
       
   410         // The view finder size must be known after prefetching.
       
   411         TRAP(error, ResolveViewFinderSizeL(viewFinderSize));
       
   412     }
       
   413 
       
   414     if (error == KErrNone)
       
   415     {
       
   416         iSize = viewFinderSize;
       
   417 
       
   418         if (iDisplay)
       
   419         {
       
   420             iDisplay->SourceSizeChanged(iSize);
       
   421             NotifyWithStringEvent(CMMAPlayerEvent::ESizeChanged, KVideoControlName);
       
   422         }
       
   423     }
       
   424 
       
   425     iRealizeWait->iError = error;
       
   426     iRealizeWait->AsyncStop();
       
   427 }
       
   428 
       
   429 void CMMACameraPlayer::ViewFinderFrameReady(CFbsBitmap& /*aFrame*/)
       
   430 {
       
   431     // Empty implementation of an interface method.
       
   432     // DirectViewFinder is used
       
   433     // instead of BitmapViewFinder
       
   434 }
       
   435 
       
   436 void CMMACameraPlayer::ImageReady(CFbsBitmap* aBitmap,
       
   437                                   HBufC8* aData,
       
   438                                   TInt aError)
       
   439 {
       
   440     ELOG1( EJavaMMAPI, "MMA::CMMACameraPlayer::ImageReady %d", aError);
       
   441 
       
   442     // This method should never be called,
       
   443     // unless we are taking snapshot
       
   444     __ASSERT_DEBUG(iSnapshotStatus, User::Invariant());
       
   445 
       
   446     __ASSERT_DEBUG(!iSnapshotBitmap, User::Invariant());
       
   447     __ASSERT_DEBUG(!iSnapshotEncoded, User::Invariant());
       
   448 
       
   449     if (aError == KErrNone)
       
   450     {
       
   451         // this class has ownership of the bitmap until
       
   452         // snapshot bitmap is got from this class.
       
   453         iSnapshotBitmap = aBitmap;
       
   454         iSnapshotEncoded = aData;
       
   455     }
       
   456 
       
   457     // notify the caller, error code or KErrNone
       
   458     User::RequestComplete(iSnapshotStatus, aError);
       
   459     iWindow->SetStarted(ETrue);
       
   460     // Status is not needed anymore
       
   461     // and this class don't own the status.
       
   462     iSnapshotStatus = NULL;
       
   463 }
       
   464 
       
   465 void CMMACameraPlayer::FrameBufferReady(MFrameBuffer* /*aFrameBuffer*/,
       
   466                                         TInt /*aError*/)
       
   467 {
       
   468     LOG( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::FrameBufferReady");
       
   469     // this callback will never be called
       
   470     // Asserted in debug build to be sure.
       
   471     __ASSERT_DEBUG(EFalse, User::Invariant());
       
   472 }
       
   473 
       
   474 void CMMACameraPlayer::SetDisplayL(MMMADisplay* aDisplay)
       
   475 {
       
   476     LOG( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::SetDisplay");
       
   477 
       
   478     // now it is ready to draw
       
   479     iDisplay = aDisplay;
       
   480 
       
   481     // Passes display into iWindow.
       
   482     // Allocates all resources needed to use a camera DirectViewFinder.
       
   483     iWindow->SetDisplay(aDisplay);
       
   484 
       
   485     iDisplay->SetWindowL(iWindow);
       
   486 
       
   487     // Set view finder size to the display only if the view finder
       
   488     // size has been resolved.
       
   489     if (iSize != TSize(0, 0))
       
   490     {
       
   491         iDisplay->SourceSizeChanged(iSize);
       
   492         NotifyWithStringEvent(CMMAPlayerEvent::ESizeChanged, KVideoControlName);
       
   493     }
       
   494 }
       
   495 
       
   496 TSize CMMACameraPlayer::SourceSize()
       
   497 {
       
   498     return iSize;
       
   499 }
       
   500 
       
   501 MMMASnapshot::TEncoding CMMACameraPlayer::TakeSnapshotL(TRequestStatus* aStatus,
       
   502         const TSize& aSize,
       
   503         const CMMAImageSettings& aSettings)
       
   504 {
       
   505     __ASSERT_DEBUG(!iSnapshotStatus, User::Invariant());
       
   506     __ASSERT_DEBUG(!iSnapshotBitmap, User::Invariant());
       
   507     __ASSERT_DEBUG(!iSnapshotEncoded, User::Invariant());
       
   508 
       
   509     // snapshots can not be taken if player is not realized
       
   510     if (iState < ERealized)
       
   511     {
       
   512         User::Leave(KErrNotReady);
       
   513     }
       
   514     // save status which will be notified
       
   515     iSnapshotStatus = aStatus;
       
   516 
       
   517     // changing status to pending
       
   518     *iSnapshotStatus = KRequestPending;
       
   519 
       
   520     // Source size not set in the beginning
       
   521     TSize sourceSize;
       
   522 
       
   523     // Use default if size is not specified.
       
   524     TInt sourceSizeIndex = iSourceSizeIndex;
       
   525 
       
   526     // Largest image size index
       
   527     TInt largestSizeIndex = 0;
       
   528 
       
   529     // Get camera characteristics
       
   530     TCameraInfo cameraInfo;
       
   531     iCamera->CameraInfo(cameraInfo);
       
   532 
       
   533     // Set default snapshot encoding type
       
   534     TEncoding encoding = EBitmap;
       
   535 
       
   536     // Set default image capture format
       
   537     CCamera::TFormat format = CCamera::EFormatFbsBitmapColor16M;
       
   538 
       
   539     LOG1( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::TakeSnapshotL: cameraInfo.iImageFormatsSupported = 0x%x", cameraInfo.iImageFormatsSupported);
       
   540     LOG1( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::TakeSnapshotL: cameraInfo.iNumImageSizesSupported = %d", cameraInfo.iNumImageSizesSupported);
       
   541 
       
   542     // Check if size was set in Java
       
   543     if (aSize.iWidth != KErrNotFound &&
       
   544             aSize.iHeight != KErrNotFound)
       
   545     {
       
   546         // Determine if jpeg capture was requested
       
   547         if ((*aSettings.iMimeType == KJpegMime) ||
       
   548                 (*aSettings.iMimeType == KImageJpegMime))
       
   549         {
       
   550             // Shortcut for supported image formats
       
   551             TUint32 imageFormats = cameraInfo.iImageFormatsSupported;
       
   552 
       
   553             // Jpeg subtype constants
       
   554             _LIT8(KJpegJfif, "jfif");
       
   555             _LIT8(KJpegExif, "exif");
       
   556 
       
   557             // Resolve requested jpeg subtype from settings and camerainfo
       
   558             if ((imageFormats & CCamera::EFormatJpeg) &&
       
   559                     (*aSettings.iType == KJpegJfif))
       
   560             {
       
   561                 // JFIF JPEG
       
   562                 format = CCamera::EFormatJpeg;
       
   563                 encoding = EEncoded;
       
   564             }
       
   565             else if ((imageFormats & CCamera::EFormatExif) &&
       
   566                      (*aSettings.iType == KJpegExif))
       
   567             {
       
   568                 // EXIF JPEG
       
   569                 format =  CCamera::EFormatExif;
       
   570                 encoding = EEncoded;
       
   571             }
       
   572         }
       
   573 
       
   574         // Try to resolve nearest source size to the one requested,
       
   575         // except for the JFIF and EXIF jpeg subtypes the match has
       
   576         // to be exact otherwise non-encode capture format will be
       
   577         // used
       
   578         ResolveCaptureSizes(format,
       
   579                             cameraInfo.iNumImageSizesSupported,
       
   580                             aSize,
       
   581                             sourceSize,
       
   582                             sourceSizeIndex,
       
   583                             largestSizeIndex);
       
   584 
       
   585         // Format was either of the jpeg formats and requested size
       
   586         // didn't match the source size
       
   587         if ((format >= CCamera::EFormatJpeg &&
       
   588                 format <= CCamera::EFormatExif) &&
       
   589                 (aSize != sourceSize))
       
   590         {
       
   591             // Try again with an non-encoded format
       
   592             format = CCamera::EFormatFbsBitmapColor16M;
       
   593             encoding = EBitmap;
       
   594             ResolveCaptureSizes(format,
       
   595                                 cameraInfo.iNumImageSizesSupported,
       
   596                                 aSize,
       
   597                                 sourceSize,
       
   598                                 sourceSizeIndex,
       
   599                                 largestSizeIndex);
       
   600         }
       
   601 
       
   602         if (sourceSizeIndex == KErrNotFound)
       
   603         {
       
   604             // If correct index was not found use the largest.
       
   605             sourceSizeIndex = largestSizeIndex;
       
   606         }
       
   607     }
       
   608     // else use default iSourceSizeIndex and default image capture format
       
   609 
       
   610     iCamera->PrepareImageCaptureL(format,
       
   611                                   sourceSizeIndex);
       
   612 
       
   613     // play sound when capturing image
       
   614     CMMACameraSound::PlayImageCaptureSoundL();
       
   615 
       
   616     // start capture, ImageReady will be called when ready
       
   617     iWindow->SetStarted(EFalse);
       
   618 
       
   619     iCamera->CaptureImage();
       
   620 		
       
   621     LOG1( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::TakeSnapshotL: format = 0x%x", format);
       
   622     LOG1( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::TakeSnapshotL: sourceSizeIndex = %d", sourceSizeIndex);
       
   623     LOG1( EJavaMMAPI, EInfo, "MMA::CMMACameraPlayer::TakeSnapshotL: encoding = %d", encoding);
       
   624 
       
   625     // Inform caller which snapshot encoding was ultimately used
       
   626     return encoding;
       
   627 }
       
   628 
       
   629 CFbsBitmap* CMMACameraPlayer::SnapshotBitmap()
       
   630 {
       
   631     CFbsBitmap* bitmap = iSnapshotBitmap;
       
   632 
       
   633     // ownership transfers to the caller
       
   634     iSnapshotBitmap = NULL;
       
   635     return bitmap;
       
   636 }
       
   637 
       
   638 HBufC8* CMMACameraPlayer::SnapshotEncoded()
       
   639 {
       
   640     HBufC8* encoded = iSnapshotEncoded;
       
   641 
       
   642     // ownership transfers to the caller
       
   643     iSnapshotEncoded = NULL;
       
   644     return encoded;
       
   645 }
       
   646 
       
   647 void CMMACameraPlayer::NotifyWithStringEvent(
       
   648     CMMAPlayerEvent::TEventType aEventType,
       
   649     const TDesC& aStringEventData)
       
   650 {
       
   651     PostStringEvent(aEventType, aStringEventData);
       
   652 }
       
   653 
       
   654 MMMASnapshot* CMMACameraPlayer::SnapshoterL()
       
   655 {
       
   656     return this;
       
   657 }
       
   658 
       
   659 TInt CMMACameraPlayer::CameraHandle()
       
   660 {
       
   661     return iCamera->Handle();
       
   662 }
       
   663 
       
   664 void CMMACameraPlayer::SetViewFinderMode(TBool aStopViewFinder)
       
   665 {
       
   666     iStopViewFinder = aStopViewFinder;
       
   667 }
       
   668 
       
   669 //  END OF FILE