Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
4df66c7c
Commit
4df66c7c
authored
9 years ago
by
Michael Niedermayer
Browse files
Options
Downloads
Patches
Plain Diff
avformat/mp3dec: split position sync code out
Signed-off-by:
Michael Niedermayer
<
michael@niedermayer.cc
>
parent
ea8785ce
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libavformat/mp3dec.c
+45
-37
45 additions, 37 deletions
libavformat/mp3dec.c
with
45 additions
and
37 deletions
libavformat/mp3dec.c
+
45
−
37
View file @
4df66c7c
...
@@ -437,49 +437,23 @@ static int check(AVIOContext *pb, int64_t pos)
...
@@ -437,49 +437,23 @@ static int check(AVIOContext *pb, int64_t pos)
return
sd
.
frame_size
;
return
sd
.
frame_size
;
}
}
static
int
mp3_seek
(
AVFormatContext
*
s
,
int
stream_index
,
int64_t
timestamp
,
static
int64_t
sync
(
AVFormatContext
*
s
,
int64_t
target_pos
,
int
flags
)
int
flags
)
{
{
MP3DecContext
*
mp3
=
s
->
priv_data
;
AVIndexEntry
*
ie
,
ie1
;
AVStream
*
st
=
s
->
streams
[
0
];
int64_t
ret
=
av_index_search_timestamp
(
st
,
timestamp
,
flags
);
int
i
,
j
;
int
dir
=
(
flags
&
AVSEEK_FLAG_BACKWARD
)
?
-
1
:
1
;
int
dir
=
(
flags
&
AVSEEK_FLAG_BACKWARD
)
?
-
1
:
1
;
int64_t
best_pos
;
int64_t
best_pos
;
int
best_score
;
int
best_score
,
i
,
j
;
int64_t
ret
;
if
(
mp3
->
usetoc
==
2
)
return
-
1
;
// generic index code
if
(
mp3
->
is_cbr
avio_seek
(
s
->
pb
,
FFMAX
(
target_pos
-
SEEK_WINDOW
,
0
),
SEEK_SET
);
&&
(
mp3
->
usetoc
==
0
||
!
mp3
->
xing_toc
)
ret
=
avio_seek
(
s
->
pb
,
target_pos
,
SEEK_SET
);
&&
st
->
duration
>
0
&&
mp3
->
header_filesize
>
s
->
internal
->
data_offset
&&
mp3
->
frames
)
{
ie
=
&
ie1
;
timestamp
=
av_clip64
(
timestamp
,
0
,
st
->
duration
);
ie
->
timestamp
=
timestamp
;
ie
->
pos
=
av_rescale
(
timestamp
,
mp3
->
header_filesize
,
st
->
duration
)
+
s
->
internal
->
data_offset
;
}
else
if
(
mp3
->
xing_toc
)
{
if
(
ret
<
0
)
return
ret
;
ie
=
&
st
->
index_entries
[
ret
];
}
else
{
return
-
1
;
}
avio_seek
(
s
->
pb
,
FFMAX
(
ie
->
pos
-
SEEK_WINDOW
,
0
),
SEEK_SET
);
ret
=
avio_seek
(
s
->
pb
,
ie
->
pos
,
SEEK_SET
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
ret
;
return
ret
;
#define MIN_VALID 3
#define MIN_VALID 3
best_pos
=
ie
->
pos
;
best_pos
=
target_
pos
;
best_score
=
999
;
best_score
=
999
;
for
(
i
=
0
;
i
<
SEEK_WINDOW
;
i
++
)
{
for
(
i
=
0
;
i
<
SEEK_WINDOW
;
i
++
)
{
int64_t
pos
=
ie
->
pos
+
(
dir
>
0
?
i
-
SEEK_WINDOW
/
4
:
-
i
);
int64_t
pos
=
target_
pos
+
(
dir
>
0
?
i
-
SEEK_WINDOW
/
4
:
-
i
);
int64_t
candidate
=
-
1
;
int64_t
candidate
=
-
1
;
int
score
=
999
;
int
score
=
999
;
...
@@ -490,7 +464,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
...
@@ -490,7 +464,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
ret
=
check
(
s
->
pb
,
pos
);
ret
=
check
(
s
->
pb
,
pos
);
if
(
ret
<
0
)
if
(
ret
<
0
)
break
;
break
;
if
((
ie
->
pos
-
pos
)
*
dir
<=
0
&&
abs
(
MIN_VALID
/
2
-
j
)
<
score
)
{
if
((
target_
pos
-
pos
)
*
dir
<=
0
&&
abs
(
MIN_VALID
/
2
-
j
)
<
score
)
{
candidate
=
pos
;
candidate
=
pos
;
score
=
abs
(
MIN_VALID
/
2
-
j
);
score
=
abs
(
MIN_VALID
/
2
-
j
);
}
}
...
@@ -504,9 +478,43 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
...
@@ -504,9 +478,43 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
}
}
}
}
ret
=
avio_seek
(
s
->
pb
,
best_pos
,
SEEK_SET
);
return
avio_seek
(
s
->
pb
,
best_pos
,
SEEK_SET
);
if
(
ret
<
0
)
}
return
ret
;
static
int
mp3_seek
(
AVFormatContext
*
s
,
int
stream_index
,
int64_t
timestamp
,
int
flags
)
{
MP3DecContext
*
mp3
=
s
->
priv_data
;
AVIndexEntry
*
ie
,
ie1
;
AVStream
*
st
=
s
->
streams
[
0
];
int64_t
ret
=
av_index_search_timestamp
(
st
,
timestamp
,
flags
);
int64_t
best_pos
;
int
i
;
if
(
mp3
->
usetoc
==
2
)
return
-
1
;
// generic index code
if
(
mp3
->
is_cbr
&&
(
mp3
->
usetoc
==
0
||
!
mp3
->
xing_toc
)
&&
st
->
duration
>
0
&&
mp3
->
header_filesize
>
s
->
internal
->
data_offset
&&
mp3
->
frames
)
{
ie
=
&
ie1
;
timestamp
=
av_clip64
(
timestamp
,
0
,
st
->
duration
);
ie
->
timestamp
=
timestamp
;
ie
->
pos
=
av_rescale
(
timestamp
,
mp3
->
header_filesize
,
st
->
duration
)
+
s
->
internal
->
data_offset
;
}
else
if
(
mp3
->
xing_toc
)
{
if
(
ret
<
0
)
return
ret
;
ie
=
&
st
->
index_entries
[
ret
];
}
else
{
return
-
1
;
}
best_pos
=
sync
(
s
,
ie
->
pos
,
flags
);
if
(
best_pos
<
0
)
return
best_pos
;
if
(
mp3
->
is_cbr
&&
ie
==
&
ie1
)
{
if
(
mp3
->
is_cbr
&&
ie
==
&
ie1
)
{
int
frame_duration
=
av_rescale
(
st
->
duration
,
1
,
mp3
->
frames
);
int
frame_duration
=
av_rescale
(
st
->
duration
,
1
,
mp3
->
frames
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment