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,
return
dc
->
command
;
}
void
*
dest
=
music_chunk_write
(
chunk
,
&
dc
->
out_audio_format
,
decoder
->
timestamp
-
dc
->
song
->
start_ms
/
1000.0
,
kbit_rate
,
&
nbytes
);
void
*
dest
=
chunk
->
Write
(
dc
->
out_audio_format
,
decoder
->
timestamp
-
dc
->
song
->
start_ms
/
1000.0
,
kbit_rate
,
&
nbytes
);
if
(
dest
==
NULL
)
{
/* the chunk is full, flush it */
decoder_flush_chunk
(
decoder
);
...
...
@@ -451,7 +451,7 @@ decoder_data(struct decoder *decoder,
/* 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
)
{
/* the chunk is full, flush it */
decoder_flush_chunk
(
decoder
);
...
...
src/DecoderInternal.cxx
View file @
e9b71a0d
...
...
@@ -88,7 +88,7 @@ decoder_flush_chunk(struct decoder *decoder)
assert
(
decoder
!=
NULL
);
assert
(
decoder
->
chunk
!=
NULL
);
if
(
music_chunk_is_empty
(
decoder
->
chunk
))
if
(
decoder
->
chunk
->
IsEmpty
(
))
music_buffer_return
(
dc
->
buffer
,
decoder
->
chunk
);
else
music_pipe_push
(
dc
->
pipe
,
decoder
->
chunk
);
...
...
src/MusicChunk.cxx
View file @
e9b71a0d
...
...
@@ -27,79 +27,61 @@ extern "C" {
#include <assert.h>
void
music_chunk_init
(
struct
music_chunk
*
chunk
)
music_chunk
::~
music_chunk
()
{
chunk
->
other
=
NULL
;
chunk
->
length
=
0
;
chunk
->
tag
=
NULL
;
chunk
->
replay_gain_serial
=
0
;
}
void
music_chunk_free
(
struct
music_chunk
*
chunk
)
{
if
(
chunk
->
tag
!=
NULL
)
tag_free
(
chunk
->
tag
);
if
(
tag
!=
NULL
)
tag_free
(
tag
);
}
#ifndef NDEBUG
bool
music_chunk_check_format
(
const
struct
music_chunk
*
chunk
,
const
struct
audio_format
*
audio_format
)
music_chunk
::
CheckFormat
(
const
struct
audio_format
&
other_format
)
const
{
assert
(
chunk
!=
NULL
);
assert
(
audio_format
!=
NULL
);
assert
(
audio_format_valid
(
audio_format
));
assert
(
audio_format_valid
(
&
other_format
));
return
chunk
->
length
==
0
||
audio_format_equals
(
&
chunk
->
audio_format
,
audio
_format
);
return
length
==
0
||
audio_format_equals
(
&
audio_format
,
&
other
_format
);
}
#endif
void
*
music_chunk_write
(
struct
music_chunk
*
chunk
,
const
struct
audio_format
*
audio_format
,
float
data_time
,
uint16_t
bit_rate
,
size_t
*
max_length_r
)
music_chunk
::
Write
(
const
struct
audio_format
&
af
,
float
data_time
,
uint16_t
_bit_rate
,
size_t
*
max_length_r
)
{
const
size_t
frame_size
=
audio_format_frame_size
(
audio_format
);
size_t
num_frames
;
assert
(
music_chunk_check_format
(
chunk
,
audio_format
));
assert
(
chunk
->
length
==
0
||
audio_format_valid
(
&
chunk
->
audio_format
));
assert
(
CheckFormat
(
af
));
assert
(
length
==
0
||
audio_format_valid
(
&
audio_format
));
if
(
chunk
->
length
==
0
)
{
if
(
length
==
0
)
{
/* if the chunk is empty, nobody has set bitRate and
times yet */
chunk
->
bit_rate
=
bit_rate
;
chunk
->
times
=
data_time
;
bit_rate
=
_
bit_rate
;
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
)
return
NULL
;
#ifndef NDEBUG
chunk
->
audio_format
=
*
audio_format
;
audio_format
=
af
;
#endif
*
max_length_r
=
num_frames
*
frame_size
;
return
chunk
->
data
+
chunk
->
length
;
return
data
+
length
;
}
bool
music_chunk_expand
(
struct
music_chunk
*
chunk
,
const
struct
audio_format
*
audio_format
,
size_t
length
)
music_chunk
::
Expand
(
const
struct
audio_format
&
af
,
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
(
chunk
->
length
+
length
<=
sizeof
(
chunk
->
data
));
assert
(
audio_format_equals
(
&
chunk
->
audio_format
,
audio_format
));
assert
(
length
+
_length
<=
sizeof
(
data
));
assert
(
audio_format_equals
(
&
audio_format
,
&
af
));
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 {
#ifndef NDEBUG
struct
audio_format
audio_format
;
#endif
};
void
music_chunk_init
(
struct
music_chunk
*
chunk
);
music_chunk
()
:
other
(
nullptr
),
length
(
0
),
tag
(
nullptr
),
replay_gain_serial
(
0
)
{}
void
music_chunk_free
(
struct
music_chunk
*
chunk
);
~
music_chunk
();
static
inline
bool
music_chunk_is_empty
(
const
struct
music_chunk
*
chunk
)
{
return
chunk
->
length
==
0
&&
chunk
->
tag
==
NULL
;
}
bool
IsEmpty
()
const
{
return
length
==
0
&&
tag
==
nullptr
;
}
#ifndef NDEBUG
/**
* Checks if the audio format if the chunk is equal to the specified
* audio_format.
*/
bool
music_chunk_check_format
(
const
struct
music_chunk
*
chunk
,
const
struct
audio_format
*
audio_format
);
/**
* Checks if the audio format if the chunk is equal to the
* specified audio_format.
*/
gcc_pure
bool
CheckFormat
(
const
struct
audio_format
&
audio_format
)
const
;
#endif
/**
* Prepares appending to the music chunk. Returns a buffer 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
* stay the same for the life cycle of this chunk
* @param data_time the time within the song
* @param bit_rate the current bit rate of the source file
* @param max_length_r the maximum write length is returned her
e
* @return a writable buffer, or NULL if the chunk is full
*/
void
*
music_chunk_write
(
struct
music_chunk
*
chunk
,
const
struct
audio_format
*
audio_format
,
float
data_time
,
uint16_t
bit_rate
,
size_t
*
max_length_r
);
/**
* Prepares appending to the music chunk. Returns a buffer
* where you may write into. After you are finished, call
* music_chunk_expand().
*
* @param chunk the music_chunk objec
t
* @param audio_format the audio format for the appended data;
* must stay the same for the life cycle of this chunk
* @param data_time the time within the song
* @param bit_rate the current bit rate of the source fil
e
* @param max_length_r the maximum write length is returned
* here
* @return a writable buffer, or NULL if the chunk is full
*/
void
*
Write
(
const
struct
audio_format
&
af
,
float
data_time
,
uint16_t
bit_rate
,
size_t
*
max_length_r
);
/**
* Increases the length of the chunk after the caller has written to
* the buffer returned by music_chunk_write().
*
* @param chunk the music_chunk object
* @param audio_format the audio format for the appended data; must
* stay the same for the life cycle of this chunk
* @param length the number of bytes which were appended
* @return true if the chunk is full
*/
bool
music_chunk_expand
(
struct
music_chunk
*
chunk
,
const
struct
audio_format
*
audio_format
,
size_t
length
);
/**
* Increases the length of the chunk after the caller has written to
* the buffer returned by music_chunk_write().
*
* @param chunk the music_chunk object
* @param audio_format the audio format for the appended data; must
* stay the same for the life cycle of this chunk
* @param length the number of bytes which were appended
* @return true if the chunk is full
*/
bool
Expand
(
const
struct
audio_format
&
af
,
size_t
length
);
};
void
music_chunk_init
(
struct
music_chunk
*
chunk
);
void
music_chunk_free
(
struct
music_chunk
*
chunk
);
#endif
src/MusicPipe.cxx
View file @
e9b71a0d
...
...
@@ -111,7 +111,7 @@ music_pipe_shift(struct music_pipe *mp)
struct
music_chunk
*
chunk
=
mp
->
head
;
if
(
chunk
!=
NULL
)
{
assert
(
!
music_chunk_is_empty
(
chunk
));
assert
(
!
chunk
->
IsEmpty
(
));
mp
->
head
=
chunk
->
next
;
--
mp
->
size
;
...
...
@@ -150,14 +150,14 @@ music_pipe_clear(struct music_pipe *mp, struct music_buffer *buffer)
void
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
));
const
ScopeLock
protect
(
mp
->
mutex
);
assert
(
mp
->
size
>
0
||
!
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
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)
assert
(
g_music_buffer
!=
NULL
);
assert
(
g_mp
!=
NULL
);
assert
(
chunk
!=
NULL
);
assert
(
music_chunk_check_format
(
chunk
,
&
input_audio_format
));
assert
(
chunk
->
CheckFormat
(
input_audio_format
));
ret
=
audio_output_all_update
();
if
(
!
ret
)
{
...
...
src/OutputThread.cxx
View file @
e9b71a0d
...
...
@@ -327,8 +327,8 @@ ao_chunk_data(struct audio_output *ao, const struct music_chunk *chunk,
size_t
*
length_r
)
{
assert
(
chunk
!=
NULL
);
assert
(
!
music_chunk_is_empty
(
chunk
));
assert
(
music_chunk_check_format
(
chunk
,
&
ao
->
in_audio_format
));
assert
(
!
chunk
->
IsEmpty
(
));
assert
(
chunk
->
CheckFormat
(
ao
->
in_audio_format
));
const
void
*
data
=
chunk
->
data
;
size_t
length
=
chunk
->
length
;
...
...
src/PlayerThread.cxx
View file @
e9b71a0d
...
...
@@ -686,7 +686,7 @@ play_chunk(struct player_control *pc,
const
struct
audio_format
*
format
,
GError
**
error_r
)
{
assert
(
music_chunk_check_format
(
chunk
,
format
));
assert
(
chunk
->
CheckFormat
(
*
format
));
if
(
chunk
->
tag
!=
NULL
)
update_song_tag
(
song
,
chunk
->
tag
);
...
...
@@ -766,7 +766,7 @@ play_next_chunk(struct player *player)
chunk
->
mix_ratio
=
nan
(
""
);
}
if
(
music_chunk_is_empty
(
other_chunk
))
{
if
(
other_chunk
->
IsEmpty
(
))
{
/* the "other" chunk was a music_chunk
which had only a tag, but no music
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