Extract stream-specific structure in recorder
For now, it only contains the stream index, but more fields will be added.
This commit is contained in:
parent
9d3c656414
commit
9ca554ca41
2 changed files with 26 additions and 19 deletions
|
@ -96,23 +96,21 @@ sc_recorder_rescale_packet(AVStream *stream, AVPacket *packet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
sc_recorder_write_stream(struct sc_recorder *recorder, int stream_index,
|
sc_recorder_write_stream(struct sc_recorder *recorder,
|
||||||
AVPacket *packet) {
|
struct sc_recorder_stream *st, AVPacket *packet) {
|
||||||
AVStream *stream = recorder->ctx->streams[stream_index];
|
AVStream *stream = recorder->ctx->streams[st->index];
|
||||||
sc_recorder_rescale_packet(stream, packet);
|
sc_recorder_rescale_packet(stream, packet);
|
||||||
return av_interleaved_write_frame(recorder->ctx, packet) >= 0;
|
return av_interleaved_write_frame(recorder->ctx, packet) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
sc_recorder_write_video(struct sc_recorder *recorder, AVPacket *packet) {
|
sc_recorder_write_video(struct sc_recorder *recorder, AVPacket *packet) {
|
||||||
return sc_recorder_write_stream(recorder, recorder->video_stream_index,
|
return sc_recorder_write_stream(recorder, &recorder->video_stream, packet);
|
||||||
packet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
sc_recorder_write_audio(struct sc_recorder *recorder, AVPacket *packet) {
|
sc_recorder_write_audio(struct sc_recorder *recorder, AVPacket *packet) {
|
||||||
return sc_recorder_write_stream(recorder, recorder->audio_stream_index,
|
return sc_recorder_write_stream(recorder, &recorder->audio_stream, packet);
|
||||||
packet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -215,9 +213,9 @@ sc_recorder_process_header(struct sc_recorder *recorder) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(recorder->video_stream_index >= 0);
|
assert(recorder->video_stream.index >= 0);
|
||||||
AVStream *video_stream =
|
AVStream *video_stream =
|
||||||
recorder->ctx->streams[recorder->video_stream_index];
|
recorder->ctx->streams[recorder->video_stream.index];
|
||||||
bool ok = sc_recorder_set_extradata(video_stream, video_pkt);
|
bool ok = sc_recorder_set_extradata(video_stream, video_pkt);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -230,9 +228,9 @@ sc_recorder_process_header(struct sc_recorder *recorder) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(recorder->audio_stream_index >= 0);
|
assert(recorder->audio_stream.index >= 0);
|
||||||
AVStream *audio_stream =
|
AVStream *audio_stream =
|
||||||
recorder->ctx->streams[recorder->audio_stream_index];
|
recorder->ctx->streams[recorder->audio_stream.index];
|
||||||
bool ok = sc_recorder_set_extradata(audio_stream, audio_pkt);
|
bool ok = sc_recorder_set_extradata(audio_stream, audio_pkt);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -505,7 +503,7 @@ sc_recorder_video_packet_sink_open(struct sc_packet_sink *sink,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
recorder->video_stream_index = stream->index;
|
recorder->video_stream.index = stream->index;
|
||||||
|
|
||||||
recorder->video_init = true;
|
recorder->video_init = true;
|
||||||
sc_cond_signal(&recorder->cond);
|
sc_cond_signal(&recorder->cond);
|
||||||
|
@ -549,7 +547,7 @@ sc_recorder_video_packet_sink_push(struct sc_packet_sink *sink,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
rec->stream_index = recorder->video_stream_index;
|
rec->stream_index = recorder->video_stream.index;
|
||||||
|
|
||||||
bool ok = sc_vecdeque_push(&recorder->video_queue, rec);
|
bool ok = sc_vecdeque_push(&recorder->video_queue, rec);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
@ -586,7 +584,7 @@ sc_recorder_audio_packet_sink_open(struct sc_packet_sink *sink,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
recorder->audio_stream_index = stream->index;
|
recorder->audio_stream.index = stream->index;
|
||||||
|
|
||||||
recorder->audio_init = true;
|
recorder->audio_init = true;
|
||||||
sc_cond_signal(&recorder->cond);
|
sc_cond_signal(&recorder->cond);
|
||||||
|
@ -632,7 +630,7 @@ sc_recorder_audio_packet_sink_push(struct sc_packet_sink *sink,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
rec->stream_index = recorder->audio_stream_index;
|
rec->stream_index = recorder->audio_stream.index;
|
||||||
|
|
||||||
bool ok = sc_vecdeque_push(&recorder->audio_queue, rec);
|
bool ok = sc_vecdeque_push(&recorder->audio_queue, rec);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
@ -663,6 +661,11 @@ sc_recorder_audio_packet_sink_disable(struct sc_packet_sink *sink) {
|
||||||
sc_mutex_unlock(&recorder->mutex);
|
sc_mutex_unlock(&recorder->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sc_recorder_stream_init(struct sc_recorder_stream *stream) {
|
||||||
|
stream->index = -1;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sc_recorder_init(struct sc_recorder *recorder, const char *filename,
|
sc_recorder_init(struct sc_recorder *recorder, const char *filename,
|
||||||
enum sc_record_format format, bool video, bool audio,
|
enum sc_record_format format, bool video, bool audio,
|
||||||
|
@ -694,8 +697,8 @@ sc_recorder_init(struct sc_recorder *recorder, const char *filename,
|
||||||
recorder->video_init = false;
|
recorder->video_init = false;
|
||||||
recorder->audio_init = false;
|
recorder->audio_init = false;
|
||||||
|
|
||||||
recorder->video_stream_index = -1;
|
sc_recorder_stream_init(&recorder->video_stream);
|
||||||
recorder->audio_stream_index = -1;
|
sc_recorder_stream_init(&recorder->audio_stream);
|
||||||
|
|
||||||
recorder->format = format;
|
recorder->format = format;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
|
|
||||||
struct sc_recorder_queue SC_VECDEQUE(AVPacket *);
|
struct sc_recorder_queue SC_VECDEQUE(AVPacket *);
|
||||||
|
|
||||||
|
struct sc_recorder_stream {
|
||||||
|
int index;
|
||||||
|
};
|
||||||
|
|
||||||
struct sc_recorder {
|
struct sc_recorder {
|
||||||
struct sc_packet_sink video_packet_sink;
|
struct sc_packet_sink video_packet_sink;
|
||||||
struct sc_packet_sink audio_packet_sink;
|
struct sc_packet_sink audio_packet_sink;
|
||||||
|
@ -45,8 +49,8 @@ struct sc_recorder {
|
||||||
bool video_init;
|
bool video_init;
|
||||||
bool audio_init;
|
bool audio_init;
|
||||||
|
|
||||||
int video_stream_index;
|
struct sc_recorder_stream video_stream;
|
||||||
int audio_stream_index;
|
struct sc_recorder_stream audio_stream;
|
||||||
|
|
||||||
const struct sc_recorder_callbacks *cbs;
|
const struct sc_recorder_callbacks *cbs;
|
||||||
void *cbs_userdata;
|
void *cbs_userdata;
|
||||||
|
|
Loading…
Reference in a new issue