summaryrefslogtreecommitdiff
path: root/audio/stream.c
diff options
context:
space:
mode:
Diffstat (limited to 'audio/stream.c')
-rw-r--r--audio/stream.c47
1 files changed, 47 insertions, 0 deletions
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;
+}