Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
d8a74802
Commit
d8a74802
authored
5 years ago
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apple/StringRef: new library wrapping CFStringRef
parent
191919d1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
13 deletions
+80
-13
StringRef.hxx
src/apple/StringRef.hxx
+73
-0
OSXOutputPlugin.cxx
src/output/plugins/OSXOutputPlugin.cxx
+7
-13
No files found.
src/apple/StringRef.hxx
0 → 100644
View file @
d8a74802
/*
* Copyright 2020 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef APPLE_STRING_REF_HXX
#define APPLE_STRING_REF_HXX
#include <CoreFoundation/CFString.h>
#include <utility>
namespace
Apple
{
class
StringRef
{
CFStringRef
ref
=
nullptr
;
public
:
explicit
StringRef
(
CFStringRef
_ref
)
noexcept
:
ref
(
_ref
)
{}
StringRef
(
StringRef
&&
src
)
noexcept
:
ref
(
std
::
exchange
(
src
.
ref
,
nullptr
))
{}
~
StringRef
()
noexcept
{
if
(
ref
)
CFRelease
(
ref
);
}
StringRef
&
operator
=
(
StringRef
&&
src
)
noexcept
{
using
std
::
swap
;
swap
(
ref
,
src
.
ref
);
return
*
this
;
}
operator
bool
()
const
noexcept
{
return
ref
!=
nullptr
;
}
bool
GetCString
(
char
*
buffer
,
std
::
size_t
size
,
CFStringEncoding
encoding
=
kCFStringEncodingUTF8
)
const
noexcept
{
return
CFStringGetCString
(
ref
,
buffer
,
size
,
encoding
);
}
};
}
// namespace Apple
#endif
This diff is collapsed.
Click to expand it.
src/output/plugins/OSXOutputPlugin.cxx
View file @
d8a74802
...
...
@@ -17,11 +17,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "apple/StringRef.hxx"
#include "config.h"
#include "OSXOutputPlugin.hxx"
#include "../OutputAPI.hxx"
#include "mixer/MixerList.hxx"
#include "util/ScopeExit.hxx"
#include "util/RuntimeError.hxx"
#include "util/Domain.hxx"
#include "util/Manual.hxx"
...
...
@@ -111,15 +111,13 @@ static void
osx_os_status_to_cstring
(
OSStatus
status
,
char
*
str
,
size_t
size
)
{
CFErrorRef
cferr
=
CFErrorCreate
(
nullptr
,
kCFErrorDomainOSStatus
,
status
,
nullptr
);
CFStringRef
cfstr
=
CFErrorCopyDescription
(
cferr
);
if
(
!
CFStringGetCString
(
cfstr
,
str
,
size
,
kCFStringEncodingUTF8
))
{
const
Apple
::
StringRef
cfstr
(
CFErrorCopyDescription
(
cferr
)
);
if
(
!
cfstr
.
GetCString
(
str
,
size
))
{
/* conversion failed, return empty string */
*
str
=
'\0'
;
}
if
(
cferr
)
CFRelease
(
cferr
);
if
(
cfstr
)
CFRelease
(
cfstr
);
}
static
bool
...
...
@@ -629,12 +627,6 @@ osx_output_set_device(OSXOutput *oo)
{
OSStatus
status
;
UInt32
size
,
numdevices
;
CFStringRef
cfname
=
nullptr
;
AtScopeExit
(
&
cfname
)
{
if
(
cfname
)
CFRelease
(
cfname
);
};
if
(
oo
->
component_subtype
!=
kAudioUnitSubType_HALOutput
)
return
;
...
...
@@ -678,6 +670,7 @@ osx_output_set_device(OSXOutput *oo)
unsigned
i
;
size
=
sizeof
(
CFStringRef
);
for
(
i
=
0
;
i
<
numdevices
;
i
++
)
{
CFStringRef
cfname
=
nullptr
;
status
=
AudioObjectGetPropertyData
(
deviceids
[
i
],
&
aopa_name
,
0
,
nullptr
,
&
size
,
&
cfname
);
...
...
@@ -690,9 +683,10 @@ osx_output_set_device(OSXOutput *oo)
errormsg
);
}
const
Apple
::
StringRef
cfname_
(
cfname
);
char
name
[
256
];
if
(
!
CFStringGetCString
(
cfname
,
name
,
sizeof
(
name
),
kCFStringEncodingUTF8
))
if
(
!
cfname_
.
GetCString
(
name
,
sizeof
(
name
)))
throw
std
::
runtime_error
(
"Unable to convert device name from CFStringRef to char*"
);
if
(
strcmp
(
oo
->
device_name
,
name
)
==
0
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment