Skip to content

Commit

Permalink
directly use std::shared_ptr<>
Browse files Browse the repository at this point in the history
  • Loading branch information
nu774 committed Nov 1, 2012
1 parent 0b9b103 commit 77961a2
Show file tree
Hide file tree
Showing 45 changed files with 146 additions and 173 deletions.
2 changes: 1 addition & 1 deletion AudioCodecX.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "CoreAudioToolbox.h"

class AudioCodecX {
x::shared_ptr<ComponentInstanceRecord> m_codec;
std::shared_ptr<ComponentInstanceRecord> m_codec;
public:
AudioCodecX() {}
AudioCodecX(OSType codec)
Expand Down
10 changes: 5 additions & 5 deletions AudioConverterX.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <cmath>

class AudioConverterX {
x::shared_ptr<OpaqueAudioConverter> m_converter;
std::shared_ptr<OpaqueAudioConverter> m_converter;
public:
AudioConverterX() {}
AudioConverterX(AudioConverterRef converter, bool takeOwn)
Expand Down Expand Up @@ -103,13 +103,13 @@ class AudioConverterX {
CHECKCA(AudioConverterSetProperty(m_converter.get(),
kAudioConverterEncodeBitRate, sizeof value, &value));
}
void getInputChannelLayout(x::shared_ptr<AudioChannelLayout> *result)
void getInputChannelLayout(std::shared_ptr<AudioChannelLayout> *result)
{
UInt32 size;
Boolean writable;
CHECKCA(AudioConverterGetPropertyInfo(m_converter.get(),
kAudioConverterInputChannelLayout, &size, &writable));
x::shared_ptr<AudioChannelLayout> acl(
std::shared_ptr<AudioChannelLayout> acl(
reinterpret_cast<AudioChannelLayout*>(std::malloc(size)),
std::free);
CHECKCA(AudioConverterGetProperty(m_converter.get(),
Expand All @@ -123,13 +123,13 @@ class AudioConverterX {
CHECKCA(AudioConverterSetProperty(m_converter.get(),
kAudioConverterInputChannelLayout, size, value));
}
void getOutputChannelLayout(x::shared_ptr<AudioChannelLayout> *result)
void getOutputChannelLayout(std::shared_ptr<AudioChannelLayout> *result)
{
UInt32 size;
Boolean writable;
CHECKCA(AudioConverterGetPropertyInfo(m_converter.get(),
kAudioConverterOutputChannelLayout, &size, &writable));
x::shared_ptr<AudioChannelLayout> acl(
std::shared_ptr<AudioChannelLayout> acl(
reinterpret_cast<AudioChannelLayout*>(std::malloc(size)),
std::free);
CHECKCA(AudioConverterGetProperty(m_converter.get(),
Expand Down
6 changes: 3 additions & 3 deletions AudioFileX.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "CoreAudioHelper.h"

class AudioFileX {
x::shared_ptr<OpaqueAudioFileID> m_file;
std::shared_ptr<OpaqueAudioFileID> m_file;
public:
AudioFileX() {}
AudioFileX(AudioFileID file, bool takeOwn)
Expand Down Expand Up @@ -59,13 +59,13 @@ class AudioFileX {
sizeof(AudioFilePacketTableInfo),
info));
}
void getChannelLayout(x::shared_ptr<AudioChannelLayout> *layout)
void getChannelLayout(std::shared_ptr<AudioChannelLayout> *layout)
{
UInt32 size;
UInt32 writable;
CHECKCA(AudioFileGetPropertyInfo(m_file.get(),
kAudioFilePropertyChannelLayout, &size, &writable));
x::shared_ptr<AudioChannelLayout> acl(
std::shared_ptr<AudioChannelLayout> acl(
reinterpret_cast<AudioChannelLayout*>(std::malloc(size)),
std::free);
CHECKCA(AudioFileGetProperty(m_file.get(),
Expand Down
2 changes: 1 addition & 1 deletion CoreAudioEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CoreAudioEncoder::CoreAudioEncoder(AudioConverterX &converter)
abl = static_cast<AudioBufferList*>(std::calloc(1, size));
abl->mBuffers[0].mNumberChannels = m_output_desc.mChannelsPerFrame;
abl->mNumberBuffers = 1;
m_output_abl = x::shared_ptr<AudioBufferList>(abl, std::free);
m_output_abl = std::shared_ptr<AudioBufferList>(abl, std::free);
}
}

Expand Down
10 changes: 5 additions & 5 deletions CoreAudioEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ class CoreAudioEncoder: public IEncoder, public IEncoderStat {
AudioConverterX m_converter;
bool m_requires_packet_desc;
bool m_variable_packet_len;
x::shared_ptr<ISource> m_src;
x::shared_ptr<ISink> m_sink;
x::shared_ptr<AudioBufferList> m_output_abl;
std::shared_ptr<ISource> m_src;
std::shared_ptr<ISink> m_sink;
std::shared_ptr<AudioBufferList> m_output_abl;
std::vector<uint8_t> m_input_buffer, m_output_buffer;
std::vector<AudioStreamPacketDescription> m_packet_desc;
AudioStreamBasicDescription m_input_desc, m_output_desc;
EncoderStat m_stat;
public:
CoreAudioEncoder(AudioConverterX &converter);
void setSource(const x::shared_ptr<ISource> &source) { m_src = source; }
void setSink(const x::shared_ptr<ISink> &sink) { m_sink = sink; }
void setSource(const std::shared_ptr<ISource> &source) { m_src = source; }
void setSink(const std::shared_ptr<ISink> &sink) { m_sink = sink; }
bool encodeChunk(UInt32 npackets);
AudioConverterX getConverter() { return m_converter; }
ISource *src() { return m_src.get(); }
Expand Down
5 changes: 2 additions & 3 deletions CoreAudioHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <vector>
#include <sstream>
#include <stdexcept>
#include "shared_ptr.h"
#include "CoreAudioToolbox.h"
#include "util.h"
#include "chanmap.h"
Expand Down Expand Up @@ -61,7 +60,7 @@ inline std::wstring CF2W(CFStringRef str)
return std::wstring(buffer.begin(), buffer.end());
}

typedef x::shared_ptr<const __CFString> CFStringPtr;
typedef std::shared_ptr<const __CFString> CFStringPtr;

inline CFStringPtr W2CF(std::wstring s)
{
Expand All @@ -71,7 +70,7 @@ inline CFStringPtr W2CF(std::wstring s)
}

class AudioChannelLayoutX {
typedef x::shared_ptr<AudioChannelLayout> owner_t;
typedef std::shared_ptr<AudioChannelLayout> owner_t;
owner_t m_instance;
public:
AudioChannelLayoutX() { create(0); }
Expand Down
4 changes: 2 additions & 2 deletions CoreAudioResampler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "CoreAudioResampler.h"

CoreAudioResampler::CoreAudioResampler(const x::shared_ptr<ISource> src,
CoreAudioResampler::CoreAudioResampler(const std::shared_ptr<ISource> src,
int rate,
uint32_t quality,
uint32_t complexity)
Expand All @@ -17,7 +17,7 @@ CoreAudioResampler::CoreAudioResampler(const x::shared_ptr<ISource> src,
m_encoder.reset(new CoreAudioEncoder(m_converter));

struct F { static void dispose(ISink *x) {} };
x::shared_ptr<ISink> sinkPtr(this, F::dispose);
std::shared_ptr<ISink> sinkPtr(this, F::dispose);
m_encoder->setSource(src);
m_encoder->setSink(sinkPtr);
}
Expand Down
4 changes: 2 additions & 2 deletions CoreAudioResampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class CoreAudioResampler: public DelegatingSource, public ISink {
AudioConverterX m_converter;
x::shared_ptr<CoreAudioEncoder> m_encoder;
std::shared_ptr<CoreAudioEncoder> m_encoder;
std::deque<float> m_fbuffer;
uint64_t m_samples_read;
AudioStreamBasicDescription m_format;
public:
CoreAudioResampler(const x::shared_ptr<ISource> src, int rate,
CoreAudioResampler(const std::shared_ptr<ISource> src, int rate,
uint32_t quality, uint32_t complexity);
uint64_t length() const { return -1; }
const AudioStreamBasicDescription &getSampleFormat() const
Expand Down
10 changes: 5 additions & 5 deletions ExtAudioFileX.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "CoreAudioHelper.h"

class ExtAudioFileX {
x::shared_ptr<OpaqueExtAudioFileID> m_file;
std::shared_ptr<OpaqueExtAudioFileID> m_file;
public:
ExtAudioFileX() {}
ExtAudioFileX(ExtAudioFileRef file, bool takeOwn)
Expand Down Expand Up @@ -51,26 +51,26 @@ class ExtAudioFileX {
kExtAudioFileProperty_FileDataFormat,
&size, result));
}
void getClientChannelLayout(x::shared_ptr<AudioChannelLayout> *layout)
void getClientChannelLayout(std::shared_ptr<AudioChannelLayout> *layout)
{
UInt32 size;
Boolean writable;
CHECKCA(ExtAudioFileGetPropertyInfo(m_file.get(),
kExtAudioFileProperty_ClientChannelLayout, &size, &writable));
x::shared_ptr<AudioChannelLayout> acl(
std::shared_ptr<AudioChannelLayout> acl(
reinterpret_cast<AudioChannelLayout*>(std::malloc(size)),
std::free);
CHECKCA(ExtAudioFileGetProperty(m_file.get(),
kExtAudioFileProperty_ClientChannelLayout, &size, acl.get()));
layout->swap(acl);
}
void getFileChannelLayout(x::shared_ptr<AudioChannelLayout> *layout)
void getFileChannelLayout(std::shared_ptr<AudioChannelLayout> *layout)
{
UInt32 size;
Boolean writable;
CHECKCA(ExtAudioFileGetPropertyInfo(m_file.get(),
kExtAudioFileProperty_FileChannelLayout, &size, &writable));
x::shared_ptr<AudioChannelLayout> acl(
std::shared_ptr<AudioChannelLayout> acl(
reinterpret_cast<AudioChannelLayout*>(std::malloc(size)),
std::free);
CHECKCA(ExtAudioFileGetProperty(m_file.get(),
Expand Down
18 changes: 9 additions & 9 deletions afsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "utf8_codecvt_facet.hpp"
#include "itunetags.h"

typedef x::shared_ptr<const __CFDictionary> CFDictionaryPtr;
typedef std::shared_ptr<const __CFDictionary> CFDictionaryPtr;

namespace caf {
inline void *load_cf_constant(const char *name)
Expand Down Expand Up @@ -161,11 +161,11 @@ namespace audiofile {
}
}

x::shared_ptr<ISource>
std::shared_ptr<ISource>
AudioFileOpenFactory(InputStream &stream, const std::wstring &path)
{
AudioFileID afid;
x::shared_ptr<InputStream> streamPtr(new InputStream(stream));
std::shared_ptr<InputStream> streamPtr(new InputStream(stream));

CHECKCA(AudioFileOpenWithCallbacks(streamPtr.get(), audiofile::read, 0,
audiofile::size, 0, 0, &afid));
Expand All @@ -174,20 +174,20 @@ AudioFileOpenFactory(InputStream &stream, const std::wstring &path)
af.getDataFormat(&asbd);

if (asbd.mFormatID == 'lpcm')
return x::shared_ptr<ISource>(new AFSource(af, streamPtr));
return std::shared_ptr<ISource>(new AFSource(af, streamPtr));
else if (asbd.mFormatID == 'alac')
return x::shared_ptr<ISource>(new ExtAFSource(af, streamPtr, path));
return std::shared_ptr<ISource>(new ExtAFSource(af, streamPtr, path));
else
throw std::runtime_error("Not supported format");
}

AFSource::AFSource(AudioFileX &af, x::shared_ptr<InputStream> &stream)
AFSource::AFSource(AudioFileX &af, std::shared_ptr<InputStream> &stream)
: m_af(af), m_offset(0), m_stream(stream)
{
fourcc fcc(m_af.getFileFormat());
m_af.getDataFormat(&m_format);
setRange(0, m_af.getAudioDataPacketCount());
x::shared_ptr<AudioChannelLayout> acl;
std::shared_ptr<AudioChannelLayout> acl;
try {
m_af.getChannelLayout(&acl);
chanmap::GetChannels(acl.get(), &m_chanmap);
Expand All @@ -213,7 +213,7 @@ size_t AFSource::readSamples(void *buffer, size_t nsamples)
}


ExtAFSource::ExtAFSource(AudioFileX &af, x::shared_ptr<InputStream> &stream,
ExtAFSource::ExtAFSource(AudioFileX &af, std::shared_ptr<InputStream> &stream,
const std::wstring &path)
: m_af(af), m_stream(stream)
{
Expand All @@ -238,7 +238,7 @@ ExtAFSource::ExtAFSource(AudioFileX &af, x::shared_ptr<InputStream> &stream,
kAudioFormatFlagIsAlignedHigh);
m_eaf.setClientDataFormat(m_format);
setRange(0, m_eaf.getFileLengthFrames());
x::shared_ptr<AudioChannelLayout> acl;
std::shared_ptr<AudioChannelLayout> acl;
try {
m_af.getChannelLayout(&acl);
chanmap::GetChannels(acl.get(), &m_chanmap);
Expand Down
10 changes: 5 additions & 5 deletions afsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
#include "ExtAudioFileX.h"
#include "ioabst.h"

x::shared_ptr<ISource>
std::shared_ptr<ISource>
AudioFileOpenFactory(InputStream &stream, const std::wstring &path);

class AFSource: public ITagParser, public PartialSource<AFSource>
{
AudioFileX m_af;
uint64_t m_offset;
x::shared_ptr<InputStream> m_stream;
std::shared_ptr<InputStream> m_stream;
std::vector<uint32_t> m_chanmap;
std::map<uint32_t, std::wstring> m_tags;
AudioStreamBasicDescription m_format;
public:
AFSource(AudioFileX &af, x::shared_ptr<InputStream> &stream);
AFSource(AudioFileX &af, std::shared_ptr<InputStream> &stream);
/*
* XXX: AudioFile_GetSizeProc is called inside of AudioFileClose().
* Therefore, we must first call AudioFileClose() before destruction.
Expand All @@ -44,12 +44,12 @@ class ExtAFSource: public ITagParser, public PartialSource<ExtAFSource>
AudioFileX m_af;
ExtAudioFileX m_eaf;
uint64_t m_offset;
x::shared_ptr<InputStream> m_stream;
std::shared_ptr<InputStream> m_stream;
std::vector<uint32_t> m_chanmap;
std::map<uint32_t, std::wstring> m_tags;
AudioStreamBasicDescription m_format;
public:
ExtAFSource(AudioFileX &af, x::shared_ptr<InputStream> &stream,
ExtAFSource(AudioFileX &af, std::shared_ptr<InputStream> &stream,
const std::wstring &path);
~ExtAFSource()
{
Expand Down
10 changes: 5 additions & 5 deletions alacenc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class ALACEncoderX: public IEncoder, public IEncoderStat {
AudioStreamBasicDescription asbd;
AudioFormatDescription afd;
};
x::shared_ptr<ISource> m_src;
x::shared_ptr<ISink> m_sink;
x::shared_ptr<ALACEncoder> m_encoder;
std::shared_ptr<ISource> m_src;
std::shared_ptr<ISink> m_sink;
std::shared_ptr<ALACEncoder> m_encoder;
std::vector<uint8_t> m_input_buffer;
std::vector<uint8_t> m_output_buffer;
ASBD m_input_desc, m_output_desc;
Expand All @@ -23,8 +23,8 @@ class ALACEncoderX: public IEncoder, public IEncoderStat {
void setFastMode(bool fast) { m_encoder->SetFastMode(fast); }
bool encodeChunk(UInt32 npackets);
void getMagicCookie(std::vector<uint8_t> *cookie);
void setSource(const x::shared_ptr<ISource> &source) { m_src = source; }
void setSink(const x::shared_ptr<ISink> &sink) { m_sink = sink; }
void setSource(const std::shared_ptr<ISource> &source) { m_src = source; }
void setSink(const std::shared_ptr<ISink> &sink) { m_sink = sink; }
ISource *src() { return m_src.get(); }
const AudioStreamBasicDescription &getInputDescription() const
{
Expand Down
2 changes: 1 addition & 1 deletion alacsrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ALACSource::ALACSource(const std::wstring &path)
acl.mChannelBitmap = bitmap;
chanmap::GetChannels(&acl, &m_chanmap);
}
m_decoder = x::shared_ptr<ALACDecoder>(new ALACDecoder());
m_decoder = std::shared_ptr<ALACDecoder>(new ALACDecoder());
CHECKCA(m_decoder->Init(&alac[0], alac.size()));
setRange(0, m_file.GetTrackDuration(m_track_id));

Expand Down
3 changes: 1 addition & 2 deletions alacsrc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <ALACDecoder.h>
#include "shared_ptr.h"
#include "iointer.h"
#include "mp4v2wrapper.h"

Expand All @@ -20,7 +19,7 @@ class ALACSource: public ITagParser, public PartialSource<ALACSource>
};
uint32_t m_track_id;
uint64_t m_position;
x::shared_ptr<ALACDecoder> m_decoder;
std::shared_ptr<ALACDecoder> m_decoder;
std::map<uint32_t, std::wstring> m_tags;
std::vector<uint32_t> m_chanmap;
AudioStreamBasicDescription m_format;
Expand Down
2 changes: 1 addition & 1 deletion chanmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void GetAACChannelMap(uint32_t bitmap, std::vector<uint32_t> *result)

} // namespace

ChannelMapper::ChannelMapper(const x::shared_ptr<ISource> &source,
ChannelMapper::ChannelMapper(const std::shared_ptr<ISource> &source,
const std::vector<uint32_t> &chanmap,
uint32_t bitmap)
: DelegatingSource(source)
Expand Down
2 changes: 1 addition & 1 deletion chanmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ChannelMapper: public DelegatingSource {
std::vector<uint32_t> m_chanmap;
std::vector<uint32_t> m_layout;
public:
ChannelMapper(const x::shared_ptr<ISource> &source,
ChannelMapper(const std::shared_ptr<ISource> &source,
const std::vector<uint32_t> &chanmap, uint32_t bitmap=0);
const std::vector<uint32_t> *getChannels() const
{
Expand Down
Loading

0 comments on commit 77961a2

Please sign in to comment.