decoder/Bridge: use std::unique_ptr<Tag>

This commit is contained in:
Max Kellermann 2017-12-20 15:24:41 +01:00
parent 73e69edac3
commit 9f33c6fe03
3 changed files with 13 additions and 20 deletions

View File

@ -47,10 +47,6 @@ DecoderBridge::~DecoderBridge()
convert->Close();
delete convert;
}
delete song_tag;
delete stream_tag;
delete decoder_tag;
}
bool
@ -222,11 +218,11 @@ DecoderBridge::DoSendTag(const Tag &tag)
bool
DecoderBridge::UpdateStreamTag(InputStream *is)
{
auto *tag = is != nullptr
? is->LockReadTag().release()
auto tag = is != nullptr
? is->LockReadTag()
: nullptr;
if (tag == nullptr) {
tag = song_tag;
tag = std::move(song_tag);
if (tag == nullptr)
return false;
@ -234,12 +230,9 @@ DecoderBridge::UpdateStreamTag(InputStream *is)
instead */
} else
/* discard the song tag; we don't need it */
delete song_tag;
song_tag.reset();
song_tag = nullptr;
delete stream_tag;
stream_tag = tag;
stream_tag = std::move(tag);
return true;
}
@ -540,8 +533,7 @@ DecoderBridge::SubmitTag(InputStream *is, Tag &&tag)
/* save the tag */
delete decoder_tag;
decoder_tag = new Tag(std::move(tag));
decoder_tag = std::make_unique<Tag>(std::move(tag));
/* check for a new stream tag */

View File

@ -24,6 +24,7 @@
#include "ReplayGainInfo.hxx"
#include <exception>
#include <memory>
class PcmConvert;
struct MusicChunk;
@ -74,13 +75,13 @@ public:
* files, because we expect the stream server to send us a new
* tag each time we play it.
*/
Tag *song_tag;
std::unique_ptr<Tag> song_tag;
/** the last tag received from the stream */
Tag *stream_tag = nullptr;
std::unique_ptr<Tag> stream_tag;
/** the last tag received from the decoder plugin */
Tag *decoder_tag = nullptr;
std::unique_ptr<Tag> decoder_tag;
/** the chunk currently being written to */
MusicChunk *current_chunk = nullptr;
@ -100,10 +101,10 @@ public:
std::exception_ptr error;
DecoderBridge(DecoderControl &_dc, bool _initial_seek_pending,
Tag *_tag)
std::unique_ptr<Tag> _tag)
:dc(_dc),
initial_seek_pending(_initial_seek_pending),
song_tag(_tag) {}
song_tag(std::move(_tag)) {}
~DecoderBridge();

View File

@ -447,7 +447,7 @@ decoder_run_song(DecoderControl &dc,
file - tags on "stream" songs are just
remembered from the last time we
played it*/
song.IsFile() ? new Tag(song.GetTag()) : nullptr);
song.IsFile() ? std::make_unique<Tag>(song.GetTag()) : nullptr);
dc.state = DecoderState::START;
dc.CommandFinishedLocked();