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
6ad93398
Commit
6ad93398
authored
Aug 28, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DetachedSong: use std::chrono::duration for start_ms and end_ms
parent
854258f3
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
57 additions
and
51 deletions
+57
-51
DetachedSong.cxx
src/DetachedSong.cxx
+6
-5
DetachedSong.hxx
src/DetachedSong.hxx
+21
-16
PlayerThread.cxx
src/PlayerThread.cxx
+10
-10
SongPrint.cxx
src/SongPrint.cxx
+2
-2
SongSave.cxx
src/SongSave.cxx
+3
-3
Song.cxx
src/db/plugins/simple/Song.cxx
+2
-2
DecoderAPI.cxx
src/decoder/DecoderAPI.cxx
+1
-1
CueParser.cxx
src/playlist/cue/CueParser.cxx
+3
-3
PlaylistEdit.cxx
src/queue/PlaylistEdit.cxx
+2
-2
QueueSave.cxx
src/queue/QueueSave.cxx
+1
-1
dump_playlist.cxx
test/dump_playlist.cxx
+2
-2
test_translate_song.cxx
test/test_translate_song.cxx
+4
-4
No files found.
src/DetachedSong.cxx
View file @
6ad93398
...
@@ -28,11 +28,12 @@ DetachedSong::DetachedSong(const LightSong &other)
...
@@ -28,11 +28,12 @@ DetachedSong::DetachedSong(const LightSong &other)
real_uri
(
other
.
real_uri
!=
nullptr
?
other
.
real_uri
:
""
),
real_uri
(
other
.
real_uri
!=
nullptr
?
other
.
real_uri
:
""
),
tag
(
*
other
.
tag
),
tag
(
*
other
.
tag
),
mtime
(
other
.
mtime
),
mtime
(
other
.
mtime
),
start_ms
(
other
.
start_ms
),
end_ms
(
other
.
end_ms
)
{}
start_time
(
SongTime
::
FromMS
(
other
.
start_ms
)),
end_time
(
SongTime
::
FromMS
(
other
.
end_ms
))
{}
DetachedSong
::~
DetachedSong
()
DetachedSong
::~
DetachedSong
()
{
{
/* this destructor exists here just so it won't
get
inlined */
/* this destructor exists here just so it won't inlined */
}
}
bool
bool
...
@@ -60,8 +61,8 @@ DetachedSong::IsInDatabase() const
...
@@ -60,8 +61,8 @@ DetachedSong::IsInDatabase() const
double
double
DetachedSong
::
GetDuration
()
const
DetachedSong
::
GetDuration
()
const
{
{
if
(
end_
ms
>
0
)
if
(
end_
time
.
IsPositive
()
)
return
(
end_
ms
-
start_ms
)
/
1000.0
;
return
(
end_
time
-
start_time
).
ToDoubleS
()
;
return
tag
.
time
-
start_
ms
/
1000.0
;
return
tag
.
time
-
start_
time
.
ToDoubleS
()
;
}
}
src/DetachedSong.hxx
View file @
6ad93398
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
#include "check.h"
#include "check.h"
#include "tag/Tag.hxx"
#include "tag/Tag.hxx"
#include "Chrono.hxx"
#include "Compiler.h"
#include "Compiler.h"
#include <string>
#include <string>
...
@@ -65,15 +66,15 @@ class DetachedSong {
...
@@ -65,15 +66,15 @@ class DetachedSong {
time_t
mtime
;
time_t
mtime
;
/**
/**
* Start of this sub-song within the file
in milliseconds
.
* Start of this sub-song within the file.
*/
*/
unsigned
start_ms
;
SongTime
start_time
;
/**
/**
* End of this sub-song within the file
in milliseconds
.
* End of this sub-song within the file.
* Unused if zero.
* Unused if zero.
*/
*/
unsigned
end_ms
;
SongTime
end_time
;
explicit
DetachedSong
(
const
LightSong
&
other
);
explicit
DetachedSong
(
const
LightSong
&
other
);
...
@@ -82,21 +83,25 @@ public:
...
@@ -82,21 +83,25 @@ public:
explicit
DetachedSong
(
const
char
*
_uri
)
explicit
DetachedSong
(
const
char
*
_uri
)
:
uri
(
_uri
),
:
uri
(
_uri
),
mtime
(
0
),
start_ms
(
0
),
end_ms
(
0
)
{}
mtime
(
0
),
start_time
(
SongTime
::
zero
()),
end_time
(
SongTime
::
zero
())
{}
explicit
DetachedSong
(
const
std
::
string
&
_uri
)
explicit
DetachedSong
(
const
std
::
string
&
_uri
)
:
uri
(
_uri
),
:
uri
(
_uri
),
mtime
(
0
),
start_ms
(
0
),
end_ms
(
0
)
{}
mtime
(
0
),
start_time
(
SongTime
::
zero
()),
end_time
(
SongTime
::
zero
())
{}
explicit
DetachedSong
(
std
::
string
&&
_uri
)
explicit
DetachedSong
(
std
::
string
&&
_uri
)
:
uri
(
std
::
move
(
_uri
)),
:
uri
(
std
::
move
(
_uri
)),
mtime
(
0
),
start_ms
(
0
),
end_ms
(
0
)
{}
mtime
(
0
),
start_time
(
SongTime
::
zero
()),
end_time
(
SongTime
::
zero
())
{}
template
<
typename
U
>
template
<
typename
U
>
DetachedSong
(
U
&&
_uri
,
Tag
&&
_tag
)
DetachedSong
(
U
&&
_uri
,
Tag
&&
_tag
)
:
uri
(
std
::
forward
<
U
>
(
_uri
)),
:
uri
(
std
::
forward
<
U
>
(
_uri
)),
tag
(
std
::
move
(
_tag
)),
tag
(
std
::
move
(
_tag
)),
mtime
(
0
),
start_ms
(
0
),
end_ms
(
0
)
{}
mtime
(
0
),
start_time
(
SongTime
::
zero
()),
end_time
(
SongTime
::
zero
())
{}
DetachedSong
(
DetachedSong
&&
)
=
default
;
DetachedSong
(
DetachedSong
&&
)
=
default
;
...
@@ -191,20 +196,20 @@ public:
...
@@ -191,20 +196,20 @@ public:
mtime
=
_value
;
mtime
=
_value
;
}
}
unsigned
GetStartMS
()
const
{
SongTime
GetStartTime
()
const
{
return
start_
ms
;
return
start_
time
;
}
}
void
SetStart
MS
(
unsigned
_value
)
{
void
SetStart
Time
(
SongTime
_value
)
{
start_
ms
=
_value
;
start_
time
=
_value
;
}
}
unsigned
GetEndMS
()
const
{
SongTime
GetEndTime
()
const
{
return
end_
ms
;
return
end_
time
;
}
}
void
SetEnd
MS
(
unsigned
_value
)
{
void
SetEnd
Time
(
SongTime
_value
)
{
end_
ms
=
_value
;
end_
time
=
_value
;
}
}
gcc_pure
gcc_pure
...
...
src/PlayerThread.cxx
View file @
6ad93398
...
@@ -291,12 +291,12 @@ Player::StartDecoder(MusicPipe &_pipe)
...
@@ -291,12 +291,12 @@ Player::StartDecoder(MusicPipe &_pipe)
assert
(
queued
||
pc
.
command
==
PlayerCommand
::
SEEK
);
assert
(
queued
||
pc
.
command
==
PlayerCommand
::
SEEK
);
assert
(
pc
.
next_song
!=
nullptr
);
assert
(
pc
.
next_song
!=
nullptr
);
unsigned
start_ms
=
pc
.
next_song
->
GetStartMS
();
SongTime
start_time
=
pc
.
next_song
->
GetStartTime
();
if
(
pc
.
command
==
PlayerCommand
::
SEEK
)
if
(
pc
.
command
==
PlayerCommand
::
SEEK
)
start_
ms
+=
pc
.
seek_time
.
ToMS
()
;
start_
time
+=
pc
.
seek_time
;
dc
.
Start
(
new
DetachedSong
(
*
pc
.
next_song
),
dc
.
Start
(
new
DetachedSong
(
*
pc
.
next_song
),
start_
ms
,
pc
.
next_song
->
GetEnd
MS
(),
start_
time
.
ToMS
(),
pc
.
next_song
->
GetEndTime
().
To
MS
(),
buffer
,
_pipe
);
buffer
,
_pipe
);
}
}
...
@@ -376,13 +376,13 @@ real_song_duration(const DetachedSong &song, double decoder_duration)
...
@@ -376,13 +376,13 @@ real_song_duration(const DetachedSong &song, double decoder_duration)
back to Song::GetDuration() */
back to Song::GetDuration() */
return
song
.
GetDuration
();
return
song
.
GetDuration
();
const
unsigned
start_ms
=
song
.
GetStartMS
();
const
SongTime
start_time
=
song
.
GetStartTime
();
const
unsigned
end_ms
=
song
.
GetEndMS
();
const
SongTime
end_time
=
song
.
GetEndTime
();
if
(
end_
ms
>
0
&&
end_ms
/
1000.0
<
decoder_duration
)
if
(
end_
time
.
IsPositive
()
&&
end_time
.
ToDoubleS
()
<
decoder_duration
)
return
(
end_
ms
-
start_ms
)
/
1000.0
;
return
(
end_
time
-
start_time
).
ToDoubleS
()
;
return
decoder_duration
-
start_
ms
/
1000.0
;
return
decoder_duration
-
start_
time
.
ToDoubleS
()
;
}
}
bool
bool
...
@@ -518,7 +518,7 @@ Player::SeekDecoder()
...
@@ -518,7 +518,7 @@ Player::SeekDecoder()
{
{
assert
(
pc
.
next_song
!=
nullptr
);
assert
(
pc
.
next_song
!=
nullptr
);
const
unsigned
start_ms
=
pc
.
next_song
->
GetStartMS
();
const
SongTime
start_time
=
pc
.
next_song
->
GetStartTime
();
if
(
!
dc
.
LockIsCurrentSong
(
*
pc
.
next_song
))
{
if
(
!
dc
.
LockIsCurrentSong
(
*
pc
.
next_song
))
{
/* the decoder is already decoding the "next" song -
/* the decoder is already decoding the "next" song -
...
@@ -568,7 +568,7 @@ Player::SeekDecoder()
...
@@ -568,7 +568,7 @@ Player::SeekDecoder()
where
=
total_time
;
where
=
total_time
;
}
}
if
(
!
dc
.
Seek
(
where
+
SongTime
::
FromMS
(
start_ms
)
))
{
if
(
!
dc
.
Seek
(
where
+
start_time
))
{
/* decoder failure */
/* decoder failure */
player_command_finished
(
pc
);
player_command_finished
(
pc
);
return
false
;
return
false
;
...
...
src/SongPrint.cxx
View file @
6ad93398
...
@@ -97,8 +97,8 @@ song_print_info(Client &client, const DetachedSong &song, bool base)
...
@@ -97,8 +97,8 @@ song_print_info(Client &client, const DetachedSong &song, bool base)
{
{
song_print_uri
(
client
,
song
,
base
);
song_print_uri
(
client
,
song
,
base
);
const
unsigned
start_ms
=
song
.
GetStartMS
();
const
unsigned
start_ms
=
song
.
GetStart
Time
().
To
MS
();
const
unsigned
end_ms
=
song
.
GetEndMS
();
const
unsigned
end_ms
=
song
.
GetEnd
Time
().
To
MS
();
if
(
end_ms
>
0
)
if
(
end_ms
>
0
)
client_printf
(
client
,
"Range: %u.%03u-%u.%03u
\n
"
,
client_printf
(
client
,
"Range: %u.%03u-%u.%03u
\n
"
,
...
...
src/SongSave.cxx
View file @
6ad93398
...
@@ -65,7 +65,7 @@ song_save(BufferedOutputStream &os, const DetachedSong &song)
...
@@ -65,7 +65,7 @@ song_save(BufferedOutputStream &os, const DetachedSong &song)
{
{
os
.
Format
(
SONG_BEGIN
"%s
\n
"
,
song
.
GetURI
());
os
.
Format
(
SONG_BEGIN
"%s
\n
"
,
song
.
GetURI
());
range_save
(
os
,
song
.
GetStart
MS
(),
song
.
GetEnd
MS
());
range_save
(
os
,
song
.
GetStart
Time
().
ToMS
(),
song
.
GetEndTime
().
To
MS
());
tag_save
(
os
,
song
.
GetTag
());
tag_save
(
os
,
song
.
GetTag
());
...
@@ -113,8 +113,8 @@ song_load(TextFile &file, const char *uri,
...
@@ -113,8 +113,8 @@ song_load(TextFile &file, const char *uri,
?
strtoul
(
endptr
+
1
,
nullptr
,
10
)
?
strtoul
(
endptr
+
1
,
nullptr
,
10
)
:
0
;
:
0
;
song
->
SetStart
MS
(
start_ms
);
song
->
SetStart
Time
(
SongTime
::
FromMS
(
start_ms
)
);
song
->
SetEnd
MS
(
end_ms
);
song
->
SetEnd
Time
(
SongTime
::
FromMS
(
end_ms
)
);
}
else
{
}
else
{
delete
song
;
delete
song
;
...
...
src/db/plugins/simple/Song.cxx
View file @
6ad93398
...
@@ -59,8 +59,8 @@ Song::NewFrom(DetachedSong &&other, Directory &parent)
...
@@ -59,8 +59,8 @@ Song::NewFrom(DetachedSong &&other, Directory &parent)
Song
*
song
=
song_alloc
(
other
.
GetURI
(),
parent
);
Song
*
song
=
song_alloc
(
other
.
GetURI
(),
parent
);
song
->
tag
=
std
::
move
(
other
.
WritableTag
());
song
->
tag
=
std
::
move
(
other
.
WritableTag
());
song
->
mtime
=
other
.
GetLastModified
();
song
->
mtime
=
other
.
GetLastModified
();
song
->
start_ms
=
other
.
GetStartMS
();
song
->
start_ms
=
other
.
GetStart
Time
().
To
MS
();
song
->
end_ms
=
other
.
GetEndMS
();
song
->
end_ms
=
other
.
GetEnd
Time
().
To
MS
();
return
song
;
return
song
;
}
}
...
...
src/decoder/DecoderAPI.cxx
View file @
6ad93398
...
@@ -521,7 +521,7 @@ decoder_data(Decoder &decoder,
...
@@ -521,7 +521,7 @@ decoder_data(Decoder &decoder,
const
auto
dest
=
const
auto
dest
=
chunk
->
Write
(
dc
.
out_audio_format
,
chunk
->
Write
(
dc
.
out_audio_format
,
decoder
.
timestamp
-
decoder
.
timestamp
-
dc
.
song
->
GetStart
MS
()
/
1000.0
,
dc
.
song
->
GetStart
Time
().
ToDoubleS
()
,
kbit_rate
);
kbit_rate
);
if
(
dest
.
IsNull
())
{
if
(
dest
.
IsNull
())
{
/* the chunk is full, flush it */
/* the chunk is full, flush it */
...
...
src/playlist/cue/CueParser.cxx
View file @
6ad93398
...
@@ -267,12 +267,12 @@ CueParser::Feed2(char *p)
...
@@ -267,12 +267,12 @@ CueParser::Feed2(char *p)
return
;
return
;
if
(
!
last_updated
&&
previous
!=
nullptr
&&
if
(
!
last_updated
&&
previous
!=
nullptr
&&
previous
->
GetStartMS
()
<
(
unsigned
)
position_ms
)
{
previous
->
GetStart
Time
().
To
MS
()
<
(
unsigned
)
position_ms
)
{
last_updated
=
true
;
last_updated
=
true
;
previous
->
SetEnd
MS
(
position_ms
);
previous
->
SetEnd
Time
(
SongTime
::
FromMS
(
position_ms
)
);
}
}
current
->
SetStart
MS
(
position_ms
);
current
->
SetStart
Time
(
SongTime
::
FromMS
(
position_ms
)
);
}
}
}
}
...
...
src/queue/PlaylistEdit.cxx
View file @
6ad93398
...
@@ -479,8 +479,8 @@ playlist::SetSongIdRange(PlayerControl &pc, unsigned id,
...
@@ -479,8 +479,8 @@ playlist::SetSongIdRange(PlayerControl &pc, unsigned id,
}
}
/* edit it */
/* edit it */
song
.
SetStart
MS
(
start_ms
);
song
.
SetStart
Time
(
SongTime
::
FromMS
(
start_ms
)
);
song
.
SetEnd
MS
(
end_ms
);
song
.
SetEnd
Time
(
SongTime
::
FromMS
(
end_ms
)
);
/* announce the change to all interested subsystems */
/* announce the change to all interested subsystems */
UpdateQueuedSong
(
pc
,
nullptr
);
UpdateQueuedSong
(
pc
,
nullptr
);
...
...
src/queue/QueueSave.cxx
View file @
6ad93398
...
@@ -53,7 +53,7 @@ static void
...
@@ -53,7 +53,7 @@ static void
queue_save_song
(
BufferedOutputStream
&
os
,
int
idx
,
const
DetachedSong
&
song
)
queue_save_song
(
BufferedOutputStream
&
os
,
int
idx
,
const
DetachedSong
&
song
)
{
{
if
(
song
.
IsInDatabase
()
&&
if
(
song
.
IsInDatabase
()
&&
song
.
GetStart
MS
()
==
0
&&
song
.
GetEndMS
()
==
0
)
song
.
GetStart
Time
().
IsZero
()
&&
song
.
GetEndTime
().
IsZero
()
)
/* use the brief format (just the URI) for "full"
/* use the brief format (just the URI) for "full"
database songs */
database songs */
queue_save_database_song
(
os
,
idx
,
song
);
queue_save_database_song
(
os
,
idx
,
song
);
...
...
test/dump_playlist.cxx
View file @
6ad93398
...
@@ -128,8 +128,8 @@ int main(int argc, char **argv)
...
@@ -128,8 +128,8 @@ int main(int argc, char **argv)
while
((
song
=
playlist
->
NextSong
())
!=
NULL
)
{
while
((
song
=
playlist
->
NextSong
())
!=
NULL
)
{
printf
(
"%s
\n
"
,
song
->
GetURI
());
printf
(
"%s
\n
"
,
song
->
GetURI
());
const
unsigned
start_ms
=
song
->
GetStartMS
();
const
unsigned
start_ms
=
song
->
GetStart
Time
().
To
MS
();
const
unsigned
end_ms
=
song
->
GetEndMS
();
const
unsigned
end_ms
=
song
->
GetEnd
Time
().
To
MS
();
if
(
end_ms
>
0
)
if
(
end_ms
>
0
)
printf
(
"range: %u:%02u..%u:%02u
\n
"
,
printf
(
"range: %u:%02u..%u:%02u
\n
"
,
...
...
test/test_translate_song.cxx
View file @
6ad93398
...
@@ -185,15 +185,15 @@ ToString(const DetachedSong &song)
...
@@ -185,15 +185,15 @@ ToString(const DetachedSong &song)
result
.
push_back
(
'|'
);
result
.
push_back
(
'|'
);
if
(
song
.
GetStart
MS
()
>
0
)
{
if
(
song
.
GetStart
Time
().
IsPositive
()
)
{
sprintf
(
buffer
,
"%u"
,
song
.
GetStartMS
());
sprintf
(
buffer
,
"%u"
,
song
.
GetStart
Time
().
To
MS
());
result
.
append
(
buffer
);
result
.
append
(
buffer
);
}
}
result
.
push_back
(
'-'
);
result
.
push_back
(
'-'
);
if
(
song
.
GetEnd
MS
()
>
0
)
{
if
(
song
.
GetEnd
Time
().
IsPositive
()
)
{
sprintf
(
buffer
,
"%u"
,
song
.
GetEndMS
());
sprintf
(
buffer
,
"%u"
,
song
.
GetEnd
Time
().
To
MS
());
result
.
append
(
buffer
);
result
.
append
(
buffer
);
}
}
...
...
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