Allocate avio_buffer for each avio_alloc_context() and free AVIOContext.buffer after use. Fixes #3.

pull/8/head
klaxa 5 years ago
parent 3bbedc7a78
commit 00434627fd

@ -111,7 +111,6 @@ void publisher_add_client(struct PublisherContext *pub, AVFormatContext *ofmt_ct
case RESERVED:
printf("Put new client at %d, ofmt_ctx: %p pb: %p\n", i, ofmt_ctx, ofmt_ctx->pb);
pub->subscribers[i].ofmt_ctx = ofmt_ctx;
pub->subscribers[i].avio_buffer = (unsigned char*) av_malloc(AV_BUFSIZE);
buffer_set_state(pub->subscribers[i].buffer, WRITABLE);
client_set_state(&pub->subscribers[i], WRITABLE);
for (j = 0; j < BUFFER_SEGMENTS; j++) {

@ -10,7 +10,6 @@
struct Client {
struct AVFormatContext *ofmt_ctx;
struct Buffer *buffer;
unsigned char *avio_buffer;
enum State state;
pthread_mutex_t state_lock;
int id;

@ -182,17 +182,20 @@ void write_segment(struct Client *c)
return;
}
avio_ctx = avio_alloc_context(c->avio_buffer, AV_BUFSIZE, 0, &info, &segment_read, NULL, NULL);
unsigned char *avio_buffer = (unsigned char*) av_malloc(AV_BUFSIZE);
avio_ctx = avio_alloc_context(avio_buffer, AV_BUFSIZE, 0, &info, &segment_read, NULL, NULL);
fmt_ctx->pb = avio_ctx;
ret = avformat_open_input(&fmt_ctx, NULL, seg->ifmt, NULL);
if (ret < 0) {
fprintf(stderr, "Could not open input\n");
av_free(avio_ctx->buffer);
return;
}
ret = avformat_find_stream_info(fmt_ctx, NULL);
if (ret < 0) {
fprintf(stderr, "Could not find stream information\n");
av_free(avio_ctx->buffer);
return;
}
@ -211,12 +214,14 @@ void write_segment(struct Client *c)
if (ret < 0) {
printf("write_frame to client failed, disconnecting...\n");
avformat_close_input(&fmt_ctx);
av_free(avio_ctx->buffer);
client_disconnect(c);
return;
}
//printf("wrote frame to client\n");
}
avformat_close_input(&fmt_ctx);
av_free(avio_ctx->buffer);
avformat_free_context(fmt_ctx);
avio_context_free(&avio_ctx);
buffer_drop_segment(c->buffer);
@ -468,7 +473,6 @@ int main(int argc, char *argv[])
pthread_join(w_threads[i], NULL);
}
avformat_close_input(&ifmt_ctx);
publisher_free(pub);
free(pub->buffer);
free(pub->fs_buffer);

Loading…
Cancel
Save