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