simp_avio_t* io;
scf_list_t* l;
+ int i;
int n = 0;
- for (l = scf_list_head(&f->inputs); l !=scf_list_sentinel(&f->inputs); l = scf_list_next(l))
- {
- io = scf_list_data(l, simp_avio_t, list);
+ for (i = 0; i < f->inputs->size; i++) {
+ io = f->inputs->data[i];
if (io->width > 0 && io->height > 0 && io->vopen) {
return -ENOMEM;
f->vframe = av_frame_alloc();
- if (!f->vframe) {
- free(f);
- return -ENOMEM;
- }
+ if (!f->vframe)
+ goto vframe_error;
f->aframe = av_frame_alloc();
- if (!f->aframe) {
- av_frame_free(&f->vframe);
- free(f);
- return -ENOMEM;
- }
+ if (!f->aframe)
+ goto aframe_error;
- scf_list_init(&f->inputs);
- scf_list_init(&f->outputs);
+ f->inputs = scf_vector_alloc();
+ if (!f->inputs)
+ goto inputs_error;
+
+ f->outputs = scf_vector_alloc();
+ if (!f->outputs)
+ goto outputs_error;
pthread_mutex_init(&f->mutex, NULL);
pthread_cond_init (&f->cond, NULL);
*pf = f;
return 0;
+
+outputs_error:
+ scf_vector_free(f->inputs);
+inputs_error:
+ av_frame_free(&f->aframe);
+aframe_error:
+ av_frame_free(&f->vframe);
+vframe_error:
+ free(f);
+ return -ENOMEM;
}
int simp_filter_close(simp_filter_t* f, int flush)
av_frame_free(&f->vframe);
av_frame_free(&f->aframe);
- for (l = scf_list_head(&f->inputs); l != scf_list_sentinel(&f->inputs); ) {
- io = scf_list_data(l, simp_avio_t, list);
- l = scf_list_next(l);
-
- scf_list_del(&io->list);
+ int i;
+ for (i = 0; i < f->inputs->size; i++) {
+ io = f->inputs->data[i];
io->abuffersrc_ctx = NULL;
io->vbuffersrc_ctx = NULL;
if (flush)
io->flush = 1;
- simp_avio_close(io);
- io = NULL;
+ if (0 == --io->refs)
+ simp_avio_close(io);
+
+ f->inputs->data[i] = NULL;
}
- for (l = scf_list_head(&f->outputs); l != scf_list_sentinel(&f->outputs); ) {
- io = scf_list_data(l, simp_avio_t, list);
- l = scf_list_next(l);
+ for (i = 0; i < f->outputs->size; i++) {
+ io = f->outputs->data[i];
if (flush)
io->flush = 1;
- scf_list_del(&io->list);
- simp_avio_close(io);
- io = NULL;
+ if (0 == --io->refs)
+ simp_avio_close(io);
+
+ f->outputs->data[i] = NULL;
}
+ scf_vector_free(f->inputs);
+ scf_vector_free(f->outputs);
return 0;
}
}
int flushed = 0;
+ int i;
while (!f->exit) {
usleep(100);
- for (l = scf_list_head(&f->inputs); l != scf_list_sentinel(&f->inputs); l = scf_list_next(l)) {
- io = scf_list_data(l, simp_avio_t, list);
+ for (i = 0; i < f->inputs->size; i++) {
+ io = f->inputs->data[i];
if (io->start_time == 0)
io->start_time = gettime();
f->error = ret;
goto error;
}
-#if 1
+#if 0
static int fd = -1;
if (-1 == fd)
fd = open("1.yuv", O_RDWR | O_CREAT | O_TRUNC, 0666);
write(fd, f->vframe->data[2] + i * f->vframe->linesize[2], f->vframe->width / 2);
}
#endif
- for (l = scf_list_head(&f->outputs); l != scf_list_sentinel(&f->outputs); l = scf_list_next(l)) {
- io = scf_list_data(l, simp_avio_t, list);
+ for (i = 0; i < f->outputs->size; i++) {
+ io = f->outputs->data[i];
if (io->vopen) {
vf = calloc(1, sizeof(simp_frame_t));
goto error;
}
- for (l = scf_list_head(&f->outputs); l != scf_list_sentinel(&f->outputs); l = scf_list_next(l)) {
- io = scf_list_data(l, simp_avio_t, list);
+ for (i = 0; i < f->outputs->size; i++) {
+ io = f->outputs->data[i];
if (io->aopen) {
af = calloc(1, sizeof(simp_frame_t));
int simp_filter_add_input(simp_filter_t* f, simp_avio_t* input)
{
if (f && input) {
- scf_list_add_tail(&f->inputs, &input->list);
+
+ int ret = scf_vector_add(f->inputs, input);
+ if (ret < 0)
+ return ret;
+
+ input->refs++;
return 0;
}
int simp_filter_add_output(simp_filter_t* f, simp_avio_t* output)
{
if (f && output) {
- scf_list_add_tail(&f->outputs, &output->list);
+
+ int ret = scf_vector_add(f->outputs, output);
+ if (ret < 0)
+ return ret;
+
+ output->refs++;
return 0;
}