Song Zhao | 1b23760 | 2020-02-13 10:58:57 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 Amlogic, Inc. All rights reserved. |
| 3 | * |
| 4 | * This source code is subject to the terms and conditions defined in the |
| 5 | * file 'LICENSE' which is part of this source code package. |
| 6 | * |
| 7 | * Description: |
| 8 | */ |
| 9 | #include <getopt.h> |
| 10 | #include <stdbool.h> |
| 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
| 14 | #include <sys/ioctl.h> |
| 15 | #include <sys/stat.h> |
| 16 | #include <sys/types.h> |
| 17 | #include <semaphore.h> |
| 18 | #include <signal.h> |
| 19 | #include <time.h> |
| 20 | #include <unistd.h> |
| 21 | |
| 22 | #include "drm.h" |
| 23 | #include "demux.h" |
| 24 | #include "v4l2-dec.h" |
| 25 | |
| 26 | static char* media_file; |
| 27 | static sem_t wait_for_end; |
| 28 | int global_plane_id; |
Ao Xu | a3a929a | 2020-04-16 18:29:51 +0800 | [diff] [blame] | 29 | char mode_str[16]; |
| 30 | unsigned int vfresh; |
Song Zhao | 1b23760 | 2020-02-13 10:58:57 -0800 | [diff] [blame] | 31 | int g_dw_mode = 16; |
Song Zhao | 6c7d1f8 | 2020-04-06 23:22:49 -0700 | [diff] [blame] | 32 | static int secure_mode = 0; |
Song Zhao | 1b23760 | 2020-02-13 10:58:57 -0800 | [diff] [blame] | 33 | int ffmpeg_log = 0; |
| 34 | |
| 35 | static void usage(int argc, char **argv) |
| 36 | { |
| 37 | printf( "Usage: %s [options]\n\n" |
| 38 | "Version 0.1\n" |
| 39 | "Options:\n" |
| 40 | "-d | --double_write double write mode.\n" |
| 41 | " 0: no DW compressed only\n" |
| 42 | " 1: DW with 1:1 ratio\n" |
| 43 | " 2: DW with 1:4 down sample\n" |
| 44 | " 4: DW with 1:2 down sample\n" |
| 45 | " 16: DW only\n" |
| 46 | "-f | --file name media file\n" |
| 47 | "-h | --help Print this message\n" |
| 48 | "-p | --plane=id select display plane. 26[pri] 28[overlay 1] 30[overlay 2] 32[video]\n" |
Ao Xu | a3a929a | 2020-04-16 18:29:51 +0800 | [diff] [blame] | 49 | "-m | --mode str set display mode. such as 3840x2160 or 3840x2160-60\n" |
| 50 | " 1920x1080 or 1920x1080-60\n" |
Song Zhao | 1b23760 | 2020-02-13 10:58:57 -0800 | [diff] [blame] | 51 | "-l | --log enable more ffmpeg demux log.\n" |
Song Zhao | 6c7d1f8 | 2020-04-06 23:22:49 -0700 | [diff] [blame] | 52 | "-s | --secure secure video path.\n" |
Song Zhao | 1b23760 | 2020-02-13 10:58:57 -0800 | [diff] [blame] | 53 | "", |
| 54 | argv[0]); |
| 55 | } |
| 56 | |
Ao Xu | a3a929a | 2020-04-16 18:29:51 +0800 | [diff] [blame] | 57 | static const char short_options[] = "d:hf:p:m:ls"; |
Song Zhao | 1b23760 | 2020-02-13 10:58:57 -0800 | [diff] [blame] | 58 | |
| 59 | static const struct option |
| 60 | long_options[] = { |
| 61 | { "double_write", required_argument, NULL, 'd' }, |
| 62 | { "file", required_argument, NULL, 'f' }, |
| 63 | { "help", no_argument, NULL, 'h' }, |
| 64 | { "plane", required_argument, NULL, 'p' }, |
Ao Xu | a3a929a | 2020-04-16 18:29:51 +0800 | [diff] [blame] | 65 | { "mode", required_argument, NULL, 'm' }, |
Song Zhao | 1b23760 | 2020-02-13 10:58:57 -0800 | [diff] [blame] | 66 | { "log", no_argument, NULL, 'l' }, |
Song Zhao | 6c7d1f8 | 2020-04-06 23:22:49 -0700 | [diff] [blame] | 67 | { "secure", no_argument, NULL, 's' }, |
Song Zhao | 1b23760 | 2020-02-13 10:58:57 -0800 | [diff] [blame] | 68 | { 0, 0, 0, 0 } |
| 69 | }; |
| 70 | |
| 71 | void decode_finish() |
| 72 | { |
| 73 | sem_post(&wait_for_end); |
| 74 | } |
| 75 | |
| 76 | int start_decoder(struct dmx_v_data *v_data) |
| 77 | { |
| 78 | int ret; |
Song Zhao | 6c7d1f8 | 2020-04-06 23:22:49 -0700 | [diff] [blame] | 79 | ret = v4l2_dec_init(v_data->type, secure_mode, decode_finish); |
Song Zhao | 1b23760 | 2020-02-13 10:58:57 -0800 | [diff] [blame] | 80 | if (ret) { |
| 81 | printf("FATAL: start_decoder error:%d\n",ret); |
| 82 | exit(1); |
| 83 | } |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | static int parse_para(int argc, char *argv[]) |
| 88 | { |
Ao Xu | a3a929a | 2020-04-16 18:29:51 +0800 | [diff] [blame] | 89 | char *p; |
| 90 | unsigned int len; |
Song Zhao | 1b23760 | 2020-02-13 10:58:57 -0800 | [diff] [blame] | 91 | for (;;) { |
| 92 | int idx; |
| 93 | int c; |
| 94 | |
| 95 | c = getopt_long(argc, argv, |
| 96 | short_options, long_options, &idx); |
| 97 | |
| 98 | if (-1 == c) |
| 99 | break; |
| 100 | |
| 101 | switch (c) { |
| 102 | case 0: /* getopt_long() flag */ |
| 103 | break; |
| 104 | |
| 105 | case 'l': |
| 106 | ffmpeg_log = 1; |
| 107 | break; |
| 108 | |
| 109 | case 'd': |
| 110 | g_dw_mode = atoi(optarg); |
| 111 | if (g_dw_mode != 0 && |
| 112 | g_dw_mode != 1 && |
| 113 | g_dw_mode != 2 && |
| 114 | g_dw_mode != 4 && |
| 115 | g_dw_mode != 16) { |
| 116 | printf("invalide dw_mode %d\n", g_dw_mode); |
| 117 | exit(1); |
| 118 | } |
| 119 | break; |
| 120 | |
| 121 | case 'f': |
| 122 | media_file = strdup(optarg); |
| 123 | break; |
| 124 | |
| 125 | case 'h': |
| 126 | usage(argc, argv); |
| 127 | return -1; |
| 128 | |
| 129 | case 'p': |
| 130 | global_plane_id = atoi(optarg); |
| 131 | break; |
| 132 | |
Song Zhao | 6c7d1f8 | 2020-04-06 23:22:49 -0700 | [diff] [blame] | 133 | case 's': |
Song Zhao | ec31504 | 2020-06-12 00:51:42 -0700 | [diff] [blame^] | 134 | #ifndef CONFIG_SECMEM |
| 135 | printf("secure mode can not be enabled, check compile option\n"); |
| 136 | exit(1); |
| 137 | #endif |
Song Zhao | 6c7d1f8 | 2020-04-06 23:22:49 -0700 | [diff] [blame] | 138 | secure_mode = 1; |
| 139 | break; |
| 140 | |
Ao Xu | a3a929a | 2020-04-16 18:29:51 +0800 | [diff] [blame] | 141 | case 'm': |
| 142 | p = strchr(optarg, '-'); |
| 143 | if (p == NULL) { |
| 144 | len = strlen(optarg); |
| 145 | } else { |
| 146 | vfresh = strtoul(p + 1, NULL, 0); |
| 147 | len = p - optarg; |
| 148 | } |
| 149 | |
| 150 | strncpy(mode_str, optarg, len); |
| 151 | printf("mode:%s, vfresh:%d.\n", mode_str, vfresh); |
| 152 | break; |
| 153 | |
Song Zhao | 1b23760 | 2020-02-13 10:58:57 -0800 | [diff] [blame] | 154 | default: |
| 155 | usage(argc, argv); |
| 156 | return -1; |
| 157 | } |
| 158 | } |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | static void sig_handler(int signo) |
| 163 | { |
| 164 | dump_v4l2_decode_state(); |
| 165 | decode_finish(); |
| 166 | } |
| 167 | |
| 168 | int main(int argc, char *argv[]) |
| 169 | { |
| 170 | int rc; |
| 171 | |
| 172 | if (parse_para(argc, argv)) |
| 173 | goto error; |
| 174 | |
| 175 | if (!media_file) { |
| 176 | printf("no file name assigned\n"); |
| 177 | goto error; |
| 178 | } |
| 179 | |
| 180 | sem_init(&wait_for_end, 0, 0); |
| 181 | |
| 182 | display_engine_register_cb(capture_buffer_recycle); |
Song Zhao | 6c7d1f8 | 2020-04-06 23:22:49 -0700 | [diff] [blame] | 183 | rc = display_engine_start(secure_mode); |
Song Zhao | 1b23760 | 2020-02-13 10:58:57 -0800 | [diff] [blame] | 184 | if (rc < 0) { |
| 185 | printf("Unable to start display engine\n"); |
| 186 | goto error; |
| 187 | } |
| 188 | printf("\ndisplay started\n"); |
| 189 | |
| 190 | struct dmx_cb cb = { |
| 191 | .write = v4l2_dec_write_es, |
| 192 | .frame_done = v4l2_dec_frame_done, |
| 193 | .meta_done = start_decoder, |
| 194 | .eos = v4l2_dec_eos, |
| 195 | }; |
| 196 | |
| 197 | signal(SIGINT, sig_handler); |
| 198 | |
| 199 | rc = demux_init(media_file, &cb); |
| 200 | if (rc) { |
| 201 | printf("demux_init fail %d\n",rc); |
| 202 | goto error; |
| 203 | } |
| 204 | printf("\ndemux started\n"); |
| 205 | |
| 206 | sem_wait(&wait_for_end); |
| 207 | |
| 208 | dmx_destroy(); |
| 209 | v4l2_dec_destroy(); |
| 210 | display_engine_stop(); |
| 211 | sem_destroy(&wait_for_end); |
| 212 | |
| 213 | return 0; |
| 214 | error: |
| 215 | return 1; |
| 216 | } |