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
a134f692
Commit
a134f692
authored
May 11, 2021
by
GrimReaperFloof
Committed by
Max Kellermann
May 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code deduplication: move mod_loadfile() into ModCommon.cxx
parent
d7475767
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
64 deletions
+121
-64
ModCommon.cxx
src/decoder/plugins/ModCommon.cxx
+85
-0
ModCommon.hxx
src/decoder/plugins/ModCommon.hxx
+30
-0
ModplugDecoderPlugin.cxx
src/decoder/plugins/ModplugDecoderPlugin.cxx
+2
-63
meson.build
src/decoder/plugins/meson.build
+4
-1
No files found.
src/decoder/plugins/ModCommon.cxx
0 → 100644
View file @
a134f692
/*
* Copyright 2003-2021 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "ModCommon.hxx"
#include "Log.hxx"
static
constexpr
size_t
MOD_PREALLOC_BLOCK
=
256
*
1024
;
static
constexpr
offset_type
MOD_FILE_LIMIT
=
100
*
1024
*
1024
;
WritableBuffer
<
uint8_t
>
mod_loadfile
(
const
Domain
*
domain
,
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
=
MOD_PREALLOC_BLOCK
;
else
{
const
auto
size
=
is
.
GetSize
();
if
(
size
==
0
)
{
LogWarning
(
*
domain
,
"file is empty"
);
return
nullptr
;
}
if
(
size
>
MOD_FILE_LIMIT
)
{
LogWarning
(
*
domain
,
"file too large"
);
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
(
*
domain
,
"stream too large"
);
delete
[]
buffer
.
data
;
buffer
.
data
=
nullptr
;
return
buffer
;
}
}
buffer
.
size
=
p
-
buffer
.
data
;
return
buffer
;
}
src/decoder/plugins/ModCommon.hxx
0 → 100644
View file @
a134f692
/*
* Copyright 2003-2021 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_MOD_COMMON_HXX
#define MPD_MOD_COMMON_HXX
#include "../DecoderAPI.hxx"
#include "input/InputStream.hxx"
#include "util/WritableBuffer.hxx"
#include "util/Domain.hxx"
WritableBuffer
<
uint8_t
>
mod_loadfile
(
const
Domain
*
domain
,
DecoderClient
*
client
,
InputStream
&
is
);
#endif
src/decoder/plugins/ModplugDecoderPlugin.cxx
View file @
a134f692
...
...
@@ -18,6 +18,7 @@
*/
#include "ModplugDecoderPlugin.hxx"
#include "ModCommon.hxx"
#include "../DecoderAPI.hxx"
#include "input/InputStream.hxx"
#include "tag/Handler.hxx"
...
...
@@ -40,8 +41,6 @@
static
constexpr
Domain
modplug_domain
(
"modplug"
);
static
constexpr
size_t
MODPLUG_FRAME_SIZE
=
4096
;
static
constexpr
size_t
MODPLUG_PREALLOC_BLOCK
=
256
*
1024
;
static
constexpr
offset_type
MODPLUG_FILE_LIMIT
=
100
*
1024
*
1024
;
static
int
modplug_loop_count
;
static
unsigned
char
modplug_resampling_mode
;
...
...
@@ -71,70 +70,10 @@ modplug_decoder_init(const ConfigBlock &block)
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
=
MODPLUG_PREALLOC_BLOCK
;
else
{
const
auto
size
=
is
.
GetSize
();
if
(
size
==
0
)
{
LogWarning
(
modplug_domain
,
"file is empty"
);
return
nullptr
;
}
if
(
size
>
MODPLUG_FILE_LIMIT
)
{
LogWarning
(
modplug_domain
,
"file too large"
);
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
(
modplug_domain
,
"stream too large"
);
delete
[]
buffer
.
data
;
buffer
.
data
=
nullptr
;
return
buffer
;
}
}
buffer
.
size
=
p
-
buffer
.
data
;
return
buffer
;
}
static
ModPlugFile
*
LoadModPlugFile
(
DecoderClient
*
client
,
InputStream
&
is
)
{
const
auto
buffer
=
mod_loadfile
(
client
,
is
);
const
auto
buffer
=
mod_loadfile
(
&
modplug_domain
,
client
,
is
);
if
(
buffer
.
IsNull
())
{
LogWarning
(
modplug_domain
,
"could not load stream"
);
return
nullptr
;
...
...
src/decoder/plugins/meson.build
View file @
a134f692
...
...
@@ -102,7 +102,10 @@ endif
libmodplug_dep = dependency('libmodplug', required: get_option('modplug'))
decoder_features.set('ENABLE_MODPLUG', libmodplug_dep.found())
if libmodplug_dep.found()
decoder_plugins_sources += 'ModplugDecoderPlugin.cxx'
decoder_plugins_sources += [
'ModplugDecoderPlugin.cxx',
'ModCommon.cxx'
]
endif
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