]> git.sesse.net Git - nageru/blobdiff - mux.cpp
Allow symlinked frame files. Useful for testing.
[nageru] / mux.cpp
diff --git a/mux.cpp b/mux.cpp
index 37bf321d5020208d8f4c2d501ab4926a5431eedb..bcbbef3c1c7ba429a534c6cda6b4e98cf9852005 100644 (file)
--- a/mux.cpp
+++ b/mux.cpp
@@ -1,12 +1,12 @@
 #include "mux.h"
 
+#include <algorithm>
 #include <assert.h>
+#include <mutex>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <algorithm>
-#include <mutex>
 #include <string>
 #include <utility>
 #include <vector>
@@ -58,10 +58,12 @@ Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const
        avstream_video->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
        if (video_codec == CODEC_H264) {
                avstream_video->codecpar->codec_id = AV_CODEC_ID_H264;
-       } else {
-               assert(video_codec == CODEC_NV12);
+       } else if (video_codec == CODEC_NV12) {
                avstream_video->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
                avstream_video->codecpar->codec_tag = avcodec_pix_fmt_to_codec_tag(AV_PIX_FMT_NV12);
+       } else {
+               assert(video_codec == CODEC_MJPEG);
+               avstream_video->codecpar->codec_id = AV_CODEC_ID_MJPEG;
        }
        avstream_video->codecpar->width = width;
        avstream_video->codecpar->height = height;
@@ -86,6 +88,8 @@ Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const
                memcpy(avstream_video->codecpar->extradata, video_extradata.data(), video_extradata.size());
        }
 
+       avstream_audio = nullptr;
+#if 0
        avstream_audio = avformat_new_stream(avctx, nullptr);
        if (avstream_audio == nullptr) {
                fprintf(stderr, "avformat_new_stream() failed\n");
@@ -96,6 +100,7 @@ Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const
                fprintf(stderr, "avcodec_parameters_copy() failed\n");
                exit(1);
        }
+#endif
 
        AVDictionary *options = NULL;
        vector<pair<string, string>> opts = MUX_OPTS;
@@ -166,7 +171,8 @@ void Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts, AVRational t
                lock_guard<mutex> lock(mu);
                if (write_strategy == WriteStrategy::WRITE_BACKGROUND) {
                        packet_queue.push_back(QueuedPacket{ av_packet_clone(&pkt_copy), pts });
-                       if (plug_count == 0) packet_queue_ready.notify_all();
+                       if (plug_count == 0)
+                               packet_queue_ready.notify_all();
                } else if (plug_count > 0) {
                        packet_queue.push_back(QueuedPacket{ av_packet_clone(&pkt_copy), pts });
                } else {
@@ -191,7 +197,7 @@ void Mux::write_packet_or_die(const AVPacket &pkt, int64_t unscaled_pts)
        int64_t old_pos = avctx->pb->pos;
        if (av_interleaved_write_frame(avctx, const_cast<AVPacket *>(&pkt)) < 0) {
                fprintf(stderr, "av_interleaved_write_frame() failed\n");
-               exit(1);
+               abort();
        }
        avio_flush(avctx->pb);
        for (MuxMetrics *metric : metrics) {
@@ -232,6 +238,8 @@ void Mux::unplug()
 
 void Mux::thread_func()
 {
+       pthread_setname_np(pthread_self(), "Mux");
+
        unique_lock<mutex> lock(mu);
        for ( ;; ) {
                packet_queue_ready.wait(lock, [this]() {