aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c109
1 files changed, 31 insertions, 78 deletions
diff --git a/main.c b/main.c
index 5557276..574c81c 100644
--- a/main.c
+++ b/main.c
@@ -145,7 +145,7 @@ int extract_and_process_header(struct instance *i)
int ret;
int n;
struct video *vid = &i->video;
-
+#if 0
ret = i->parser.func(&i->parser.ctx,
i->in.p + i->in.offs,
i->in.size - i->in.offs,
@@ -168,7 +168,7 @@ int extract_and_process_header(struct instance *i)
parse_stream_init(&i->parser.ctx);
dbg("Extracted header of size %d", fs);
-
+#endif
ret = video_queue_buf_out(i, 0, fs);
if (ret)
return -1;
@@ -235,41 +235,39 @@ int save_frame(struct instance *i, const void *buf, unsigned int size)
return 0;
}
-/* This threads is responsible for parsing the stream and
- * feeding video decoder with consecutive frames to decode */
-void *parser_thread_func(void *args)
+static int input_read(struct instance *i, unsigned int *used, unsigned int *fs)
+{
+ return 0;
+}
+
+/* This threads is responsible for reading input file or stream and
+ * feeding video enccoder with consecutive frames to encode */
+void *input_thread_func(void *args)
{
struct instance *i = (struct instance *)args;
struct video *vid = &i->video;
- int used, fs, n;
+ unsigned int used, fs, n;
int ret;
- dbg("Parser thread started");
+ dbg("input thread started");
- while (!i->error && !i->finish && !i->parser.finished) {
+ while (!i->error && !i->finish) {
n = 0;
pthread_mutex_lock(&i->lock);
while (n < vid->out_buf_cnt && vid->out_buf_flag[n])
n++;
pthread_mutex_unlock(&i->lock);
- if (n < vid->out_buf_cnt && !i->parser.finished) {
+ if (n < vid->out_buf_cnt) {
- ret = i->parser.func(&i->parser.ctx,
- i->in.p + i->in.offs,
- i->in.size - i->in.offs,
- vid->out_buf_addr[n],
- vid->out_buf_size,
- &used, &fs, 0);
+ ret = input_read(i, &used, &fs);
if (ret == 0 && i->in.offs == i->in.size) {
- info("Parser has extracted all frames");
- i->parser.finished = 1;
+ info("read all frames");
+ i->finish = 1;
fs = 0;
}
- dbg("Extracted frame of size %d", fs);
-
ret = video_queue_buf_out(i, n, fs);
pthread_mutex_lock(&i->lock);
@@ -282,7 +280,7 @@ void *parser_thread_func(void *args)
}
}
- dbg("Parser thread finished");
+ dbg("input thread finished");
return NULL;
}
@@ -293,7 +291,7 @@ void *main_thread_func(void *args)
struct video *vid = &i->video;
struct pollfd pfd;
short revents;
- int ret, n, finished, disp_idx;
+ int ret, n, finished;
dbg("main thread started");
@@ -331,32 +329,17 @@ void *main_thread_func(void *args)
vid->cap_buf_flag[n] = 0;
- dbg("decoded frame %ld", vid->total_captured);
+ dbg("encoded frame %ld", vid->total_captured);
if (finished)
break;
vid->total_captured++;
- disp_idx = i->use_dmabuf ? n : 0;
-
- time_start();
-
- drm_display_buf(vid->cap_buf_addr[n][0],
- &i->disp_buf[disp_idx], bytesused,
- i->width, i->height);
-
- print_time_delta("disp");
-
save_frame(i, (void *)vid->cap_buf_addr[n][0],
bytesused);
- if (i->use_dmabuf)
- ret = video_queue_buf_cap_dmabuf(
- i, n, &i->disp_buf[n]);
- else
- ret = video_queue_buf_cap(i, n);
-
+ ret = video_queue_buf_cap(i, n);
if (!ret)
vid->cap_buf_flag[n] = 1;
}
@@ -393,7 +376,7 @@ int main(int argc, char **argv)
{
struct instance inst;
struct video *vid = &inst.video;
- pthread_t parser_thread;
+ pthread_t input_thread;
pthread_t main_thread;
int ret, n;
@@ -403,20 +386,12 @@ int main(int argc, char **argv)
return 1;
}
- info("decoding resolution is %dx%d", inst.width, inst.height);
+ info("encoding resolution is %dx%d", inst.width, inst.height);
pthread_mutex_init(&inst.lock, 0);
vid->total_captured = 0;
- ret = drm_init();
- if (ret)
- goto err;
-
- ret = parse_stream_init(&inst.parser.ctx);
- if (ret)
- goto err;
-
ret = input_open(&inst, inst.in.name);
if (ret)
goto err;
@@ -430,14 +405,13 @@ int main(int argc, char **argv)
if (ret)
goto err;
#endif
- ret = video_setup_output(&inst, inst.parser.codec,
- STREAM_BUUFER_SIZE, 1);
+ ret = video_setup_output(&inst, inst.codec, STREAM_BUUFER_SIZE, 1);
if (ret)
goto err;
- ret = video_set_control(&inst);
- if (ret)
- goto err;
+// ret = video_set_control(&inst);
+// if (ret)
+// goto err;
if (inst.use_dmabuf)
ret = video_setup_capture_dmabuf(&inst, 2, inst.width,
@@ -447,15 +421,6 @@ int main(int argc, char **argv)
if (ret)
goto err;
- if (inst.use_dmabuf)
- ret = drm_create_bufs(&inst.disp_buf[0], vid->cap_buf_cnt,
- inst.width, inst.height, 0);
- else
- ret = drm_create_bufs(&inst.disp_buf[0], 1, inst.width,
- inst.height, 1);
- if (ret)
- goto err;
-
ret = extract_and_process_header(&inst);
if (ret)
goto err;
@@ -467,12 +432,7 @@ int main(int argc, char **argv)
/* queue all capture buffers */
for (n = 0; n < vid->cap_buf_cnt; n++) {
- if (inst.use_dmabuf)
- ret = video_queue_buf_cap_dmabuf(&inst, n,
- &inst.disp_buf[n]);
- else
- ret = video_queue_buf_cap(&inst, n);
-
+ ret = video_queue_buf_cap(&inst, n);
if (ret)
goto err;
@@ -486,27 +446,20 @@ int main(int argc, char **argv)
dbg("Launching threads");
- if (pthread_create(&parser_thread, NULL, parser_thread_func, &inst))
+ if (pthread_create(&input_thread, NULL, input_thread_func, &inst))
goto err;
if (pthread_create(&main_thread, NULL, main_thread_func, &inst))
goto err;
- pthread_join(parser_thread, 0);
+ pthread_join(input_thread, 0);
pthread_join(main_thread, 0);
dbg("Threads have finished");
video_stop(&inst);
- info("Total frames captured %ld", vid->total_captured);
-
- if (inst.use_dmabuf)
- drm_destroy_bufs(inst.disp_buf, vid->cap_buf_cnt, 0);
- else
- drm_destroy_bufs(inst.disp_buf, 1, 1);
-
- drm_deinit();
+ info("Total frames encoded %ld", vid->total_captured);
cleanup(&inst);