Skip to content

Commit

Permalink
add safety check on play state for ffenc
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlf committed Apr 11, 2024
1 parent 7dc0aca commit d178fe4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/filters/ff_enc.c
Expand Up @@ -52,7 +52,7 @@ typedef struct _gf_ffenc_ctx

//internal data
Bool gen_dsi;

Bool playing;
u32 gop_size;
u32 target_rate;

Expand Down Expand Up @@ -629,6 +629,7 @@ static GF_Err ffenc_process_video(GF_Filter *filter, struct _gf_ffenc_ctx *ctx)
}
#else
ctx->frame->pkt_dts = ctx->frame->pts;
GF_LOG(GF_LOG_DEBUG, GF_LOG_CODEC, ("[FFEnc] Encoding video frame PTS "LLU"\n", ctx->frame->pts));
res = avcodec_send_frame(ctx->encoder, ctx->frame);
if (temp_data) {
gf_free(temp_data);
Expand Down Expand Up @@ -1137,6 +1138,7 @@ static GF_Err ffenc_process_audio(GF_Filter *filter, struct _gf_ffenc_ctx *ctx)
ctx->frame->pkt_dts = ctx->frame->pkt_pts = ctx->frame->pts = ctx->first_byte_cts;
res = avcodec_encode_audio2(ctx->encoder, pkt, ctx->frame, &gotpck);
#else
GF_LOG(GF_LOG_DEBUG, GF_LOG_CODEC, ("[FFEnc] Encoding audio frame PTS "LLU"\n", ctx->frame->pts));
ctx->frame->pkt_dts = ctx->frame->pts = ctx->first_byte_cts;
res = avcodec_send_frame(ctx->encoder, ctx->frame);
switch (res) {
Expand Down Expand Up @@ -1351,7 +1353,9 @@ static GF_Err ffenc_process_audio(GF_Filter *filter, struct _gf_ffenc_ctx *ctx)
static GF_Err ffenc_process(GF_Filter *filter)
{
GF_FFEncodeCtx *ctx = (GF_FFEncodeCtx *) gf_filter_get_udta(filter);
if (!ctx->out_pid || gf_filter_pid_would_block(ctx->out_pid))
if (!ctx->out_pid || gf_filter_pid_would_block(ctx->out_pid)
//make sure we receive a play event
|| !ctx->playing)
return GF_OK;
return ctx->process(filter, ctx);
}
Expand Down Expand Up @@ -2173,8 +2177,14 @@ static GF_Err ffenc_update_arg(GF_Filter *filter, const char *arg_name, const GF

static Bool ffenc_process_event(GF_Filter *filter, const GF_FilterEvent *evt)
{
if (evt->base.type==GF_FEVT_ENCODE_HINTS) {
GF_FFEncodeCtx *ctx = gf_filter_get_udta(filter);
GF_FFEncodeCtx *ctx = gf_filter_get_udta(filter);
if (evt->base.type==GF_FEVT_PLAY) {
ctx->playing = GF_TRUE;
}
else if (evt->base.type==GF_FEVT_PLAY) {
ctx->playing = GF_FALSE;
}
else if (evt->base.type==GF_FEVT_ENCODE_HINTS) {
if (evt->encode_hints.gen_dsi_only) {
ctx->generate_dsi_only = GF_TRUE;
}
Expand Down

0 comments on commit d178fe4

Please sign in to comment.