blob: 9201e0b0fbb23d6db9a4a541cac0aecd979c4a85 [file] [log] [blame]
Song Zhao1b237602020-02-13 10:58:57 -08001/*
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
26static char* media_file;
27static sem_t wait_for_end;
28int global_plane_id;
29int g_dw_mode = 16;
Song Zhao6c7d1f82020-04-06 23:22:49 -070030static int secure_mode = 0;
Song Zhao1b237602020-02-13 10:58:57 -080031int ffmpeg_log = 0;
32
33static void usage(int argc, char **argv)
34{
35 printf( "Usage: %s [options]\n\n"
36 "Version 0.1\n"
37 "Options:\n"
38 "-d | --double_write double write mode.\n"
39 " 0: no DW compressed only\n"
40 " 1: DW with 1:1 ratio\n"
41 " 2: DW with 1:4 down sample\n"
42 " 4: DW with 1:2 down sample\n"
43 " 16: DW only\n"
44 "-f | --file name media file\n"
45 "-h | --help Print this message\n"
46 "-p | --plane=id select display plane. 26[pri] 28[overlay 1] 30[overlay 2] 32[video]\n"
47 "-l | --log enable more ffmpeg demux log.\n"
Song Zhao6c7d1f82020-04-06 23:22:49 -070048 "-s | --secure secure video path.\n"
Song Zhao1b237602020-02-13 10:58:57 -080049 "",
50 argv[0]);
51}
52
Song Zhao6c7d1f82020-04-06 23:22:49 -070053static const char short_options[] = "d:hf:p:ls";
Song Zhao1b237602020-02-13 10:58:57 -080054
55static const struct option
56long_options[] = {
57 { "double_write", required_argument, NULL, 'd' },
58 { "file", required_argument, NULL, 'f' },
59 { "help", no_argument, NULL, 'h' },
60 { "plane", required_argument, NULL, 'p' },
61 { "log", no_argument, NULL, 'l' },
Song Zhao6c7d1f82020-04-06 23:22:49 -070062 { "secure", no_argument, NULL, 's' },
Song Zhao1b237602020-02-13 10:58:57 -080063 { 0, 0, 0, 0 }
64};
65
66void decode_finish()
67{
68 sem_post(&wait_for_end);
69}
70
71int start_decoder(struct dmx_v_data *v_data)
72{
73 int ret;
Song Zhao6c7d1f82020-04-06 23:22:49 -070074 ret = v4l2_dec_init(v_data->type, secure_mode, decode_finish);
Song Zhao1b237602020-02-13 10:58:57 -080075 if (ret) {
76 printf("FATAL: start_decoder error:%d\n",ret);
77 exit(1);
78 }
79 return 0;
80}
81
82static int parse_para(int argc, char *argv[])
83{
84 for (;;) {
85 int idx;
86 int c;
87
88 c = getopt_long(argc, argv,
89 short_options, long_options, &idx);
90
91 if (-1 == c)
92 break;
93
94 switch (c) {
95 case 0: /* getopt_long() flag */
96 break;
97
98 case 'l':
99 ffmpeg_log = 1;
100 break;
101
102 case 'd':
103 g_dw_mode = atoi(optarg);
104 if (g_dw_mode != 0 &&
105 g_dw_mode != 1 &&
106 g_dw_mode != 2 &&
107 g_dw_mode != 4 &&
108 g_dw_mode != 16) {
109 printf("invalide dw_mode %d\n", g_dw_mode);
110 exit(1);
111 }
112 break;
113
114 case 'f':
115 media_file = strdup(optarg);
116 break;
117
118 case 'h':
119 usage(argc, argv);
120 return -1;
121
122 case 'p':
123 global_plane_id = atoi(optarg);
124 break;
125
Song Zhao6c7d1f82020-04-06 23:22:49 -0700126 case 's':
127 secure_mode = 1;
128 break;
129
Song Zhao1b237602020-02-13 10:58:57 -0800130 default:
131 usage(argc, argv);
132 return -1;
133 }
134 }
135 return 0;
136}
137
138static void sig_handler(int signo)
139{
140 dump_v4l2_decode_state();
141 decode_finish();
142}
143
144int main(int argc, char *argv[])
145{
146 int rc;
147
148 if (parse_para(argc, argv))
149 goto error;
150
151 if (!media_file) {
152 printf("no file name assigned\n");
153 goto error;
154 }
155
156 sem_init(&wait_for_end, 0, 0);
157
158 display_engine_register_cb(capture_buffer_recycle);
Song Zhao6c7d1f82020-04-06 23:22:49 -0700159 rc = display_engine_start(secure_mode);
Song Zhao1b237602020-02-13 10:58:57 -0800160 if (rc < 0) {
161 printf("Unable to start display engine\n");
162 goto error;
163 }
164 printf("\ndisplay started\n");
165
166 struct dmx_cb cb = {
167 .write = v4l2_dec_write_es,
168 .frame_done = v4l2_dec_frame_done,
169 .meta_done = start_decoder,
170 .eos = v4l2_dec_eos,
171 };
172
173 signal(SIGINT, sig_handler);
174
175 rc = demux_init(media_file, &cb);
176 if (rc) {
177 printf("demux_init fail %d\n",rc);
178 goto error;
179 }
180 printf("\ndemux started\n");
181
182 sem_wait(&wait_for_end);
183
184 dmx_destroy();
185 v4l2_dec_destroy();
186 display_engine_stop();
187 sem_destroy(&wait_for_end);
188
189 return 0;
190error:
191 return 1;
192}