aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/main.c b/main.c
index 87bb900..44a0f9b 100644
--- a/main.c
+++ b/main.c
@@ -126,10 +126,7 @@ int save_encoded(struct instance *i, const void *buf, unsigned int size)
if (!i->save_encoded)
return 0;
- if (!i->save_path)
- ret = sprintf(filename, "/mnt/sdcard/encoded.%s", ext);
- else
- ret = sprintf(filename, "%s/encoded.%s", i->save_path, ext);
+ ret = sprintf(filename, "%s/encoded.%s", i->save_path, ext);
if (ret < 0) {
err("sprintf fail (%s)", strerror(errno));
return -1;
@@ -138,14 +135,14 @@ int save_encoded(struct instance *i, const void *buf, unsigned int size)
if (out->fd)
goto write;
- dbg("create file %s", filename);
-
out->fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC, mode);
if (out->fd < 0) {
err("cannot open file (%s)", strerror(errno));
return -1;
}
+ info("created file %s", filename);
+
write:
written = pwrite(out->fd, buf, size, out->offs);
if (written < 0) {
@@ -155,13 +152,13 @@ write:
out->offs += written;
- dbg("written %zd bytes at offset: %zu", written, out->offs);
+ dbg("written %zd bytes at offset %zu", written, out->offs);
return 0;
}
static int input_read(struct instance *inst, unsigned int index,
- unsigned int *used, unsigned int *fs)
+ unsigned int *used, unsigned int *fs)
{
struct video *vid = &inst->video;
unsigned char *to = vid->out_buf_addr[index];
@@ -169,6 +166,9 @@ static int input_read(struct instance *inst, unsigned int index,
*used = vid->out_buf_size;
*fs = vid->out_buf_size;
+ if (inst->disable_gentest)
+ return 0;
+
gentest_fill(inst->width, inst->height, to, vid->out_buf_size);
return 0;
@@ -210,6 +210,10 @@ void *input_thread_func(void *args)
pthread_mutex_unlock(&i->lock);
dbg("queued output buffer %d", n);
+ } else {
+ pthread_mutex_lock(&i->lock);
+ pthread_cond_wait(&i->cond, &i->lock);
+ pthread_mutex_unlock(&i->lock);
}
}
@@ -264,7 +268,8 @@ void *main_thread_func(void *args)
vid->cap_buf_flag[n] = 0;
pthread_mutex_unlock(&i->lock);
- info("encoded frame %ld", vid->total_encoded);
+ if (i->verbose)
+ info("encoded frame %ld", vid->total_encoded);
if (finished)
break;
@@ -297,6 +302,7 @@ next_event:
pthread_mutex_lock(&i->lock);
vid->out_buf_flag[n] = 0;
pthread_mutex_unlock(&i->lock);
+ pthread_cond_signal(&i->cond);
}
dbg("dequeued output buffer %d", n);
@@ -323,6 +329,9 @@ int main(int argc, char **argv)
pthread_mutex_init(&inst.lock, 0);
+ pthread_condattr_init(&inst.attr);
+ pthread_cond_init(&inst.cond, &inst.attr);
+
vid->total_encoded = 0;
ret = video_open(&inst, inst.video.name);
@@ -406,6 +415,8 @@ int main(int argc, char **argv)
return 0;
err:
pthread_mutex_destroy(&inst.lock);
+ pthread_cond_destroy(&inst.cond);
+ pthread_condattr_destroy(&inst.attr);
cleanup(&inst);
gentest_deinit();
return 1;