Skip to content

Commit

Permalink
Handle decoder only frames
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Aug 8, 2024
1 parent 499bf2c commit a6ec2aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions c_src/xav/xav_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,14 @@ ERL_NIF_TERM decode(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
decoder_decode(xav_decoder->decoder, xav_decoder->decoder->pkt, xav_decoder->decoder->frame);
if (ret == -2) {
return xav_nif_error(env, "no_keyframe");
} else if (ret == AVERROR(EAGAIN)) {
// Some frames are meant for decoder only
// and they don't include actual video samples.
decoder_free_frame(xav_decoder->decoder);
return enif_make_atom(env, "ok");
} else if (ret != 0) {
return xav_nif_raise(env, "failed_to_decode");
AVERROR(EAGAIN);
}

// convert
Expand Down
9 changes: 8 additions & 1 deletion lib/decoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,21 @@ defmodule Xav.Decoder do

@doc """
Decodes an audio/video frame.
Some frames are meant for decoder only and might not
contain actual video samples.
In such cases, `:ok` term is returned.
"""
@spec decode(t(), binary(), pts: integer(), dts: integer()) ::
{:ok, Xav.Frame.t()} | {:error, atom()}
:ok | {:ok, Xav.Frame.t()} | {:error, atom()}
def decode(decoder, data, opts \\ []) do
pts = opts[:pts] || 0
dts = opts[:dts] || 0

case Xav.Decoder.NIF.decode(decoder, data, pts, dts) do
:ok ->
:ok

{:ok, {data, format, width, height, pts}} ->
{:ok, Xav.Frame.new(data, format, width, height, pts)}

Expand Down

0 comments on commit a6ec2aa

Please sign in to comment.