aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanimir Varbanov <stanimir.varbanov@linaro.org>2015-10-02 15:15:30 +0300
committerStanimir Varbanov <stanimir.varbanov@linaro.org>2015-10-02 15:16:01 +0300
commitc4d8aa4472457c952c8a167b4030e64a377da625 (patch)
tree64f3e3a0cae1635140d3d9577b027d3529465c9e
parent4517616b25393381e0a611b6e0b913fd28d4a1d3 (diff)
downloadv4l2-encode-c4d8aa4472457c952c8a167b4030e64a377da625.tar.gz
make it to build
Signed-off-by: Stanimir Varbanov <stanimir.varbanov@linaro.org>
-rw-r--r--args.c29
-rw-r--r--common.h25
-rw-r--r--main.c109
-rw-r--r--video.c54
-rw-r--r--video.h2
5 files changed, 39 insertions, 180 deletions
diff --git a/args.c b/args.c
index 689e705..9ec8bf3 100644
--- a/args.c
+++ b/args.c
@@ -28,21 +28,19 @@
#include <linux/videodev2.h>
#include "common.h"
-#include "parser.h"
-
void print_usage(char *name)
{
printf("Usage:\n");
printf("\t%s\n", name);
- printf("\t-c <codec> - The codec of the encoded stream\n");
+ printf("\t-c <codec> - The codec to be used for encoding\n");
printf("\t\t Available codecs: mpeg4, h264\n");
printf("\t-d use dmabuf instead of mmap\n");
- printf("\t-i <file> - Input file name\n");
- printf("\t-m <device> - video decoder device (e.g. /dev/video8)\n");
+ printf("\t-i <file> - Input file name in NV12\n");
+ printf("\t-m <device> - video encoder device (e.g. /dev/video33)\n");
printf("\t-w video width\n");
printf("\t-h video height\n");
- printf("\t-f save frames on disk\n");
+ printf("\t-f save encoded frames on disk\n");
printf("\n");
}
@@ -79,7 +77,7 @@ int parse_args(struct instance *i, int argc, char **argv)
while ((c = getopt(argc, argv, "w:h:c:di:m:f:")) != -1) {
switch (c) {
case 'c':
- i->parser.codec = get_codec(optarg);
+ i->codec = get_codec(optarg);
break;
case 'd':
i->use_dmabuf = 1;
@@ -111,26 +109,11 @@ int parse_args(struct instance *i, int argc, char **argv)
return -1;
}
- if (!i->parser.codec) {
+ if (!i->codec) {
err("Unknown or not set codec (-c)");
return -1;
}
- switch (i->parser.codec) {
- case V4L2_PIX_FMT_XVID:
- case V4L2_PIX_FMT_H263:
- case V4L2_PIX_FMT_MPEG4:
- i->parser.func = parse_mpeg4_stream;
- break;
- case V4L2_PIX_FMT_H264:
- i->parser.func = parse_h264_stream;
- break;
- case V4L2_PIX_FMT_MPEG1:
- case V4L2_PIX_FMT_MPEG2:
- i->parser.func = parse_mpeg2_stream;
- break;
- }
-
return 0;
}
diff --git a/common.h b/common.h
index 9265035..870058c 100644
--- a/common.h
+++ b/common.h
@@ -27,10 +27,6 @@
#include <stdio.h>
#include <semaphore.h>
-#include "parser.h"
-#include "queue.h"
-#include "drm-funcs.h"
-
/* When ADD_DETAILS is defined every debug and error message contains
* information about the file, function and line of code where it has
* been called */
@@ -128,20 +124,6 @@ struct video {
unsigned long total_captured;
};
-/* Parser related parameters */
-struct parser {
- struct mfc_parser_context ctx;
- unsigned long codec;
- /* Callback function to the real parsing function.
- * Dependent on the codec used. */
- int (*func)(struct mfc_parser_context *ctx,
- char* in, int in_size, char* out, int out_size,
- int *consumed, int *frame_size, char get_head);
- /* Set when the parser has finished and end of file has
- * been reached */
- int finished;
-};
-
struct instance {
int width;
int height;
@@ -156,18 +138,15 @@ struct instance {
/* video decoder related parameters */
struct video video;
- /* Parser related parameters */
- struct parser parser;
+ /* Codec to be used for encoding */
+ unsigned long codec;
pthread_mutex_t lock;
- struct queue queue;
/* Control */
int error; /* The error flag */
int finish; /* Flag set when decoding has been completed and all
threads finish */
-
- struct drm_buffer disp_buf[MAX_CAP_BUF];
};
#endif /* INCLUDE_COMMON_H */
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);
diff --git a/video.c b/video.c
index e99ba66..4b40ebd 100644
--- a/video.c
+++ b/video.c
@@ -188,50 +188,6 @@ int video_queue_buf_cap(struct instance *i, int index)
CAP_PLANES);
}
-int video_queue_buf_cap_dmabuf(struct instance *i, int index,
- struct drm_buffer *b)
-{
- struct video *vid = &i->video;
- struct v4l2_buffer buf;
- struct v4l2_plane planes[2];
- int ret;
-
- if (index >= vid->cap_buf_cnt) {
- err("Tried to queue a non exisiting buffer");
- return -1;
- }
-
- memzero(buf);
- memset(planes, 0, sizeof(planes));
- buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
- buf.memory = V4L2_MEMORY_DMABUF;
- buf.index = index;
- buf.length = CAP_PLANES;
- buf.m.planes = planes;
-
- buf.m.planes[0].m.fd = b->dbuf_fd;
-
- buf.m.planes[0].bytesused = vid->cap_buf_size[0];
- buf.m.planes[1].bytesused = vid->cap_buf_size[1];
-
- buf.m.planes[0].data_offset = 0;
- buf.m.planes[1].data_offset = 0;
-
- buf.m.planes[0].length = vid->cap_buf_size[0];
-
- ret = ioctl(vid->fd, VIDIOC_QBUF, &buf);
- if (ret) {
- err("Failed to queue buffer (index=%d) on CAPTURE (%s)",
- buf.index, strerror(errno));
- return -1;
- }
-
- dbg(" Queued buffer on %s queue with index %d",
- dbg_type[1], buf.index);
-
- return 0;
-}
-
static int video_dequeue_buf(struct instance *i, struct v4l2_buffer *buf)
{
struct video *vid = &i->video;
@@ -350,15 +306,6 @@ int video_stop(struct instance *i)
struct v4l2_decoder_cmd dec;
int ret;
-#if 0
- memzero(dec);
- dec.cmd = V4L2_DEC_CMD_STOP;
- ret = ioctl(vid->fd, VIDIOC_DECODER_CMD, &dec);
- if (ret < 0) {
- err("DECODER_CMD failed (%s)", strerror(errno));
- return -1;
- }
-#endif
ret = video_stream(i, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
VIDIOC_STREAMOFF);
if (ret < 0)
@@ -616,4 +563,3 @@ int video_setup_output(struct instance *i, unsigned long codec,
return 0;
}
-
diff --git a/video.h b/video.h
index 15033a1..84f38dc 100644
--- a/video.h
+++ b/video.h
@@ -49,8 +49,6 @@ int video_queue_buf_out(struct instance *i, int n, int length);
/* Queue CAPTURE buffer */
int video_queue_buf_cap(struct instance *i, int n);
-int video_queue_buf_cap_dmabuf(struct instance *i, int index,
- struct drm_buffer *b);
/* Control MFC streaming */
int video_stream(struct instance *i, enum v4l2_buf_type type, int status);