Coverage Report

Created: 2025-12-12 07:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvpx/vp9/common/vp9_frame_buffers.c
Line
Count
Source
1
/*
2
 *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
 *  that can be found in the LICENSE file in the root of the source
6
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
9
 */
10
11
#include <assert.h>
12
13
#include "vp9/common/vp9_frame_buffers.h"
14
#include "vpx_mem/vpx_mem.h"
15
16
16.7k
int vp9_alloc_internal_frame_buffers(InternalFrameBufferList *list) {
17
16.7k
  const int num_buffers = VP9_MAXIMUM_REF_BUFFERS + VPX_MAXIMUM_WORK_BUFFERS;
18
16.7k
  assert(list != NULL);
19
16.7k
  vp9_free_internal_frame_buffers(list);
20
21
16.7k
  list->int_fb =
22
16.7k
      (InternalFrameBuffer *)vpx_calloc(num_buffers, sizeof(*list->int_fb));
23
16.7k
  if (list->int_fb) {
24
16.7k
    list->num_internal_frame_buffers = num_buffers;
25
16.7k
    return 0;
26
16.7k
  }
27
0
  return -1;
28
16.7k
}
29
30
33.5k
void vp9_free_internal_frame_buffers(InternalFrameBufferList *list) {
31
33.5k
  int i;
32
33
33.5k
  assert(list != NULL);
34
35
301k
  for (i = 0; i < list->num_internal_frame_buffers; ++i) {
36
268k
    vpx_free(list->int_fb[i].data);
37
268k
    list->int_fb[i].data = NULL;
38
268k
  }
39
33.5k
  vpx_free(list->int_fb);
40
33.5k
  list->int_fb = NULL;
41
33.5k
  list->num_internal_frame_buffers = 0;
42
33.5k
}
43
44
int vp9_get_frame_buffer(void *cb_priv, size_t min_size,
45
199k
                         vpx_codec_frame_buffer_t *fb) {
46
199k
  int i;
47
199k
  InternalFrameBufferList *const int_fb_list =
48
199k
      (InternalFrameBufferList *)cb_priv;
49
199k
  if (int_fb_list == NULL) return -1;
50
51
  // Find a free frame buffer.
52
764k
  for (i = 0; i < int_fb_list->num_internal_frame_buffers; ++i) {
53
764k
    if (!int_fb_list->int_fb[i].in_use) break;
54
764k
  }
55
56
199k
  if (i == int_fb_list->num_internal_frame_buffers) return -1;
57
58
199k
  if (int_fb_list->int_fb[i].size < min_size) {
59
31.9k
    vpx_free(int_fb_list->int_fb[i].data);
60
    // The data must be zeroed to fix a valgrind error from the C loop filter
61
    // due to access uninitialized memory in frame border. It could be
62
    // skipped if border were totally removed.
63
31.9k
    int_fb_list->int_fb[i].data = (uint8_t *)vpx_calloc(1, min_size);
64
31.9k
    if (!int_fb_list->int_fb[i].data) return -1;
65
31.9k
    int_fb_list->int_fb[i].size = min_size;
66
31.9k
  }
67
68
199k
  fb->data = int_fb_list->int_fb[i].data;
69
199k
  fb->size = int_fb_list->int_fb[i].size;
70
199k
  int_fb_list->int_fb[i].in_use = 1;
71
72
  // Set the frame buffer's private data to point at the internal frame buffer.
73
199k
  fb->priv = &int_fb_list->int_fb[i];
74
199k
  return 0;
75
199k
}
76
77
202k
int vp9_release_frame_buffer(void *cb_priv, vpx_codec_frame_buffer_t *fb) {
78
202k
  InternalFrameBuffer *const int_fb = (InternalFrameBuffer *)fb->priv;
79
202k
  (void)cb_priv;
80
202k
  if (int_fb) int_fb->in_use = 0;
81
202k
  return 0;
82
202k
}