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
fec6aac0
Commit
fec6aac0
authored
May 11, 2021
by
GrimReaperFloof
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code deduplication: move mod_loadfile() into ModCommon.cxx
parent
541c31c8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
59 deletions
+7
-59
OpenmptDecoderPlugin.cxx
src/decoder/plugins/OpenmptDecoderPlugin.cxx
+3
-58
meson.build
src/decoder/plugins/meson.build
+4
-1
No files found.
src/decoder/plugins/OpenmptDecoderPlugin.cxx
View file @
fec6aac0
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
*/
*/
#include "OpenmptDecoderPlugin.hxx"
#include "OpenmptDecoderPlugin.hxx"
#include "ModCommon.hxx"
#include "../DecoderAPI.hxx"
#include "../DecoderAPI.hxx"
#include "input/InputStream.hxx"
#include "input/InputStream.hxx"
#include "tag/Handler.hxx"
#include "tag/Handler.hxx"
...
@@ -35,7 +36,6 @@
...
@@ -35,7 +36,6 @@
static
constexpr
Domain
openmpt_domain
(
"openmpt"
);
static
constexpr
Domain
openmpt_domain
(
"openmpt"
);
static
constexpr
size_t
OPENMPT_FRAME_SIZE
=
4096
;
static
constexpr
size_t
OPENMPT_FRAME_SIZE
=
4096
;
static
constexpr
size_t
OPENMPT_PREALLOC_BLOCK
=
256
*
1024
;
static
constexpr
int32_t
OPENMPT_SAMPLE_RATE
=
48000
;
static
constexpr
int32_t
OPENMPT_SAMPLE_RATE
=
48000
;
static
int
openmpt_stereo_separation
;
static
int
openmpt_stereo_separation
;
...
@@ -60,68 +60,13 @@ openmpt_decoder_init(const ConfigBlock &block)
...
@@ -60,68 +60,13 @@ openmpt_decoder_init(const ConfigBlock &block)
return
true
;
return
true
;
}
}
static
WritableBuffer
<
uint8_t
>
mod_loadfile
(
DecoderClient
*
client
,
InputStream
&
is
)
{
//known/unknown size, preallocate array, lets read in chunks
const
bool
is_stream
=
!
is
.
KnownSize
();
WritableBuffer
<
uint8_t
>
buffer
;
if
(
is_stream
)
buffer
.
size
=
OPENMPT_PREALLOC_BLOCK
;
else
{
const
auto
size
=
is
.
GetSize
();
if
(
size
==
0
)
{
LogWarning
(
openmpt_domain
,
"file is empty"
);
return
nullptr
;
}
buffer
.
size
=
size
;
}
buffer
.
data
=
new
uint8_t
[
buffer
.
size
];
uint8_t
*
const
end
=
buffer
.
end
();
uint8_t
*
p
=
buffer
.
begin
();
while
(
true
)
{
size_t
ret
=
decoder_read
(
client
,
is
,
p
,
end
-
p
);
if
(
ret
==
0
)
{
if
(
is
.
LockIsEOF
())
/* end of file */
break
;
/* I/O error - skip this song */
delete
[]
buffer
.
data
;
buffer
.
data
=
nullptr
;
return
buffer
;
}
p
+=
ret
;
if
(
p
==
end
)
{
if
(
!
is_stream
)
break
;
LogWarning
(
openmpt_domain
,
"stream too large"
);
delete
[]
buffer
.
data
;
buffer
.
data
=
nullptr
;
return
buffer
;
}
}
buffer
.
size
=
p
-
buffer
.
data
;
return
buffer
;
}
static
void
static
void
mod_decode
(
DecoderClient
&
client
,
InputStream
&
is
)
mod_decode
(
DecoderClient
&
client
,
InputStream
&
is
)
{
{
int
ret
;
int
ret
;
char
audio_buffer
[
OPENMPT_FRAME_SIZE
];
char
audio_buffer
[
OPENMPT_FRAME_SIZE
];
const
auto
buffer
=
mod_loadfile
(
&
client
,
is
);
const
auto
buffer
=
mod_loadfile
(
&
openmpt_domain
,
&
client
,
is
);
if
(
buffer
.
IsNull
())
{
if
(
buffer
.
IsNull
())
{
LogWarning
(
openmpt_domain
,
"could not load stream"
);
LogWarning
(
openmpt_domain
,
"could not load stream"
);
return
;
return
;
...
@@ -171,7 +116,7 @@ mod_decode(DecoderClient &client, InputStream &is)
...
@@ -171,7 +116,7 @@ mod_decode(DecoderClient &client, InputStream &is)
static
bool
static
bool
openmpt_scan_stream
(
InputStream
&
is
,
TagHandler
&
handler
)
noexcept
openmpt_scan_stream
(
InputStream
&
is
,
TagHandler
&
handler
)
noexcept
{
{
const
auto
buffer
=
mod_loadfile
(
nullptr
,
is
);
const
auto
buffer
=
mod_loadfile
(
&
openmpt_domain
,
nullptr
,
is
);
if
(
buffer
.
IsNull
())
{
if
(
buffer
.
IsNull
())
{
LogWarning
(
openmpt_domain
,
"could not load stream"
);
LogWarning
(
openmpt_domain
,
"could not load stream"
);
return
false
;
return
false
;
...
...
src/decoder/plugins/meson.build
View file @
fec6aac0
...
@@ -111,7 +111,10 @@ endif
...
@@ -111,7 +111,10 @@ endif
libopenmpt_dep = dependency('libopenmpt', required: get_option('openmpt'))
libopenmpt_dep = dependency('libopenmpt', required: get_option('openmpt'))
decoder_features.set('ENABLE_OPENMPT', libopenmpt_dep.found())
decoder_features.set('ENABLE_OPENMPT', libopenmpt_dep.found())
if libopenmpt_dep.found()
if libopenmpt_dep.found()
decoder_plugins_sources += 'OpenmptDecoderPlugin.cxx'
decoder_plugins_sources += [
'OpenmptDecoderPlugin.cxx',
'ModCommon.cxx'
]
endif
endif
libmpcdec_dep = c_compiler.find_library('mpcdec', required: get_option('mpcdec'))
libmpcdec_dep = c_compiler.find_library('mpcdec', required: get_option('mpcdec'))
...
...
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