Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
c96904f5
Commit
c96904f5
authored
Apr 25, 2020
by
Marton Balint
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avcodec/decode: use a single list bsf for codec decode bsfs
Signed-off-by:
Marton Balint
<
cus@passwd.hu
>
parent
a75924ec
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
151 deletions
+24
-151
cuviddec.c
libavcodec/cuviddec.c
+1
-1
decode.c
libavcodec/decode.c
+22
-144
internal.h
libavcodec/internal.h
+1
-6
No files found.
libavcodec/cuviddec.c
View file @
c96904f5
...
@@ -946,7 +946,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
...
@@ -946,7 +946,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
}
}
if
(
avctx
->
codec
->
bsfs
)
{
if
(
avctx
->
codec
->
bsfs
)
{
const
AVCodecParameters
*
par
=
avctx
->
internal
->
filter
.
bsfs
[
avctx
->
internal
->
filter
.
nb_bsfs
-
1
]
->
par_out
;
const
AVCodecParameters
*
par
=
avctx
->
internal
->
bsf
->
par_out
;
ctx
->
cuparse_ext
.
format
.
seqhdr_data_length
=
par
->
extradata_size
;
ctx
->
cuparse_ext
.
format
.
seqhdr_data_length
=
par
->
extradata_size
;
memcpy
(
ctx
->
cuparse_ext
.
raw_seqhdr_data
,
memcpy
(
ctx
->
cuparse_ext
.
raw_seqhdr_data
,
par
->
extradata
,
par
->
extradata
,
...
...
libavcodec/decode.c
View file @
c96904f5
...
@@ -204,146 +204,37 @@ static int unrefcount_frame(AVCodecInternal *avci, AVFrame *frame)
...
@@ -204,146 +204,37 @@ static int unrefcount_frame(AVCodecInternal *avci, AVFrame *frame)
int
ff_decode_bsfs_init
(
AVCodecContext
*
avctx
)
int
ff_decode_bsfs_init
(
AVCodecContext
*
avctx
)
{
{
AVCodecInternal
*
avci
=
avctx
->
internal
;
AVCodecInternal
*
avci
=
avctx
->
internal
;
DecodeFilterContext
*
s
=
&
avci
->
filter
;
const
char
*
bsfs_str
;
int
ret
;
int
ret
;
if
(
s
->
nb_bsfs
)
if
(
avci
->
bsf
)
return
0
;
return
0
;
bsfs_str
=
avctx
->
codec
->
bsfs
?
avctx
->
codec
->
bsfs
:
"null"
;
ret
=
av_bsf_list_parse_str
(
avctx
->
codec
->
bsfs
,
&
avci
->
bsf
);
while
(
bsfs_str
&&
*
bsfs_str
)
{
AVBSFContext
**
tmp
;
const
AVBitStreamFilter
*
filter
;
char
*
bsf
,
*
bsf_options_str
,
*
bsf_name
;
bsf
=
av_get_token
(
&
bsfs_str
,
","
);
if
(
!
bsf
)
{
ret
=
AVERROR
(
ENOMEM
);
goto
fail
;
}
bsf_name
=
av_strtok
(
bsf
,
"="
,
&
bsf_options_str
);
if
(
!
bsf_name
)
{
av_freep
(
&
bsf
);
ret
=
AVERROR
(
ENOMEM
);
goto
fail
;
}
filter
=
av_bsf_get_by_name
(
bsf_name
);
if
(
!
filter
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"A non-existing bitstream filter %s "
"requested by a decoder. This is a bug, please report it.
\n
"
,
bsf_name
);
av_freep
(
&
bsf
);
ret
=
AVERROR_BUG
;
goto
fail
;
}
tmp
=
av_realloc_array
(
s
->
bsfs
,
s
->
nb_bsfs
+
1
,
sizeof
(
*
s
->
bsfs
));
if
(
!
tmp
)
{
av_freep
(
&
bsf
);
ret
=
AVERROR
(
ENOMEM
);
goto
fail
;
}
s
->
bsfs
=
tmp
;
ret
=
av_bsf_alloc
(
filter
,
&
s
->
bsfs
[
s
->
nb_bsfs
]);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
av_freep
(
&
bsf
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"Error parsing decoder bitstream filters '%s': %s
\n
"
,
avctx
->
codec
->
bsfs
,
av_err2str
(
ret
));
if
(
ret
!=
AVERROR
(
ENOMEM
))
ret
=
AVERROR_BUG
;
goto
fail
;
goto
fail
;
}
}
s
->
nb_bsfs
++
;
if
(
s
->
nb_bsfs
==
1
)
{
/* We do not currently have an API for passing the input timebase into decoders,
/* We do not currently have an API for passing the input timebase into decoders,
* but no filters used here should actually need it.
* but no filters used here should actually need it.
* So we make up some plausible-looking number (the MPEG 90kHz timebase) */
* So we make up some plausible-looking number (the MPEG 90kHz timebase) */
s
->
bsfs
[
s
->
nb_bsfs
-
1
]
->
time_base_in
=
(
AVRational
){
1
,
90000
};
avci
->
bsf
->
time_base_in
=
(
AVRational
){
1
,
90000
};
ret
=
avcodec_parameters_from_context
(
s
->
bsfs
[
s
->
nb_bsfs
-
1
]
->
par_in
,
ret
=
avcodec_parameters_from_context
(
avci
->
bsf
->
par_in
,
avctx
);
avctx
);
if
(
ret
<
0
)
}
else
{
s
->
bsfs
[
s
->
nb_bsfs
-
1
]
->
time_base_in
=
s
->
bsfs
[
s
->
nb_bsfs
-
2
]
->
time_base_out
;
ret
=
avcodec_parameters_copy
(
s
->
bsfs
[
s
->
nb_bsfs
-
1
]
->
par_in
,
s
->
bsfs
[
s
->
nb_bsfs
-
2
]
->
par_out
);
}
if
(
ret
<
0
)
{
av_freep
(
&
bsf
);
goto
fail
;
}
if
(
bsf_options_str
&&
filter
->
priv_class
)
{
const
AVOption
*
opt
=
av_opt_next
(
s
->
bsfs
[
s
->
nb_bsfs
-
1
]
->
priv_data
,
NULL
);
const
char
*
shorthand
[
2
]
=
{
NULL
};
if
(
opt
)
shorthand
[
0
]
=
opt
->
name
;
ret
=
av_opt_set_from_string
(
s
->
bsfs
[
s
->
nb_bsfs
-
1
]
->
priv_data
,
bsf_options_str
,
shorthand
,
"="
,
":"
);
if
(
ret
<
0
)
{
if
(
ret
!=
AVERROR
(
ENOMEM
))
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Invalid options for bitstream filter %s "
"requested by the decoder. This is a bug, please report it.
\n
"
,
bsf_name
);
ret
=
AVERROR_BUG
;
}
av_freep
(
&
bsf
);
goto
fail
;
goto
fail
;
}
}
av_freep
(
&
bsf
);
ret
=
av_bsf_init
(
s
->
bsfs
[
s
->
nb_bsfs
-
1
]
);
ret
=
av_bsf_init
(
avci
->
bsf
);
if
(
ret
<
0
)
if
(
ret
<
0
)
goto
fail
;
goto
fail
;
if
(
*
bsfs_str
)
bsfs_str
++
;
}
return
0
;
return
0
;
fail:
fail:
ff_decode_bsfs_uninit
(
avctx
);
ff_decode_bsfs_uninit
(
avctx
);
return
ret
;
return
ret
;
}
}
/* try to get one output packet from the filter chain */
static
int
bsfs_poll
(
AVCodecContext
*
avctx
,
AVPacket
*
pkt
)
{
DecodeFilterContext
*
s
=
&
avctx
->
internal
->
filter
;
int
idx
,
ret
;
/* start with the last filter in the chain */
idx
=
s
->
nb_bsfs
-
1
;
while
(
idx
>=
0
)
{
/* request a packet from the currently selected filter */
ret
=
av_bsf_receive_packet
(
s
->
bsfs
[
idx
],
pkt
);
if
(
ret
==
AVERROR
(
EAGAIN
))
{
/* no packets available, try the next filter up the chain */
idx
--
;
continue
;
}
else
if
(
ret
<
0
&&
ret
!=
AVERROR_EOF
)
{
return
ret
;
}
/* got a packet or EOF -- pass it to the caller or to the next filter
* down the chain */
if
(
idx
==
s
->
nb_bsfs
-
1
)
{
return
ret
;
}
else
{
idx
++
;
ret
=
av_bsf_send_packet
(
s
->
bsfs
[
idx
],
ret
<
0
?
NULL
:
pkt
);
if
(
ret
<
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Error pre-processing a packet before decoding
\n
"
);
av_packet_unref
(
pkt
);
return
ret
;
}
}
}
return
AVERROR
(
EAGAIN
);
}
int
ff_decode_get_packet
(
AVCodecContext
*
avctx
,
AVPacket
*
pkt
)
int
ff_decode_get_packet
(
AVCodecContext
*
avctx
,
AVPacket
*
pkt
)
{
{
AVCodecInternal
*
avci
=
avctx
->
internal
;
AVCodecInternal
*
avci
=
avctx
->
internal
;
...
@@ -352,7 +243,7 @@ int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
...
@@ -352,7 +243,7 @@ int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
if
(
avci
->
draining
)
if
(
avci
->
draining
)
return
AVERROR_EOF
;
return
AVERROR_EOF
;
ret
=
bsfs_poll
(
avctx
,
pkt
);
ret
=
av_bsf_receive_packet
(
avci
->
bsf
,
pkt
);
if
(
ret
==
AVERROR_EOF
)
if
(
ret
==
AVERROR_EOF
)
avci
->
draining
=
1
;
avci
->
draining
=
1
;
if
(
ret
<
0
)
if
(
ret
<
0
)
...
@@ -713,7 +604,7 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke
...
@@ -713,7 +604,7 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke
return
ret
;
return
ret
;
}
}
ret
=
av_bsf_send_packet
(
avci
->
filter
.
bsfs
[
0
]
,
avci
->
buffer_pkt
);
ret
=
av_bsf_send_packet
(
avci
->
bsf
,
avci
->
buffer_pkt
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
av_packet_unref
(
avci
->
buffer_pkt
);
av_packet_unref
(
avci
->
buffer_pkt
);
return
ret
;
return
ret
;
...
@@ -2072,14 +1963,6 @@ int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
...
@@ -2072,14 +1963,6 @@ int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
return
ret
;
return
ret
;
}
}
static
void
bsfs_flush
(
AVCodecContext
*
avctx
)
{
DecodeFilterContext
*
s
=
&
avctx
->
internal
->
filter
;
for
(
int
i
=
0
;
i
<
s
->
nb_bsfs
;
i
++
)
av_bsf_flush
(
s
->
bsfs
[
i
]);
}
void
avcodec_flush_buffers
(
AVCodecContext
*
avctx
)
void
avcodec_flush_buffers
(
AVCodecContext
*
avctx
)
{
{
AVCodecInternal
*
avci
=
avctx
->
internal
;
AVCodecInternal
*
avci
=
avctx
->
internal
;
...
@@ -2117,7 +2000,8 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
...
@@ -2117,7 +2000,8 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
avctx
->
pts_correction_last_pts
=
avctx
->
pts_correction_last_pts
=
avctx
->
pts_correction_last_dts
=
INT64_MIN
;
avctx
->
pts_correction_last_dts
=
INT64_MIN
;
bsfs_flush
(
avctx
);
if
(
av_codec_is_decoder
(
avctx
->
codec
))
av_bsf_flush
(
avci
->
bsf
);
if
(
!
avctx
->
refcounted_frames
)
if
(
!
avctx
->
refcounted_frames
)
av_frame_unref
(
avci
->
to_free
);
av_frame_unref
(
avci
->
to_free
);
...
@@ -2125,11 +2009,5 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
...
@@ -2125,11 +2009,5 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
void
ff_decode_bsfs_uninit
(
AVCodecContext
*
avctx
)
void
ff_decode_bsfs_uninit
(
AVCodecContext
*
avctx
)
{
{
DecodeFilterContext
*
s
=
&
avctx
->
internal
->
filter
;
av_bsf_free
(
&
avctx
->
internal
->
bsf
);
int
i
;
for
(
i
=
0
;
i
<
s
->
nb_bsfs
;
i
++
)
av_bsf_free
(
&
s
->
bsfs
[
i
]);
av_freep
(
&
s
->
bsfs
);
s
->
nb_bsfs
=
0
;
}
}
libavcodec/internal.h
View file @
c96904f5
...
@@ -113,11 +113,6 @@ typedef struct DecodeSimpleContext {
...
@@ -113,11 +113,6 @@ typedef struct DecodeSimpleContext {
AVFrame
*
out_frame
;
AVFrame
*
out_frame
;
}
DecodeSimpleContext
;
}
DecodeSimpleContext
;
typedef
struct
DecodeFilterContext
{
AVBSFContext
**
bsfs
;
int
nb_bsfs
;
}
DecodeFilterContext
;
typedef
struct
AVCodecInternal
{
typedef
struct
AVCodecInternal
{
/**
/**
* Whether the parent AVCodecContext is a copy of the context which had
* Whether the parent AVCodecContext is a copy of the context which had
...
@@ -140,7 +135,7 @@ typedef struct AVCodecInternal {
...
@@ -140,7 +135,7 @@ typedef struct AVCodecInternal {
void
*
thread_ctx
;
void
*
thread_ctx
;
DecodeSimpleContext
ds
;
DecodeSimpleContext
ds
;
DecodeFilterContext
filter
;
AVBSFContext
*
bsf
;
/**
/**
* Properties (timestamps+side data) extracted from the last packet passed
* Properties (timestamps+side data) extracted from the last packet passed
...
...
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