[FFmpeg-devel] [PATCH v5 3/3] aadec: improve seeking in mp3 content
Michael Niedermayer
michael at niedermayer.cc
Fri Jul 13 02:48:48 EEST 2018
On Wed, Jul 11, 2018 at 11:53:25PM +0200, Karsten Otto wrote:
> MP3 frames may not be aligned to aa chunk boundaries. When seeking,
> calculate the expected frame offset in the target chunk. Adjust the
> timestamp and truncate the next packet accordingly.
>
> This solution works for the majority of tested audio material. For
> some rare encodings with mp3 padding or embedded id3 tags, it will
> mispredict the correct offset, and at worst skip an extra frame.
> ---
> libavformat/aadec.c | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/libavformat/aadec.c b/libavformat/aadec.c
> index 17ad20686b..2d78def6e8 100644
> --- a/libavformat/aadec.c
> +++ b/libavformat/aadec.c
> @@ -37,6 +37,7 @@
> #define TEA_BLOCK_SIZE 8
> #define CHAPTER_HEADER_SIZE 8
> #define TIMEPREC 1000
> +#define MP3_FRAME_SIZE 104
>
> typedef struct AADemuxContext {
> AVClass *class;
> @@ -50,6 +51,7 @@ typedef struct AADemuxContext {
> int64_t current_chapter_size;
> int64_t content_start;
> int64_t content_end;
> + int seek_offset;
> } AADemuxContext;
>
> static int get_second_size(char *codec_name)
> @@ -228,6 +230,7 @@ static int aa_read_header(AVFormatContext *s)
> ff_update_cur_dts(s, st, 0);
> avio_seek(pb, start, SEEK_SET);
> c->current_chapter_size = 0;
> + c->seek_offset = 0;
>
> return 0;
> }
> @@ -266,6 +269,8 @@ static int aa_read_packet(AVFormatContext *s, AVPacket *pkt)
> // is this the last block in this chapter?
> if (c->current_chapter_size / c->current_codec_second_size == 0) {
> c->current_codec_second_size = c->current_chapter_size % c->current_codec_second_size;
> + if (c->seek_offset > c->current_codec_second_size)
> + c->seek_offset = 0;
> }
>
> // decrypt c->current_codec_second_size bytes
> @@ -293,12 +298,13 @@ static int aa_read_packet(AVFormatContext *s, AVPacket *pkt)
> if (c->current_chapter_size <= 0)
> c->current_chapter_size = 0;
>
> - ret = av_new_packet(pkt, written);
> + ret = av_new_packet(pkt, written - c->seek_offset);
Please document how the existing checks gurantee that written >= c->seek_offset
thanks
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
When you are offended at any man's fault, turn to yourself and study your
own failings. Then you will forget your anger. -- Epictetus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180713/eb414f52/attachment.sig>
More information about the ffmpeg-devel
mailing list