1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <assert.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <OMXAL/OpenMAXAL.h>
22#include <OMXAL/OpenMAXAL_Android.h>
23
24int main(int argc __unused, char **argv __unused)
25{
26    XAresult result;
27    XAObjectItf engineObject;
28    printf("xaCreateEngine\n");
29    result = xaCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL);
30    printf("result = %d\n", result);
31    assert(XA_RESULT_SUCCESS == result);
32    printf("engineObject = %p\n", engineObject);
33    printf("realize\n");
34    result = (*engineObject)->Realize(engineObject, XA_BOOLEAN_FALSE);
35    printf("result = %d\n", result);
36    printf("GetInterface for ENGINE\n");
37    XAEngineItf engineEngine;
38    result = (*engineObject)->GetInterface(engineObject, XA_IID_ENGINE, &engineEngine);
39    printf("result = %d\n", result);
40    printf("engineEngine = %p\n", engineEngine);
41    assert(XA_RESULT_SUCCESS == result);
42
43    XAObjectItf outputMixObject;
44    printf("CreateOutputMix");
45    result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL);
46    printf("result = %d, outputMixObject=%p\n", result, outputMixObject);
47    result = (*outputMixObject)->Realize(outputMixObject, XA_BOOLEAN_FALSE);
48    printf("result = %d\n", result);
49
50    XAObjectItf deviceObject;
51    printf("CreateCameraDevice\n");
52    result = (*engineEngine)->CreateCameraDevice(engineEngine, &deviceObject,
53            XA_DEFAULTDEVICEID_CAMERA, 0, NULL, NULL);
54    printf("result = %d, deviceObject=%p\n", result, deviceObject);
55
56    printf("CreateRadioDevice\n");
57    result = (*engineEngine)->CreateRadioDevice(engineEngine, &deviceObject, 0, NULL, NULL);
58    printf("result = %d, deviceObject=%p\n", result, deviceObject);
59
60    printf("CreateLEDDevice\n");
61    result = (*engineEngine)->CreateLEDDevice(engineEngine, &deviceObject, XA_DEFAULTDEVICEID_LED,
62            0, NULL, NULL);
63    printf("result = %d, deviceObject=%p\n", result, deviceObject);
64
65    printf("CreateVibraDevice\n");
66    result = (*engineEngine)->CreateVibraDevice(engineEngine, &deviceObject,
67            XA_DEFAULTDEVICEID_VIBRA, 0, NULL, NULL);
68    printf("result = %d, deviceObject=%p\n", result, deviceObject);
69
70    printf("CreateMediaPlayer\n");
71    XAObjectItf playerObject;
72#if 1
73    XADataLocator_AndroidBufferQueue locABQ;
74    memset(&locABQ, 0, sizeof(locABQ));
75    locABQ.locatorType = XA_DATALOCATOR_ANDROIDBUFFERQUEUE;
76    locABQ.numBuffers = 1;
77#else
78    XADataLocator_URI locUri;
79    locUri.locatorType = XA_DATALOCATOR_URI;
80    locUri.URI = (XAchar *) "/sdcard/hello.wav";
81#endif
82    XADataFormat_MIME fmtMime;
83    fmtMime.formatType = XA_DATAFORMAT_MIME;
84    fmtMime.mimeType = NULL;
85    fmtMime.containerType = XA_CONTAINERTYPE_UNSPECIFIED;
86    XADataSource dataSrc;
87#if 1
88    dataSrc.pLocator = &locABQ;
89#else
90    dataSrc.pLocator = &locUri;
91#endif
92    dataSrc.pFormat = &fmtMime;
93    XADataSink audioSnk;
94    XADataLocator_OutputMix locOM;
95    locOM.locatorType = XA_DATALOCATOR_OUTPUTMIX;
96    locOM.outputMix = outputMixObject;
97    audioSnk.pLocator = &locOM;
98    audioSnk.pFormat = NULL;
99    XADataLocator_NativeDisplay locND;
100    locND.locatorType = XA_DATALOCATOR_NATIVEDISPLAY;
101    locND.hWindow = NULL; // FIXME wrong
102    locND.hDisplay = NULL;
103    XADataSink imageVideoSink;
104    imageVideoSink.pLocator = &locND;
105    imageVideoSink.pFormat = NULL;
106    result = (*engineEngine)->CreateMediaPlayer(engineEngine, &playerObject, &dataSrc, NULL,
107            &audioSnk, &imageVideoSink, NULL, NULL, 0, NULL, NULL);
108    printf("result = %d, playerObject=%p\n", result, playerObject);
109    result = (*playerObject)->Realize(playerObject, XA_BOOLEAN_FALSE);
110    printf("result = %d\n", result);
111
112    printf("GetInterface for PLAY\n");
113    XAPlayItf playerPlay;
114    result = (*playerObject)->GetInterface(playerObject, XA_IID_PLAY, &playerPlay);
115    printf("result = %d\n", result);
116    printf("playerPlay = %p\n", playerPlay);
117    assert(XA_RESULT_SUCCESS == result);
118
119    printf("SetPlayState to PLAYING\n");
120    result = (*playerPlay)->SetPlayState(playerPlay, XA_PLAYSTATE_PLAYING);
121    printf("result = %d\n", result);
122    assert(XA_RESULT_SUCCESS == result);
123
124    printf("destroying media player\n");
125    (*playerObject)->Destroy(playerObject);
126
127    printf("destroying output mix\n");
128    (*outputMixObject)->Destroy(outputMixObject);
129
130    printf("destroying engine\n");
131    (*engineObject)->Destroy(engineObject);
132    printf("exit\n");
133
134    return EXIT_SUCCESS;
135}
136