Add OutOfMemory log helper
Add a special LOG_OOM() function to log all OutOfMemory errors (i.e. allocations returning NULL).
This commit is contained in:
@@ -34,11 +34,13 @@ static struct record_packet *
|
||||
record_packet_new(const AVPacket *packet) {
|
||||
struct record_packet *rec = malloc(sizeof(*rec));
|
||||
if (!rec) {
|
||||
LOG_OOM();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rec->packet = av_packet_alloc();
|
||||
if (!rec->packet) {
|
||||
LOG_OOM();
|
||||
free(rec);
|
||||
return NULL;
|
||||
}
|
||||
@@ -81,7 +83,7 @@ recorder_write_header(struct recorder *recorder, const AVPacket *packet) {
|
||||
|
||||
uint8_t *extradata = av_malloc(packet->size * sizeof(uint8_t));
|
||||
if (!extradata) {
|
||||
LOGC("Could not allocate extradata");
|
||||
LOG_OOM();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -228,13 +230,11 @@ static bool
|
||||
recorder_open(struct recorder *recorder, const AVCodec *input_codec) {
|
||||
bool ok = sc_mutex_init(&recorder->mutex);
|
||||
if (!ok) {
|
||||
LOGC("Could not create mutex");
|
||||
return false;
|
||||
}
|
||||
|
||||
ok = sc_cond_init(&recorder->queue_cond);
|
||||
if (!ok) {
|
||||
LOGC("Could not create cond");
|
||||
goto error_mutex_destroy;
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ recorder_open(struct recorder *recorder, const AVCodec *input_codec) {
|
||||
|
||||
recorder->ctx = avformat_alloc_context();
|
||||
if (!recorder->ctx) {
|
||||
LOGE("Could not allocate output context");
|
||||
LOG_OOM();
|
||||
goto error_cond_destroy;
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ recorder_push(struct recorder *recorder, const AVPacket *packet) {
|
||||
|
||||
struct record_packet *rec = record_packet_new(packet);
|
||||
if (!rec) {
|
||||
LOGC("Could not allocate record packet");
|
||||
LOG_OOM();
|
||||
sc_mutex_unlock(&recorder->mutex);
|
||||
return false;
|
||||
}
|
||||
@@ -375,7 +375,7 @@ recorder_init(struct recorder *recorder,
|
||||
struct sc_size declared_frame_size) {
|
||||
recorder->filename = strdup(filename);
|
||||
if (!recorder->filename) {
|
||||
LOGE("Could not strdup filename");
|
||||
LOG_OOM();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user