• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ossia / score / 32611180996

23 Aug 2026 01:46AM UTC coverage: 21.758% (+0.2%) from 21.606%
32611180996

Pull #2212

github

web-flow
Merge c941893f5 into 9bf315f7c
Pull Request #2212: test: make rendering testable from master

64 of 327 new or added lines in 26 files covered. (19.57%)

142 existing lines in 16 files now uncovered.

47692 of 219192 relevant lines covered (21.76%)

59072.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

13.86
/src/plugins/score-plugin-media/Video/FrameQueue.cpp
1
#include <Media/Libav.hpp>
2

3
#if SCORE_HAS_LIBAV
4
#include <Video/FrameQueue.hpp>
5
#include <Video/VideoInterface.hpp>
6

7
#include <ossia/detail/flat_set.hpp>
8
#if defined(SCORE_LIBAV_FRAME_DEBUGGING)
9
#include <score/tools/Debug.hpp>
10

11
#include <ossia/detail/algorithms.hpp>
12
#endif
13

14
extern "C" {
15
#include <libavcodec/avcodec.h>
16
}
17
namespace Video
18
{
19

20
#if defined(SCORE_LIBAV_FRAME_DEBUGGING)
21
void frame_counters::allocate(AVFrame* av)
22
{
23
  std::lock_guard lock{mtx};
24
  auto it = ossia::find_if(allocated, [av](const auto& x) { return x.frame == av; });
25
  SCORE_ASSERT(it == allocated.end());
26
  allocated.push_back({av, boost::stacktrace::stacktrace{}});
27
}
28

29
void frame_counters::deallocate(AVFrame* av)
30
{
31
  std::lock_guard lock{mtx};
32
  auto it = ossia::find_if(allocated, [av](const auto& x) { return x.frame == av; });
33
  if(it == allocated.end())
34
  {
35
    qDebug() << "deallocating unknown frame?";
36
    return;
37
  }
38
  allocated.erase(it);
39

40
  it = ossia::find_if(allocated, [av](const auto& x) { return x.frame == av; });
41
  SCORE_ASSERT(it == allocated.end());
42
}
43

44
#endif
45

46
uint8_t* initFrameBuffer(AVFrame& frame, std::size_t bytes)
×
47
{
48
  // Reuse the buffer a recycled frame still carries, but only when it is still
49
  // big enough: a mid-stream format change grows `bytes`, and the plane
50
  // pointers a caller wrote into data[] do not have to start at the buffer.
NEW
51
  if(frame.buf[0] && frame.buf[0]->size >= bytes)
×
52
  {
NEW
53
    frame.data[0] = frame.buf[0]->data;
×
NEW
54
    return frame.data[0];
×
55
  }
56

NEW
57
  if(frame.buf[0])
×
NEW
58
    av_buffer_unref(&frame.buf[0]);
×
59

NEW
60
  auto buf = av_buffer_alloc(bytes);
×
NEW
61
  if(!buf)
×
NEW
62
    return nullptr;
×
63

NEW
64
  frame.buf[0] = buf;
×
NEW
65
  frame.data[0] = buf->data;
×
NEW
66
  return buf->data;
×
UNCOV
67
}
×
68

69
FrameQueue::FrameQueue() { }
8 ✔
70

71
FrameQueue::~FrameQueue() { }
8 ✔
72

73
void FreeAVFrame::operator()(AVFrame* f) const noexcept
×
74
{
75
  SCORE_LIBAV_FRAME_DEALLOC_CHECK(f);
×
76
  av_frame_free(&f);
×
77
}
×
78
AVFramePointer FrameQueue::newFrame() noexcept
×
79
{
80
  // We were working on a frame in this thread (e.g. during a seek, when retrying with EAGAIN..)
81
  if(!m_decodeThreadFrameBuffer.empty())
×
82
  {
83
    auto f = m_decodeThreadFrameBuffer.back();
×
84
    m_decodeThreadFrameBuffer.pop_back();
×
85
    av_frame_unref(f);
×
86
    return AVFramePointer{f};
×
87
  }
88

89
  // Frames freed from the rendering thread
90
  {
91
    AVFrame* f{};
×
92
    if(released.try_dequeue(f))
×
93
    {
94
      av_frame_unref(f);
×
95
      return AVFramePointer{f};
×
96
    }
97
  }
98

99
  // We actually need to allocate :throw_up_emoji:
100
  auto new_frame = av_frame_alloc();
×
101
  new_frame->buf[0] = nullptr;
×
102
  new_frame->data[0] = nullptr;
×
103

104
  SCORE_LIBAV_FRAME_ALLOC_CHECK(new_frame);
×
105
  return AVFramePointer{new_frame};
×
106
}
×
107

108
void FrameQueue::enqueue_decoding_error(AVFrame* f)
×
109
{
110
  this->m_decodeThreadFrameBuffer.push_back(f);
×
111
}
×
112

113
void FrameQueue::enqueue(AVFrame* f)
×
114
{
115
  available.enqueue(f);
×
116
}
×
117

118
AVFrame* FrameQueue::dequeue() noexcept
×
119
{
120
  AVFrame* f{};
×
121
  AVFrame* prev_f{};
×
122

123
  // We only want the latest frame
124
  while(available.try_dequeue(f))
×
125
  {
126
    release(prev_f);
×
127
    prev_f = f;
×
128
  }
129

130
  return f;
×
131
}
132

133
AVFrame* FrameQueue::dequeue_one() noexcept
×
134
{
135
  AVFrame* f{};
×
136
  available.try_dequeue(f);
×
137
  return f;
×
138
}
139

140
void FrameQueue::set_discard_frame(AVFrame* f)
×
141
{
142
  m_discardUntil.exchange(f);
×
143
}
×
144

145
AVFrame* FrameQueue::discard_and_dequeue() noexcept
×
146
{
147
  AVFrame* f{};
×
148
  AVFrame* prev_f{};
×
149

150
  if(auto to_discard = m_discardUntil.exchange(nullptr))
×
151
  {
152
    while(available.try_dequeue(f) && f != to_discard)
×
153
    {
154
      release(f);
×
155
    }
156

157
    return to_discard;
×
158
  }
159
  // We only want the latest frame
160
  while(available.try_dequeue(f))
×
161
  {
162
    if(prev_f)
×
163
      release(prev_f);
×
164
    prev_f = f;
×
165
  }
166
  return f;
×
167
}
×
168

169
AVFrame* FrameQueue::discard_and_dequeue_one() noexcept
×
170
{
171
  AVFrame* f{};
×
172

173
  if(auto to_discard = m_discardUntil.exchange(nullptr))
×
174
  {
175
    while(available.try_dequeue(f) && f != to_discard)
×
176
    {
177
      release(f);
×
178
    }
179

180
    return to_discard;
×
181
  }
182

183
  available.try_dequeue(f);
×
184
  return f;
×
185
}
×
186

187
void FrameQueue::release(AVFrame* frame) noexcept
×
188
{
189
  if(frame)
×
190
  {
191
    released.enqueue(frame);
×
192
  }
×
193
}
×
194

195
void FrameQueue::drain()
23 ✔
196
{
197
  thread_local ossia::flat_set<AVFrame*> frames_to_free;
23 ✔
198
  frames_to_free.clear();
23 ✔
199
  {
200
    AVFrame* frame{};
23 ✔
201
    while(available.try_dequeue(frame))
23 ✔
202
    {
203
      SCORE_LIBAV_FRAME_DEALLOC_CHECK(frame);
×
204
      frames_to_free.insert(frame);
×
205
    }
206
  }
207

208
  // TODO we must check that this is safe as the queue
209
  // does not support dequeueing from the same thread as the
210
  // enqueuing
211
  {
212
    AVFrame* frame{};
23 ✔
213
    while(released.try_dequeue(frame))
23 ✔
214
    {
215
      SCORE_LIBAV_FRAME_DEALLOC_CHECK(frame);
×
216
      frames_to_free.insert(frame);
×
217
    }
218
  }
219

220
  for(auto frame : m_decodeThreadFrameBuffer)
23 ✔
221
  {
222
    SCORE_LIBAV_FRAME_DEALLOC_CHECK(frame);
×
223
    frames_to_free.insert(frame);
×
224
  }
225
  m_decodeThreadFrameBuffer.clear();
23 ✔
226

227
  for(auto frame : frames_to_free)
23 ✔
228
    av_frame_free(&frame);
×
229
  frames_to_free.clear();
23 ✔
230
}
23 ✔
231

232
}
233
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc