efl

Форк
0
/
emotion_generic_example.c 
233 строки · 6.0 Кб
1
//Compile with:
2
// gcc -o emotion_generic_example emotion_generic_example.c `pkg-config --libs --cflags emotion evas ecore ecore-evas eina eo`
3
#ifndef EFL_BETA_API_SUPPORT
4
# define EFL_BETA_API_SUPPORT
5
#endif
6

7
#include <Ecore.h>
8
#include <Ecore_Evas.h>
9
#include <Evas.h>
10
#include <Emotion.h>
11
#include <stdio.h>
12
#include <string.h>
13
#include <unistd.h>
14

15
#define WIDTH  (320)
16
#define HEIGHT (240)
17

18
static Eina_List *filenames = NULL;
19
static Eina_List *curfile = NULL;
20

21
static void
22
_playback_started_cb(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
23
{
24
    printf("Emotion object started playback.\n");
25
}
26

27
static void
28
_playback_stopped_cb(void *data EINA_UNUSED, const Efl_Event *ev)
29
{
30
   printf("Emotion playback stopped.\n");
31
   emotion_object_play_set(ev->object, EINA_FALSE);
32
   emotion_object_position_set(ev->object, 0);
33
}
34

35
static Evas_Object *
36
_create_emotion_object(Evas *e)
37
{
38
   Evas_Object *em = emotion_object_add(e);
39

40
   emotion_object_init(em, "generic");
41

42
   efl_event_callback_add
43
     (em, EFL_CANVAS_VIDEO_EVENT_PLAYBACK_START, _playback_started_cb, NULL);
44
   efl_event_callback_add
45
     (em, EFL_CANVAS_VIDEO_EVENT_PLAYBACK_STOP, _playback_stopped_cb, NULL);
46

47
   return em;
48
}
49

50
static void
51
_on_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *event_info)
52
{
53
   Evas_Event_Key_Down *ev = event_info;
54
   Evas_Object *em = data;
55

56
   if (!strcmp(ev->key, "Return"))
57
     {
58
	emotion_object_play_set(em, EINA_TRUE);
59
     }
60
   else if (!strcmp(ev->key, "space"))
61
     {
62
	emotion_object_play_set(em, EINA_FALSE);
63
     }
64
   else if (!strcmp(ev->key, "Escape"))
65
     {
66
	ecore_main_loop_quit();
67
     }
68
   else if (!strcmp(ev->key, "t"))
69
     {
70
	int w, h;
71
	emotion_object_size_get(em, &w, &h);
72
	fprintf(stderr, "example -> size: %dx%d\n", w, h);
73
     }
74
   else if (!strcmp(ev->key, "s"))
75
     {
76
        float len, pos;
77
        len = emotion_object_play_length_get(em);
78
        pos = 0.98 * len;
79
	fprintf(stderr, "skipping to position %0.3f\n", pos);
80
	emotion_object_position_set(em, pos);
81
     }
82
   else if (!strcmp(ev->key, "1"))
83
     {
84
	fprintf(stderr, "setting speed to 1.0\n");
85
	emotion_object_play_speed_set(em, 1.0);
86
     }
87
   else if (!strcmp(ev->key, "2"))
88
     {
89
	fprintf(stderr, "setting speed to 2.0\n");
90
	emotion_object_play_speed_set(em, 2.0);
91
     }
92
   else if (!strcmp(ev->key, "n"))
93
     {
94
	const char *file;
95
	if (!curfile)
96
	  curfile = filenames;
97
	else
98
	  curfile = eina_list_next(curfile);
99
	file = eina_list_data_get(curfile);
100
	fprintf(stderr, "playing next file: %s\n", file);
101
	emotion_object_file_set(em, file);
102
     }
103
   else if (!strcmp(ev->key, "p"))
104
     {
105
	const char *file;
106
	if (!curfile)
107
	  curfile = eina_list_last(filenames);
108
	else
109
	  curfile = eina_list_prev(curfile);
110
	file = eina_list_data_get(curfile);
111
	fprintf(stderr, "playing next file: %s\n", file);
112
	emotion_object_file_set(em, file);
113
     }
114
   else if (!strcmp(ev->key, "d"))
115
     {
116
	evas_object_del(em);
117
     }
118
   else if (!strcmp(ev->key, "l"))
119
     {
120
	// force frame dropping
121
	sleep(5);
122
     }
123
   else
124
     {
125
	fprintf(stderr, "unhandled key: %s\n", ev->key);
126
     }
127
}
128

129
static void
130
_frame_decode_cb(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
131
{
132
   // fprintf(stderr, "smartcb: frame_decode\n");
133
}
134

135
static void
136
_length_change_cb(void *data EINA_UNUSED, const Efl_Event *ev)
137
{
138
   fprintf(stderr, "smartcb: length_change: %0.3f\n", emotion_object_play_length_get(ev->object));
139
}
140

141
static void
142
_position_update_cb(void *data EINA_UNUSED, const Efl_Event *ev)
143
{
144
   fprintf(stderr, "smartcb: position_update: %0.3f\n", emotion_object_position_get(ev->object));
145
}
146

147
static void
148
_progress_change_cb(void *data EINA_UNUSED, const Efl_Event *ev)
149
{
150
   fprintf(stderr, "smartcb: progress_change: %0.3f, %s\n",
151
	   emotion_object_progress_status_get(ev->object),
152
	   emotion_object_progress_info_get(ev->object));
153
}
154

155
EFL_CALLBACKS_ARRAY_DEFINE(emotion_object_example_callbacks,
156
       { EFL_CANVAS_VIDEO_EVENT_FRAME_DECODE, _frame_decode_cb },
157
       { EFL_CANVAS_VIDEO_EVENT_LENGTH_CHANGE, _length_change_cb },
158
       { EFL_CANVAS_VIDEO_EVENT_POSITION_CHANGE, _position_update_cb },
159
       { EFL_CANVAS_VIDEO_EVENT_PROGRESS_CHANGE, _progress_change_cb });
160

161
int
162
main(int argc, const char *argv[])
163
{
164
   Ecore_Evas *ee;
165
   Evas *e;
166
   Evas_Object *bg, *em;
167
   int i;
168

169
   if (argc < 2)
170
     {
171
	printf("One argument is necessary. Usage:\n");
172
	printf("\t%s <filename>\n", argv[0]);
173
     }
174

175
   eina_init();
176
   for (i = 1; i < argc; i++)
177
     filenames = eina_list_append(filenames, eina_stringshare_add(argv[i]));
178

179
   curfile = filenames;
180

181
   if (!ecore_evas_init())
182
     return EXIT_FAILURE;
183

184
   /* this will give you a window with an Evas canvas under the first
185
    * engine available */
186
   ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
187
   if (!ee)
188
     goto error;
189

190
   ecore_evas_show(ee);
191

192
   /* the canvas pointer, de facto */
193
   e = ecore_evas_get(ee);
194

195
   /* adding a background to this example */
196
   bg = evas_object_rectangle_add(e);
197
   evas_object_name_set(bg, "our dear rectangle");
198
   evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */
199
   evas_object_move(bg, 0, 0); /* at canvas' origin */
200
   evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
201
   evas_object_show(bg);
202

203
   /* Creating the emotion object */
204
   em = _create_emotion_object(e);
205
   emotion_object_file_set(em, eina_list_data_get(curfile));
206
   evas_object_move(em, 0, 0);
207
   evas_object_resize(em, WIDTH, HEIGHT);
208
   evas_object_show(em);
209

210
   efl_event_callback_array_add(em, emotion_object_example_callbacks(), NULL);
211

212
   evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN, _on_key_down, em);
213
   evas_object_focus_set(bg, EINA_TRUE);
214

215
   emotion_object_play_set(em, EINA_TRUE);
216

217
   ecore_main_loop_begin();
218

219
   ecore_evas_free(ee);
220
   ecore_evas_shutdown();
221
   return 0;
222

223
error:
224
   fprintf(stderr, "error: Requires at least one Evas engine built and linked"
225
                   " to ecore-evas for this example to run properly.\n");
226

227
   EINA_LIST_FREE(filenames, curfile)
228
      eina_stringshare_del(eina_list_data_get(curfile));
229

230
   ecore_evas_shutdown();
231
   eina_shutdown();
232
   return -1;
233
}
234

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.