From c1cb78d574c0429aa5e3ff3a2b3886e4bc153212 Mon Sep 17 00:00:00 2001 From: bbergeron Date: Wed, 3 Apr 2024 17:32:01 -0400 Subject: Reset Git repo and use a pseudonym to sign commits I used to sign my commits with my real name and my personal email address, which I wanted scrubbed off the "B." pseudosphere. Re-creating a new git repository was safer than simpler than re-writing the history (although the latter could've also worked but, oh well). --- audio/stream.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 audio/stream.c (limited to 'audio/stream.c') diff --git a/audio/stream.c b/audio/stream.c new file mode 100644 index 0000000..7bab674 --- /dev/null +++ b/audio/stream.c @@ -0,0 +1,47 @@ +#include "stream.h" + +int stream_init(struct Stream *stream, AVFormatContext *s, int codec_id, int sample_rate, int format, const AVChannelLayout *layout, AVDictionary **opts) +{ + int err; + AVStream *av_stream; + + if ((av_stream = avformat_new_stream(s, NULL)) == NULL) + return AVERROR(ENOMEM); + av_stream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + av_stream->codecpar->codec_id = codec_id; + av_stream->codecpar->sample_rate = sample_rate; + av_stream->codecpar->format = format; + av_stream->codecpar->ch_layout = *layout; + + if ((err = avformat_init_output(s, opts)) < 0) + return err; + + stream->av_stream = av_stream; + stream->s = s; + return 0; +} + +int stream_send (struct Stream *stream, AVPacket *pkt) +{ + int err; + int64_t duration; + + // NOTE: + // Before encoding; + // - frame_out->pts DOES matter + // + // After encoding; + // - pkt->pts is set to something + // - pkt->timebase is unset, but would be '1 / output_sample_rate' + // - pkt->duration is set to the amount of sample in the packet + // - pkt->dts seems to be pkt->pts + pkt->stream_index = stream->av_stream->index; + //av_packet_rescale_ts(pkt_out, encoder->time_base, stream->time_base); + //print_pts(pkt_out, &stream->time_base); + + duration = pkt->duration; + if ((err = av_interleaved_write_frame(stream->s, pkt)) < 0) + return err; + + return duration; +} -- cgit v1.2.3