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
c7695253
Commit
c7695253
authored
Jan 07, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decoder/Opus: implement seeking
parent
f0060718
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
6 deletions
+49
-6
OggFind.cxx
src/decoder/OggFind.cxx
+1
-2
OggFind.hxx
src/decoder/OggFind.hxx
+8
-0
OpusDecoderPlugin.cxx
src/decoder/OpusDecoderPlugin.cxx
+40
-4
No files found.
src/decoder/OggFind.cxx
View file @
c7695253
...
...
@@ -20,7 +20,6 @@
#include "config.h"
#include "OggFind.hxx"
#include "OggSyncState.hxx"
#include "InputStream.hxx"
#include "util/Error.hxx"
bool
...
...
@@ -38,7 +37,7 @@ OggFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet)
}
}
static
bool
bool
OggSeekPageAtOffset
(
OggSyncState
&
oy
,
ogg_stream_state
&
os
,
InputStream
&
is
,
InputStream
::
offset_type
offset
,
int
whence
)
{
...
...
src/decoder/OggFind.hxx
View file @
c7695253
...
...
@@ -21,6 +21,7 @@
#define MPD_OGG_FIND_HXX
#include "check.h"
#include "InputStream.hxx"
#include <ogg/ogg.h>
...
...
@@ -37,6 +38,13 @@ bool
OggFindEOS
(
OggSyncState
&
oy
,
ogg_stream_state
&
os
,
ogg_packet
&
packet
);
/**
* Seek the #InputStream and find the next Ogg page.
*/
bool
OggSeekPageAtOffset
(
OggSyncState
&
oy
,
ogg_stream_state
&
os
,
InputStream
&
is
,
InputStream
::
offset_type
offset
,
int
whence
);
/**
* Try to find the end-of-stream (EOS) packet. Seek to the end of the
* file if necessary.
*
...
...
src/decoder/OpusDecoderPlugin.cxx
View file @
c7695253
...
...
@@ -80,6 +80,8 @@ class MPDOpusDecoder {
int
opus_serialno
;
ogg_int64_t
eos_granulepos
;
size_t
frame_size
;
public
:
...
...
@@ -99,6 +101,8 @@ public:
DecoderCommand
HandleBOS
(
const
ogg_packet
&
packet
);
DecoderCommand
HandleTags
(
const
ogg_packet
&
packet
);
DecoderCommand
HandleAudio
(
const
ogg_packet
&
packet
);
bool
Seek
(
OggSyncState
&
oy
,
double
where
);
};
MPDOpusDecoder
::~
MPDOpusDecoder
()
...
...
@@ -252,15 +256,16 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet)
return
DecoderCommand
::
STOP
;
}
const
ogg_int64_t
eos_granulepos
=
LoadEOSGranulePos
(
input_stream
,
&
decoder
,
opus_serialno
);
eos_granulepos
=
LoadEOSGranulePos
(
input_stream
,
&
decoder
,
opus_serialno
);
const
double
duration
=
eos_granulepos
>=
0
?
double
(
eos_granulepos
)
/
opus_sample_rate
:
-
1.0
;
const
AudioFormat
audio_format
(
opus_sample_rate
,
SampleFormat
::
S16
,
channels
);
decoder_initialized
(
decoder
,
audio_format
,
false
,
duration
);
decoder_initialized
(
decoder
,
audio_format
,
eos_granulepos
>
0
,
duration
);
frame_size
=
audio_format
.
GetFrameSize
();
/* allocate an output buffer for 16 bit PCM samples big enough
...
...
@@ -324,6 +329,29 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
return
DecoderCommand
::
NONE
;
}
bool
MPDOpusDecoder
::
Seek
(
OggSyncState
&
oy
,
double
where_s
)
{
assert
(
eos_granulepos
>
0
);
assert
(
input_stream
.
seekable
);
assert
(
input_stream
.
size
>
0
);
assert
(
input_stream
.
offset
>=
0
);
const
ogg_int64_t
where_granulepos
(
where_s
*
opus_sample_rate
);
/* interpolate the file offset where we expect to find the
given granule position */
/* TODO: implement binary search */
InputStream
::
offset_type
offset
(
where_granulepos
*
input_stream
.
size
/
eos_granulepos
);
if
(
!
OggSeekPageAtOffset
(
oy
,
os
,
input_stream
,
offset
,
SEEK_SET
))
return
false
;
decoder_timestamp
(
decoder
,
where_s
);
return
true
;
}
static
void
mpd_opus_stream_decode
(
Decoder
&
decoder
,
InputStream
&
input_stream
)
...
...
@@ -343,12 +371,20 @@ mpd_opus_stream_decode(Decoder &decoder,
while
(
true
)
{
auto
cmd
=
d
.
HandlePackets
();
if
(
cmd
==
DecoderCommand
::
SEEK
)
{
if
(
d
.
Seek
(
oy
,
decoder_seek_where
(
decoder
)))
decoder_command_finished
(
decoder
);
else
decoder_seek_error
(
decoder
);
continue
;
}
if
(
cmd
!=
DecoderCommand
::
NONE
)
break
;
if
(
!
d
.
ReadNextPage
(
oy
))
break
;
}
}
...
...
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