obs-ffmpeg: Define DARRAY macro type

Passing struct darray type will loose the actual type of the contents.
Uses a defined type of `DARRAY(struct encoder_packet)` to carry the
type when crossing functions.
This commit is contained in:
Norihiro Kamae 2023-06-12 00:47:20 +09:00 committed by Lain
parent fa02582db6
commit 097e011194
2 changed files with 12 additions and 14 deletions

View file

@ -813,12 +813,12 @@ static inline bool has_audio(struct ffmpeg_muxer *stream)
return !!obs_output_get_audio_encoder(stream->output, 0);
}
static void push_back_packet(struct darray *packets,
static void push_back_packet(mux_packets_t *packets,
struct encoder_packet *packet)
{
struct encoder_packet pkt;
obs_encoder_packet_ref(&pkt, packet);
darray_push_back(sizeof(pkt), packets, &pkt);
da_push_back(*packets, &pkt);
}
static void ffmpeg_mux_data(void *data, struct encoder_packet *packet)
@ -841,8 +841,7 @@ static void ffmpeg_mux_data(void *data, struct encoder_packet *packet)
if (pts_usec >= first_pts_usec) {
if (packet->type != OBS_ENCODER_AUDIO) {
push_back_packet(&stream->mux_packets.da,
packet);
push_back_packet(&stream->mux_packets, packet);
return;
}
@ -852,7 +851,7 @@ static void ffmpeg_mux_data(void *data, struct encoder_packet *packet)
}
} else if (stream->split_file && should_split(stream, packet)) {
if (has_audio(stream)) {
push_back_packet(&stream->mux_packets.da, packet);
push_back_packet(&stream->mux_packets, packet);
return;
} else {
if (!prepare_split_file(stream, packet))
@ -1123,13 +1122,11 @@ static inline void replay_buffer_purge(struct ffmpeg_muxer *stream,
purge(stream);
}
static void insert_packet(struct darray *array, struct encoder_packet *packet,
static void insert_packet(mux_packets_t *packets, struct encoder_packet *packet,
int64_t video_offset, int64_t *audio_offsets,
int64_t video_pts_offset, int64_t *audio_dts_offsets)
{
struct encoder_packet pkt;
DARRAY(struct encoder_packet) packets;
packets.da = *array;
size_t idx;
obs_encoder_packet_ref(&pkt, packet);
@ -1144,14 +1141,13 @@ static void insert_packet(struct darray *array, struct encoder_packet *packet,
pkt.pts -= audio_dts_offsets[pkt.track_idx];
}
for (idx = packets.num; idx > 0; idx--) {
struct encoder_packet *p = packets.array + (idx - 1);
for (idx = packets->num; idx > 0; idx--) {
struct encoder_packet *p = packets->array + (idx - 1);
if (p->dts_usec < pkt.dts_usec)
break;
}
da_insert(packets, idx, &pkt);
*array = packets.da;
da_insert(*packets, idx, &pkt);
}
static void *replay_buffer_mux_thread(void *data)
@ -1244,7 +1240,7 @@ static void replay_buffer_save(struct ffmpeg_muxer *stream)
}
}
insert_packet(&stream->mux_packets.da, pkt, video_offset,
insert_packet(&stream->mux_packets, pkt, video_offset,
audio_offsets, video_pts_offset,
audio_dts_offsets);
}

View file

@ -9,6 +9,8 @@
#include <util/platform.h>
#include <util/threading.h>
typedef DARRAY(struct encoder_packet) mux_packets_t;
struct ffmpeg_muxer {
obs_output_t *output;
os_process_pipe_t *pipe;
@ -34,7 +36,7 @@ struct ffmpeg_muxer {
int keyframes;
obs_hotkey_id hotkey;
volatile bool muxing;
DARRAY(struct encoder_packet) mux_packets;
mux_packets_t mux_packets;
/* split file */
bool found_video;