Commit 13816c1c authored by Max Kellermann's avatar Max Kellermann

output/{recorder,httpd,shout}: use std::unique_ptr to manage PreparedEncoder pointer

parent c54a920d
......@@ -35,6 +35,7 @@
#include "util/ScopeExit.hxx"
#include <stdexcept>
#include <memory>
#include <assert.h>
#include <stdlib.h>
......@@ -45,7 +46,7 @@ class RecorderOutput final : AudioOutput {
/**
* The configured encoder plugin.
*/
PreparedEncoder *prepared_encoder = nullptr;
std::unique_ptr<PreparedEncoder> prepared_encoder;
Encoder *encoder;
/**
......@@ -72,10 +73,6 @@ class RecorderOutput final : AudioOutput {
RecorderOutput(const ConfigBlock &block);
~RecorderOutput() {
delete prepared_encoder;
}
public:
static AudioOutput *Create(EventLoop &, const ConfigBlock &block) {
return new RecorderOutput(block);
......@@ -136,7 +133,7 @@ RecorderOutput::RecorderOutput(const ConfigBlock &block)
/* initialize encoder */
prepared_encoder = encoder_init(*encoder_plugin, block);
prepared_encoder.reset(encoder_init(*encoder_plugin, block));
}
inline void
......
......@@ -30,6 +30,7 @@
#include <shout/shout.h>
#include <stdexcept>
#include <memory>
#include <assert.h>
#include <stdlib.h>
......@@ -42,7 +43,7 @@ struct ShoutOutput final : AudioOutput {
shout_t *shout_conn;
shout_metadata_t *shout_meta;
PreparedEncoder *prepared_encoder = nullptr;
std::unique_ptr<PreparedEncoder> prepared_encoder;
Encoder *encoder;
float quality = -2.0;
......@@ -162,7 +163,7 @@ ShoutOutput::ShoutOutput(const ConfigBlock &block)
throw FormatRuntimeError("couldn't find shout encoder plugin \"%s\"",
encoding);
prepared_encoder = encoder_init(*encoder_plugin, block);
prepared_encoder.reset(encoder_init(*encoder_plugin, block));
unsigned shout_format;
if (strcmp(encoding, "mp3") == 0 || strcmp(encoding, "lame") == 0)
......@@ -243,8 +244,6 @@ ShoutOutput::~ShoutOutput()
shout_init_count--;
if (shout_init_count == 0)
shout_shutdown();
delete prepared_encoder;
}
AudioOutput *
......
......@@ -39,6 +39,7 @@
#include <queue>
#include <list>
#include <memory>
struct ConfigBlock;
class EventLoop;
......@@ -60,7 +61,7 @@ class HttpdOutput final : AudioOutput, ServerSocket {
/**
* The configured encoder plugin.
*/
PreparedEncoder *prepared_encoder = nullptr;
std::unique_ptr<PreparedEncoder> prepared_encoder;
Encoder *encoder = nullptr;
/**
......@@ -152,7 +153,6 @@ private:
public:
HttpdOutput(EventLoop &_loop, const ConfigBlock &block);
~HttpdOutput();
static AudioOutput *Create(EventLoop &event_loop,
const ConfigBlock &block) {
......
......@@ -79,7 +79,7 @@ HttpdOutput::HttpdOutput(EventLoop &_loop, const ConfigBlock &block)
/* initialize encoder */
prepared_encoder = encoder_init(*encoder_plugin, block);
prepared_encoder.reset(encoder_init(*encoder_plugin, block));
/* determine content type */
content_type = prepared_encoder->GetMimeType();
......@@ -87,11 +87,6 @@ HttpdOutput::HttpdOutput(EventLoop &_loop, const ConfigBlock &block)
content_type = "application/octet-stream";
}
HttpdOutput::~HttpdOutput()
{
delete prepared_encoder;
}
inline void
HttpdOutput::Bind()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment