Skip to content

Commit

Permalink
Remove realloc, using ngx_pcalloc from now (fixes #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioribeiro committed May 15, 2013
1 parent 6f2f11e commit eda370d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ngx_http_aac_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ static ngx_int_t ngx_http_aac_handler(ngx_http_request_t *r) {
destination = ngx_pcalloc(r->pool, sizeof(audio_buffer));
destination->data = NULL;
destination->len = 0;
destination->pool = r->pool;

conf = ngx_http_get_module_loc_conf(r, ngx_http_aac_module);
ngx_http_complex_value(r, conf->videosegments_rootpath, &rootpath);
Expand Down Expand Up @@ -223,11 +224,12 @@ static int write_packet(void *opaque, unsigned char *buf, int buf_size) {
int old_size;
audio_buffer *destination = (audio_buffer *)opaque;

if (destination->data == NULL) {
destination->data = ngx_pcalloc(destination->pool, NGX_AAC_AUDIO_CHUNK_MAX_SIZE * sizeof(unsigned char));
}

old_size = destination->len;
destination->len += buf_size;

/* TODO improve realloc */
destination->data = av_realloc(destination->data, destination->len * sizeof(unsigned char));
memcpy(destination->data + old_size, buf, buf_size * sizeof(unsigned char));

return buf_size;
Expand Down
2 changes: 2 additions & 0 deletions ngx_http_aac_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#define NGX_HTTP_AAC_MODULE_VIDEO_SEGMENT_NOT_FOUND 3
#define NGX_HTTP_AAC_MODULE_AUDIO_STREAM_NOT_FOUND 4
#define NGX_HTTP_AAC_MODULE_NO_DECODER 5
#define NGX_AAC_AUDIO_CHUNK_MAX_SIZE 96100

typedef struct {
unsigned char *data;
int len;
ngx_pool_t *pool;
} audio_buffer;


Expand Down

0 comments on commit eda370d

Please sign in to comment.