-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvp8_reference_frame_vector.cc
102 lines (82 loc) · 3.23 KB
/
vp8_reference_frame_vector.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/gpu/vp8_reference_frame_vector.h"
#include "media/gpu/vp8_picture.h"
namespace media {
Vp8ReferenceFrameVector::Vp8ReferenceFrameVector() {
// TODO(posciak): Remove this once VP8Decoder is created on the same thread
// as its methods are called on.
DETACH_FROM_SEQUENCE(sequence_checker_);
}
Vp8ReferenceFrameVector::~Vp8ReferenceFrameVector() {
// TODO(posciak): Add this once VP8Decoder is created on the same thread
// as its methods are called on.
// DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
// Based on update_reference_frames() in libvpx: vp8/encoder/onyx_if.c
void Vp8ReferenceFrameVector::Refresh(scoped_refptr<VP8Picture> pic) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(pic);
bool keyframe = pic->frame_hdr->IsKeyframe();
const auto& frame_hdr = pic->frame_hdr;
if (keyframe) {
reference_frames_[Vp8RefType::VP8_FRAME_LAST] = pic;
reference_frames_[Vp8RefType::VP8_FRAME_GOLDEN] = pic;
reference_frames_[Vp8RefType::VP8_FRAME_ALTREF] = pic;
return;
}
if (frame_hdr->refresh_alternate_frame) {
reference_frames_[Vp8RefType::VP8_FRAME_ALTREF] = pic;
} else {
switch (frame_hdr->copy_buffer_to_alternate) {
case Vp8FrameHeader::COPY_LAST_TO_ALT:
DCHECK(reference_frames_[Vp8RefType::VP8_FRAME_LAST]);
reference_frames_[Vp8RefType::VP8_FRAME_ALTREF] =
reference_frames_[Vp8RefType::VP8_FRAME_LAST];
break;
case Vp8FrameHeader::COPY_GOLDEN_TO_ALT:
DCHECK(reference_frames_[Vp8RefType::VP8_FRAME_GOLDEN]);
reference_frames_[Vp8RefType::VP8_FRAME_ALTREF] =
reference_frames_[Vp8RefType::VP8_FRAME_GOLDEN];
break;
case Vp8FrameHeader::NO_ALT_REFRESH:
DCHECK(reference_frames_[Vp8RefType::VP8_FRAME_ALTREF]);
break;
}
}
if (frame_hdr->refresh_golden_frame) {
reference_frames_[Vp8RefType::VP8_FRAME_GOLDEN] = pic;
} else {
switch (frame_hdr->copy_buffer_to_golden) {
case Vp8FrameHeader::COPY_LAST_TO_GOLDEN:
DCHECK(reference_frames_[Vp8RefType::VP8_FRAME_LAST]);
reference_frames_[Vp8RefType::VP8_FRAME_GOLDEN] =
reference_frames_[Vp8RefType::VP8_FRAME_LAST];
break;
case Vp8FrameHeader::COPY_ALT_TO_GOLDEN:
DCHECK(reference_frames_[Vp8RefType::VP8_FRAME_ALTREF]);
reference_frames_[Vp8RefType::VP8_FRAME_GOLDEN] =
reference_frames_[Vp8RefType::VP8_FRAME_ALTREF];
break;
case Vp8FrameHeader::NO_GOLDEN_REFRESH:
DCHECK(reference_frames_[Vp8RefType::VP8_FRAME_GOLDEN]);
break;
}
}
if (frame_hdr->refresh_last)
reference_frames_[Vp8RefType::VP8_FRAME_LAST] = pic;
else
DCHECK(reference_frames_[Vp8RefType::VP8_FRAME_LAST]);
}
void Vp8ReferenceFrameVector::Clear() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (auto& f : reference_frames_)
f = nullptr;
}
scoped_refptr<VP8Picture> Vp8ReferenceFrameVector::GetFrame(
Vp8RefType type) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return reference_frames_[type];
}
} // namespace media