Skip to content

Commit

Permalink
Add packet size
Browse files Browse the repository at this point in the history
  • Loading branch information
dmorn committed Nov 8, 2023
1 parent 487b866 commit 0139148
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions c_src/libav.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ ERL_NIF_TERM enif_packet_metadata(ErlNifEnv *env, int argc,
enif_make_long(env, packet->pts), &map);
enif_make_map_put(env, map, enif_make_atom(env, "dts"),
enif_make_long(env, packet->dts), &map);
enif_make_map_put(env, map, enif_make_atom(env, "size"),
enif_make_long(env, packet->size), &map);
enif_make_map_put(env, map, enif_make_atom(env, "stream_index"),
enif_make_int(env, packet->stream_index), &map);

Expand Down
12 changes: 10 additions & 2 deletions lib/avx/packet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ defmodule AVx.Packet do
@type t :: %__MODULE__{
ref: reference(),
payload: nil | binary(),
size: pos_integer(),
stream_index: pos_integer(),
pts: pos_integer(),
dts: pos_integer()
}

defstruct ref: nil, payload: nil, stream_index: -1, pts: -1, dts: -1
defstruct ref: nil, payload: nil, size: 0, stream_index: -1, pts: -1, dts: -1

@spec new(reference()) :: t()
def new(nil) do
Expand All @@ -16,7 +17,14 @@ defmodule AVx.Packet do

def new(ref) do
meta = AVx.NIF.packet_metadata(ref)
%__MODULE__{ref: ref, stream_index: meta.stream_index, pts: meta.pts, dts: meta.dts}

%__MODULE__{
ref: ref,
size: meta.size,
stream_index: meta.stream_index,
pts: meta.pts,
dts: meta.dts
}
end

@spec unpack(t()) :: t()
Expand Down

0 comments on commit 0139148

Please sign in to comment.