1 | /* |
2 | Copyright (c) 2012, Broadcom Europe Ltd |
3 | All rights reserved. |
4 | |
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the following conditions are met: |
7 | * Redistributions of source code must retain the above copyright |
8 | notice, this list of conditions and the following disclaimer. |
9 | * Redistributions in binary form must reproduce the above copyright |
10 | notice, this list of conditions and the following disclaimer in the |
11 | documentation and/or other materials provided with the distribution. |
12 | * Neither the name of the copyright holder nor the |
13 | names of its contributors may be used to endorse or promote products |
14 | derived from this software without specific prior written permission. |
15 | |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | #include <stdlib.h> |
29 | #include <stdio.h> |
30 | #include <string.h> |
31 | #include <unistd.h> |
32 | #include "applog.h" |
33 | #include "vidtex.h" |
34 | |
35 | #ifdef __ANDROID__ |
36 | #include "launcher.h" |
37 | #else |
38 | #include "launcher_rpi.h" |
39 | #endif |
40 | |
41 | VCOS_LOG_CAT_T app_log_category; |
42 | |
43 | static int launch_vidtex(const void *params, EGLNativeWindowType win) |
44 | { |
45 | return vidtex_run((const VIDTEX_PARAMS_T *)params, win); |
46 | } |
47 | |
48 | static void usage(const char *argv0) |
49 | { |
50 | fprintf(stderr, "Usage: %s [-d duration-ms] [-i] [uri]\n" , argv0); |
51 | } |
52 | |
53 | int main(int argc, char **argv) |
54 | { |
55 | // Parse command line options/arguments. |
56 | VIDTEX_PARAMS_T params = {0}; |
57 | int rc; |
58 | int status = 0; |
59 | |
60 | opterr = 0; |
61 | |
62 | while ((rc = getopt(argc, argv, "d:iuvy" )) != -1) |
63 | { |
64 | switch (rc) |
65 | { |
66 | case 'd': |
67 | params.duration_ms = atoi(optarg); |
68 | break; |
69 | |
70 | case 'i': |
71 | params.opts |= VIDTEX_OPT_IMG_PER_FRAME; |
72 | break; |
73 | |
74 | case 'y': |
75 | params.opts |= VIDTEX_OPT_Y_TEXTURE; |
76 | break; |
77 | |
78 | case 'u': |
79 | params.opts |= VIDTEX_OPT_U_TEXTURE; |
80 | break; |
81 | |
82 | case 'v': |
83 | params.opts |= VIDTEX_OPT_V_TEXTURE; |
84 | break; |
85 | |
86 | default: |
87 | usage(argv[0]); |
88 | return 2; |
89 | } |
90 | } |
91 | |
92 | if (optind < argc - 1) |
93 | { |
94 | usage(argv[0]); |
95 | return 2; |
96 | } |
97 | |
98 | if (optind < argc) |
99 | { |
100 | strncpy(params.uri, argv[optind], sizeof(params.uri) - 1); |
101 | params.uri[sizeof(params.uri) - 1] = '\0'; |
102 | } |
103 | |
104 | // Init vcos logging. |
105 | vcos_log_set_level(VCOS_LOG_CATEGORY, VCOS_LOG_INFO); |
106 | vcos_log_register("vidtex" , VCOS_LOG_CATEGORY); |
107 | |
108 | // Run video-on-texture application in a separate thread. |
109 | #ifdef __ANDROID__ |
110 | status = Launcher::runApp("vidtex" , launch_vidtex, ¶ms, sizeof(params)); |
111 | #else |
112 | status = runApp("vidtex" , launch_vidtex, ¶ms, sizeof(params)); |
113 | #endif |
114 | return (status == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
115 | } |
116 | |