Skip to content

Commit fc26329

Browse files
authored
Avoid taking ownership of Arc<Frame<T>> in scenechange API (#2958)
1 parent 182bbff commit fc26329

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

src/api/channel/by_gop.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ impl<T: Pixel> SceneChange<T> {
6666
fn split(&mut self, lookahead: &[Arc<Frame<T>>]) -> Option<(usize, bool)> {
6767
self.processed += 1;
6868

69+
let lookahead_ref: Vec<_> = lookahead[self.frames..].iter().collect();
70+
6971
let new_gop = self.detector.analyze_next_frame(
70-
&lookahead[self.frames..],
72+
&lookahead_ref,
7173
self.processed,
7274
self.last_keyframe,
7375
);

src/api/internal.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ impl<T: Pixel> ContextInner<T> {
357357
let lookahead_frames = self
358358
.frame_q
359359
.range(self.next_lookahead_frame - 1..)
360-
.filter_map(|(&_input_frameno, frame)| frame.clone())
361-
.collect::<Vec<_>>();
360+
.filter_map(|(&_input_frameno, frame)| frame.as_ref())
361+
.collect::<Vec<&Arc<Frame<T>>>>();
362362

363363
if is_flushing {
364364
// This is the last time send_frame is called, process all the
@@ -371,10 +371,22 @@ impl<T: Pixel> ContextInner<T> {
371371
break;
372372
}
373373

374-
self.compute_keyframe_placement(cur_lookahead_frames);
374+
Self::compute_keyframe_placement(
375+
cur_lookahead_frames,
376+
&self.keyframes_forced,
377+
&mut self.keyframe_detector,
378+
&mut self.next_lookahead_frame,
379+
&mut self.keyframes,
380+
);
375381
}
376382
} else {
377-
self.compute_keyframe_placement(&lookahead_frames);
383+
Self::compute_keyframe_placement(
384+
&lookahead_frames,
385+
&self.keyframes_forced,
386+
&mut self.keyframe_detector,
387+
&mut self.next_lookahead_frame,
388+
&mut self.keyframes,
389+
);
378390
}
379391
}
380392

@@ -837,19 +849,21 @@ impl<T: Pixel> ContextInner<T> {
837849

838850
#[hawktracer(compute_keyframe_placement)]
839851
pub fn compute_keyframe_placement(
840-
&mut self, lookahead_frames: &[Arc<Frame<T>>],
852+
lookahead_frames: &[&Arc<Frame<T>>], keyframes_forced: &BTreeSet<u64>,
853+
keyframe_detector: &mut SceneChangeDetector<T>,
854+
next_lookahead_frame: &mut u64, keyframes: &mut BTreeSet<u64>,
841855
) {
842-
if self.keyframes_forced.contains(&self.next_lookahead_frame)
843-
|| self.keyframe_detector.analyze_next_frame(
856+
if keyframes_forced.contains(next_lookahead_frame)
857+
|| keyframe_detector.analyze_next_frame(
844858
lookahead_frames,
845-
self.next_lookahead_frame,
846-
*self.keyframes.iter().last().unwrap(),
859+
*next_lookahead_frame,
860+
*keyframes.iter().last().unwrap(),
847861
)
848862
{
849-
self.keyframes.insert(self.next_lookahead_frame);
863+
keyframes.insert(*next_lookahead_frame);
850864
}
851865

852-
self.next_lookahead_frame += 1;
866+
*next_lookahead_frame += 1;
853867
}
854868

855869
#[hawktracer(compute_frame_invariants)]

src/scenechange/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<T: Pixel> SceneChangeDetector<T> {
166166
/// This will gracefully handle the first frame in the video as well.
167167
#[hawktracer(analyze_next_frame)]
168168
pub fn analyze_next_frame(
169-
&mut self, frame_set: &[Arc<Frame<T>>], input_frameno: u64,
169+
&mut self, frame_set: &[&Arc<Frame<T>>], input_frameno: u64,
170170
previous_keyframe: u64,
171171
) -> bool {
172172
// Use score deque for adaptive threshold for scene cut
@@ -254,7 +254,7 @@ impl<T: Pixel> SceneChangeDetector<T> {
254254

255255
// Initially fill score deque with frame scores
256256
fn initialize_score_deque(
257-
&mut self, frame_set: &[Arc<Frame<T>>], input_frameno: u64,
257+
&mut self, frame_set: &[&Arc<Frame<T>>], input_frameno: u64,
258258
init_len: usize,
259259
) {
260260
for x in 0..init_len {

0 commit comments

Comments
 (0)