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
e9b71a0d
Commit
e9b71a0d
authored
Jan 04, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MusicChunk: move functions to methods
parent
efbfe66f
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
89 additions
and
104 deletions
+89
-104
DecoderAPI.cxx
src/DecoderAPI.cxx
+5
-5
DecoderInternal.cxx
src/DecoderInternal.cxx
+1
-1
MusicChunk.cxx
src/MusicChunk.cxx
+25
-43
MusicChunk.hxx
src/MusicChunk.hxx
+50
-47
MusicPipe.cxx
src/MusicPipe.cxx
+3
-3
OutputAll.cxx
src/OutputAll.cxx
+1
-1
OutputThread.cxx
src/OutputThread.cxx
+2
-2
PlayerThread.cxx
src/PlayerThread.cxx
+2
-2
No files found.
src/DecoderAPI.cxx
View file @
e9b71a0d
...
@@ -429,10 +429,10 @@ decoder_data(struct decoder *decoder,
...
@@ -429,10 +429,10 @@ decoder_data(struct decoder *decoder,
return
dc
->
command
;
return
dc
->
command
;
}
}
void
*
dest
=
music_chunk_write
(
chunk
,
&
dc
->
out_audio_format
,
void
*
dest
=
chunk
->
Write
(
dc
->
out_audio_format
,
decoder
->
timestamp
-
decoder
->
timestamp
-
dc
->
song
->
start_ms
/
1000.0
,
dc
->
song
->
start_ms
/
1000.0
,
kbit_rate
,
&
nbytes
);
kbit_rate
,
&
nbytes
);
if
(
dest
==
NULL
)
{
if
(
dest
==
NULL
)
{
/* the chunk is full, flush it */
/* the chunk is full, flush it */
decoder_flush_chunk
(
decoder
);
decoder_flush_chunk
(
decoder
);
...
@@ -451,7 +451,7 @@ decoder_data(struct decoder *decoder,
...
@@ -451,7 +451,7 @@ decoder_data(struct decoder *decoder,
/* expand the music pipe chunk */
/* expand the music pipe chunk */
full
=
music_chunk_expand
(
chunk
,
&
dc
->
out_audio_format
,
nbytes
);
full
=
chunk
->
Expand
(
dc
->
out_audio_format
,
nbytes
);
if
(
full
)
{
if
(
full
)
{
/* the chunk is full, flush it */
/* the chunk is full, flush it */
decoder_flush_chunk
(
decoder
);
decoder_flush_chunk
(
decoder
);
...
...
src/DecoderInternal.cxx
View file @
e9b71a0d
...
@@ -88,7 +88,7 @@ decoder_flush_chunk(struct decoder *decoder)
...
@@ -88,7 +88,7 @@ decoder_flush_chunk(struct decoder *decoder)
assert
(
decoder
!=
NULL
);
assert
(
decoder
!=
NULL
);
assert
(
decoder
->
chunk
!=
NULL
);
assert
(
decoder
->
chunk
!=
NULL
);
if
(
music_chunk_is_empty
(
decoder
->
chunk
))
if
(
decoder
->
chunk
->
IsEmpty
(
))
music_buffer_return
(
dc
->
buffer
,
decoder
->
chunk
);
music_buffer_return
(
dc
->
buffer
,
decoder
->
chunk
);
else
else
music_pipe_push
(
dc
->
pipe
,
decoder
->
chunk
);
music_pipe_push
(
dc
->
pipe
,
decoder
->
chunk
);
...
...
src/MusicChunk.cxx
View file @
e9b71a0d
...
@@ -27,79 +27,61 @@ extern "C" {
...
@@ -27,79 +27,61 @@ extern "C" {
#include <assert.h>
#include <assert.h>
void
music_chunk
::~
music_chunk
()
music_chunk_init
(
struct
music_chunk
*
chunk
)
{
{
chunk
->
other
=
NULL
;
if
(
tag
!=
NULL
)
chunk
->
length
=
0
;
tag_free
(
tag
);
chunk
->
tag
=
NULL
;
chunk
->
replay_gain_serial
=
0
;
}
void
music_chunk_free
(
struct
music_chunk
*
chunk
)
{
if
(
chunk
->
tag
!=
NULL
)
tag_free
(
chunk
->
tag
);
}
}
#ifndef NDEBUG
#ifndef NDEBUG
bool
bool
music_chunk_check_format
(
const
struct
music_chunk
*
chunk
,
music_chunk
::
CheckFormat
(
const
struct
audio_format
&
other_format
)
const
const
struct
audio_format
*
audio_format
)
{
{
assert
(
chunk
!=
NULL
);
assert
(
audio_format_valid
(
&
other_format
));
assert
(
audio_format
!=
NULL
);
assert
(
audio_format_valid
(
audio_format
));
return
chunk
->
length
==
0
||
return
length
==
0
||
audio_format_equals
(
&
chunk
->
audio_format
,
audio
_format
);
audio_format_equals
(
&
audio_format
,
&
other
_format
);
}
}
#endif
#endif
void
*
void
*
music_chunk_write
(
struct
music_chunk
*
chunk
,
music_chunk
::
Write
(
const
struct
audio_format
&
af
,
const
struct
audio_format
*
audio_format
,
float
data_time
,
uint16_t
_bit_rate
,
float
data_time
,
uint16_t
bit_rate
,
size_t
*
max_length_r
)
size_t
*
max_length_r
)
{
{
const
size_t
frame_size
=
audio_format_frame_size
(
audio_format
);
assert
(
CheckFormat
(
af
));
size_t
num_frames
;
assert
(
length
==
0
||
audio_format_valid
(
&
audio_format
));
assert
(
music_chunk_check_format
(
chunk
,
audio_format
));
assert
(
chunk
->
length
==
0
||
audio_format_valid
(
&
chunk
->
audio_format
));
if
(
chunk
->
length
==
0
)
{
if
(
length
==
0
)
{
/* if the chunk is empty, nobody has set bitRate and
/* if the chunk is empty, nobody has set bitRate and
times yet */
times yet */
chunk
->
bit_rate
=
bit_rate
;
bit_rate
=
_
bit_rate
;
chunk
->
times
=
data_time
;
times
=
data_time
;
}
}
num_frames
=
(
sizeof
(
chunk
->
data
)
-
chunk
->
length
)
/
frame_size
;
const
size_t
frame_size
=
audio_format_frame_size
(
&
af
);
size_t
num_frames
=
(
sizeof
(
data
)
-
length
)
/
frame_size
;
if
(
num_frames
==
0
)
if
(
num_frames
==
0
)
return
NULL
;
return
NULL
;
#ifndef NDEBUG
#ifndef NDEBUG
chunk
->
audio_format
=
*
audio_format
;
audio_format
=
af
;
#endif
#endif
*
max_length_r
=
num_frames
*
frame_size
;
*
max_length_r
=
num_frames
*
frame_size
;
return
chunk
->
data
+
chunk
->
length
;
return
data
+
length
;
}
}
bool
bool
music_chunk_expand
(
struct
music_chunk
*
chunk
,
music_chunk
::
Expand
(
const
struct
audio_format
&
af
,
size_t
_length
)
const
struct
audio_format
*
audio_format
,
size_t
length
)
{
{
const
size_t
frame_size
=
audio_format_frame_size
(
audio_format
);
const
size_t
frame_size
=
audio_format_frame_size
(
&
af
);
assert
(
chunk
!=
NULL
);
assert
(
length
+
_length
<=
sizeof
(
data
));
assert
(
chunk
->
length
+
length
<=
sizeof
(
chunk
->
data
));
assert
(
audio_format_equals
(
&
audio_format
,
&
af
));
assert
(
audio_format_equals
(
&
chunk
->
audio_format
,
audio_format
));
chunk
->
length
+=
length
;
length
+=
_
length
;
return
chunk
->
length
+
frame_size
>
sizeof
(
chunk
->
data
);
return
length
+
frame_size
>
sizeof
(
data
);
}
}
src/MusicChunk.hxx
View file @
e9b71a0d
...
@@ -91,60 +91,63 @@ struct music_chunk {
...
@@ -91,60 +91,63 @@ struct music_chunk {
#ifndef NDEBUG
#ifndef NDEBUG
struct
audio_format
audio_format
;
struct
audio_format
audio_format
;
#endif
#endif
};
void
music_chunk
()
music_chunk_init
(
struct
music_chunk
*
chunk
);
:
other
(
nullptr
),
length
(
0
),
tag
(
nullptr
),
replay_gain_serial
(
0
)
{}
void
~
music_chunk
();
music_chunk_free
(
struct
music_chunk
*
chunk
);
static
inline
bool
bool
IsEmpty
()
const
{
music_chunk_is_empty
(
const
struct
music_chunk
*
chunk
)
return
length
==
0
&&
tag
==
nullptr
;
{
}
return
chunk
->
length
==
0
&&
chunk
->
tag
==
NULL
;
}
#ifndef NDEBUG
#ifndef NDEBUG
/**
/**
* Checks if the audio format if the chunk is equal to the specified
* Checks if the audio format if the chunk is equal to the
* audio_format.
* specified audio_format.
*/
*/
bool
gcc_pure
music_chunk_check_format
(
const
struct
music_chunk
*
chunk
,
bool
CheckFormat
(
const
struct
audio_format
&
audio_format
)
const
;
const
struct
audio_format
*
audio_format
);
#endif
#endif
/**
/**
* Prepares appending to the music chunk. Returns a buffer where you
* Prepares appending to the music chunk. Returns a buffer
* may write into. After you are finished, call music_chunk_expand().
* where you may write into. After you are finished, call
*
* music_chunk_expand().
* @param chunk the music_chunk object
*
* @param audio_format the audio format for the appended data; mus
t
* @param chunk the music_chunk objec
t
* stay the same for the life cycle of this chunk
* @param audio_format the audio format for the appended data;
* @param data_time the time within the song
* must stay the same for the life cycle of this chunk
* @param bit_rate the current bit rate of the source file
* @param data_time the time within the song
* @param max_length_r the maximum write length is returned her
e
* @param bit_rate the current bit rate of the source fil
e
* @return a writable buffer, or NULL if the chunk is full
* @param max_length_r the maximum write length is returned
*/
* here
void
*
* @return a writable buffer, or NULL if the chunk is full
music_chunk_write
(
struct
music_chunk
*
chunk
,
*/
const
struct
audio_format
*
audio_format
,
void
*
Write
(
const
struct
audio_format
&
af
,
float
data_time
,
uint16_t
bit_rate
,
float
data_time
,
uint16_t
bit_rate
,
size_t
*
max_length_r
);
size_t
*
max_length_r
);
/**
/**
* Increases the length of the chunk after the caller has written to
* Increases the length of the chunk after the caller has written to
* the buffer returned by music_chunk_write().
* the buffer returned by music_chunk_write().
*
*
* @param chunk the music_chunk object
* @param chunk the music_chunk object
* @param audio_format the audio format for the appended data; must
* @param audio_format the audio format for the appended data; must
* stay the same for the life cycle of this chunk
* stay the same for the life cycle of this chunk
* @param length the number of bytes which were appended
* @param length the number of bytes which were appended
* @return true if the chunk is full
* @return true if the chunk is full
*/
*/
bool
bool
Expand
(
const
struct
audio_format
&
af
,
size_t
length
);
music_chunk_expand
(
struct
music_chunk
*
chunk
,
};
const
struct
audio_format
*
audio_format
,
size_t
length
);
void
music_chunk_init
(
struct
music_chunk
*
chunk
);
void
music_chunk_free
(
struct
music_chunk
*
chunk
);
#endif
#endif
src/MusicPipe.cxx
View file @
e9b71a0d
...
@@ -111,7 +111,7 @@ music_pipe_shift(struct music_pipe *mp)
...
@@ -111,7 +111,7 @@ music_pipe_shift(struct music_pipe *mp)
struct
music_chunk
*
chunk
=
mp
->
head
;
struct
music_chunk
*
chunk
=
mp
->
head
;
if
(
chunk
!=
NULL
)
{
if
(
chunk
!=
NULL
)
{
assert
(
!
music_chunk_is_empty
(
chunk
));
assert
(
!
chunk
->
IsEmpty
(
));
mp
->
head
=
chunk
->
next
;
mp
->
head
=
chunk
->
next
;
--
mp
->
size
;
--
mp
->
size
;
...
@@ -150,14 +150,14 @@ music_pipe_clear(struct music_pipe *mp, struct music_buffer *buffer)
...
@@ -150,14 +150,14 @@ music_pipe_clear(struct music_pipe *mp, struct music_buffer *buffer)
void
void
music_pipe_push
(
struct
music_pipe
*
mp
,
struct
music_chunk
*
chunk
)
music_pipe_push
(
struct
music_pipe
*
mp
,
struct
music_chunk
*
chunk
)
{
{
assert
(
!
music_chunk_is_empty
(
chunk
));
assert
(
!
chunk
->
IsEmpty
(
));
assert
(
chunk
->
length
==
0
||
audio_format_valid
(
&
chunk
->
audio_format
));
assert
(
chunk
->
length
==
0
||
audio_format_valid
(
&
chunk
->
audio_format
));
const
ScopeLock
protect
(
mp
->
mutex
);
const
ScopeLock
protect
(
mp
->
mutex
);
assert
(
mp
->
size
>
0
||
!
audio_format_defined
(
&
mp
->
audio_format
));
assert
(
mp
->
size
>
0
||
!
audio_format_defined
(
&
mp
->
audio_format
));
assert
(
!
audio_format_defined
(
&
mp
->
audio_format
)
||
assert
(
!
audio_format_defined
(
&
mp
->
audio_format
)
||
music_chunk_check_format
(
chunk
,
&
mp
->
audio_format
));
chunk
->
CheckFormat
(
mp
->
audio_format
));
#ifndef NDEBUG
#ifndef NDEBUG
if
(
!
audio_format_defined
(
&
mp
->
audio_format
)
&&
chunk
->
length
>
0
)
if
(
!
audio_format_defined
(
&
mp
->
audio_format
)
&&
chunk
->
length
>
0
)
...
...
src/OutputAll.cxx
View file @
e9b71a0d
...
@@ -282,7 +282,7 @@ audio_output_all_play(struct music_chunk *chunk, GError **error_r)
...
@@ -282,7 +282,7 @@ audio_output_all_play(struct music_chunk *chunk, GError **error_r)
assert
(
g_music_buffer
!=
NULL
);
assert
(
g_music_buffer
!=
NULL
);
assert
(
g_mp
!=
NULL
);
assert
(
g_mp
!=
NULL
);
assert
(
chunk
!=
NULL
);
assert
(
chunk
!=
NULL
);
assert
(
music_chunk_check_format
(
chunk
,
&
input_audio_format
));
assert
(
chunk
->
CheckFormat
(
input_audio_format
));
ret
=
audio_output_all_update
();
ret
=
audio_output_all_update
();
if
(
!
ret
)
{
if
(
!
ret
)
{
...
...
src/OutputThread.cxx
View file @
e9b71a0d
...
@@ -327,8 +327,8 @@ ao_chunk_data(struct audio_output *ao, const struct music_chunk *chunk,
...
@@ -327,8 +327,8 @@ ao_chunk_data(struct audio_output *ao, const struct music_chunk *chunk,
size_t
*
length_r
)
size_t
*
length_r
)
{
{
assert
(
chunk
!=
NULL
);
assert
(
chunk
!=
NULL
);
assert
(
!
music_chunk_is_empty
(
chunk
));
assert
(
!
chunk
->
IsEmpty
(
));
assert
(
music_chunk_check_format
(
chunk
,
&
ao
->
in_audio_format
));
assert
(
chunk
->
CheckFormat
(
ao
->
in_audio_format
));
const
void
*
data
=
chunk
->
data
;
const
void
*
data
=
chunk
->
data
;
size_t
length
=
chunk
->
length
;
size_t
length
=
chunk
->
length
;
...
...
src/PlayerThread.cxx
View file @
e9b71a0d
...
@@ -686,7 +686,7 @@ play_chunk(struct player_control *pc,
...
@@ -686,7 +686,7 @@ play_chunk(struct player_control *pc,
const
struct
audio_format
*
format
,
const
struct
audio_format
*
format
,
GError
**
error_r
)
GError
**
error_r
)
{
{
assert
(
music_chunk_check_format
(
chunk
,
format
));
assert
(
chunk
->
CheckFormat
(
*
format
));
if
(
chunk
->
tag
!=
NULL
)
if
(
chunk
->
tag
!=
NULL
)
update_song_tag
(
song
,
chunk
->
tag
);
update_song_tag
(
song
,
chunk
->
tag
);
...
@@ -766,7 +766,7 @@ play_next_chunk(struct player *player)
...
@@ -766,7 +766,7 @@ play_next_chunk(struct player *player)
chunk
->
mix_ratio
=
nan
(
""
);
chunk
->
mix_ratio
=
nan
(
""
);
}
}
if
(
music_chunk_is_empty
(
other_chunk
))
{
if
(
other_chunk
->
IsEmpty
(
))
{
/* the "other" chunk was a music_chunk
/* the "other" chunk was a music_chunk
which had only a tag, but no music
which had only a tag, but no music
data - we cannot cross-fade that;
data - we cannot cross-fade that;
...
...
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