Coverage Report

Created: 2025-12-03 07:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aom/av1/common/frame_buffers.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
12
#include <assert.h>
13
14
#include "av1/common/frame_buffers.h"
15
#include "aom_mem/aom_mem.h"
16
17
34.8k
int av1_alloc_internal_frame_buffers(InternalFrameBufferList *list) {
18
34.8k
  assert(list != NULL);
19
34.8k
  av1_free_internal_frame_buffers(list);
20
21
34.8k
  list->num_internal_frame_buffers =
22
34.8k
      AOM_MAXIMUM_REF_BUFFERS + AOM_MAXIMUM_WORK_BUFFERS;
23
34.8k
  list->int_fb = (InternalFrameBuffer *)aom_calloc(
24
34.8k
      list->num_internal_frame_buffers, sizeof(*list->int_fb));
25
34.8k
  if (list->int_fb == NULL) {
26
0
    list->num_internal_frame_buffers = 0;
27
0
    return 1;
28
0
  }
29
34.8k
  return 0;
30
34.8k
}
31
32
69.6k
void av1_free_internal_frame_buffers(InternalFrameBufferList *list) {
33
69.6k
  int i;
34
35
69.6k
  assert(list != NULL);
36
37
627k
  for (i = 0; i < list->num_internal_frame_buffers; ++i) {
38
557k
    aom_free(list->int_fb[i].data);
39
557k
    list->int_fb[i].data = NULL;
40
557k
  }
41
69.6k
  aom_free(list->int_fb);
42
69.6k
  list->int_fb = NULL;
43
69.6k
  list->num_internal_frame_buffers = 0;
44
69.6k
}
45
46
7.05k
void av1_zero_unused_internal_frame_buffers(InternalFrameBufferList *list) {
47
7.05k
  int i;
48
49
7.05k
  assert(list != NULL);
50
51
119k
  for (i = 0; i < list->num_internal_frame_buffers; ++i) {
52
112k
    if (list->int_fb[i].data && !list->int_fb[i].in_use)
53
9.14k
      memset(list->int_fb[i].data, 0, list->int_fb[i].size);
54
112k
  }
55
7.05k
}
56
57
int av1_get_frame_buffer(void *cb_priv, size_t min_size,
58
73.5k
                         aom_codec_frame_buffer_t *fb) {
59
73.5k
  int i;
60
73.5k
  InternalFrameBufferList *const int_fb_list =
61
73.5k
      (InternalFrameBufferList *)cb_priv;
62
73.5k
  if (int_fb_list == NULL) return -1;
63
64
  // Find a free frame buffer.
65
155k
  for (i = 0; i < int_fb_list->num_internal_frame_buffers; ++i) {
66
155k
    if (!int_fb_list->int_fb[i].in_use) break;
67
155k
  }
68
69
73.5k
  if (i == int_fb_list->num_internal_frame_buffers) return -1;
70
71
73.5k
  if (int_fb_list->int_fb[i].size < min_size) {
72
53.7k
    aom_free(int_fb_list->int_fb[i].data);
73
    // The data must be zeroed to fix a valgrind error from the C loop filter
74
    // due to access uninitialized memory in frame border. It could be
75
    // skipped if border were totally removed.
76
53.7k
    int_fb_list->int_fb[i].data = (uint8_t *)aom_calloc(1, min_size);
77
53.7k
    if (!int_fb_list->int_fb[i].data) {
78
0
      int_fb_list->int_fb[i].size = 0;
79
0
      return -1;
80
0
    }
81
53.7k
    int_fb_list->int_fb[i].size = min_size;
82
53.7k
  }
83
84
73.5k
  fb->data = int_fb_list->int_fb[i].data;
85
73.5k
  fb->size = int_fb_list->int_fb[i].size;
86
73.5k
  int_fb_list->int_fb[i].in_use = 1;
87
88
  // Set the frame buffer's private data to point at the internal frame buffer.
89
73.5k
  fb->priv = &int_fb_list->int_fb[i];
90
73.5k
  return 0;
91
73.5k
}
92
93
73.5k
int av1_release_frame_buffer(void *cb_priv, aom_codec_frame_buffer_t *fb) {
94
73.5k
  InternalFrameBuffer *const int_fb = (InternalFrameBuffer *)fb->priv;
95
73.5k
  (void)cb_priv;
96
73.5k
  if (int_fb) int_fb->in_use = 0;
97
73.5k
  return 0;
98
73.5k
}