aboutsummaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2020-02-25 16:34:15 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2020-02-25 16:34:15 +0100
commit15e4fdf200920c990f3cc271143f43919cd6f27c (patch)
tree41bc62a60cab6b20fed9c22f4df42c5b01cc3354 /src/input
parent691617b1b651abe3c0413ab4e9349e56c8cf54e5 (diff)
downloaddabmux-15e4fdf200920c990f3cc271143f43919cd6f27c.tar.gz
dabmux-15e4fdf200920c990f3cc271143f43919cd6f27c.tar.bz2
dabmux-15e4fdf200920c990f3cc271143f43919cd6f27c.zip
Replace new/delete in ZMQ input by vector
Diffstat (limited to 'src/input')
-rw-r--r--src/input/Zmq.cpp22
-rw-r--r--src/input/Zmq.h3
2 files changed, 13 insertions, 12 deletions
diff --git a/src/input/Zmq.cpp b/src/input/Zmq.cpp
index 0a9d59d..603f514 100644
--- a/src/input/Zmq.cpp
+++ b/src/input/Zmq.cpp
@@ -268,7 +268,6 @@ size_t ZmqBase::readFrame(uint8_t* buffer, size_t size)
size_t over_max = m_frame_buffer.size() - m_config.prebuffering;
while (over_max--) {
- delete[] m_frame_buffer.front();
m_frame_buffer.pop_front();
}
}
@@ -288,7 +287,6 @@ size_t ZmqBase::readFrame(uint8_t* buffer, size_t size)
* frames even though we could drop less.
* */
for (int frame_del_count = 0; frame_del_count < 5; frame_del_count++) {
- delete[] m_frame_buffer.front();
m_frame_buffer.pop_front();
}
}
@@ -323,9 +321,11 @@ size_t ZmqBase::readFrame(uint8_t* buffer, size_t size)
}
else {
/* Normal situation, give a frame from the frame_buffer */
- uint8_t* newframe = m_frame_buffer.front();
- memcpy(buffer, newframe, size);
- delete[] newframe;
+ auto& newframe = m_frame_buffer.front();
+ if (newframe.size() != size) {
+ throw logic_error("Inconsistent ZMQ sizes");
+ }
+ memcpy(buffer, newframe.data(), newframe.size());
m_frame_buffer.pop_front();
return size;
}
@@ -388,9 +388,9 @@ int ZmqMPEG::readFromSocket(size_t framesize)
}
else if (m_enable_input) {
// copy the input frame blockwise into the frame_buffer
- auto framedata = new uint8_t[framesize];
- memcpy(framedata, data, framesize);
- m_frame_buffer.push_back(framedata);
+ vector<uint8_t> framedata(framesize);
+ copy(data, data + framesize, framedata.begin());
+ m_frame_buffer.push_back(move(framedata));
}
else {
return 0;
@@ -466,9 +466,9 @@ int ZmqAAC::readFromSocket(size_t framesize)
for (uint8_t* framestart = data;
framestart < &data[5*framesize];
framestart += framesize) {
- auto audioframe = new uint8_t[framesize];
- memcpy(audioframe, framestart, framesize);
- m_frame_buffer.push_back(audioframe);
+ vector<uint8_t> audioframe(framesize);
+ copy(framestart, framestart + framesize, audioframe.begin());
+ m_frame_buffer.push_back(move(audioframe));
}
}
else {
diff --git a/src/input/Zmq.h b/src/input/Zmq.h
index 2e37b5f..f4992f1 100644
--- a/src/input/Zmq.h
+++ b/src/input/Zmq.h
@@ -45,6 +45,7 @@
#include <list>
#include <string>
+#include <vector>
#include <cstdint>
#include "zmq.hpp"
#include "input/inputs.h"
@@ -212,7 +213,7 @@ class ZmqBase : public InputBase, public RemoteControllable {
bool m_enable_input;
/* stores elements of type char[<superframesize>] */
- std::list<uint8_t*> m_frame_buffer;
+ std::list<std::vector<uint8_t> > m_frame_buffer;
dab_input_zmq_config_t m_config;