summaryrefslogtreecommitdiff
path: root/src/modules/ecordova
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-11-03 19:22:56 -0200
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-11-03 19:22:56 -0200
commit9f641d1b69c05656f5e8ca78be274a98cdf44407 (patch)
treebddd4bc96ab3fb8d68309baa1f8f0a97b5658efe /src/modules/ecordova
parentff27c7b1cefbe43c90299871464ca1fd3ae157c2 (diff)
ecordova: Moved media too to tizen
Diffstat (limited to 'src/modules/ecordova')
-rw-r--r--src/modules/ecordova/tizen/ecordova_inappbrowser.c78
-rw-r--r--src/modules/ecordova/tizen/ecordova_inappbrowser_private.h16
-rw-r--r--src/modules/ecordova/tizen/ecordova_media.c533
-rw-r--r--src/modules/ecordova/tizen/ecordova_media_private.h26
-rw-r--r--src/modules/ecordova/tizen/ecordova_mediafile.c189
-rw-r--r--src/modules/ecordova/tizen/ecordova_mediafile_private.h21
-rw-r--r--src/modules/ecordova/tizen/ecordova_networkinformation.c2
7 files changed, 771 insertions, 94 deletions
diff --git a/src/modules/ecordova/tizen/ecordova_inappbrowser.c b/src/modules/ecordova/tizen/ecordova_inappbrowser.c
deleted file mode 100644
index 4d6cc1686e..0000000000
--- a/src/modules/ecordova/tizen/ecordova_inappbrowser.c
+++ /dev/null
@@ -1,78 +0,0 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "ecordova_inappbrowser_private.h"
6
7#define MY_CLASS ECORDOVA_INAPPBROWSER_CLASS
8#define MY_CLASS_NAME "Ecordova_InAppBrowser"
9
10static Eo_Base *
11_ecordova_inappbrowser_eo_base_constructor(Eo *obj,
12 Ecordova_InAppBrowser_Data *pd)
13{
14 DBG("(%p)", obj);
15
16 pd->obj = obj;
17
18 return eo_do_super_ret(obj, MY_CLASS, obj, eo_constructor());
19}
20
21static void
22_ecordova_inappbrowser_constructor(Eo *obj EINA_UNUSED,
23 Ecordova_InAppBrowser_Data *pd EINA_UNUSED)
24{
25 DBG("(%p)", obj);
26}
27
28static void
29_ecordova_inappbrowser_eo_base_destructor(Eo *obj,
30 Ecordova_InAppBrowser_Data *pd EINA_UNUSED)
31{
32 DBG("(%p)", obj);
33
34 eo_do_super(obj, MY_CLASS, eo_destructor());
35}
36
37static Ecordova_InAppBrowser*
38_ecordova_inappbrowser_open(Eo *obj EINA_UNUSED,
39 void *pd EINA_UNUSED,
40 const char *url EINA_UNUSED,
41 const char *target EINA_UNUSED,
42 const Eina_Hash *options EINA_UNUSED)
43{
44 ERR("Not implemented.");
45 return NULL;
46}
47
48static void
49_ecordova_inappbrowser_close(Eo *obj EINA_UNUSED,
50 Ecordova_InAppBrowser_Data *pd EINA_UNUSED)
51{
52 ERR("Not implemented.");
53}
54
55static void
56_ecordova_inappbrowser_show(Eo *obj EINA_UNUSED,
57 Ecordova_InAppBrowser_Data *pd EINA_UNUSED)
58{
59 ERR("Not implemented.");
60}
61
62static void
63_ecordova_inappbrowser_script_execute(Eo *obj EINA_UNUSED,
64 Ecordova_InAppBrowser_Data *pd EINA_UNUSED,
65 const Ecordova_InAppBrowser_InjectDetails *injectDetails EINA_UNUSED)
66{
67 ERR("Not implemented.");
68}
69
70static void
71_ecordova_inappbrowser_css_insert(Eo *obj EINA_UNUSED,
72 Ecordova_InAppBrowser_Data *pd EINA_UNUSED,
73 const Ecordova_InAppBrowser_InjectDetails *injectDetails EINA_UNUSED)
74{
75 ERR("Not implemented.");
76}
77
78#include "ecordova_inappbrowser.eo.c"
diff --git a/src/modules/ecordova/tizen/ecordova_inappbrowser_private.h b/src/modules/ecordova/tizen/ecordova_inappbrowser_private.h
deleted file mode 100644
index 4526e8773b..0000000000
--- a/src/modules/ecordova/tizen/ecordova_inappbrowser_private.h
+++ /dev/null
@@ -1,16 +0,0 @@
1#ifndef _ECORDOVA_INAPPBROWSER_PRIVATE_H
2#define _ECORDOVA_INAPPBROWSER_PRIVATE_H
3
4#include "ecordova_private.h"
5
6typedef struct _Ecordova_InAppBrowser_Data Ecordova_InAppBrowser_Data;
7
8/**
9 * Ecordova.InAppBrowser private data
10 */
11struct _Ecordova_InAppBrowser_Data
12{
13 Eo *obj;
14};
15
16#endif
diff --git a/src/modules/ecordova/tizen/ecordova_media.c b/src/modules/ecordova/tizen/ecordova_media.c
new file mode 100644
index 0000000000..4fef7d10ae
--- /dev/null
+++ b/src/modules/ecordova/tizen/ecordova_media.c
@@ -0,0 +1,533 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#if defined(TIZEN_MEDIA_METADATA_EXTRACTOR) && defined(TIZEN_MEDIA_PLAYER) && defined(TIZEN_MEDIA_RECORDER)
6#include "ecordova_media_private.h"
7
8#define MY_CLASS ECORDOVA_MEDIA_CLASS
9#define MY_CLASS_NAME "Ecordova_Media"
10
11typedef void(* Action_Cb)(Ecordova_Media_Data *, void *);
12
13typedef struct {
14 Action_Cb callback;
15 void *data;
16} Action;
17
18static void _completed_cb(void *);
19static void _error_cb(int, void *);
20static void _prepared_cb(void *);
21static void _set_position_cb(void *);
22static void _execute(Ecordova_Media_Data *, Action_Cb, void *);
23static void _pause_action(Ecordova_Media_Data *, void *);
24static void _start_action(Ecordova_Media_Data *, void *);
25static void _stop_action(Ecordova_Media_Data *, void *);
26static void _get_position_action(Ecordova_Media_Data *, void *);
27static void _set_position_action(Ecordova_Media_Data *, void *);
28static void _set_volume_action(Ecordova_Media_Data *, void *);
29static void _update_status(Ecordova_Media_Data *);
30static void _release(Ecordova_Media_Data *);
31static void _state_changed_cb(recorder_state_e, recorder_state_e, bool, void *);
32static void _start_record(Ecordova_Media_Data *);
33
34static Eo_Base *
35_ecordova_media_eo_base_constructor(Eo *obj, Ecordova_Media_Data *pd)
36{
37 DBG("(%p)", obj);
38
39 pd->obj = obj;
40 pd->player = NULL;
41 pd->recorder = NULL;
42 pd->status = ECORDOVA_MEDIA_STATUS_MEDIA_NONE;
43 pd->pending = NULL;
44 pd->record_pending = false;
45
46 return eo_do_super_ret(obj, MY_CLASS, obj, eo_constructor());
47}
48
49static void
50_ecordova_media_constructor(Eo *obj,
51 Ecordova_Media_Data *pd,
52 const char *src)
53{
54 DBG("(%p)", obj);
55 EINA_SAFETY_ON_NULL_RETURN(src);
56
57 int ret = player_create(&pd->player);
58 EINA_SAFETY_ON_FALSE_RETURN(PLAYER_ERROR_NONE == ret);
59
60 ret = recorder_create_audiorecorder(&pd->recorder);
61 EINA_SAFETY_ON_FALSE_RETURN(RECORDER_ERROR_NONE == ret);
62
63 ret = player_set_uri(pd->player, src);
64 if (PLAYER_ERROR_NONE != ret)
65 {
66 ERR("Error setting source media: %s", src);
67 _release(pd);
68 return;
69 }
70
71 ret = player_set_completed_cb(pd->player,
72 _completed_cb,
73 pd);
74 if (PLAYER_ERROR_NONE != ret)
75 {
76 ERR("Error setting completed callback: %d", ret);
77 _release(pd);
78 return;
79 }
80
81 ret = player_set_error_cb(pd->player,
82 _error_cb,
83 pd);
84 if (PLAYER_ERROR_NONE != ret)
85 {
86 ERR("Error setting completed callback: %d", ret);
87 _release(pd);
88 return;
89 }
90
91 ret = recorder_set_state_changed_cb(pd->recorder,
92 _state_changed_cb,
93 pd);
94 if (RECORDER_ERROR_NONE != ret)
95 {
96 ERR("Error setting recorder state changed callback: %d", ret);
97 _release(pd);
98 return;
99 }
100
101 ret = recorder_set_audio_encoder(pd->recorder, RECORDER_AUDIO_CODEC_AAC);
102 if (RECORDER_ERROR_NONE != ret)
103 {
104 ERR("Error setting audio encoder: %d", ret);
105 _release(pd);
106 return;
107 }
108
109 ret = recorder_attr_set_audio_samplerate(pd->recorder, 44100);
110 if (RECORDER_ERROR_NONE != ret)
111 {
112 ERR("Error setting audio sample rate: %d", ret);
113 _release(pd);
114 return;
115 }
116
117 ret = recorder_set_file_format(pd->recorder, RECORDER_FILE_FORMAT_3GP);
118 if (RECORDER_ERROR_NONE != ret)
119 {
120 ERR("Error setting file format for audio encoder: %d", ret);
121 _release(pd);
122 return;
123 }
124
125 ret = recorder_attr_set_audio_encoder_bitrate(pd->recorder, 28800);
126 if (RECORDER_ERROR_NONE != ret)
127 {
128 ERR("Error setting audio encoder bitrate: %d", ret);
129 _release(pd);
130 return;
131 }
132
133 ret = recorder_set_filename(pd->recorder, src);
134 if (RECORDER_ERROR_NONE != ret)
135 {
136 ERR("Error setting recorder filename: %d", ret);
137 _release(pd);
138 return;
139 }
140}
141
142static void
143_ecordova_media_eo_base_destructor(Eo *obj, Ecordova_Media_Data *pd)
144{
145 DBG("(%p)", obj);
146
147 _release(pd);
148
149 eo_do_super(obj, MY_CLASS, eo_destructor());
150}
151
152static void
153_ecordova_media_current_position_get(Eo *obj, Ecordova_Media_Data *pd)
154{
155 DBG("(%p)", obj);
156 _execute(pd, _get_position_action, NULL);
157}
158
159static int
160_ecordova_media_duration_get(Eo *obj EINA_UNUSED, Ecordova_Media_Data *pd)
161{
162 int duration = -1;
163
164 int ret = player_get_duration(pd->player, &duration);
165 EINA_SAFETY_ON_FALSE_RETURN_VAL(PLAYER_ERROR_NONE == ret, -1);
166
167 return duration / 1000;
168}
169
170static void
171_ecordova_media_pause(Eo *obj, Ecordova_Media_Data *pd)
172{
173 DBG("(%p)", obj);
174 _execute(pd, _pause_action, NULL);
175}
176
177static void
178_ecordova_media_play(Eo *obj, Ecordova_Media_Data *pd)
179{
180 DBG("(%p)", obj);
181 _execute(pd, _start_action, NULL);
182}
183
184static void
185_ecordova_media_release(Eo *obj, Ecordova_Media_Data *pd)
186{
187 DBG("(%p)", obj);
188 _release(pd);
189}
190
191static void
192_ecordova_media_seek(Eo *obj, Ecordova_Media_Data *pd, int milliseconds)
193{
194 DBG("(%p)", obj);
195 int *data = malloc(sizeof(milliseconds));
196 *data = milliseconds;
197 _execute(pd, _set_position_action, data);
198}
199
200static void
201_ecordova_media_volume_set(Eo *obj, Ecordova_Media_Data *pd, double volume)
202{
203 DBG("(%p)", obj);
204 double *data = malloc(sizeof(volume));
205 *data = volume;
206 _execute(pd, _set_volume_action, data);
207}
208
209static void
210_ecordova_media_record_start(Eo *obj, Ecordova_Media_Data *pd)
211{
212 DBG("(%p)", obj);
213
214 recorder_state_e state = RECORDER_STATE_NONE;
215 int ret = recorder_get_state(pd->recorder, &state);
216 EINA_SAFETY_ON_FALSE_RETURN(RECORDER_ERROR_NONE == ret);
217
218 switch (state)
219 {
220 case RECORDER_STATE_NONE:
221 case RECORDER_STATE_CREATED:
222 ret = recorder_prepare(pd->recorder);
223 EINA_SAFETY_ON_FALSE_RETURN(RECORDER_ERROR_NONE == ret);
224 pd->record_pending = true;
225 return;
226 case RECORDER_STATE_READY:
227 if (pd->record_pending)
228 {
229 ERR("%s", "The recorder has already been started and is pending.");
230 return;
231 }
232 _start_record(pd);
233 return;
234 case RECORDER_STATE_RECORDING:
235 ERR("%s", "The recorder is already recording.");
236 return;
237 case RECORDER_STATE_PAUSED:
238 ERR("%s", "Unreachable!");
239 return;
240 }
241}
242
243static void
244_ecordova_media_stop(Eo *obj, Ecordova_Media_Data *pd)
245{
246 DBG("(%p)", obj);
247 _execute(pd, _stop_action, NULL);
248}
249
250static void
251_ecordova_media_record_stop(Eo *obj, Ecordova_Media_Data *pd)
252{
253 DBG("(%p)", obj);
254
255 recorder_state_e state = RECORDER_STATE_NONE;
256 int ret = recorder_get_state(pd->recorder, &state);
257 EINA_SAFETY_ON_FALSE_RETURN(RECORDER_ERROR_NONE == ret);
258
259 switch (state)
260 {
261 case RECORDER_STATE_NONE:
262 case RECORDER_STATE_CREATED:
263 case RECORDER_STATE_READY:
264 ERR("%s", "The recorder is not recording.");
265 return;
266 case RECORDER_STATE_RECORDING:
267 ret = recorder_commit(pd->recorder);
268 return;
269 case RECORDER_STATE_PAUSED:
270 ERR("%s", "Unreachable!");
271 return;
272 }
273}
274
275static void
276_completed_cb(void *data)
277{
278 Ecordova_Media_Data *pd = data;
279 DBG("(%p)", pd->obj);
280
281 // TODO: Check what thread this callback is running to make sure it's on the main thread
282
283 _update_status(pd);
284
285 eo_do(pd->obj, eo_event_callback_call(ECORDOVA_MEDIA_EVENT_MEDIA_SUCCESS, NULL));
286}
287
288static void
289_error_cb(int error EINA_UNUSED, void *data)
290{
291 Ecordova_Media_Data *pd = data;
292 DBG("(%p)", pd->obj);
293
294 // TODO: ¿ check error ?
295
296 // TODO: Check what thread this callback is running to make sure it's on the main thread
297
298 _update_status(pd);
299
300 eo_do(pd->obj, eo_event_callback_call(ECORDOVA_MEDIA_EVENT_MEDIA_ERROR, NULL));
301}
302
303static void
304_prepared_cb(void *data)
305{
306 Ecordova_Media_Data *pd = data;
307 DBG("(%p)", pd->obj);
308
309 Action *action;
310 EINA_LIST_FREE(pd->pending, action)
311 {
312 action->callback(pd, action->data);
313 free(action->data);
314 free(action);
315 }
316
317}
318
319static void
320_set_position_cb(void *data)
321{
322 Ecordova_Media_Data *pd = data;
323 DBG("(%p)", pd->obj);
324
325 // TODO: Check what thread this callback is running to make sure it's on the main thread
326
327 eo_do(pd->obj, eo_event_callback_call(ECORDOVA_MEDIA_EVENT_MEDIA_SUCCESS, NULL));
328}
329
330static void
331_execute(Ecordova_Media_Data *pd, Action_Cb action_cb, void *data)
332{
333 DBG("(%p)", pd->obj);
334
335 switch (pd->status)
336 {
337 case ECORDOVA_MEDIA_STATUS_MEDIA_NONE:
338 {
339 int ret = player_prepare_async(pd->player,
340 _prepared_cb,
341 pd);
342 EINA_SAFETY_ON_FALSE_RETURN(PLAYER_ERROR_NONE == ret);
343
344 pd->status = ECORDOVA_MEDIA_STATUS_MEDIA_STARTING;
345 eo_do(pd->obj,
346 eo_event_callback_call(ECORDOVA_MEDIA_EVENT_MEDIA_STATUS, &pd->status));
347 // fall-through
348 }
349 case ECORDOVA_MEDIA_STATUS_MEDIA_STARTING:
350 {
351 Action *action = malloc(sizeof(Action));
352 action->callback = action_cb;
353 action->data = data;
354
355 pd->pending = eina_list_append(pd->pending, action);
356 return;
357 }
358 default:
359 action_cb(pd, data);
360 }
361}
362
363static void
364_pause_action(Ecordova_Media_Data *pd, void *data EINA_UNUSED)
365{
366 DBG("(%p)", pd->obj);
367
368 int ret = player_pause(pd->player);
369 EINA_SAFETY_ON_FALSE_RETURN(PLAYER_ERROR_NONE == ret);
370
371 _update_status(pd);
372}
373
374static void
375_stop_action(Ecordova_Media_Data *pd, void *data EINA_UNUSED)
376{
377 DBG("(%p)", pd->obj);
378
379 int ret = player_stop(pd->player);
380 EINA_SAFETY_ON_FALSE_RETURN(PLAYER_ERROR_NONE == ret);
381
382 _update_status(pd);
383}
384
385static void
386_start_action(Ecordova_Media_Data *pd, void *data EINA_UNUSED)
387{
388 DBG("(%p)", pd->obj);
389
390 int ret = player_stop(pd->player);
391 EINA_SAFETY_ON_FALSE_RETURN(PLAYER_ERROR_NONE == ret);
392
393 _update_status(pd);
394}
395
396static void
397_get_position_action(Ecordova_Media_Data *pd, void *data EINA_UNUSED)
398{
399 DBG("(%p)", pd->obj);
400
401 int position = 0;
402 int ret = player_get_play_position(pd->player, &position);
403 EINA_SAFETY_ON_FALSE_RETURN(PLAYER_ERROR_NONE == ret);
404
405 position /= 1000;
406 eo_do(pd->obj,
407 eo_event_callback_call(ECORDOVA_MEDIA_EVENT_MEDIA_POSITION, &position));
408}
409
410static void
411_set_position_action(Ecordova_Media_Data *pd, void *data)
412{
413 DBG("(%p)", pd->obj);
414
415 int *position = data;
416 int ret = player_set_play_position(pd->player,
417 *position,
418 false,
419 _set_position_cb,
420 pd);
421 free(position);
422 EINA_SAFETY_ON_FALSE_RETURN(PLAYER_ERROR_NONE == ret);
423}
424
425static void
426_set_volume_action(Ecordova_Media_Data *pd, void *data)
427{
428 DBG("(%p)", pd->obj);
429
430 double *volume = data;
431 int ret = player_set_volume(pd->player, *volume, *volume);
432 free(volume);
433 EINA_SAFETY_ON_FALSE_RETURN(PLAYER_ERROR_NONE == ret);
434 eo_do(pd->obj, eo_event_callback_call(ECORDOVA_MEDIA_EVENT_MEDIA_SUCCESS, NULL));
435}
436
437static void
438_update_status(Ecordova_Media_Data *pd)
439{
440 player_state_e state = PLAYER_STATE_NONE;
441
442 int ret = player_get_state(pd->player, &state);
443 EINA_SAFETY_ON_FALSE_RETURN(PLAYER_ERROR_NONE == ret);
444
445 Ecordova_Media_Status new_status = ECORDOVA_MEDIA_STATUS_MEDIA_NONE;
446 switch (state)
447 {
448 case PLAYER_STATE_NONE:
449 new_status = ECORDOVA_MEDIA_STATUS_MEDIA_NONE;
450 break;
451 case PLAYER_STATE_IDLE:
452 new_status = ECORDOVA_MEDIA_STATUS_MEDIA_STARTING;
453 break;
454 case PLAYER_STATE_READY:
455 new_status = ECORDOVA_MEDIA_STATUS_MEDIA_STOPPED;
456 break;
457 case PLAYER_STATE_PLAYING:
458 new_status = ECORDOVA_MEDIA_STATUS_MEDIA_RUNNING;
459 break;
460 case PLAYER_STATE_PAUSED:
461 new_status = ECORDOVA_MEDIA_STATUS_MEDIA_PAUSED;
462 break;
463 }
464
465 if (new_status == pd->status)
466 return;
467
468 pd->status = new_status;
469 eo_do(pd->obj, eo_event_callback_call(ECORDOVA_MEDIA_EVENT_MEDIA_STATUS, &pd->status));
470}
471
472static void
473_release(Ecordova_Media_Data *pd)
474{
475 if (pd->player)
476 {
477 player_unset_error_cb(pd->player);
478 player_unset_completed_cb(pd->player);
479 if (ECORDOVA_MEDIA_STATUS_MEDIA_NONE != pd->status)
480 player_unprepare(pd->player);
481 player_destroy(pd->player);
482 pd->player = NULL;
483 }
484
485 if (pd->recorder)
486 {
487 recorder_unset_state_changed_cb(pd->recorder);
488 recorder_state_e state = RECORDER_STATE_NONE;
489 if (RECORDER_ERROR_NONE == recorder_get_state(pd->recorder, &state) &&
490 RECORDER_STATE_NONE != state && RECORDER_STATE_CREATED != state)
491 recorder_unprepare(pd->recorder);
492 recorder_destroy(pd->recorder);
493 pd->recorder = NULL;
494 }
495
496 Action *action;
497 EINA_LIST_FREE(pd->pending, action)
498 {
499 free(action->data);
500 free(action);
501 }
502}
503
504static void
505_state_changed_cb(recorder_state_e previous,
506 recorder_state_e current,
507 bool by_policy EINA_UNUSED,
508 void *data)
509{
510 Ecordova_Media_Data *pd = data;
511 if (RECORDER_STATE_READY == current && pd->record_pending)
512 {
513 _start_record(pd);
514 return;
515 }
516
517 if (RECORDER_STATE_RECORDING == current)
518 pd->record_pending = false;
519
520 // TODO: Check what thread this callback is running to make sure it's on the main thread
521 if (RECORDER_STATE_RECORDING == previous && RECORDER_STATE_READY == current)
522 eo_do(pd->obj, eo_event_callback_call(ECORDOVA_MEDIA_EVENT_MEDIA_SUCCESS, NULL));
523}
524
525static void
526_start_record(Ecordova_Media_Data *pd)
527{
528 int ret = recorder_start(pd->recorder);
529 EINA_SAFETY_ON_FALSE_RETURN(RECORDER_ERROR_NONE == ret);
530}
531
532#include "ecordova_media.eo.c"
533#endif
diff --git a/src/modules/ecordova/tizen/ecordova_media_private.h b/src/modules/ecordova/tizen/ecordova_media_private.h
new file mode 100644
index 0000000000..84d7dbe9ec
--- /dev/null
+++ b/src/modules/ecordova/tizen/ecordova_media_private.h
@@ -0,0 +1,26 @@
1#ifndef _ECORDOVA_MEDIA_PRIVATE_H
2#define _ECORDOVA_MEDIA_PRIVATE_H
3
4#include "ecordova_private.h"
5
6#include <player.h>
7#include <recorder.h>
8
9#include <stdbool.h>
10
11typedef struct _Ecordova_Media_Data Ecordova_Media_Data;
12
13/**
14 * Ecordova.Media private data
15 */
16struct _Ecordova_Media_Data
17{
18 Eo *obj;
19 player_h player;
20 recorder_h recorder;
21 Ecordova_Media_Status status;
22 Eina_List *pending;
23 bool record_pending;
24};
25
26#endif
diff --git a/src/modules/ecordova/tizen/ecordova_mediafile.c b/src/modules/ecordova/tizen/ecordova_mediafile.c
new file mode 100644
index 0000000000..dd3084541b
--- /dev/null
+++ b/src/modules/ecordova/tizen/ecordova_mediafile.c
@@ -0,0 +1,189 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#if defined(TIZEN_MEDIA_METADATA_EXTRACTOR) && defined(TIZEN_MEDIA_PLAYER) && defined(TIZEN_MEDIA_RECORDER)
6#include "ecordova_mediafile_private.h"
7#include <stdbool.h>
8#include <limits.h>
9
10#define MY_CLASS ECORDOVA_MEDIAFILE_CLASS
11#define MY_CLASS_NAME "Ecordova_MediaFile"
12
13static void _extract_cb(void *, Ecore_Thread *);
14static void _extract_end_cb(void *, Ecore_Thread *);
15static void _extract_cancel_cb(void *, Ecore_Thread *);
16static void _internal_error_notify(Ecordova_MediaFile_Data *pd);
17static bool _bool_metadata_get(metadata_extractor_h, metadata_extractor_attr_e);
18static int _int_metadata_get(metadata_extractor_h, metadata_extractor_attr_e);
19
20#define NO_ERROR (INT_MAX)
21
22static Eo_Base *
23_ecordova_mediafile_eo_base_constructor(Eo *obj, Ecordova_MediaFile_Data *pd)
24{
25 DBG("(%p)", obj);
26
27 pd->obj = obj;
28 pd->extractor = NULL;
29 pd->error = NO_ERROR;
30
31 return eo_do_super_ret(obj, MY_CLASS, obj, eo_constructor());
32}
33
34static void
35_ecordova_mediafile_constructor(Eo *obj,
36 Ecordova_MediaFile_Data *pd EINA_UNUSED,
37 const char *name,
38 const char *url,
39 const char *type,
40 time_t last_modified_date,
41 long size)
42{
43 DBG("(%p)", obj);
44 eo_do_super(obj, MY_CLASS, ecordova_file_constructor(name,
45 url,
46 type,
47 last_modified_date,
48 size));
49}
50
51static void
52_ecordova_mediafile_eo_base_destructor(Eo *obj, Ecordova_MediaFile_Data *pd)
53{
54 DBG("(%p)", obj);
55
56 if (pd->extractor)
57 metadata_extractor_destroy(pd->extractor);
58
59 eo_do_super(obj, MY_CLASS, eo_destructor());
60}
61
62static void
63_ecordova_mediafile_format_data_get(Eo *obj EINA_UNUSED,
64 Ecordova_MediaFile_Data *pd)
65{
66 Ecore_Thread *thread = ecore_thread_run(_extract_cb,
67 _extract_end_cb,
68 _extract_cancel_cb,
69 pd);
70 if (!thread)
71 _internal_error_notify(pd);
72}
73
74static void
75_extract_cb(void *data, Ecore_Thread *thread EINA_UNUSED)
76{
77 Ecordova_MediaFile_Data *pd = data;
78 int ret;
79
80 if (!pd->extractor)
81 {
82 ret = metadata_extractor_create(&pd->extractor);
83 if (METADATA_EXTRACTOR_ERROR_NONE != ret)
84 goto on_error;
85
86 const char *url = eo_do_super_ret(pd->obj,
87 MY_CLASS,
88 url,
89 ecordova_file_url_get());
90 ret = metadata_extractor_set_path(pd->extractor, url);
91 if (METADATA_EXTRACTOR_ERROR_NONE != ret)
92 goto on_error;
93 }
94
95 pd->metadata.codecs = NULL; // TODO: what is it?
96 pd->metadata.duration = _int_metadata_get(pd->extractor, METADATA_DURATION) / 1000;
97
98 bool has_video = _bool_metadata_get(pd->extractor, METADATA_HAS_VIDEO);
99 bool has_audio = _bool_metadata_get(pd->extractor, METADATA_HAS_AUDIO);
100
101 DBG("has_video=%d, has_audio=%d", has_video, has_audio);
102 if (has_video)
103 {
104 pd->metadata.width = _int_metadata_get(pd->extractor, METADATA_VIDEO_WIDTH);
105 pd->metadata.height = _int_metadata_get(pd->extractor, METADATA_VIDEO_HEIGHT);
106 pd->metadata.bitrate = _int_metadata_get(pd->extractor, METADATA_VIDEO_BITRATE);
107 }
108 else
109 {
110 pd->metadata.bitrate = _int_metadata_get(pd->extractor, METADATA_AUDIO_BITRATE);
111 }
112
113 pd->error = NO_ERROR;
114 return;
115
116on_error:
117 pd->error = ECORDOVA_CAPTURE_ERRORCODE_CAPTURE_INTERNAL_ERR;
118}
119
120static void
121_extract_end_cb(void *data, Ecore_Thread *thread EINA_UNUSED)
122{
123 Ecordova_MediaFile_Data *pd = data;
124 if (NO_ERROR != pd->error)
125 {
126 Ecordova_Capture_Error error = {.code = pd->error};
127 eo_do(pd->obj,
128 eo_event_callback_call(ECORDOVA_MEDIAFILE_EVENT_ERROR,
129 &error));
130 return;
131 }
132
133 eo_do(pd->obj,
134 eo_event_callback_call(ECORDOVA_MEDIAFILE_EVENT_SUCCESS,
135 &pd->metadata));
136}
137
138static void
139_extract_cancel_cb(void *data, Ecore_Thread *thread EINA_UNUSED)
140{
141 Ecordova_MediaFile_Data *pd = data;
142 _internal_error_notify(pd);
143}
144
145static void
146_internal_error_notify(Ecordova_MediaFile_Data *pd)
147{
148 Ecordova_Capture_Error error = {
149 .code = ECORDOVA_CAPTURE_ERRORCODE_CAPTURE_INTERNAL_ERR
150 };
151 eo_do(pd->obj, eo_event_callback_call(ECORDOVA_MEDIAFILE_EVENT_ERROR, &error));
152}
153
154static bool
155_bool_metadata_get(metadata_extractor_h extractor,
156 metadata_extractor_attr_e attr)
157{
158 bool result = false;
159 char *value = NULL;
160 int ret = metadata_extractor_get_metadata(extractor, attr, &value);
161 if (value)
162 {
163 result = strcmp(value, "TRUE") == 0;
164 free(value);
165 }
166
167 EINA_SAFETY_ON_FALSE_RETURN_VAL(METADATA_EXTRACTOR_ERROR_NONE == ret, false);
168 return result;
169}
170
171static int
172_int_metadata_get(metadata_extractor_h extractor,
173 metadata_extractor_attr_e attr)
174{
175 int result = 0;
176 char *value = NULL;
177 int ret = metadata_extractor_get_metadata(extractor, attr, &value);
178 if (value)
179 {
180 result = atoi(value);
181 free(value);
182 }
183
184 EINA_SAFETY_ON_FALSE_RETURN_VAL(METADATA_EXTRACTOR_ERROR_NONE == ret, 0);
185 return result;
186}
187
188#include "ecordova_mediafile.eo.c"
189#endif
diff --git a/src/modules/ecordova/tizen/ecordova_mediafile_private.h b/src/modules/ecordova/tizen/ecordova_mediafile_private.h
new file mode 100644
index 0000000000..1e7e8621d2
--- /dev/null
+++ b/src/modules/ecordova/tizen/ecordova_mediafile_private.h
@@ -0,0 +1,21 @@
1#ifndef _ECORDOVA_MEDIAFILE_PRIVATE_H
2#define _ECORDOVA_MEDIAFILE_PRIVATE_H
3
4#include "ecordova_private.h"
5
6#include <metadata_extractor.h>
7
8typedef struct _Ecordova_MediaFile_Data Ecordova_MediaFile_Data;
9
10/**
11 * Ecordova.MediaFile private data
12 */
13struct _Ecordova_MediaFile_Data
14{
15 Eo *obj;
16 metadata_extractor_h extractor;
17 Ecordova_Capture_ErrorCode error;
18 Ecordova_MediaFileData metadata;
19};
20
21#endif
diff --git a/src/modules/ecordova/tizen/ecordova_networkinformation.c b/src/modules/ecordova/tizen/ecordova_networkinformation.c
index e89dc7018a..c8740d2a10 100644
--- a/src/modules/ecordova/tizen/ecordova_networkinformation.c
+++ b/src/modules/ecordova/tizen/ecordova_networkinformation.c
@@ -2,6 +2,7 @@
2# include <config.h> 2# include <config.h>
3#endif 3#endif
4 4
5#ifdef HAVE_TIZEN_NETWORK_CONNECTION
5#include "ecordova_networkinformation_private.h" 6#include "ecordova_networkinformation_private.h"
6 7
7#define MY_CLASS ECORDOVA_NETWORKINFORMATION_CLASS 8#define MY_CLASS ECORDOVA_NETWORKINFORMATION_CLASS
@@ -96,3 +97,4 @@ _type_changed_cb(connection_type_e type, void *user_data)
96} 97}
97 98
98#include "ecordova_networkinformation.eo.c" 99#include "ecordova_networkinformation.eo.c"
100#endif