Remove malloc in chiaki_frame_processor_fec()

This commit is contained in:
Florian Märkl 2019-07-30 22:27:08 +02:00
commit 09a0a0946e
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
3 changed files with 15 additions and 16 deletions

View file

@ -48,7 +48,8 @@ typedef struct chiaki_frame_processor_t
typedef enum chiaki_frame_flush_result_t {
CHIAKI_FRAME_PROCESSOR_FLUSH_RESULT_SUCCESS = 0,
CHIAKI_FRAME_PROCESSOR_FLUSH_RESULT_FEC_SUCCESS = 1,
CHIAKI_FRAME_PROCESSOR_FLUSH_RESULT_FAILED = 2
CHIAKI_FRAME_PROCESSOR_FLUSH_RESULT_FEC_FAILED = 2,
CHIAKI_FRAME_PROCESSOR_FLUSH_RESULT_FAILED = 3
} ChiakiFrameProcessorFlushResult;
CHIAKI_EXPORT void chiaki_frame_processor_init(ChiakiFrameProcessor *frame_processor, ChiakiLog *log);
@ -56,6 +57,11 @@ CHIAKI_EXPORT void chiaki_frame_processor_fini(ChiakiFrameProcessor *frame_proce
CHIAKI_EXPORT ChiakiErrorCode chiaki_frame_processor_alloc_frame(ChiakiFrameProcessor *frame_processor, ChiakiTakionAVPacket *packet);
CHIAKI_EXPORT ChiakiErrorCode chiaki_frame_processor_put_unit(ChiakiFrameProcessor *frame_processor, ChiakiTakionAVPacket *packet);
/**
* @param frame unless CHIAKI_FRAME_PROCESSOR_FLUSH_RESULT_FAILED returned, will receive a pointer into the internal buffer of frame_processor.
* MUST NOT be used after the next call to this frame processor!
*/
CHIAKI_EXPORT ChiakiFrameProcessorFlushResult chiaki_frame_processor_flush(ChiakiFrameProcessor *frame_processor, uint8_t **frame, size_t *frame_size);
static inline bool chiaki_frame_processor_flush_possible(ChiakiFrameProcessor *frame_processor)

View file

@ -18,10 +18,11 @@
#include <chiaki/frameprocessor.h>
#include <chiaki/fec.h>
#include <jerasure.h>
#include <string.h>
#include <assert.h>
#define UNIT_SLOTS_MAX 256
@ -169,9 +170,6 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_frame_processor_put_unit(ChiakiFrameProcess
return CHIAKI_ERR_SUCCESS;
}
#include <jerasure.h>
static ChiakiErrorCode chiaki_frame_processor_fec(ChiakiFrameProcessor *frame_processor)
{
CHIAKI_LOGI(frame_processor->log, "Frame Processor received %u+%u / %u+%u units, attempting FEC",
@ -252,11 +250,7 @@ CHIAKI_EXPORT ChiakiFrameProcessorFlushResult chiaki_frame_processor_flush(Chiak
result = CHIAKI_FRAME_PROCESSOR_FLUSH_RESULT_FEC_SUCCESS;
}
uint8_t *buf = malloc(frame_processor->frame_buf_size); // TODO: this should come from outside instead of mallocing all the time
if(!buf)
return CHIAKI_FRAME_PROCESSOR_FLUSH_RESULT_FAILED;
size_t buf_size = 0;
size_t cur = 0;
for(size_t i=0; i<frame_processor->units_source_expected; i++)
{
ChiakiFrameUnit *unit = frame_processor->unit_slots + i;
@ -268,12 +262,11 @@ CHIAKI_EXPORT ChiakiFrameProcessorFlushResult chiaki_frame_processor_flush(Chiak
}
size_t part_size = unit->data_size - 2;
uint8_t *buf_ptr = frame_processor->frame_buf + i*frame_processor->buf_size_per_unit;
//CHIAKI_LOGD(frame_processor->log, "unit size: %#zx, in buf: %#x", unit->data_size, frame_processor->buf_size_per_unit - (unsigned int)ntohs(*((uint16_t *)buf_ptr)));
memcpy(buf + buf_size, buf_ptr + 2, part_size);
buf_size += part_size;
memmove(frame_processor->frame_buf + cur, buf_ptr + 2, part_size);
cur += part_size;
}
*frame = buf;
*frame_size = buf_size;
*frame = frame_processor->frame_buf;
*frame_size = cur;
return result;
}

View file

@ -138,7 +138,7 @@ static ChiakiErrorCode chiaki_video_receiver_flush_frame(ChiakiVideoReceiver *vi
if(video_receiver->session->video_sample_cb)
video_receiver->session->video_sample_cb(frame, frame_size, video_receiver->session->video_sample_cb_user);
free(frame);
video_receiver->frame_index_prev = video_receiver->frame_index_cur;
return CHIAKI_ERR_SUCCESS;
}