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
56a7fcf1
Commit
56a7fcf1
authored
Jan 13, 2014
by
Andrée Ekroth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encoder/shine: remove unnecessary buffer
Now writes to the de-interleaved buffers directly, instead of writing to an intermediate fifo buffer. Fix indentation and 80 char width lines.
parent
8cd15a02
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
42 deletions
+44
-42
ShineEncoderPlugin.cxx
src/encoder/ShineEncoderPlugin.cxx
+44
-42
No files found.
src/encoder/ShineEncoderPlugin.cxx
View file @
56a7fcf1
...
@@ -45,26 +45,19 @@ struct ShineEncoder {
...
@@ -45,26 +45,19 @@ struct ShineEncoder {
shine_config_t
config
;
shine_config_t
config
;
uint16_t
frame_size
;
size_t
frame_size
;
int16_t
buffer
[
SHINE_MAX_SAMPLES
*
CHANNELS
];
size_t
input_pos
;
int16_t
channels
[
CHANNELS
][
SHINE_MAX_SAMPLES
];
int16_t
*
stereo
[
CHANNELS
];
int16_t
*
stereo
[
CHANNELS
];
Manual
<
DynamicFifoBuffer
<
int16_t
>>
input_buffer
;
size_t
input_size
;
Manual
<
DynamicFifoBuffer
<
uint8_t
>>
output_buffer
;
Manual
<
DynamicFifoBuffer
<
uint8_t
>>
output_buffer
;
ShineEncoder
()
ShineEncoder
()
:
encoder
(
shine_encoder_plugin
){}
:
encoder
(
shine_encoder_plugin
),
stereo
{
channels
[
0
],
channels
[
1
]
},
input_size
(
0
)
{}
bool
Configure
(
const
config_param
&
param
,
Error
&
error
);
bool
Configure
(
const
config_param
&
param
,
Error
&
error
);
bool
Setup
(
Error
&
error
);
bool
Setup
(
Error
&
error
);
bool
WriteChunk
s
(
bool
flush
,
Error
&
error
);
bool
WriteChunk
(
bool
flush
,
Error
&
error
);
};
};
static
constexpr
Domain
shine_encoder_domain
(
"shine_encoder"
);
static
constexpr
Domain
shine_encoder_domain
(
"shine_encoder"
);
...
@@ -105,14 +98,16 @@ shine_encoder_finish(Encoder *_encoder)
...
@@ -105,14 +98,16 @@ shine_encoder_finish(Encoder *_encoder)
inline
bool
inline
bool
ShineEncoder
::
Setup
(
Error
&
error
)
ShineEncoder
::
Setup
(
Error
&
error
)
{
{
input_size
=
0
;
config
.
mpeg
.
mode
=
audio_format
.
channels
==
2
?
STEREO
:
MONO
;
config
.
mpeg
.
mode
=
audio_format
.
channels
==
2
?
STEREO
:
MONO
;
config
.
wave
.
samplerate
=
audio_format
.
sample_rate
;
config
.
wave
.
samplerate
=
audio_format
.
sample_rate
;
config
.
wave
.
channels
=
audio_format
.
channels
==
2
?
PCM_STEREO
:
PCM_MONO
;
config
.
wave
.
channels
=
audio_format
.
channels
==
2
?
PCM_STEREO
:
PCM_MONO
;
if
(
shine_check_config
(
config
.
wave
.
samplerate
,
config
.
mpeg
.
bitr
)
<
0
)
{
if
(
shine_check_config
(
config
.
wave
.
samplerate
,
config
.
mpeg
.
bitr
)
<
0
)
{
error
.
Format
(
config_domain
,
error
.
Format
(
config_domain
,
"error configuring shine. samplerate %d and bitrate %d configuration not supported."
,
"error configuring shine. "
"samplerate %d and bitrate %d configuration"
" not supported."
,
config
.
wave
.
samplerate
,
config
.
wave
.
samplerate
,
config
.
mpeg
.
bitr
);
config
.
mpeg
.
bitr
);
...
@@ -145,7 +140,10 @@ shine_encoder_open(Encoder *_encoder, AudioFormat &audio_format, Error &error)
...
@@ -145,7 +140,10 @@ shine_encoder_open(Encoder *_encoder, AudioFormat &audio_format, Error &error)
if
(
!
encoder
->
Setup
(
error
))
if
(
!
encoder
->
Setup
(
error
))
return
false
;
return
false
;
encoder
->
input_buffer
.
Construct
(
BUFFER_INIT_SIZE
);
encoder
->
stereo
[
0
]
=
new
int16_t
[
encoder
->
frame_size
];
encoder
->
stereo
[
1
]
=
new
int16_t
[
encoder
->
frame_size
];
encoder
->
input_pos
=
0
;
encoder
->
output_buffer
.
Construct
(
BUFFER_INIT_SIZE
);
encoder
->
output_buffer
.
Construct
(
BUFFER_INIT_SIZE
);
return
true
;
return
true
;
...
@@ -157,42 +155,31 @@ shine_encoder_close(Encoder *_encoder)
...
@@ -157,42 +155,31 @@ shine_encoder_close(Encoder *_encoder)
ShineEncoder
*
encoder
=
(
ShineEncoder
*
)
_encoder
;
ShineEncoder
*
encoder
=
(
ShineEncoder
*
)
_encoder
;
shine_close
(
encoder
->
shine
);
shine_close
(
encoder
->
shine
);
encoder
->
input_buffer
.
Destruct
();
delete
[]
encoder
->
stereo
[
0
];
delete
[]
encoder
->
stereo
[
1
];
encoder
->
output_buffer
.
Destruct
();
encoder
->
output_buffer
.
Destruct
();
}
}
bool
bool
ShineEncoder
::
WriteChunk
s
(
bool
flush
,
gcc_unused
Error
&
error
)
ShineEncoder
::
WriteChunk
(
bool
flush
,
gcc_unused
Error
&
error
)
{
{
const
size_t
chunk_size
=
frame_size
*
audio_format
.
channels
;
if
(
flush
||
input_pos
==
frame_size
)
{
/*
* shine requires data in specific sizes, therefore we need to
* buffer the received data and encode in chunks.
*/
while
(
input_size
>=
chunk_size
||
(
flush
&&
input_size
>
0
))
{
long
written
;
long
written
;
const
size_t
read
=
input_buffer
->
Read
(
buffer
,
chunk_size
);
input_size
-=
read
;
/* de-interleave data */
for
(
size_t
i
=
0
;
i
<
read
/
audio_format
.
channels
;
i
++
)
{
channels
[
0
][
i
]
=
buffer
[
i
*
audio_format
.
channels
];
channels
[
1
][
i
]
=
buffer
[
i
*
audio_format
.
channels
+
1
];
}
if
(
flush
)
{
if
(
flush
)
{
/* fill remaining with 0s */
/* fill remaining with 0s */
for
(
size_t
i
=
read
/
audio_format
.
channels
;
i
<
frame_size
;
i
++
)
{
for
(
;
input_pos
<
frame_size
;
input_pos
++
)
{
channels
[
0
][
i
]
=
channels
[
1
][
i
]
=
0
;
stereo
[
0
][
input_pos
]
=
stereo
[
1
][
input_pos
]
=
0
;
}
}
}
}
const
uint8_t
*
out
=
shine_encode_buffer
(
shine
,
stereo
,
&
written
);
const
uint8_t
*
out
=
shine_encode_buffer
(
shine
,
stereo
,
&
written
);
if
(
written
>
0
)
if
(
written
>
0
)
output_buffer
->
Append
((
const
uint8_t
*
)
out
,
written
);
output_buffer
->
Append
(
out
,
written
);
input_pos
=
0
;
}
}
return
true
;
return
true
;
...
@@ -205,11 +192,25 @@ shine_encoder_write(Encoder *_encoder,
...
@@ -205,11 +192,25 @@ shine_encoder_write(Encoder *_encoder,
{
{
ShineEncoder
*
encoder
=
(
ShineEncoder
*
)
_encoder
;
ShineEncoder
*
encoder
=
(
ShineEncoder
*
)
_encoder
;
const
int16_t
*
data
=
(
const
int16_t
*
)
_data
;
const
int16_t
*
data
=
(
const
int16_t
*
)
_data
;
length
/=
sizeof
(
*
data
)
*
encoder
->
audio_format
.
channels
;
size_t
written
=
0
;
/* write all data to de-interleaved buffers */
while
(
written
<
length
)
{
for
(;
written
<
length
&&
encoder
->
input_pos
<
encoder
->
frame_size
;
written
++
,
encoder
->
input_pos
++
)
{
const
size_t
base
=
written
*
encoder
->
audio_format
.
channels
;
encoder
->
stereo
[
0
][
encoder
->
input_pos
]
=
data
[
base
];
encoder
->
stereo
[
1
][
encoder
->
input_pos
]
=
data
[
base
+
1
];
}
/* write if chunk is filled */
encoder
->
WriteChunk
(
false
,
error
);
}
encoder
->
input_buffer
->
Append
(
data
,
length
/
sizeof
(
*
data
));
return
true
;
encoder
->
input_size
+=
length
/
sizeof
(
*
data
);
return
encoder
->
WriteChunks
(
false
,
error
);
}
}
static
bool
static
bool
...
@@ -218,7 +219,8 @@ shine_encoder_flush(Encoder *_encoder, gcc_unused Error &error)
...
@@ -218,7 +219,8 @@ shine_encoder_flush(Encoder *_encoder, gcc_unused Error &error)
ShineEncoder
*
encoder
=
(
ShineEncoder
*
)
_encoder
;
ShineEncoder
*
encoder
=
(
ShineEncoder
*
)
_encoder
;
long
written
;
long
written
;
encoder
->
WriteChunks
(
true
,
error
);
/* flush buffers and flush shine */
encoder
->
WriteChunk
(
true
,
error
);
const
uint8_t
*
data
=
shine_flush
(
encoder
->
shine
,
&
written
);
const
uint8_t
*
data
=
shine_flush
(
encoder
->
shine
,
&
written
);
if
(
written
>
0
)
if
(
written
>
0
)
...
...
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