Skip to content
This repository
Browse code

cleanup VideoWindow

- add log messages for any fatal errors
- reformat code
  • Loading branch information...
commit e594c229758b7fe28da3ed771e2900135ece1e8a 1 parent e57da86
Jonathan Hoffmann authored November 12, 2012

Showing 1 changed file with 66 additions and 46 deletions. Show diff stats Hide diff stats

  1. 112  VideoWindow/main.c
112  VideoWindow/main.c
@@ -157,7 +157,6 @@ initialize_egl_window(screen_context_t ctx, char * window_group_name) {
157 157
     }
158 158
 
159 159
     rc = eglBindAPI(EGL_OPENGL_ES_API);
160  
-
161 160
     if (rc != EGL_TRUE) {
162 161
         egl_perror("eglBindApi");
163 162
         terminate_egl_window();
@@ -166,11 +165,11 @@ initialize_egl_window(screen_context_t ctx, char * window_group_name) {
166 165
 
167 166
     if(!eglChooseConfig(g_egl_disp, attrib_list, &g_egl_conf, 1, &num_configs)) {
168 167
         terminate_egl_window();
  168
+        fprintf(stderr, "eglChooseConfig failed\n");
169 169
         return EXIT_FAILURE;
170 170
     }
171 171
 
172 172
     g_egl_ctx = eglCreateContext(g_egl_disp, g_egl_conf, EGL_NO_CONTEXT, NULL);
173  
-
174 173
     if (g_egl_ctx == EGL_NO_CONTEXT) {
175 174
         egl_perror("eglCreateContext");
176 175
         terminate_egl_window();
@@ -189,6 +188,7 @@ initialize_egl_window(screen_context_t ctx, char * window_group_name) {
189 188
      * which contains the video.
190 189
      */
191 190
     if (screen_create_window_group(g_screen_win, window_group_name) != 0) {
  191
+        perror("screen_create_window_group");
192 192
         return EXIT_FAILURE;
193 193
     }
194 194
 
@@ -407,7 +407,6 @@ strm_dict_t* calculate_rect(int width, int height) {
407 407
 int main(int argc, char *argv[])
408 408
 {
409 409
     int rc;
410  
-    int exit_application = 0;
411 410
 
412 411
     // Renderer variables
413 412
     mmr_connection_t*     mmr_connection = 0;
@@ -458,13 +457,16 @@ int main(int argc, char *argv[])
458 457
 
459 458
     // Create the Screen Context.
460 459
     if (screen_create_context(&g_screen_ctx, SCREEN_APPLICATION_CONTEXT) != 0) {
  460
+        fprintf(stderr, "screen_create_context failed\n");
461 461
         return EXIT_FAILURE;
462 462
     }
463 463
 
464 464
     // Create the window and initialize EGL for GL_ES_1 rendering
465 465
     rc = initialize_egl_window(g_screen_ctx, window_group_name);
466  
-    if (rc != EXIT_SUCCESS)
  466
+    if (rc != EXIT_SUCCESS) {
  467
+        fprintf(stderr, "initialize_egl_window failed\n");
467 468
         return EXIT_FAILURE;
  469
+    }
468 470
 
469 471
     // Query width and height of the window surface created by utility code
470 472
     eglQuerySurface(g_egl_disp, g_egl_surf, EGL_WIDTH, &surface_width);
@@ -516,22 +518,26 @@ int main(int argc, char *argv[])
516 518
     // Configure mm-renderer.
517 519
     mmr_connection = mmr_connect(NULL);
518 520
     if (mmr_connection == NULL) {
  521
+        fprintf(stderr, "mmr_connect failed\n");
519 522
         return EXIT_FAILURE;
520 523
     }
521 524
 
522 525
     mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO);
523 526
     if (mmr_context == NULL) {
  527
+        fprintf(stderr, "mmr_context_create failed\n");
524 528
         return EXIT_FAILURE;
525 529
     }
526 530
 
527 531
     // Configure video and audio output.
528 532
     video_device_output_id = mmr_output_attach(mmr_context, video_device_url, "video");
529 533
     if (video_device_output_id == -1) {
  534
+        fprintf(stderr, "mmr_output_attach(video) failed\n");
530 535
         return EXIT_FAILURE;
531 536
     }
532 537
 
533 538
     audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio");
534 539
     if (audio_device_output_id == -1) {
  540
+        fprintf(stderr, "mmr_output_attach(audio) failed\n");
535 541
         return EXIT_FAILURE;
536 542
     }
537 543
 
@@ -546,11 +552,13 @@ int main(int argc, char *argv[])
546 552
 
547 553
     rc = snprintf(media_file, PATH_MAX, "file://%s/%s", cwd, video_file_relative_path);
548 554
     if ((rc == -1) || (rc >= PATH_MAX)) {
  555
+        fprintf(stderr, "snprintf(media_file) failed\n");
549 556
         return EXIT_FAILURE;
550 557
     }
551 558
 
552 559
     // Attach the input media.
553 560
     if (mmr_input_attach(mmr_context, media_file, "track") != 0) {
  561
+        fprintf(stderr, "mmr_input_attach(track) failed\n");
554 562
         return EXIT_FAILURE;
555 563
     }
556 564
 
@@ -559,11 +567,13 @@ int main(int argc, char *argv[])
559 567
 
560 568
     // Set the speed to 0 to pause the video initially
561 569
     if (mmr_speed_set(mmr_context, video_speed) != 0) {
  570
+        fprintf(stderr, "mmr_set_speed(0) failed\n");
562 571
         return EXIT_FAILURE;
563 572
     }
564 573
 
565 574
     // Change to the play state, although speed is zero
566 575
     if (mmr_play(mmr_context) != 0) {
  576
+        fprintf(stderr, "mmr_play failed\n");
567 577
         return EXIT_FAILURE;
568 578
     }
569 579
 
@@ -571,10 +581,12 @@ int main(int argc, char *argv[])
571 581
      */
572 582
     dict = calculate_rect(surface_width, surface_height);
573 583
     if (NULL == dict) {
  584
+        fprintf(stderr, "calculate_rect failed\n");
574 585
         return EXIT_FAILURE;
575 586
     }
576 587
 
577 588
     if (mmr_output_parameters(mmr_context, video_device_output_id, dict) != 0) {
  589
+        fprintf(stderr, "mmr_output_parameters failed\n");
578 590
         return EXIT_FAILURE;
579 591
     }
580 592
 
@@ -589,7 +601,7 @@ int main(int argc, char *argv[])
589 601
     screen_window_t video_window = (screen_window_t)0;
590 602
     bool app_window_above = true;
591 603
     int screen_val;
592  
-
  604
+    int exit_value = EXIT_SUCCESS;
593 605
 
594 606
     // Handle keyboard events and stop playback upon user request.
595 607
     for (;;) {
@@ -598,40 +610,38 @@ int main(int argc, char *argv[])
598 610
             return EXIT_FAILURE;
599 611
         }
600 612
         if (event) {
601  
-
602  
-            if (bps_event_get_domain(event) == navigator_get_domain())
603  
-            {
  613
+            if (bps_event_get_domain(event) == navigator_get_domain()) {
604 614
                 if (bps_event_get_code(event) == NAVIGATOR_EXIT) {
605  
-
606  
-                exit_application = 1;
607  
-                }
608  
-                else if( NAVIGATOR_SWIPE_DOWN == bps_event_get_code(event)) {
  615
+                    break;
  616
+                } else if(NAVIGATOR_SWIPE_DOWN == bps_event_get_code(event)) {
609 617
                     if ((screen_window_t)0 != video_window) {
610 618
 
611 619
                         app_window_above = !app_window_above;
612 620
                         if (app_window_above) {
613 621
                             screen_val = 1;
614  
-                        }
615  
-                        else {
  622
+                        } else {
616 623
                             screen_val = -1;
617 624
                         }
618 625
                         if (screen_set_window_property_iv(video_window, SCREEN_PROPERTY_ZORDER, &screen_val) != 0) {
619  
-                            return EXIT_FAILURE;
  626
+                            fprintf(stderr, "screen_set_window_property(ZORDER) failed\n");
  627
+                            exit_value = EXIT_FAILURE;
  628
+                            break;
620 629
                         }
621 630
 
622 631
                         screen_val = 1;
623 632
                         if (screen_set_window_property_iv(video_window, SCREEN_PROPERTY_VISIBLE, &screen_val) != 0) {
624  
-                            return EXIT_FAILURE;
  633
+                            fprintf(stderr, "screen_set_window_property(VISIBLE) failed\n");
  634
+                            exit_value = EXIT_FAILURE;
  635
+                            break;
625 636
                         }
626 637
 
627 638
                         rc = screen_flush_context(g_screen_ctx, SCREEN_WAIT_IDLE);
628  
-                        if (rc != 0)
  639
+                        if (rc != 0) {
629 640
                             fprintf (stderr, "Warning: Failed to flush\n");
630  
-
  641
+                        }
631 642
                     }
632 643
                 }
633  
-            }
634  
-            else if (bps_event_get_domain(event) == screen_get_domain()) {
  644
+            } else if (bps_event_get_domain(event) == screen_get_domain()) {
635 645
                 screen_event_t screen_event = screen_event_get_event(event);
636 646
                 int event_type;
637 647
                 screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &event_type);
@@ -640,57 +650,65 @@ int main(int argc, char *argv[])
640 650
                     char id[256];
641 651
 
642 652
                     rc = screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void**)&video_window);
643  
-                    if (rc != 0)
644  
-                        return EXIT_FAILURE;
645  
-                    printf("video_window%d\n",(int)video_window);
  653
+                    if (rc != 0) {
  654
+                        fprintf(stderr, "screen_get_event_property(WINDOW) failed\n");
  655
+                        exit_value = EXIT_FAILURE;
  656
+                        break;
  657
+                    }
  658
+                    fprintf(stderr, "video_window%d\n",(int)video_window);
646 659
 
647 660
                     rc = screen_get_window_property_cv(video_window, SCREEN_PROPERTY_ID_STRING, 256, id);
648  
-                    if (rc != 0)
649  
-                        return EXIT_FAILURE;
650  
-
651  
-                    printf ("window ID is %s\n", id);
652  
-                    if (strncmp(id, window_group_name, strlen(window_group_name)) != 0)
653  
-                        return EXIT_FAILURE;
654  
-                }
655  
-
656  
-
657  
-                else if(event_type == SCREEN_EVENT_MTOUCH_TOUCH) {
  661
+                    if (rc != 0) {
  662
+                        fprintf(stderr, "screen_get_window_property(ID) failed\n");
  663
+                        exit_value = EXIT_FAILURE;
  664
+                        break;
  665
+                    }
  666
+                    fprintf(stderr, "window ID is %s\n", id);
658 667
 
  668
+                    if (strncmp(id, window_group_name, strlen(window_group_name)) != 0) {
  669
+                        fprintf(stderr, "window ID mismatch\n");
  670
+                        exit_value = EXIT_FAILURE;
  671
+                        break;
  672
+                    }
  673
+                } else if(event_type == SCREEN_EVENT_MTOUCH_TOUCH) {
659 674
                     if (video_speed == 0) {
660 675
                         video_speed = 1000;
661 676
                         render(false);
662  
-                    }
663  
-                    else {
  677
+                    } else {
664 678
                         video_speed = 0;
665 679
                         render(true);
666 680
                     }
  681
+
667 682
                     if (mmr_speed_set(mmr_context, video_speed) != 0) {
668  
-                        return EXIT_FAILURE;
  683
+                        fprintf(stderr, "mmr_speed_set(%d) failed\n", video_speed);
  684
+                        exit_value = EXIT_FAILURE;
  685
+                        break;
669 686
                     }
670 687
                 }
671 688
             }
672  
-            if (exit_application) {
673  
-                break;
674  
-            }
675 689
         }
676 690
     }
677 691
 
678 692
     screen_stop_events(g_screen_ctx);
679 693
 
680 694
     if (mmr_stop(mmr_context) != 0) {
681  
-        return EXIT_FAILURE;
  695
+        fprintf(stderr, "mmr_stop failed\n");
  696
+        exit_value = EXIT_FAILURE;
682 697
     }
683 698
 
684 699
     if (mmr_output_detach(mmr_context, audio_device_output_id) != 0) {
685  
-        return EXIT_FAILURE;
  700
+        fprintf(stderr, "mmr_output_detach(audio) failed\n");
  701
+        exit_value = EXIT_FAILURE;
686 702
     }
687 703
 
688 704
     if (mmr_output_detach(mmr_context, video_device_output_id) != 0) {
689  
-        return EXIT_FAILURE;
  705
+        fprintf(stderr, "mmr_output_detach(video) failed\n");
  706
+        exit_value = EXIT_FAILURE;
690 707
     }
691 708
 
692 709
     if (mmr_context_destroy(mmr_context) != 0) {
693  
-        return EXIT_FAILURE;
  710
+        fprintf(stderr, "mmr_context_destroy failed\n");
  711
+        exit_value = EXIT_FAILURE;
694 712
     }
695 713
 
696 714
     mmr_context = 0;
@@ -703,15 +721,17 @@ int main(int argc, char *argv[])
703 721
     bps_shutdown();
704 722
 
705 723
     if (screen_destroy_window(g_screen_win) != 0) {
706  
-        return EXIT_FAILURE;
  724
+        fprintf(stderr, "screen_destroy_window failed\n");
  725
+        exit_value = EXIT_FAILURE;
707 726
     }
708 727
 
709 728
     if (screen_destroy_context(g_screen_ctx) != 0) {
710  
-        return EXIT_FAILURE;
  729
+        fprintf(stderr, "screen_destroy_context failed\n");
  730
+        exit_value = EXIT_FAILURE;
711 731
     }
712 732
 
713 733
     g_screen_ctx = 0;
714 734
     g_screen_win = 0;
715 735
 
716  
-    return EXIT_SUCCESS;
  736
+    return exit_value;
717 737
 }

0 notes on commit e594c22

Please sign in to comment.
Something went wrong with that request. Please try again.