]> git.sesse.net Git - nageru/commitdiff
Make the VideoEncoder own the stream audio encoder (and make it unconditionally)...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 23 Apr 2016 21:36:49 +0000 (23:36 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 23 Apr 2016 21:36:49 +0000 (23:36 +0200)
quicksync_encoder.cpp
quicksync_encoder.h
video_encoder.cpp
video_encoder.h

index b3a832c3d0a19ed633a2bb9d61813b47b00594c9..7d211798a504d07e91137e77a77815732ebad3a1 100644 (file)
@@ -193,7 +193,7 @@ FrameReorderer::Frame FrameReorderer::get_first_frame()
 
 class QuickSyncEncoderImpl {
 public:
-       QuickSyncEncoderImpl(const std::string &filename, QSurface *surface, const string &va_display, int width, int height, Mux *stream_mux);
+       QuickSyncEncoderImpl(const std::string &filename, QSurface *surface, const string &va_display, int width, int height, Mux *stream_mux, AudioEncoder *stream_audio_encoder);
        ~QuickSyncEncoderImpl();
        void add_audio(int64_t pts, vector<float> audio);
        bool begin_frame(GLuint *y_tex, GLuint *cbcr_tex);
@@ -273,7 +273,7 @@ private:
        QSurface *surface;
 
        unique_ptr<AudioEncoder> file_audio_encoder;
-       unique_ptr<AudioEncoder> stream_audio_encoder;
+       AudioEncoder *stream_audio_encoder;
 
        Mux* stream_mux;  // To HTTP.
        unique_ptr<Mux> file_mux;  // To local disk.
@@ -1651,9 +1651,7 @@ void QuickSyncEncoderImpl::save_codeddata(storage_task task)
                }
 
                file_audio_encoder->encode_audio(audio, audio_pts + global_delay());
-               if (stream_audio_encoder) {
-                       stream_audio_encoder->encode_audio(audio, audio_pts + global_delay());
-               }
+               stream_audio_encoder->encode_audio(audio, audio_pts + global_delay());
 
                if (audio_pts == task.pts) break;
        }
@@ -1732,18 +1730,12 @@ namespace {
 
 }  // namespace
 
-QuickSyncEncoderImpl::QuickSyncEncoderImpl(const std::string &filename, QSurface *surface, const string &va_display, int width, int height, Mux *stream_mux)
-       : current_storage_frame(0), surface(surface), stream_mux(stream_mux), frame_width(width), frame_height(height)
+QuickSyncEncoderImpl::QuickSyncEncoderImpl(const std::string &filename, QSurface *surface, const string &va_display, int width, int height, Mux *stream_mux, AudioEncoder *stream_audio_encoder)
+       : current_storage_frame(0), surface(surface), stream_audio_encoder(stream_audio_encoder), stream_mux(stream_mux), frame_width(width), frame_height(height)
 {
        file_audio_encoder.reset(new AudioEncoder(AUDIO_OUTPUT_CODEC_NAME, DEFAULT_AUDIO_OUTPUT_BIT_RATE));
        open_output_file(filename);
        file_audio_encoder->add_mux(file_mux.get());
-       if (global_flags.stream_audio_codec_name.empty()) {
-               file_audio_encoder->add_mux(stream_mux);
-       } else {
-               stream_audio_encoder.reset(new AudioEncoder(global_flags.stream_audio_codec_name, global_flags.stream_audio_codec_bitrate));
-               stream_audio_encoder->add_mux(stream_mux);
-       }
 
        frame_width_mbaligned = (frame_width + 15) & (~15);
        frame_height_mbaligned = (frame_height + 15) & (~15);
@@ -2056,10 +2048,8 @@ void QuickSyncEncoderImpl::encode_remaining_audio()
        pending_audio_frames.clear();
 
        // Encode any leftover audio in the queues, and also any delayed frames.
+       // Note: stream_audio_encoder is not owned by us, so don't call encode_last_audio().
        file_audio_encoder->encode_last_audio();
-       if (stream_audio_encoder) {
-               stream_audio_encoder->encode_last_audio();
-       }
 }
 
 void QuickSyncEncoderImpl::add_packet_for_uncompressed_frame(int64_t pts, int64_t duration, const uint8_t *data)
@@ -2181,8 +2171,8 @@ void QuickSyncEncoderImpl::encode_frame(QuickSyncEncoderImpl::PendingFrame frame
 }
 
 // Proxy object.
-QuickSyncEncoder::QuickSyncEncoder(const std::string &filename, QSurface *surface, const string &va_display, int width, int height, Mux *stream_mux)
-       : impl(new QuickSyncEncoderImpl(filename, surface, va_display, width, height, stream_mux)) {}
+QuickSyncEncoder::QuickSyncEncoder(const std::string &filename, QSurface *surface, const string &va_display, int width, int height, Mux *stream_mux, AudioEncoder *stream_audio_encoder)
+       : impl(new QuickSyncEncoderImpl(filename, surface, va_display, width, height, stream_mux, stream_audio_encoder)) {}
 
 // Must be defined here because unique_ptr<> destructor needs to know the impl.
 QuickSyncEncoder::~QuickSyncEncoder() {}
index 994987ebd6afaf8f517e5d7c32a90f8b8fa498bc..9ec7c85b88a28e76777b8474ec6449fdd61eceaa 100644 (file)
 #include <string>
 #include <vector>
 
-#include "mux.h"
 #include "ref_counted_frame.h"
 #include "ref_counted_gl_sync.h"
 
+class AudioEncoder;
+class Mux;
 class QuickSyncEncoderImpl;
 class QSurface;
 
@@ -45,7 +46,7 @@ class QSurface;
 // .cpp file.
 class QuickSyncEncoder {
 public:
-        QuickSyncEncoder(const std::string &filename, QSurface *surface, const std::string &va_display, int width, int height, Mux *stream_mux);
+        QuickSyncEncoder(const std::string &filename, QSurface *surface, const std::string &va_display, int width, int height, Mux *stream_mux, AudioEncoder *stream_audio_encoder);
         ~QuickSyncEncoder();
 
        void add_audio(int64_t pts, std::vector<float> audio);
index ed9a93ec245cbd2e9ac1bad9cee1ab20f7920522..0df3b4ffe66c2bf8019be319233faa010c3796f8 100644 (file)
@@ -38,8 +38,15 @@ VideoEncoder::VideoEncoder(QSurface *surface, const std::string &va_display, int
 {
        open_output_stream();
 
+       if (global_flags.stream_audio_codec_name.empty()) {
+               stream_audio_encoder.reset(new AudioEncoder(AUDIO_OUTPUT_CODEC_NAME, DEFAULT_AUDIO_OUTPUT_BIT_RATE));
+       } else {
+               stream_audio_encoder.reset(new AudioEncoder(global_flags.stream_audio_codec_name, global_flags.stream_audio_codec_bitrate));
+       }
+       stream_audio_encoder->add_mux(stream_mux.get());
+
        string filename = generate_local_dump_filename(/*frame=*/0);
-       quicksync_encoder.reset(new QuickSyncEncoder(filename, surface, va_display, width, height, stream_mux.get()));
+       quicksync_encoder.reset(new QuickSyncEncoder(filename, surface, va_display, width, height, stream_mux.get(), stream_audio_encoder.get()));
 }
 
 VideoEncoder::~VideoEncoder()
@@ -53,7 +60,7 @@ void VideoEncoder::do_cut(int frame)
        string filename = generate_local_dump_filename(frame);
        printf("Starting new recording: %s\n", filename.c_str());
        quicksync_encoder->shutdown();
-       quicksync_encoder.reset(new QuickSyncEncoder(filename, surface, va_display, width, height, stream_mux.get()));
+       quicksync_encoder.reset(new QuickSyncEncoder(filename, surface, va_display, width, height, stream_mux.get(), stream_audio_encoder.get()));
 }
 
 void VideoEncoder::add_audio(int64_t pts, std::vector<float> audio)
index 489d9d318c9c9650846f939c8ab82f93b295ea00..bf203f1438cbc2b1a2138fb1764fc576fa8b93c7 100644 (file)
@@ -10,6 +10,7 @@
 #include <string>
 #include <vector>
 
+#include "audio_encoder.h"
 #include "mux.h"
 #include "ref_counted_frame.h"
 #include "ref_counted_gl_sync.h"
@@ -47,6 +48,7 @@ private:
        HTTPD *httpd;
 
        std::unique_ptr<Mux> stream_mux;  // To HTTP.
+       std::unique_ptr<AudioEncoder> stream_audio_encoder;
 
        // While Mux object is constructing, <stream_mux_writing_header> is true,
        // and the header is being collected into stream_mux_header.