/** * \brief Free memory allocated to frame * \param pic picture pointer * \return 1 on success, 0 on failure */ int kvz_videoframe_free(videoframe_t * const frame) { kvz_image_free(frame->source); frame->source = NULL; kvz_image_free(frame->rec); frame->rec = NULL; kvz_cu_array_free(&frame->cu_array); FREE_POINTER(frame->sao_luma); FREE_POINTER(frame->sao_chroma); free(frame); return 1; }
static void tear_down_tests() { kvz_image_free(g_pic); kvz_image_free(g_ref); kvz_image_free(g_big_pic); kvz_image_free(g_big_ref); kvz_image_free(g_64x64_zero); kvz_image_free(g_64x64_max); }
/** * \brief Remove picture from picturelist * \param list list to use * \param n index to remove * \return 1 on success */ int kvz_image_list_rem(image_list_t * const list, const unsigned n) { // Must be within list boundaries if (n >= list->used_size) { return 0; } kvz_image_free(list->images[n]); if (!kvz_cu_array_free(list->cu_arrays[n])) { fprintf(stderr, "Could not free cu_array!\n"); assert(0); //Stop here return 0; } // The last item is easy to remove if (n == list->used_size - 1) { list->images[n] = NULL; list->cu_arrays[n] = NULL; list->pocs[n] = 0; list->used_size--; } else { int i = n; // Shift all following pics one backward in the list for (i = n; i < list->used_size - 1; ++i) { list->images[i] = list->images[i + 1]; list->cu_arrays[i] = list->cu_arrays[i + 1]; list->pocs[i] = list->pocs[i + 1]; } list->images[list->used_size - 1] = NULL; list->cu_arrays[list->used_size - 1] = NULL; list->pocs[list->used_size - 1] = 0; list->used_size--; } return 1; }
/** * \brief Free memory allocated to the picture_list * \param list image_list pointer * \return 1 on success, 0 on failure */ int kvz_image_list_destroy(image_list_t *list) { unsigned int i; if (list->used_size > 0) { for (i = 0; i < list->used_size; ++i) { kvz_image_free(list->images[i]); list->images[i] = NULL; kvz_cu_array_free(list->cu_arrays[i]); list->cu_arrays[i] = NULL; list->pocs[i] = 0; } } if (list->size > 0) { free(list->images); free(list->cu_arrays); free(list->pocs); } list->images = NULL; list->cu_arrays = NULL; list->pocs = NULL; free(list); return 1; }
/** * \brief Free an image. * * Decrement reference count of the image and deallocate associated memory * if no references exist any more. * * \param im image to free */ void kvz_image_free(kvz_picture *const im) { if (im == NULL) return; int32_t new_refcount = ATOMIC_DEC(&(im->refcount)); if (new_refcount > 0) { // There are still references so we don't free the data yet. return; } if (im->base_image != im) { // Free our reference to the base image. kvz_image_free(im->base_image); } else { free(im->fulldata); } // Make sure freed data won't be used. im->base_image = NULL; im->fulldata = NULL; im->y = im->u = im->v = NULL; im->data[COLOR_Y] = im->data[COLOR_U] = im->data[COLOR_V] = NULL; free(im); }
static int kvazaar_field_encoding_adapter(kvz_encoder *enc, kvz_picture *pic_in, kvz_data_chunk **data_out, uint32_t *len_out, kvz_picture **pic_out, kvz_picture **src_out, kvz_frame_info *info_out) { if (enc->control->cfg->source_scan_type == KVZ_INTERLACING_NONE) { // For progressive, simply call the normal encoding function. return kvazaar_encode(enc, pic_in, data_out, len_out, pic_out, src_out, info_out); } // For interlaced, make two fields out of the input frame and call encode on them separately. encoder_state_t *state = &enc->states[enc->cur_state_num]; kvz_picture *first_field = NULL, *second_field = NULL; struct { kvz_data_chunk* data_out; uint32_t len_out; } first = { 0 }, second = { 0 }; if (pic_in != NULL) { first_field = kvz_image_alloc(state->encoder_control->in.width, state->encoder_control->in.height); if (first_field == NULL) { goto kvazaar_field_encoding_adapter_failure; } second_field = kvz_image_alloc(state->encoder_control->in.width, state->encoder_control->in.height); if (second_field == NULL) { goto kvazaar_field_encoding_adapter_failure; } yuv_io_extract_field(pic_in, pic_in->interlacing, 0, first_field); yuv_io_extract_field(pic_in, pic_in->interlacing, 1, second_field); first_field->pts = pic_in->pts; first_field->dts = pic_in->dts; first_field->interlacing = pic_in->interlacing; // Should the second field have higher pts and dts? It shouldn't affect anything. second_field->pts = pic_in->pts; second_field->dts = pic_in->dts; second_field->interlacing = pic_in->interlacing; } if (!kvazaar_encode(enc, first_field, &first.data_out, &first.len_out, pic_out, NULL, info_out)) { goto kvazaar_field_encoding_adapter_failure; } if (!kvazaar_encode(enc, second_field, &second.data_out, &second.len_out, NULL, NULL, NULL)) { goto kvazaar_field_encoding_adapter_failure; } kvz_image_free(first_field); kvz_image_free(second_field); // Concatenate bitstreams. if (len_out != NULL) { *len_out = first.len_out + second.len_out; } if (data_out != NULL) { *data_out = first.data_out; if (first.data_out != NULL) { kvz_data_chunk *chunk = first.data_out; while (chunk->next != NULL) { chunk = chunk->next; } chunk->next = second.data_out; } } if (src_out != NULL) { // TODO: deinterlace the fields to one picture. } return 1; kvazaar_field_encoding_adapter_failure: kvz_image_free(first_field); kvz_image_free(second_field); kvz_bitstream_free_chunks(first.data_out); kvz_bitstream_free_chunks(second.data_out); return 0; }