Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleanup VideoWindow

- add log messages for any fatal errors
- reformat code
  • Loading branch information...
commit e594c229758b7fe28da3ed771e2900135ece1e8a 1 parent e57da86
@jhoffmannrim jhoffmannrim authored
Showing with 66 additions and 46 deletions.
  1. +66 −46 VideoWindow/main.c
View
112 VideoWindow/main.c
@@ -157,7 +157,6 @@ initialize_egl_window(screen_context_t ctx, char * window_group_name) {
}
rc = eglBindAPI(EGL_OPENGL_ES_API);
-
if (rc != EGL_TRUE) {
egl_perror("eglBindApi");
terminate_egl_window();
@@ -166,11 +165,11 @@ initialize_egl_window(screen_context_t ctx, char * window_group_name) {
if(!eglChooseConfig(g_egl_disp, attrib_list, &g_egl_conf, 1, &num_configs)) {
terminate_egl_window();
+ fprintf(stderr, "eglChooseConfig failed\n");
return EXIT_FAILURE;
}
g_egl_ctx = eglCreateContext(g_egl_disp, g_egl_conf, EGL_NO_CONTEXT, NULL);
-
if (g_egl_ctx == EGL_NO_CONTEXT) {
egl_perror("eglCreateContext");
terminate_egl_window();
@@ -189,6 +188,7 @@ initialize_egl_window(screen_context_t ctx, char * window_group_name) {
* which contains the video.
*/
if (screen_create_window_group(g_screen_win, window_group_name) != 0) {
+ perror("screen_create_window_group");
return EXIT_FAILURE;
}
@@ -407,7 +407,6 @@ strm_dict_t* calculate_rect(int width, int height) {
int main(int argc, char *argv[])
{
int rc;
- int exit_application = 0;
// Renderer variables
mmr_connection_t* mmr_connection = 0;
@@ -458,13 +457,16 @@ int main(int argc, char *argv[])
// Create the Screen Context.
if (screen_create_context(&g_screen_ctx, SCREEN_APPLICATION_CONTEXT) != 0) {
+ fprintf(stderr, "screen_create_context failed\n");
return EXIT_FAILURE;
}
// Create the window and initialize EGL for GL_ES_1 rendering
rc = initialize_egl_window(g_screen_ctx, window_group_name);
- if (rc != EXIT_SUCCESS)
+ if (rc != EXIT_SUCCESS) {
+ fprintf(stderr, "initialize_egl_window failed\n");
return EXIT_FAILURE;
+ }
// Query width and height of the window surface created by utility code
eglQuerySurface(g_egl_disp, g_egl_surf, EGL_WIDTH, &surface_width);
@@ -516,22 +518,26 @@ int main(int argc, char *argv[])
// Configure mm-renderer.
mmr_connection = mmr_connect(NULL);
if (mmr_connection == NULL) {
+ fprintf(stderr, "mmr_connect failed\n");
return EXIT_FAILURE;
}
mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO);
if (mmr_context == NULL) {
+ fprintf(stderr, "mmr_context_create failed\n");
return EXIT_FAILURE;
}
// Configure video and audio output.
video_device_output_id = mmr_output_attach(mmr_context, video_device_url, "video");
if (video_device_output_id == -1) {
+ fprintf(stderr, "mmr_output_attach(video) failed\n");
return EXIT_FAILURE;
}
audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio");
if (audio_device_output_id == -1) {
+ fprintf(stderr, "mmr_output_attach(audio) failed\n");
return EXIT_FAILURE;
}
@@ -546,11 +552,13 @@ int main(int argc, char *argv[])
rc = snprintf(media_file, PATH_MAX, "file://%s/%s", cwd, video_file_relative_path);
if ((rc == -1) || (rc >= PATH_MAX)) {
+ fprintf(stderr, "snprintf(media_file) failed\n");
return EXIT_FAILURE;
}
// Attach the input media.
if (mmr_input_attach(mmr_context, media_file, "track") != 0) {
+ fprintf(stderr, "mmr_input_attach(track) failed\n");
return EXIT_FAILURE;
}
@@ -559,11 +567,13 @@ int main(int argc, char *argv[])
// Set the speed to 0 to pause the video initially
if (mmr_speed_set(mmr_context, video_speed) != 0) {
+ fprintf(stderr, "mmr_set_speed(0) failed\n");
return EXIT_FAILURE;
}
// Change to the play state, although speed is zero
if (mmr_play(mmr_context) != 0) {
+ fprintf(stderr, "mmr_play failed\n");
return EXIT_FAILURE;
}
@@ -571,10 +581,12 @@ int main(int argc, char *argv[])
*/
dict = calculate_rect(surface_width, surface_height);
if (NULL == dict) {
+ fprintf(stderr, "calculate_rect failed\n");
return EXIT_FAILURE;
}
if (mmr_output_parameters(mmr_context, video_device_output_id, dict) != 0) {
+ fprintf(stderr, "mmr_output_parameters failed\n");
return EXIT_FAILURE;
}
@@ -589,7 +601,7 @@ int main(int argc, char *argv[])
screen_window_t video_window = (screen_window_t)0;
bool app_window_above = true;
int screen_val;
-
+ int exit_value = EXIT_SUCCESS;
// Handle keyboard events and stop playback upon user request.
for (;;) {
@@ -598,40 +610,38 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
if (event) {
-
- if (bps_event_get_domain(event) == navigator_get_domain())
- {
+ if (bps_event_get_domain(event) == navigator_get_domain()) {
if (bps_event_get_code(event) == NAVIGATOR_EXIT) {
-
- exit_application = 1;
- }
- else if( NAVIGATOR_SWIPE_DOWN == bps_event_get_code(event)) {
+ break;
+ } else if(NAVIGATOR_SWIPE_DOWN == bps_event_get_code(event)) {
if ((screen_window_t)0 != video_window) {
app_window_above = !app_window_above;
if (app_window_above) {
screen_val = 1;
- }
- else {
+ } else {
screen_val = -1;
}
if (screen_set_window_property_iv(video_window, SCREEN_PROPERTY_ZORDER, &screen_val) != 0) {
- return EXIT_FAILURE;
+ fprintf(stderr, "screen_set_window_property(ZORDER) failed\n");
+ exit_value = EXIT_FAILURE;
+ break;
}
screen_val = 1;
if (screen_set_window_property_iv(video_window, SCREEN_PROPERTY_VISIBLE, &screen_val) != 0) {
- return EXIT_FAILURE;
+ fprintf(stderr, "screen_set_window_property(VISIBLE) failed\n");
+ exit_value = EXIT_FAILURE;
+ break;
}
rc = screen_flush_context(g_screen_ctx, SCREEN_WAIT_IDLE);
- if (rc != 0)
+ if (rc != 0) {
fprintf (stderr, "Warning: Failed to flush\n");
-
+ }
}
}
- }
- else if (bps_event_get_domain(event) == screen_get_domain()) {
+ } else if (bps_event_get_domain(event) == screen_get_domain()) {
screen_event_t screen_event = screen_event_get_event(event);
int event_type;
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &event_type);
@@ -640,57 +650,65 @@ int main(int argc, char *argv[])
char id[256];
rc = screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void**)&video_window);
- if (rc != 0)
- return EXIT_FAILURE;
- printf("video_window%d\n",(int)video_window);
+ if (rc != 0) {
+ fprintf(stderr, "screen_get_event_property(WINDOW) failed\n");
+ exit_value = EXIT_FAILURE;
+ break;
+ }
+ fprintf(stderr, "video_window%d\n",(int)video_window);
rc = screen_get_window_property_cv(video_window, SCREEN_PROPERTY_ID_STRING, 256, id);
- if (rc != 0)
- return EXIT_FAILURE;
-
- printf ("window ID is %s\n", id);
- if (strncmp(id, window_group_name, strlen(window_group_name)) != 0)
- return EXIT_FAILURE;
- }
-
-
- else if(event_type == SCREEN_EVENT_MTOUCH_TOUCH) {
+ if (rc != 0) {
+ fprintf(stderr, "screen_get_window_property(ID) failed\n");
+ exit_value = EXIT_FAILURE;
+ break;
+ }
+ fprintf(stderr, "window ID is %s\n", id);
+ if (strncmp(id, window_group_name, strlen(window_group_name)) != 0) {
+ fprintf(stderr, "window ID mismatch\n");
+ exit_value = EXIT_FAILURE;
+ break;
+ }
+ } else if(event_type == SCREEN_EVENT_MTOUCH_TOUCH) {
if (video_speed == 0) {
video_speed = 1000;
render(false);
- }
- else {
+ } else {
video_speed = 0;
render(true);
}
+
if (mmr_speed_set(mmr_context, video_speed) != 0) {
- return EXIT_FAILURE;
+ fprintf(stderr, "mmr_speed_set(%d) failed\n", video_speed);
+ exit_value = EXIT_FAILURE;
+ break;
}
}
}
- if (exit_application) {
- break;
- }
}
}
screen_stop_events(g_screen_ctx);
if (mmr_stop(mmr_context) != 0) {
- return EXIT_FAILURE;
+ fprintf(stderr, "mmr_stop failed\n");
+ exit_value = EXIT_FAILURE;
}
if (mmr_output_detach(mmr_context, audio_device_output_id) != 0) {
- return EXIT_FAILURE;
+ fprintf(stderr, "mmr_output_detach(audio) failed\n");
+ exit_value = EXIT_FAILURE;
}
if (mmr_output_detach(mmr_context, video_device_output_id) != 0) {
- return EXIT_FAILURE;
+ fprintf(stderr, "mmr_output_detach(video) failed\n");
+ exit_value = EXIT_FAILURE;
}
if (mmr_context_destroy(mmr_context) != 0) {
- return EXIT_FAILURE;
+ fprintf(stderr, "mmr_context_destroy failed\n");
+ exit_value = EXIT_FAILURE;
}
mmr_context = 0;
@@ -703,15 +721,17 @@ int main(int argc, char *argv[])
bps_shutdown();
if (screen_destroy_window(g_screen_win) != 0) {
- return EXIT_FAILURE;
+ fprintf(stderr, "screen_destroy_window failed\n");
+ exit_value = EXIT_FAILURE;
}
if (screen_destroy_context(g_screen_ctx) != 0) {
- return EXIT_FAILURE;
+ fprintf(stderr, "screen_destroy_context failed\n");
+ exit_value = EXIT_FAILURE;
}
g_screen_ctx = 0;
g_screen_win = 0;
- return EXIT_SUCCESS;
+ return exit_value;
}
Please sign in to comment.
Something went wrong with that request. Please try again.