Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

WIP on memory leak fix

  • Loading branch information...
commit 130306dcc488bf24b6e29ea7f2f3f2e8b0de6d74 1 parent 0579d11
@srstrong srstrong authored
View
98 c_src/async_parallel_filter.c
@@ -119,44 +119,27 @@ typedef struct _thread_struct_t
typedef struct _codec_t
{
AVClass *av_class;
- int pass_through;
thread_struct *threads;
} codec_t;
static void process(ID3ASFilterContext *context, AVFrame *frame, AVRational timebase)
{
- /*
- for (int i = 0; i < context->num_downstream_filters; i++)
- {
- AVFrame *foo = av_frame_clone(frame);
- context->downstream_filters[i]->filter->execute(context->downstream_filters[i], foo, timebase);
- av_frame_free(&foo);
- }
- return;
- */
-
codec_t *this = context->priv_data;
- if (this->pass_through) {
- send_to_graph(context, frame, timebase);
+ for (int i = 0; i < context->num_downstream_filters; i++) {
+
+ frame_entry_t *frame_entry = (frame_entry_t *) malloc(sizeof(frame_entry_t));
+ frame_entry->timebase = timebase;
+ frame_entry->frame = av_frame_clone(frame);
+ frame_entry->exit_thread = 0;
+
+ ADD_TO_QUEUE(context, this->threads[i].inbound_frame_queue, frame_entry);
}
- else {
-
+
+ if (sync_mode) {
for (int i = 0; i < context->num_downstream_filters; i++) {
-
- frame_entry_t *frame_entry = (frame_entry_t *) malloc(sizeof(frame_entry_t));
- frame_entry->timebase = timebase;
- frame_entry->frame = av_frame_clone(frame);
- frame_entry->exit_thread = 0;
-
- ADD_TO_QUEUE(context, this->threads[i].inbound_frame_queue, frame_entry);
- }
-
- if (sync_mode) {
- for (int i = 0; i < context->num_downstream_filters; i++) {
- pthread_cond_wait(&this->threads[i].complete, &this->threads[i].complete_mutex);
- }
+ pthread_cond_wait(&this->threads[i].complete, &this->threads[i].complete_mutex);
}
}
}
@@ -165,21 +148,16 @@ static void flush(ID3ASFilterContext *context)
{
codec_t *this = context->priv_data;
- if (this->pass_through) {
- flush_graph(context);
- }
- else {
- for (int i = 0; i < context->num_downstream_filters; i++) {
-
- frame_entry_t *frame_entry = (frame_entry_t *) malloc(sizeof(frame_entry_t));
- frame_entry->exit_thread = 1;
-
- ADD_TO_QUEUE(context, this->threads[i].inbound_frame_queue, frame_entry);
- }
+ for (int i = 0; i < context->num_downstream_filters; i++) {
- for (int i = 0; i < context->num_downstream_filters; i++) {
- pthread_join(this->threads[i].thread, NULL);
- }
+ frame_entry_t *frame_entry = (frame_entry_t *) malloc(sizeof(frame_entry_t));
+ frame_entry->exit_thread = 1;
+
+ ADD_TO_QUEUE(context, this->threads[i].inbound_frame_queue, frame_entry);
+ }
+
+ for (int i = 0; i < context->num_downstream_filters; i++) {
+ pthread_join(this->threads[i].thread, NULL);
}
}
@@ -228,28 +206,22 @@ static void init(ID3ASFilterContext *context, AVDictionary *codec_options)
{
codec_t *this = context->priv_data;
- if (context->num_downstream_filters < 2) {
- this->pass_through = 1;
- }
- else {
- this->pass_through = 0;
- this->threads = (thread_struct *) malloc(sizeof(thread_struct) * context->num_downstream_filters);
+ this->threads = (thread_struct *) malloc(sizeof(thread_struct) * context->num_downstream_filters);
- for (int i = 0; i < context->num_downstream_filters; i++)
- {
- this->threads[i].thread_id = thread_id++;
- this->threads[i].context = context;
- this->threads[i].downstream_filter = context->downstream_filters[i];
- this->threads[i].codec_t = this;
- pthread_cond_init(&this->threads[i].complete, NULL);
- pthread_mutex_init(&this->threads[i].complete_mutex, NULL);
- pthread_mutex_lock(&this->threads[i].complete_mutex);
-
- INIT_QUEUE(this->threads[i].inbound_frame_queue);
-
- pthread_create(&this->threads[i].thread, NULL, &thread_proc, &this->threads[i]);
- }
- }
+ for (int i = 0; i < context->num_downstream_filters; i++)
+ {
+ this->threads[i].thread_id = thread_id++;
+ this->threads[i].context = context;
+ this->threads[i].downstream_filter = context->downstream_filters[i];
+ this->threads[i].codec_t = this;
+ pthread_cond_init(&this->threads[i].complete, NULL);
+ pthread_mutex_init(&this->threads[i].complete_mutex, NULL);
+ pthread_mutex_lock(&this->threads[i].complete_mutex);
+
+ INIT_QUEUE(this->threads[i].inbound_frame_queue);
+
+ pthread_create(&this->threads[i].thread, NULL, &thread_proc, &this->threads[i]);
+ }
}
static const AVOption options[] = {
View
1  c_src/effects_processor.c
@@ -40,7 +40,6 @@ static void process(ID3ASFilterContext *context, AVFrame *frame, AVRational time
ERROR("Error from get_frame");
exit(-1);
}
-
send_to_graph(context, this->output_frame, this->output_timebase);
av_frame_unref(this->output_frame);
View
3  c_src/video_encoded_input.c
@@ -20,7 +20,6 @@ typedef struct _codec_t
static int decode(ID3ASFilterContext *context, AVPacket *pkt)
{
-
codec_t *this = context->priv_data;
int got_frame = 0;
int len = avcodec_decode_video2(this->context, this->frame, &got_frame, pkt);
@@ -33,6 +32,8 @@ static int decode(ID3ASFilterContext *context, AVPacket *pkt)
}
else if (got_frame)
{
+ av_frame_make_writable(this->frame);
+
add_frame_info_to_frame(this->frame_info_queue, this->frame);
this->frame->pts = this->frame->pkt_pts;
View
22 c_src/video_raw_generator.c
@@ -22,7 +22,7 @@ typedef struct _codec_t
static int read_exact(int fd, unsigned char *buf, int len)
{
int i, got = 0;
-
+
do {
if ((i = read(fd, buf + got, len - got)) <= 0)
{
@@ -43,15 +43,22 @@ static void process(ID3ASFilterContext *context,
{
codec_t *this = context->priv_data;
+ this->frame->format = this->pixfmt;
+ this->frame->width = this->width;
+ this->frame->height = this->height;
+ this->frame->interlaced_frame = this->interlaced ? 1 : 0;
+
+ av_frame_get_buffer(this->frame, 32);
+
read_exact(this->device_fd, this->data, this->data_size);
avpicture_fill((AVPicture *) this->frame, this->data, this->pixfmt, this->width, this->height);
set_frame_metadata(this->frame, metadata);
-
- TRACE("GOT FRAME!");
-
+
send_to_graph(context, this->frame, NINETY_KHZ);
+
+ av_frame_unref(this->frame);
}
static void flush(ID3ASFilterContext *context)
@@ -64,14 +71,9 @@ static void init(ID3ASFilterContext *context, AVDictionary *codec_options)
codec_t *this = context->priv_data;
this->frame = av_frame_alloc();
- this->frame->format = this->pixfmt;
- this->frame->width = this->width;
- this->frame->height = this->height;
- this->frame->interlaced_frame = this->interlaced ? 1 : 0;
-
this->data_size = avpicture_fill((AVPicture *) this->frame, NULL, this->pixfmt, this->width, this->height);
this->data = malloc(this->data_size);
-
+
this->device_fd = open(this->device_name, O_RDONLY);
}
Please sign in to comment.
Something went wrong with that request. Please try again.