• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /* MIDITime implementation */
18 
19 #include "sles_allinclusive.h"
20 
21 
IMIDITime_GetDuration(SLMIDITimeItf self,SLuint32 * pDuration)22 static SLresult IMIDITime_GetDuration(SLMIDITimeItf self, SLuint32 *pDuration)
23 {
24     SL_ENTER_INTERFACE
25 
26     if (NULL == pDuration) {
27         result = SL_RESULT_PARAMETER_INVALID;
28     } else {
29         IMIDITime *thiz = (IMIDITime *) self;
30         SLuint32 duration = thiz->mDuration;
31         *pDuration = duration;
32         result = SL_RESULT_SUCCESS;
33     }
34 
35     SL_LEAVE_INTERFACE
36 }
37 
38 
IMIDITime_SetPosition(SLMIDITimeItf self,SLuint32 position)39 static SLresult IMIDITime_SetPosition(SLMIDITimeItf self, SLuint32 position)
40 {
41     SL_ENTER_INTERFACE
42 
43     IMIDITime *thiz = (IMIDITime *) self;
44     // const, no lock needed
45     if (!(position < thiz->mDuration)) {
46         result = SL_RESULT_PARAMETER_INVALID;
47     } else {
48         interface_lock_poke(thiz);
49         thiz->mPosition = position;
50         interface_unlock_poke(thiz);
51         result = SL_RESULT_SUCCESS;
52     }
53 
54     SL_LEAVE_INTERFACE
55 }
56 
57 
IMIDITime_GetPosition(SLMIDITimeItf self,SLuint32 * pPosition)58 static SLresult IMIDITime_GetPosition(SLMIDITimeItf self, SLuint32 *pPosition)
59 {
60     SL_ENTER_INTERFACE
61 
62     if (NULL == pPosition) {
63         result = SL_RESULT_PARAMETER_INVALID;
64     } else {
65         IMIDITime *thiz = (IMIDITime *) self;
66         interface_lock_peek(thiz);
67         SLuint32 position = thiz->mPosition;
68         interface_unlock_peek(thiz);
69         *pPosition = position;
70         result = SL_RESULT_SUCCESS;
71     }
72 
73     SL_LEAVE_INTERFACE
74 }
75 
76 
IMIDITime_SetLoopPoints(SLMIDITimeItf self,SLuint32 startTick,SLuint32 numTicks)77 static SLresult IMIDITime_SetLoopPoints(SLMIDITimeItf self, SLuint32 startTick, SLuint32 numTicks)
78 {
79     SL_ENTER_INTERFACE
80 
81     IMIDITime *thiz = (IMIDITime *) self;
82     // const, no lock needed
83     SLuint32 duration = thiz->mDuration;
84     if (!((startTick < duration) && (numTicks <= duration - startTick))) {
85         result = SL_RESULT_PARAMETER_INVALID;
86     } else {
87         interface_lock_exclusive(thiz);
88         thiz->mStartTick = startTick;
89         thiz->mNumTicks = numTicks;
90         interface_unlock_exclusive(thiz);
91         result = SL_RESULT_SUCCESS;
92     }
93 
94     SL_LEAVE_INTERFACE
95 }
96 
97 
IMIDITime_GetLoopPoints(SLMIDITimeItf self,SLuint32 * pStartTick,SLuint32 * pNumTicks)98 static SLresult IMIDITime_GetLoopPoints(SLMIDITimeItf self, SLuint32 *pStartTick,
99     SLuint32 *pNumTicks)
100 {
101     SL_ENTER_INTERFACE
102 
103     if (NULL == pStartTick || NULL == pNumTicks) {
104         result = SL_RESULT_PARAMETER_INVALID;
105     } else {
106         IMIDITime *thiz = (IMIDITime *) self;
107         interface_lock_shared(thiz);
108         SLuint32 startTick = thiz->mStartTick;
109         SLuint32 numTicks = thiz->mNumTicks;
110         interface_unlock_shared(thiz);
111         *pStartTick = startTick;
112         *pNumTicks = numTicks;
113         result = SL_RESULT_SUCCESS;
114     }
115 
116     SL_LEAVE_INTERFACE
117 }
118 
119 
120 static const struct SLMIDITimeItf_ IMIDITime_Itf = {
121     IMIDITime_GetDuration,
122     IMIDITime_SetPosition,
123     IMIDITime_GetPosition,
124     IMIDITime_SetLoopPoints,
125     IMIDITime_GetLoopPoints
126 };
127 
IMIDITime_init(void * self)128 void IMIDITime_init(void *self)
129 {
130     IMIDITime *thiz = (IMIDITime *) self;
131     thiz->mItf = &IMIDITime_Itf;
132     thiz->mDuration = 0;
133     thiz->mPosition = 0;
134     thiz->mStartTick = 0;
135     thiz->mNumTicks = 0;
136 }
137