21
21
#include < vector>
22
22
23
23
#include < vpdq/cpp/hashing/bufferhasher.h>
24
- #include < vpdq/cpp/hashing/ffmpegwrapper.h>
25
24
#include < vpdq/cpp/hashing/vpdqHashType.h>
26
25
27
26
namespace facebook {
@@ -83,6 +82,12 @@ class VpdqHasher {
83
82
**/
84
83
void push_back (TFrame&& frame);
85
84
85
+ /* * @brief Stop and join all hashing threads.
86
+ *
87
+ * @note Not thread safe.
88
+ **/
89
+ void stop_hashing ();
90
+
86
91
/* * @brief Block until all frames are finished hashing and get the final
87
92
* result.
88
93
*
@@ -98,6 +103,8 @@ class VpdqHasher {
98
103
VpdqHasher (VpdqHasher&&) = delete ;
99
104
VpdqHasher& operator =(VpdqHasher&&) = delete ;
100
105
106
+ ~VpdqHasher () { stop_hashing (); }
107
+
101
108
private:
102
109
/* * @brief True if hashing is multithreaded, false if singlethreaded.
103
110
**/
@@ -210,10 +217,14 @@ void VpdqHasher<TFrame>::push_back(TFrame&& frame) {
210
217
}
211
218
212
219
template <typename TFrame>
213
- std::vector<vpdqFeature> VpdqHasher<TFrame>::finish () {
220
+ void VpdqHasher<TFrame>::stop_hashing () {
214
221
if (m_multithreaded) {
215
222
{
216
223
std::lock_guard<std::mutex> lock (m_queue_mutex);
224
+ if (m_done_hashing) {
225
+ return ;
226
+ }
227
+
217
228
m_done_hashing = true ;
218
229
}
219
230
@@ -222,6 +233,11 @@ std::vector<vpdqFeature> VpdqHasher<TFrame>::finish() {
222
233
thread.join ();
223
234
}
224
235
}
236
+ }
237
+
238
+ template <typename TFrame>
239
+ std::vector<vpdqFeature> VpdqHasher<TFrame>::finish() {
240
+ this ->stop_hashing ();
225
241
226
242
// Sort out of order frames by frame number
227
243
std::sort (
@@ -259,10 +275,6 @@ void VpdqHasher<TFrame>::consumer() {
259
275
}
260
276
}
261
277
262
- // Explicit template instantiation for all frame types.
263
- template class VpdqHasher <GenericFrame>;
264
- template class VpdqHasher <ffmpeg::FFmpegFrame>;
265
-
266
278
} // namespace hashing
267
279
} // namespace vpdq
268
280
} // namespace facebook
0 commit comments