khronosfws/openmax_al/src/adaptation/xaadaptation.h
changeset 12 5a06f39ad45b
equal deleted inserted replaced
0:71ca22bcf22a 12:5a06f39ad45b
       
     1 /*
       
     2 * Copyright (c) 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef XAADAPTATION_H_
       
    19 #define XAADAPTATION_H_
       
    20 
       
    21 #include <pthread.h>
       
    22 #include <semaphore.h>
       
    23 #include <string.h>
       
    24 #include <unistd.h>
       
    25 #include "openmaxalwrapper.h"
       
    26 #include "XAAdaptationContextBase.h"
       
    27 #include "XAGlobals.h"
       
    28 #include <gst.h>
       
    29 #include <gstappsrc.h>
       
    30 #include <gstappsink.h>
       
    31 #include <gstappbuffer.h>
       
    32 #include <photography.h>
       
    33 #include <OpenMAXAL_ContentPipe.h>
       
    34 #include "XAPlatform.h"
       
    35 #include "XAStaticCapsAdaptation.h"
       
    36 
       
    37 #ifdef XA_IMPL_MEASURE_GST_DELAY
       
    38 #include <time.h>
       
    39 #endif /* XA_IMPL_MEASURE_GST_DELAY */
       
    40 
       
    41 /* MACROS */
       
    42 #define FLIP_NONE               0
       
    43 #define FLIP_CLOCKWISE          1 /* Rotate clockwise 90 degrees */
       
    44 #define FLIP_ROTATE_180         2 /* Rotate 180 degrees */
       
    45 #define FLIP_COUNTERCLOCKWISE   3 /* Rotate counter-clockwise 90 degrees */
       
    46 #define FLIP_HORIZONTAL         4 /* Flip image horizontally */
       
    47 #define FLIP_VERTICAL           5 /* Flip image vertically */
       
    48 
       
    49 /* TYPEDEFS */
       
    50 typedef gboolean (*GstBusCb)( GstBus *bus, GstMessage *message, gpointer data );
       
    51 #define XA_IMPL_SUPPORTED_AUDIO_OUT_NUM 3
       
    52 #define XA_IMPL_OMIX_MAX_CONNECTED_MEDIAPLAYERS 10
       
    53 #define CONTENT_PIPE_BUFFER_SIZE 1000
       
    54 #define TEST_VIDEO_WIDTH     640
       
    55 #define TEST_VIDEO_HEIGHT    480
       
    56 
       
    57 typedef enum
       
    58 {
       
    59     XA_AUDIO_WAVENC = 0,
       
    60     XA_AUDIO_VORBISENC,
       
    61     XA_AUDIO_PCM,
       
    62     XA_NUM_OF_AUDIOENCODERS /* Do not move this line */
       
    63 } XAAudioEnc;
       
    64 
       
    65 typedef enum
       
    66 {
       
    67     XA_VIDEO_JPEGENC = 0,
       
    68     XA_VIDEO_THEORAENC,
       
    69     XA_NUM_OF_VIDEOENCODERS /* Do not move this line */
       
    70 } XAVideoEnc;
       
    71 
       
    72 typedef enum CP_STATE
       
    73 {
       
    74 	CPStateNull =0,
       
    75 	CPStateInitialized,
       
    76 	CPStatePrerolling,
       
    77 	CPStateStarted,
       
    78 	CPStateRunning,
       
    79 	CPStatePaused,
       
    80 	CPStateStopped,
       
    81 	CPStateWaitForData,
       
    82 	CPStateEOS,
       
    83 	CPStateError
       
    84 }CP_STATE;
       
    85 
       
    86 typedef enum
       
    87 {
       
    88     XA_IMAGE_JPEGENC = 0,
       
    89     XA_IMAGE_RAW,
       
    90     XA_NUM_OF_IMAGEENCODERS /* Do not move this line */
       
    91 } XAImageEnc;
       
    92 
       
    93 typedef enum
       
    94 {
       
    95     XA_RADIO_IDLE,
       
    96     XA_RADIO_SEEKING,
       
    97     XA_RADIO_SETTING_FREQUENCY,
       
    98     XA_RADIO_SETTING_FREQUENCY_RANGE
       
    99 } XARadioState;
       
   100 
       
   101 typedef enum
       
   102 {
       
   103     XA_RADIO_RDS_IDLE,
       
   104     XA_RADIO_RDS_GETTING_ODA_GROUP
       
   105 } XARadioRDSState;
       
   106 /* STRUCTURES */
       
   107 
       
   108 typedef struct XAAdaptEvtHdlr_
       
   109 {
       
   110     xaAdaptEventHandler handlerfunc;    /* function handling the callback */
       
   111     void               *handlercontext; /* context of handler */
       
   112     XAuint32            eventtypes;     /* what kind of events this handles */
       
   113 } XAAdaptEvtHdlr;
       
   114 
       
   115 /* Structure for content pipe thread context */
       
   116 typedef struct XAAdaptCpThrCtx_
       
   117 {
       
   118 	XADataLocator_ContentPipe* pipe; 	/* pointer to content Pipe structure (Sink/Source) */
       
   119 	CPhandle	dataHandle; 			/* Handle to content pipe data */
       
   120 	CP_STATE	state;
       
   121 	XAConfigExtensionCpKey cpConfig; 	/* enum value for CP using e.g. ReadBuffer or WriteBuffer */
       
   122 	XAImplSemHandle stateSem;
       
   123 	XAImplSemHandle mpStateSem;
       
   124 	XAImplSemHandle mpPrerollStateSem;
       
   125 
       
   126 	GstAppSrc	*appSrc; 				/* Pointer to appSrc where data is read from. Not owned */
       
   127 	GstAppSink  *appSink; 				/* Pointer to AppSink where dats is fed. Not owned */
       
   128 }XAAdaptCpThrCtx;
       
   129 
       
   130 /* context to track buffer insufficient event */
       
   131 typedef struct recordItfCtx_{
       
   132     XAImplSemHandle bufInsufficientSem;
       
   133     XAboolean buffer_insufficient;
       
   134 }recodtItfCtx;
       
   135 
       
   136 /*
       
   137  * Structure that holds all common variables for every
       
   138  * Gst-Adaptation context structures.
       
   139  */
       
   140 typedef struct XAAdaptationBaseCtx_
       
   141 {
       
   142     /* Common Variables for all adaptation elements */
       
   143     XAuint32        ctxId;
       
   144     GstState        binWantedState;   /** requested gst-bin target state **/
       
   145     GstElement      *bin;       /** Container for all gst elements **/
       
   146 
       
   147     GstBus          *bus;       /** Gst-bus where gst sends messages **/
       
   148     GMainLoop       *busloop;       /** Gst-bus listener loop **/
       
   149     pthread_t       busloopThr;
       
   150     GstBusCb        busCb;      /** Gst-Bus callback funtion*/
       
   151 
       
   152     GArray*         evtHdlrs;    /* array of event handlers */
       
   153 
       
   154     XAboolean       waitingasyncop;
       
   155     sem_t           semAsyncWait;
       
   156     guint           asynctimer;
       
   157 
       
   158     XAConfigExtensionCpKey cpConfig; /* enum value for CP using e.g. ReadBuffer or WriteBuffer */
       
   159 
       
   160 	/* Content Pipe variables */
       
   161 	XAImplThreadHandle	pipeSrcThr, pipeSinkThr;
       
   162 	XAAdaptCpThrCtx		pipeSrcThrCtx, pipeSinkThrCtx;
       
   163 
       
   164 #ifdef XA_IMPL_MEASURE_GST_DELAY
       
   165     clock_t     startTime;
       
   166     clock_t     endTime;
       
   167     double      diff;
       
   168 #endif /*XA_IMPL_MEASURE_GST_DELAY*/
       
   169     // VASU MOD BEGINS
       
   170     XAboolean thread_launched;
       
   171     pthread_mutex_t ds_mutex;
       
   172     pthread_cond_t ds_condition;
       
   173     XAboolean cond_mutx_inited;
       
   174     // VASU MOD ENDS
       
   175     /* FUNCTIONS*/
       
   176 
       
   177 } XAAdaptationBaseCtx_;
       
   178 
       
   179 typedef struct XAEngineAdaptationCtx_
       
   180 {
       
   181     /* Parent*/
       
   182     XAAdaptationBaseCtx_    baseObj;
       
   183 
       
   184 } XAEngineAdaptationCtx_;
       
   185 
       
   186 typedef struct XAMetadataAdaptVars_
       
   187 {
       
   188 
       
   189     XAuint32        childcount;
       
   190     XAuint32        nodedepth;
       
   191     XAuint32        traversemode;
       
   192 
       
   193     GstTagList*     generaltags;
       
   194     GstStructure*   audiotags;
       
   195     GstStructure*   videotags;
       
   196     GstStructure**   currentchild; /*points to one of previous 3*/
       
   197 
       
   198 } XAMetadataAdaptVars;
       
   199 
       
   200 
       
   201 /*
       
   202  * Structure for Media Player specific gst-adaptation.
       
   203  */
       
   204 typedef struct XAMediaPlayerAdaptationCtx_
       
   205 {
       
   206     /* Parent*/
       
   207     XAAdaptationBaseCtx_    baseObj;
       
   208 
       
   209     /* OMX-AL Variables */
       
   210     XADataSource            *xaSource, *xaBankSrc;
       
   211     XADataSink              *xaAudioSink, *xaVideoSink, *xaLEDArray, *xaVibra;
       
   212 
       
   213     /* GST elements */
       
   214     GstElement              *source;
       
   215     XAboolean               isobjsrc;    /*is source another XA object?*/
       
   216     GstElement              *codecbin;
       
   217     GstElement              *audioppbin;
       
   218     GstElement              *videoppbin;
       
   219     GstElement				*filter;
       
   220     GstElement              *videoppBScrbin;
       
   221     GstElement              *inputSelector;
       
   222     GstPad                  *blackScrSrcPad;
       
   223     GstPad                  *videoScrSrcPad;
       
   224     GstPad                  *blackScrSinkPad;
       
   225     GstPad                  *videoScrSinkPad;
       
   226     GstElement              *audiosink;
       
   227     XAboolean               isobjasink;   /*is audio sink another XA object?*/
       
   228     GstElement              *videosink;
       
   229     XAboolean               isobjvsink;   /*is video sink another XA object?*/
       
   230 
       
   231     XAboolean               mute;
       
   232     XAuint32                imageEffectID;
       
   233     XAboolean               isStereoPosition;
       
   234     XAmillidegree           curRotation;
       
   235     XAuint32                curMirror;
       
   236 
       
   237     XAint32                 buffering;
       
   238 
       
   239     /* internals */
       
   240     XAboolean               trackpositionenabled;
       
   241     guint                   runpositiontimer;
       
   242     GSourceFunc             positionCb;
       
   243     gint64                  lastpos;
       
   244 
       
   245     XAboolean               loopingenabled;
       
   246     gint64                  loopstart;
       
   247     gint64                  loopend;
       
   248 
       
   249     gdouble                 playrate;
       
   250     guint32                 rateprops;
       
   251 
       
   252     XAboolean				cameraSinkSynced;
       
   253 
       
   254     XAMetadataAdaptVars     *metadatavars;
       
   255 
       
   256 } XAMediaPlayerAdaptationCtx_;
       
   257 
       
   258 typedef struct XASnapshotItfVars_
       
   259 {
       
   260 
       
   261     /*User variables*/
       
   262     XAuint32        numpics;
       
   263     XAuint32        fps;
       
   264     XAboolean       freeze;
       
   265     gchar*          fnametemplate;
       
   266     XADataSink*     xaSink;
       
   267 
       
   268     /* internal variables */
       
   269     gboolean        waitforbuffer;
       
   270     gboolean        parsenegotiated;
       
   271     XAuint32        numpicstaken;
       
   272 
       
   273     GstBus*         ssbus;
       
   274     GstElement*     sspipeline;
       
   275     GstElement*     ssbuffersrc;
       
   276     GstElement*     ssparser;
       
   277     GstElement*     ssscaler;
       
   278     GstElement*     ssfilter;
       
   279     GstElement*     ssencoder;
       
   280     GstElement*     sstagger;
       
   281     GstElement*     sssink;
       
   282     gulong          sighandler;
       
   283 
       
   284     GstBuffer*      snapshotbuffer;
       
   285 
       
   286 } XASnapshotItfVars;
       
   287 
       
   288 typedef struct XAMediaRecorderAdaptationCtx_
       
   289 {
       
   290     /* Parent*/
       
   291     XAAdaptationBaseCtx_ baseObj;
       
   292 
       
   293     /* OMX-AL Variables */
       
   294     XADataSource            *xaAudioSource, *xaVideoSource;
       
   295     XADataSink              *xaSink;
       
   296     XAuint8                 recModes;
       
   297 
       
   298     /* GST elements */
       
   299     GstElement              *datasink;
       
   300     XAboolean               isobjsink;   /*is sink another XA object?*/
       
   301     GstElement              *codecbin;
       
   302     GstElement              *audioppbin;
       
   303     GstElement              *audiofilter;
       
   304     GstElement              *videoppbin;
       
   305     GstElement              *videofilter;
       
   306     GstElement              *videoextract;
       
   307     GstElement              *audiosource;
       
   308     GstElement              *audioqueue;
       
   309     XAboolean               isobjasrc;    /*is audio source another XA object?*/
       
   310     GstElement              *videosource;
       
   311     GstState				vsrcOrigState;
       
   312     GstElement              *videoqueue;
       
   313     XAboolean               isobjvsrc;    /*is video source another XA object?*/
       
   314     XAboolean               encodingchanged;
       
   315 
       
   316     XAboolean               mute;
       
   317     XAuint32                imageEffectID;
       
   318     XAboolean               isStereoPosition;
       
   319     XAuint32                xaRecordState;
       
   320     XAmillidegree           curRotation;
       
   321     XAuint32                curMirror;
       
   322     XAboolean               isRecord;
       
   323 
       
   324     /* internals */
       
   325     XAboolean               trackpositionenabled;
       
   326     gboolean                runpositiontimer;
       
   327     GSourceFunc             positionCb;
       
   328 
       
   329     XAImplThreadHandle      recordingEventThr;
       
   330     recodtItfCtx            recThrCtx;
       
   331 
       
   332 
       
   333     /* Variables for snapshot */
       
   334     XASnapshotItfVars       snapshotVars;
       
   335 
       
   336     XAMetadataAdaptVars     *metadatavars;
       
   337 
       
   338     /* Variables for encoders */
       
   339     XAAudioEncoderSettings  audioEncSettings;
       
   340     XAVideoSettings         videoEncSettings;
       
   341     XAImageSettings         imageEncSettings;
       
   342 
       
   343     /*buffersink variable*/
       
   344     guint64                 writepos;
       
   345 
       
   346 } XAMediaRecorderAdaptationCtx_;
       
   347 
       
   348 
       
   349 /*
       
   350  * Structure for Camera specific gst-adaptation variables
       
   351  */
       
   352 typedef struct XACameraAdaptationCtx_ {
       
   353 
       
   354     /* Parent*/
       
   355     XAAdaptationBaseCtx_ baseObj;
       
   356 
       
   357     /* OMX-AL Variables */
       
   358     XAuint32        deviceID;
       
   359     XAuint32        imageEffectID;
       
   360     XAmillidegree   curRotation;
       
   361     XAuint32        curMirror;
       
   362 
       
   363     /* GST Variables */
       
   364     GstFocusStatus focusStatus;
       
   365 
       
   366     /* Internals */
       
   367     XAboolean		recording;
       
   368     XAboolean		playing;
       
   369     XAboolean		snapshotting;
       
   370 } XACameraAdaptationCtx_;
       
   371 
       
   372 /*
       
   373  * Structure for Camera specific gst-adaptation variables
       
   374  */
       
   375 typedef struct XARadioAdaptationCtx_ {
       
   376 
       
   377     /* Parent*/
       
   378     XAAdaptationBaseCtx_ baseObj;
       
   379 
       
   380     /* OMX-AL Variables */
       
   381     XAuint32 frequency;
       
   382     XAuint8 range;
       
   383 
       
   384     pthread_t emulationThread;
       
   385     pthread_t rdsEmulationThread;
       
   386     XARadioRDSState rdsState;
       
   387     XARadioState state;
       
   388 
       
   389     /* GST Variables */
       
   390 } XARadioAdaptationCtx_;
       
   391 
       
   392 
       
   393 typedef struct XAOMixAdaptConnObj_
       
   394 {
       
   395     /*pointer to connected context*/
       
   396     XAAdaptationBaseCtx* ctx;
       
   397     /*pointer to sink currently used by connected ctx*/
       
   398     GstElement* currentSink;
       
   399 } XAOMixAdaptConnObj;
       
   400 
       
   401 typedef struct XAOutputMixAdaptationCtx_
       
   402 {
       
   403     /* Parent*/
       
   404     XAAdaptationBaseCtx_ baseObj;
       
   405     /* Internal variables */
       
   406     XAboolean   isStereoPosition;
       
   407     XAboolean	mute;
       
   408 
       
   409     XAuint32    currentrouting;
       
   410 
       
   411     GArray* 	availableDevices;
       
   412     GArray*     connectedObjects;
       
   413 } XAOutputMixAdaptationCtx_;
       
   414 
       
   415 /*
       
   416  * Structure for Ledarray specific gst-adaptation variables
       
   417  */
       
   418 typedef struct XALEDArrayAdaptationCtx_ {
       
   419 
       
   420     /* Parent*/
       
   421     XAAdaptationBaseCtx_ baseObj;
       
   422 
       
   423     /* OMX-AL Variables */
       
   424     XAuint32    deviceID;
       
   425 
       
   426     /* GST Variables */
       
   427 
       
   428 } XALedarrayAdaptationCtx_;
       
   429 
       
   430 /*
       
   431  * Structure for Vibra specific gst-adaptation variables
       
   432  */
       
   433 typedef struct XAVibraAdaptationCtx_ {
       
   434 
       
   435     /* Parent*/
       
   436     XAAdaptationBaseCtx_ baseObj;
       
   437 
       
   438     /* OMX-AL Variables */
       
   439     XAuint32    deviceID;
       
   440 
       
   441     /* GST Variables */
       
   442 } XAVibraAdaptationCtx_;
       
   443 
       
   444 /* FUNCTIONS */
       
   445 /*
       
   446  * gboolean XAAdaptationBase_GstBusCb( GstBus *bus, GstMessage *message, gpointer data );
       
   447  * Default CallBack handler for gst-bus messages. This will be called if object specific callback is
       
   448  * not implemented.
       
   449  */
       
   450 gboolean XAAdaptationBase_GstBusCb( GstBus *bus, GstMessage *message, gpointer data );
       
   451 
       
   452 XAresult XAAdaptationBase_InitGstListener(XAAdaptationBaseCtx* ctx);
       
   453 void * XAAdaptationBase_LaunchGstListener(void* args);
       
   454 void XAAdaptationBase_StopGstListener(XAAdaptationBaseCtx* ctx);
       
   455 void XAAdaptationBase_SendAdaptEvents(XAAdaptationBaseCtx* ctx, XAAdaptEvent* event);
       
   456 
       
   457 void XAAdaptationBase_PrepareAsyncWait(XAAdaptationBaseCtx* ctx);
       
   458 void XAAdaptationBase_StartAsyncWait(XAAdaptationBaseCtx* ctx);
       
   459 gboolean XAAdaptationBase_CancelAsyncWait(gpointer ctx);
       
   460 void XAAdaptationBase_CompleteAsyncWait(XAAdaptationBaseCtx* ctx);
       
   461 
       
   462 GstElement* XAAdaptationBase_CreateGstSource( XADataSource* xaSrc, const char *name, XAboolean *isobj, XAboolean *isPCM, XAboolean *isRawImage );
       
   463 GstElement* XAAdaptationBase_CreateGstSink( XADataSink* xaSrc, const char *name, XAboolean *isobj );
       
   464 GstElement* XAAdaptationBase_CreateVideoPP( );
       
   465 
       
   466 GstElement* XAAdaptationBase_CreateVideoPPBlackScr( );
       
   467 GstElement* XAAdaptationBase_CreateInputSelector( );
       
   468 GstElement* XAAdaptationBase_CreateAudioPP( );
       
   469 void XAAdaptationBase_PadBlockCb(GstPad *pad, gboolean blocked, gpointer user_data);
       
   470 void XAAdaptationBase_SetAllCaps (GstCaps * caps, char *field, ...);
       
   471 
       
   472 XAresult XAMediaPlayerAdapt_UpdatePositionCbTimer(XAMediaPlayerAdaptationCtx_* mCtx);
       
   473 
       
   474 XAresult XAMediaRecorderAdapt_ChangeEncoders( XAMediaRecorderAdaptationCtx_* mCtx );
       
   475 XAresult XAMediaRecorderAdapt_CheckCodec( XAMediaRecorderAdaptationCtx_* mCtx, XACapsType encType, XAuint32 encoderId );
       
   476 
       
   477 XAresult XAMetadataAdapt_TryWriteTags(XAAdaptationBaseCtx* mCtx, GstBin* binToWriteTo);
       
   478 void XAMetadataAdapt_FreeVars(XAMetadataAdaptVars *vars);
       
   479 
       
   480 GstElement* XAOutputMixAdapt_GetSink(XAAdaptationBaseCtx* bCtx);
       
   481 
       
   482 
       
   483 XAresult XAOutputMixAdapt_ConnectObject(XAAdaptationBaseCtx* omCtx, XAAdaptationBaseCtx* bCtx, GstElement* usedMix);
       
   484 XAresult XAOutputMixAdapt_DisconnectObject(XAAdaptationBaseCtx* omCtx, XAAdaptationBaseCtx* bCtx);
       
   485 void* XAAdaptationBase_ContentPipeScrThrFunc( void* arg);
       
   486 void* XAAdaptationBase_ContentPipeSinkThrFunc( void* arg);
       
   487 CPresult XAAdaptationBase_ContentPipeSrcCb(CP_EVENTTYPE eEvent, CPuint iParam);
       
   488 CPresult XAAdaptationBase_ContentPipeSinkCb(CP_EVENTTYPE eEvent, CPuint iParam);
       
   489 
       
   490 #endif /* XAADAPTATION_H_ */