javauis/mmapi_akn/baseline/src/nativeplayerfactory.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2002 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 has NativePlayerFactory JNI functions
       
    15 *
       
    16 */
       
    17 
       
    18 #include <jdebug.h>
       
    19 
       
    20 #include "com_nokia_microedition_media_NativePlayerFactory.h"
       
    21 #include "cmmamanager.h"
       
    22 #include "cmmaplayer.h"
       
    23 
       
    24 /**
       
    25  * Adds player to event source. If player could not be created
       
    26  * handle KErrNone indicates in Java side that there wasn't suitable factory.
       
    27  */
       
    28 LOCAL_C void HandleCreatePlayerL(CMMAPlayer* aPlayer,
       
    29                                  CMMAEventSource* aEventSource,
       
    30                                  TInt* aHandle)
       
    31 {
       
    32     if (aPlayer)
       
    33     {
       
    34         // Player was created, add it to event source
       
    35         CleanupStack::PushL(aPlayer);
       
    36         aEventSource->AddPlayerL(aPlayer);
       
    37         *aHandle = JavaMakeHandle(aPlayer);
       
    38         CleanupStack::Pop(aPlayer);
       
    39     }
       
    40     else
       
    41     {
       
    42         // Data was not supported and there is no error.
       
    43         // Return KErrNone to java side
       
    44         *aHandle = KErrNone;
       
    45     }
       
    46 }
       
    47 
       
    48 /**
       
    49  * Local function that calls CMMAManager's CreatePlayerL method.
       
    50  */
       
    51 LOCAL_C void CreatePlayerHeaderDataL(CMMAManager* aManager,
       
    52                                      CMMAEventSource* aEventSource,
       
    53                                      const TDesC8* aHeaderData,
       
    54                                      TInt* aHandle)
       
    55 {
       
    56     HandleCreatePlayerL(aManager->CreatePlayerL(*aHeaderData),
       
    57                         aEventSource,
       
    58                         aHandle);
       
    59 }
       
    60 
       
    61 /**
       
    62  * JNI function from NativePlayerFactory class.
       
    63  */
       
    64 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_NativePlayerFactory__1createPlayerHeaderData
       
    65 (JNIEnv* aJni, jclass,
       
    66  jint aEventSourceHandle, jint aManagerHandle,
       
    67  jbyteArray aHeaderData)
       
    68 {
       
    69     // Development time check.
       
    70     __ASSERT_DEBUG((aEventSourceHandle > 0) && (aManagerHandle > 0), User::Invariant());
       
    71 
       
    72     CMMAEventSource* eventSource =
       
    73         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
    74     CMMAManager* manager = JavaUnhand< CMMAManager >(aManagerHandle);
       
    75 
       
    76     // Returning just KErrNone if there is no header data
       
    77     TInt playerHandle = KErrNone;
       
    78     if (aHeaderData)
       
    79     {
       
    80         // Get pointer to Java header data
       
    81         jbyte* data = aJni->GetByteArrayElements(aHeaderData, NULL);
       
    82         // if data is null Java data could not be obtained to native and
       
    83         // KErrNoMemory is returned to Java
       
    84         if (!data)
       
    85         {
       
    86             return KErrNoMemory;
       
    87         }
       
    88 
       
    89         TInt headerDataLength = aJni->GetArrayLength(aHeaderData);
       
    90         TPtrC8 headerData((TUint8*)data, headerDataLength);
       
    91         TInt err = eventSource->ExecuteTrap(&CreatePlayerHeaderDataL,
       
    92                                             manager,
       
    93                                             eventSource,
       
    94                                             (const TDesC8*)&headerData,
       
    95                                             &playerHandle);
       
    96 
       
    97         // release bytes got with GetByteArrayElements
       
    98         aJni->ReleaseByteArrayElements(aHeaderData,
       
    99                                        data,
       
   100                                        0);
       
   101         if (err != KErrNone)
       
   102         {
       
   103             // Leave occured return error code to Java
       
   104             playerHandle = err;
       
   105             DEBUG_INT("MMA::NativePlayerFactory createPlayerHeaderData err %d",
       
   106                       playerHandle);
       
   107         }
       
   108     }
       
   109     return playerHandle;
       
   110 }
       
   111 
       
   112 /**
       
   113  * Local function that calls CMMAManager's CreatePlayerL method.
       
   114  */
       
   115 LOCAL_C void CreatePlayerLocatorL(CMMAManager* aManager,
       
   116                                   CMMAEventSource* aEventSource,
       
   117                                   const TDesC* aProtocol,
       
   118                                   const TDesC* aMiddlePart,
       
   119                                   const TDesC* aParameters,
       
   120                                   TInt* aHandle)
       
   121 {
       
   122     HandleCreatePlayerL(aManager->CreatePlayerL(*aProtocol,
       
   123                         *aMiddlePart,
       
   124                         *aParameters),
       
   125                         aEventSource,
       
   126                         aHandle);
       
   127 }
       
   128 
       
   129 /**
       
   130  * JNI function from NativePlayerFactory class.
       
   131  */
       
   132 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_NativePlayerFactory__1createPlayerLocator
       
   133 (JNIEnv* aJni, jclass,
       
   134  jint aEventSourceHandle, jint aManagerHandle,
       
   135  jstring aProtocol, jstring aMiddlePart, jstring aParameters)
       
   136 {
       
   137     // Development time check.
       
   138     __ASSERT_DEBUG((aEventSourceHandle > 0) && (aManagerHandle > 0), User::Invariant());
       
   139 
       
   140     CMMAEventSource* eventSource =
       
   141         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
   142     CMMAManager* manager = JavaUnhand< CMMAManager >(aManagerHandle);
       
   143 
       
   144     // Get Java strings to native
       
   145     RJString protocol(*aJni, aProtocol);
       
   146     RJString middlePart(*aJni, aMiddlePart);
       
   147 
       
   148     // If Java parameters is null, empty descriptor will be given to
       
   149     // CreatePlayerL method.
       
   150     TPtrC parameters(KNullDesC);
       
   151     RJString* tmp = NULL;
       
   152     if (aParameters != NULL)
       
   153     {
       
   154         tmp = new RJString(*aJni, aParameters);
       
   155         if (tmp)
       
   156         {
       
   157             parameters.Set(*tmp);
       
   158         }
       
   159         else
       
   160         {
       
   161             // failed to create string
       
   162             return KErrNoMemory;
       
   163         }
       
   164     }
       
   165 
       
   166     TInt playerHandle = KErrNoMemory;
       
   167     TInt err = eventSource->ExecuteTrap(&CreatePlayerLocatorL,
       
   168                                         manager,
       
   169                                         eventSource,
       
   170                                         (const TDesC*)&protocol,
       
   171                                         (const TDesC*)&middlePart,
       
   172                                         (const TDesC*)&parameters,
       
   173                                         &playerHandle);
       
   174     delete tmp;
       
   175     if (err != KErrNone)
       
   176     {
       
   177         // Leave occured return error code to Java
       
   178         playerHandle = err;
       
   179         DEBUG_INT("MMA::NativePlayerFactory createPlayerLocator err %d",
       
   180                   playerHandle);
       
   181     }
       
   182     return playerHandle;
       
   183 }
       
   184 
       
   185 /**
       
   186  * Local function that calls CMMAManager's CreatePlayerL method.
       
   187  */
       
   188 LOCAL_C void CreatePlayerContentTypeL(CMMAManager* aManager,
       
   189                                       CMMAEventSource* aEventSource,
       
   190                                       const TDesC* aContentType,
       
   191                                       TInt* aHandle)
       
   192 {
       
   193     HandleCreatePlayerL(aManager->CreatePlayerL(*aContentType),
       
   194                         aEventSource,
       
   195                         aHandle);
       
   196 }
       
   197 
       
   198 /**
       
   199  * JNI function from NativePlayerFactory class.
       
   200  */
       
   201 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_NativePlayerFactory__1createPlayerContentType
       
   202 (JNIEnv* aJni, jclass,
       
   203  jint aEventSourceHandle, jint aManagerHandle,
       
   204  jstring aContentType)
       
   205 {
       
   206     // Development time check.
       
   207     __ASSERT_DEBUG((aEventSourceHandle > 0) && (aManagerHandle > 0), User::Invariant());
       
   208 
       
   209     CMMAEventSource* eventSource =
       
   210         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
   211     CMMAManager* manager = JavaUnhand< CMMAManager >(aManagerHandle);
       
   212 
       
   213     RJString contentType(*aJni, aContentType);
       
   214     TInt playerHandle = KErrNoMemory;
       
   215     TInt err = eventSource->ExecuteTrap(&CreatePlayerContentTypeL,
       
   216                                         manager,
       
   217                                         eventSource,
       
   218                                         (const TDesC*)&contentType,
       
   219                                         &playerHandle);
       
   220     if (err != KErrNone)
       
   221     {
       
   222         // Leave occured return error code to Java
       
   223         playerHandle = err;
       
   224         DEBUG_INT("MMA::NativePlayerFactory createPlayerContentType err %d",
       
   225                   playerHandle);
       
   226     }
       
   227     return playerHandle;
       
   228 }
       
   229 
       
   230 //  END OF FILE