38 XAresult ret = XA_RESULT_SUCCESS; |
38 XAresult ret = XA_RESULT_SUCCESS; |
39 XAboolean closeSink = XA_BOOLEAN_FALSE; |
39 XAboolean closeSink = XA_BOOLEAN_FALSE; |
40 XAboolean requestStateChange = XA_BOOLEAN_FALSE; |
40 XAboolean requestStateChange = XA_BOOLEAN_FALSE; |
41 GstStateChangeReturn gstRet = GST_STATE_CHANGE_SUCCESS; |
41 GstStateChangeReturn gstRet = GST_STATE_CHANGE_SUCCESS; |
42 XAMediaRecorderAdaptationCtx* mCtx = NULL; |
42 XAMediaRecorderAdaptationCtx* mCtx = NULL; |
43 XAboolean recording = XA_BOOLEAN_FALSE; |
43 DEBUG_API_A1_STR("->XARecordItfAdapt_SetRecordState %s",RECORDSTATENAME(state)); |
44 DEBUG_API_A1("->XARecordItfAdapt_SetRecordState %s",RECORDSTATENAME(state)); |
|
45 if (!bCtx || bCtx->baseObj.ctxId != XAMediaRecorderAdaptation) |
44 if (!bCtx || bCtx->baseObj.ctxId != XAMediaRecorderAdaptation) |
46 { |
45 { |
47 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
46 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
48 DEBUG_API("<-XARecordItfAdapt_SetRecordState"); |
47 DEBUG_API("<-XARecordItfAdapt_SetRecordState"); |
49 return XA_RESULT_PARAMETER_INVALID; |
48 return XA_RESULT_PARAMETER_INVALID; |
50 } |
49 } |
51 |
50 |
52 mCtx = (XAMediaRecorderAdaptationCtx*) bCtx; |
51 mCtx = (XAMediaRecorderAdaptationCtx*) bCtx; |
53 |
52 |
54 mCtx->isRecord = XA_BOOLEAN_TRUE; |
|
55 |
|
56 switch (state) |
53 switch (state) |
57 { |
54 { |
58 case XA_RECORDSTATE_STOPPED: |
55 case XA_RECORDSTATE_STOPPED: |
59 { |
56 { |
60 // Audio sourse should be stopped |
57 // Audio sourse should be stopped |
61 if (mCtx->audiosource) |
58 if (!bCtx->busError && mCtx->audiosource && mCtx->isRecord == XA_BOOLEAN_TRUE) |
62 { |
59 { |
|
60 XAAdaptationGst_PrepareAsyncWait(bCtx); |
63 if (gst_element_send_event(mCtx->audiosource, |
61 if (gst_element_send_event(mCtx->audiosource, |
64 gst_event_new_eos()) == TRUE) |
62 gst_event_new_eos()) == TRUE) |
65 { |
63 { |
66 DEBUG_INFO ("posted eos"); |
64 DEBUG_INFO ("posted eos"); |
|
65 XAAdaptationGst_StartAsyncWait(bCtx); |
67 } |
66 } |
68 else |
67 else |
69 { |
68 { |
70 DEBUG_ERR("FAIL : post eos"); |
69 DEBUG_ERR("FAIL : post eos"); |
71 } |
70 } |
72 } |
71 } |
73 |
72 |
74 bCtx->binWantedState = GST_STATE_PAUSED; |
73 bCtx->binWantedState = GST_STATE_READY; |
75 closeSink = XA_BOOLEAN_TRUE; |
74 closeSink = XA_BOOLEAN_TRUE; |
76 if (mCtx->runpositiontimer > 0) |
75 if (mCtx->runpositiontimer > 0) |
77 { |
76 { |
78 g_source_remove(mCtx->runpositiontimer); |
77 g_source_remove(mCtx->runpositiontimer); |
79 mCtx->runpositiontimer = 0; |
78 mCtx->runpositiontimer = 0; |
80 } |
79 } |
81 |
80 |
82 if (mCtx->recThrCtx.bufInsufficientSem) |
|
83 { |
|
84 DEBUG_INFO("No buffer-insufficient received, posting record thr semaphore."); |
|
85 if (XAImpl_PostSemaphore(mCtx->recThrCtx.bufInsufficientSem) |
|
86 != XA_RESULT_SUCCESS) |
|
87 { |
|
88 DEBUG_ERR("Posting buffer-insufficient semaphore FAILED!"); |
|
89 } |
|
90 } |
|
91 |
|
92 break; |
81 break; |
93 } |
82 } |
94 case XA_RECORDSTATE_PAUSED: |
83 case XA_RECORDSTATE_PAUSED: |
95 { |
84 { |
|
85 mCtx->isRecord = XA_BOOLEAN_TRUE; |
96 if (mCtx->xaRecordState == XA_RECORDSTATE_STOPPED |
86 if (mCtx->xaRecordState == XA_RECORDSTATE_STOPPED |
97 && mCtx->encodingchanged) |
87 && mCtx->encodingchanged) |
98 { |
88 { |
99 ret = XAMediaRecorderAdapt_ChangeEncoders(mCtx); |
89 ret = XAMediaRecorderAdapt_ChangeEncoders(mCtx); |
100 mCtx->encodingchanged = XA_BOOLEAN_FALSE; |
90 mCtx->encodingchanged = XA_BOOLEAN_FALSE; |
122 { |
113 { |
123 return ret; |
114 return ret; |
124 } |
115 } |
125 } |
116 } |
126 |
117 |
127 if (mCtx->recThrCtx.bufInsufficientSem) |
|
128 { |
|
129 /* Recording to address and recording thread semaphora is created */ |
|
130 if (!XAImpl_StartThread(&(mCtx->recordingEventThr), NULL, |
|
131 &XAMediaRecorderAdapt_RecordEventThr, (void*) mCtx)) |
|
132 { |
|
133 DEBUG_ERR("Start thread Failed"); |
|
134 return XA_RESULT_INTERNAL_ERROR; |
|
135 } |
|
136 } |
|
137 |
|
138 bCtx->binWantedState = GST_STATE_PLAYING; |
118 bCtx->binWantedState = GST_STATE_PLAYING; |
139 recording = XA_BOOLEAN_TRUE; |
|
140 break; |
119 break; |
141 } |
120 } |
142 default: |
121 default: |
143 DEBUG_ERR("Unhandled state") |
122 DEBUG_ERR("Unhandled state"); |
144 ; |
|
145 ret = XA_RESULT_PARAMETER_INVALID; |
123 ret = XA_RESULT_PARAMETER_INVALID; |
146 break; |
124 break; |
147 } |
125 } |
148 |
126 |
149 if (ret == XA_RESULT_SUCCESS) |
127 if (ret == XA_RESULT_SUCCESS) |
175 gstRet = gst_element_set_state(GST_ELEMENT(bCtx->bin), |
153 gstRet = gst_element_set_state(GST_ELEMENT(bCtx->bin), |
176 bCtx->binWantedState); |
154 bCtx->binWantedState); |
177 switch (gstRet) |
155 switch (gstRet) |
178 { |
156 { |
179 case GST_STATE_CHANGE_FAILURE: |
157 case GST_STATE_CHANGE_FAILURE: |
180 DEBUG_ERR_A1("FAILED to change state (target %d)",bCtx->binWantedState) |
158 DEBUG_ERR_A1("FAILED to change state (target %d)",bCtx->binWantedState); |
181 ; |
|
182 bCtx->binWantedState = GST_STATE(bCtx->bin); |
159 bCtx->binWantedState = GST_STATE(bCtx->bin); |
183 ret = XA_RESULT_INTERNAL_ERROR; |
160 ret = XA_RESULT_INTERNAL_ERROR; |
184 break; |
161 break; |
185 case GST_STATE_CHANGE_ASYNC: |
162 case GST_STATE_CHANGE_ASYNC: |
186 DEBUG_INFO_A1("Change state will happen asyncronously (target %d)",bCtx->binWantedState); |
163 DEBUG_INFO_A1("Change state will happen asyncronously (target %d)",bCtx->binWantedState); |
187 XAAdaptationGst_StartAsyncWait(bCtx); |
164 XAAdaptationGst_StartAsyncWait(bCtx); |
188 ret = XA_RESULT_SUCCESS; |
165 ret = XA_RESULT_SUCCESS; |
189 break; |
166 break; |
190 case GST_STATE_CHANGE_NO_PREROLL: |
167 case GST_STATE_CHANGE_NO_PREROLL: |
191 DEBUG_INFO("GST_STATE_CHANGE_NO_PREROLL") |
168 DEBUG_INFO("GST_STATE_CHANGE_NO_PREROLL"); |
192 ; |
|
193 /* deliberate fall-through */ |
169 /* deliberate fall-through */ |
194 case GST_STATE_CHANGE_SUCCESS: |
170 case GST_STATE_CHANGE_SUCCESS: |
195 DEBUG_INFO_A1("Successfully changed state (target %d)",bCtx->binWantedState) |
171 DEBUG_INFO_A1("Successfully changed state (target %d)",bCtx->binWantedState); |
196 ; |
|
197 ret = XA_RESULT_SUCCESS; |
172 ret = XA_RESULT_SUCCESS; |
198 break; |
173 break; |
199 default: |
174 default: |
200 DEBUG_ERR_A1("Unhandled error (%d)",gstRet) |
175 DEBUG_ERR_A1("Unhandled error (%d)",gstRet); |
201 ; |
|
202 ret = XA_RESULT_UNKNOWN_ERROR; |
176 ret = XA_RESULT_UNKNOWN_ERROR; |
203 break; |
177 break; |
204 } |
178 } |
205 bCtx->waitingasyncop = XA_BOOLEAN_FALSE; |
179 bCtx->waitingasyncop = XA_BOOLEAN_FALSE; |
206 } |
180 } |
208 { /* close the sink*/ |
182 { /* close the sink*/ |
209 gst_element_send_event(bCtx->bin, gst_event_new_flush_start()); |
183 gst_element_send_event(bCtx->bin, gst_event_new_flush_start()); |
210 gst_element_send_event(bCtx->bin, gst_event_new_flush_stop()); |
184 gst_element_send_event(bCtx->bin, gst_event_new_flush_stop()); |
211 } |
185 } |
212 |
186 |
213 if (recording && mCtx->isobjvsrc && mCtx->videosource) |
|
214 { |
|
215 GstPad *pad = gst_element_get_static_pad( |
|
216 GST_ELEMENT(mCtx->videosource), "MRObjSrc"); |
|
217 if (pad && gst_pad_is_linked(pad)) |
|
218 { |
|
219 DEBUG_INFO_A2("unblock element:%s pad:%s", |
|
220 gst_element_get_name(mCtx->videosource), |
|
221 gst_pad_get_name(pad)); |
|
222 gst_pad_set_blocked_async(pad, FALSE, XAAdaptationGst_PadBlockCb, |
|
223 NULL); |
|
224 } |
|
225 |
|
226 if (GST_STATE( GST_ELEMENT(mCtx->videosource)) != GST_STATE_PLAYING) |
|
227 { |
|
228 GstStateChangeReturn gret = GST_STATE_CHANGE_SUCCESS; |
|
229 DEBUG_INFO("Start camera source"); |
|
230 gret = gst_element_set_state(GST_ELEMENT(mCtx->videosource), |
|
231 GST_STATE_PLAYING); |
|
232 if (gret == GST_STATE_CHANGE_SUCCESS) |
|
233 gret = gst_element_get_state(GST_ELEMENT(mCtx->videosource), |
|
234 NULL, NULL, XA_ADAPT_ASYNC_TIMEOUT_SHORT_NSEC); |
|
235 } |
|
236 } |
|
237 DEBUG_API("<-XARecordItfAdapt_SetRecordState"); |
187 DEBUG_API("<-XARecordItfAdapt_SetRecordState"); |
238 return ret; |
188 return ret; |
239 } |
189 } |
240 |
190 |
241 /* |
191 /* |