1 /*
2  * Copyright (C) 2010 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 /* Our own merged version of SLDataSource and SLDataSink */
18 
19 typedef union {
20     SLuint32 mLocatorType;
21     SLDataLocator_Address mAddress;
22     SLDataLocator_BufferQueue mBufferQueue;
23     SLDataLocator_IODevice mIODevice;
24     SLDataLocator_MIDIBufferQueue mMIDIBufferQueue;
25     SLDataLocator_OutputMix mOutputMix;
26     SLDataLocator_URI mURI;
27     XADataLocator_NativeDisplay mNativeDisplay;
28 #ifdef ANDROID
29     SLDataLocator_AndroidFD mFD;
30     SLDataLocator_AndroidBufferQueue mABQ;
31 #endif
32 } DataLocator;
33 
34 typedef union {
35     SLuint32 mFormatType;
36     SLDataFormat_PCM mPCM;
37     SLAndroidDataFormat_PCM_EX mPCMEx;
38     SLDataFormat_MIME mMIME;
39     XADataFormat_RawImage mRawImage;
40 } DataFormat;
41 
42 typedef struct {
43     union {
44         SLDataSource mSource;
45         SLDataSink mSink;
46         struct {
47             DataLocator *pLocator;
48             DataFormat *pFormat;
49         } mNeutral;
50     } u;
51     DataLocator mLocator;
52     DataFormat mFormat;
53 } DataLocatorFormat;
54 
55 #define SL_DATALOCATOR_NULL 0   // application specified a NULL value for pLocator
56                                 // (not a valid value for mLocatorType)
57 #define XA_DATALOCATOR_NULL SL_DATALOCATOR_NULL
58 #define SL_DATAFORMAT_NULL 0    // application specified a NULL value for pFormat
59                                 // (not a valid value for mLocatorType)
60 #define XA_DATAFORMAT_NULL SL_DATAFORMAT_NULL
61 
62 // bit masks used to configure the allowed data locators for a given data source or data sink
63 #define DATALOCATOR_MASK_NONE            0L
64 #define DATALOCATOR_MASK_NULL            (1L << SL_DATALOCATOR_NULL)
65 #define DATALOCATOR_MASK_URI             (1L << SL_DATALOCATOR_URI)
66 #define DATALOCATOR_MASK_ADDRESS         (1L << SL_DATALOCATOR_ADDRESS)
67 #define DATALOCATOR_MASK_IODEVICE        (1L << SL_DATALOCATOR_IODEVICE)
68 #define DATALOCATOR_MASK_OUTPUTMIX       (1L << SL_DATALOCATOR_OUTPUTMIX)
69 #define DATALOCATOR_MASK_NATIVEDISPLAY   (1L << XA_DATALOCATOR_NATIVEDISPLAY)
70 #define DATALOCATOR_MASK_BUFFERQUEUE     (1L << SL_DATALOCATOR_BUFFERQUEUE)
71 #define DATALOCATOR_MASK_MIDIBUFFERQUEUE (1L << SL_DATALOCATOR_MIDIBUFFERQUEUE)
72 #define DATALOCATOR_MASK_ANDROIDFD                \
73                  (0x100L << (SL_DATALOCATOR_ANDROIDFD - SL_DATALOCATOR_ANDROIDFD))
74 #define DATALOCATOR_MASK_ANDROIDSIMPLEBUFFERQUEUE \
75                  (0x100L << (SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE - SL_DATALOCATOR_ANDROIDFD))
76 #define DATALOCATOR_MASK_ANDROIDBUFFERQUEUE       \
77                  (0x100L << (SL_DATALOCATOR_ANDROIDBUFFERQUEUE - SL_DATALOCATOR_ANDROIDFD))
78 #define DATALOCATOR_MASK_ALL             0x7FFL
79 
80 // bit masks used to configure the allowed data formats for a given data source or data sink
81 #define DATAFORMAT_MASK_NONE             0L
82 #define DATAFORMAT_MASK_NULL             (1L << SL_DATAFORMAT_NULL)
83 #define DATAFORMAT_MASK_MIME             (1L << SL_DATAFORMAT_MIME)
84 #define DATAFORMAT_MASK_PCM              (1L << SL_DATAFORMAT_PCM)
85 #define DATAFORMAT_MASK_PCM_EX           (1L << SL_ANDROID_DATAFORMAT_PCM_EX)
86 #define DATAFORMAT_MASK_RAWIMAGE         (1L << XA_DATAFORMAT_RAWIMAGE)
87 #define DATAFORMAT_MASK_ALL              0xFL
88 
89 extern SLresult checkDataSource(const char *name, const SLDataSource *pDataSrc,
90         DataLocatorFormat *myDataSourceLocator, SLuint32 allowedDataLocatorMask,
91         SLuint32 allowedDataFormatMask);
92 extern SLresult checkDataSink(const char *name, const SLDataSink *pDataSink,
93         DataLocatorFormat *myDataSinkLocator, SLuint32 allowedDataLocatorMask,
94         SLuint32 allowedDataFormatMask);
95 extern SLresult checkSourceSinkVsInterfacesCompatibility(
96         const DataLocatorFormat *pSrcDataLocatorFormat,
97         const DataLocatorFormat *pSinkDataLocatorFormat,
98         const ClassTable *clazz, unsigned requiredMask);
99 extern void freeDataLocatorFormat(DataLocatorFormat *dlf);
100 
101 
102 /* For stream information storage */
103 typedef struct {
104     XAuint32 domain;
105     union {
106         XAMediaContainerInformation containerInfo;
107         XAVideoStreamInformation videoInfo;
108         XAAudioStreamInformation audioInfo;
109         XAImageStreamInformation imageInfo;
110         XATimedTextStreamInformation textInfo;
111         XAMIDIStreamInformation midiInfo;
112         XAVendorStreamInformation vendorInfo;
113     };
114 } StreamInfo;
115 
116 // FIXME a terrible hack until OpenMAX AL spec is updated
117 #define XA_DOMAINTYPE_CONTAINER 0
118