Essentia  2.1-beta6-dev
devnull.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2021 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Essentia
5  *
6  * Essentia is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License as published by the Free
8  * Software Foundation (FSF), either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the Affero GNU General Public License
17  * version 3 along with this program. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef ESSENTIA_DEVNULL_H
21 #define ESSENTIA_DEVNULL_H
22 
23 #include "../streamingalgorithm.h"
24 
25 namespace essentia {
26 namespace streaming {
27 
28 template <typename TokenType>
29 class DevNull : public Algorithm {
30  protected:
32 
33  public:
35  static ForcedMutex _devnullInitMutex;
36  static int _devnullId = 0;
37 
38  ForcedMutexLocker lock(_devnullInitMutex);
39 
40  int devnullId = _devnullId++;
41  std::ostringstream name;
42  name << "DevNull<" << nameOfType(typeid(TokenType)) << ">[" << devnullId << "]";
43  setName(name.str());
44  declareInput(_frames, 1, "data", "the incoming data to discard");
45  E_DEBUG(EFactory, "Created " << _name);
46  }
47 
49 
51  int nframes = std::min(_frames.available(),
52  _frames.buffer().bufferInfo().maxContiguousElements);
53  nframes = std::max(nframes, 1); // in case phantomsize == 0
54 
55  EXEC_DEBUG("Consuming " << nframes << " tokens");
56 
57  if (!_frames.acquire(nframes)) {
58  EXEC_DEBUG("Could not consume because not enough input tokens");
59  return NO_INPUT;
60  }
61 
62  // do nothing, only release the tokens we just acquired
63  _frames.release(nframes);
64 
65  return OK;
66  }
67 };
68 
69 
72  DEVNULL
73 };
74 
79 void connect(SourceBase& source, DevNullConnector devnull);
80 
81 inline void operator>>(SourceBase& source, DevNullConnector devnull) {
82  connect(source, devnull);
83 }
84 
85 
89 void disconnect(SourceBase& source, DevNullConnector devnull);
90 
91 } // namespace streaming
92 } // namespace essentia
93 
94 #endif // ESSENTIA_DEVNULL_H
void setName(const std::string &name)
Definition: configurable.h:53
std::string _name
Definition: configurable.h:171
const std::string & name() const
Definition: configurable.h:48
Definition: threading.h:95
Definition: threading.h:80
Definition: streamingalgorithm.h:140
void declareInput(SinkBase &sink, const std::string &name, const std::string &desc)
Definition: devnull.h:29
DevNull()
Definition: devnull.h:34
AlgorithmStatus process()
Definition: devnull.h:50
void declareParameters()
Definition: devnull.h:48
Sink< TokenType > _frames
Definition: devnull.h:31
Definition: sink.h:35
Definition: sourcebase.h:52
#define E_DEBUG(module, msg)
Definition: debugging.h:157
#define EXEC_DEBUG(msg)
Definition: debugging.h:161
void disconnect(SourceBase &source, DevNullConnector devnull)
void operator>>(SourceBase &source, DevNullConnector devnull)
Definition: devnull.h:81
DevNullConnector
Definition: devnull.h:70
@ NOWHERE
Definition: devnull.h:71
@ DEVNULL
Definition: devnull.h:72
void connect(SourceBase &source, DevNullConnector devnull)
AlgorithmStatus
Definition: streamingalgorithm.h:106
@ OK
Definition: streamingalgorithm.h:107
@ NO_INPUT
Definition: streamingalgorithm.h:111
Definition: algorithm.h:28
std::string nameOfType(const std::type_info &type)
@ EFactory
Definition: debugging.h:44