Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle decoder only frames #10

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions c_src/xav/xav_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ 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");
}
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
Loading