javauis/mmapi_akn/baseline/src/sourcestreamreader.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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 JNI wrappers for CMMASourceStream
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "jutils.h"
       
    20 #include "com_nokia_microedition_media_protocol_SourceStreamReader.h"
       
    21 #include "cmmasourcestream.h"
       
    22 #include "cmmaeventsource.h"
       
    23 
       
    24 // If eventsource is already disposed, then do nothing
       
    25 #define CHECK_HANDLE(x, j) { if ( !( x ) || ( ( x )->Players().Count() == 0 ) ) { return ( j ); } }
       
    26 LOCAL_C void WriteDataL(TInt aSourceStream,
       
    27                         TInt aPlayer,
       
    28                         CMMAEventSource* aEventSource,
       
    29                         const TUint8* aData,
       
    30                         TInt aLength,
       
    31                         TInt aState)
       
    32 {
       
    33     if (!aEventSource->FindPlayer(aPlayer))
       
    34     {
       
    35         // Native object was already deleted
       
    36         User::Leave(KErrBadHandle);
       
    37     }
       
    38     CMMASourceStream* sourceStream =
       
    39         JavaUnhand< CMMASourceStream >(aSourceStream);
       
    40 
       
    41     sourceStream->WriteL(aData, aLength, aState);
       
    42 }
       
    43 
       
    44 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_protocol_SourceStreamReader__1write
       
    45 (JNIEnv* aJni, jclass, jint aSourceStream, jint aEventSource,
       
    46  jbyteArray aData, jint aLength, jint aState, jint aPlayerHandle)
       
    47 {
       
    48     CMMAEventSource* eventSource =
       
    49         JavaUnhand< CMMAEventSource >(aEventSource);
       
    50 
       
    51     CHECK_HANDLE(eventSource, KErrNone);
       
    52 
       
    53     jbyte* data = aJni->GetByteArrayElements(aData, NULL);
       
    54 
       
    55     TInt err = eventSource->ExecuteTrap(&WriteDataL,
       
    56                                         aSourceStream,
       
    57                                         aPlayerHandle,
       
    58                                         eventSource,
       
    59                                         (const TUint8*)data,
       
    60                                         aLength,
       
    61                                         aState);
       
    62 
       
    63     aJni->ReleaseByteArrayElements(aData, data, JNI_ABORT);
       
    64     return err;
       
    65 }
       
    66 
       
    67 // END OF FILE