]> git.sesse.net Git - nageru/commitdiff
Move X264Encoder out of QuickSyncEncoder. This completes independent restart of the...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 23 Apr 2016 21:45:39 +0000 (23:45 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 23 Apr 2016 21:45:39 +0000 (23:45 +0200)
quicksync_encoder.cpp
quicksync_encoder.h
video_encoder.cpp
video_encoder.h

index 7d211798a504d07e91137e77a77815732ebad3a1..41ace54263d1d235e8a02c4a905ac9fc34e8f3c0 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, AudioEncoder *stream_audio_encoder);
+       QuickSyncEncoderImpl(const std::string &filename, QSurface *surface, const string &va_display, int width, int height, Mux *stream_mux, AudioEncoder *stream_audio_encoder, X264Encoder *x264_encoder);
        ~QuickSyncEncoderImpl();
        void add_audio(int64_t pts, vector<float> audio);
        bool begin_frame(GLuint *y_tex, GLuint *cbcr_tex);
@@ -275,12 +275,12 @@ private:
        unique_ptr<AudioEncoder> file_audio_encoder;
        AudioEncoder *stream_audio_encoder;
 
+       unique_ptr<FrameReorderer> reorderer;
+       X264Encoder *x264_encoder;  // nullptr if not using x264.
+
        Mux* stream_mux;  // To HTTP.
        unique_ptr<Mux> file_mux;  // To local disk.
 
-       unique_ptr<FrameReorderer> reorderer;
-       unique_ptr<X264Encoder> x264_encoder;  // nullptr if not using x264.
-
        Display *x11_display = nullptr;
 
        // Encoder parameters
@@ -1730,8 +1730,8 @@ namespace {
 
 }  // namespace
 
-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)
+QuickSyncEncoderImpl::QuickSyncEncoderImpl(const std::string &filename, QSurface *surface, const string &va_display, int width, int height, Mux *stream_mux, AudioEncoder *stream_audio_encoder, X264Encoder *x264_encoder)
+       : current_storage_frame(0), surface(surface), stream_audio_encoder(stream_audio_encoder), x264_encoder(x264_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);
@@ -1747,7 +1747,9 @@ QuickSyncEncoderImpl::QuickSyncEncoderImpl(const std::string &filename, QSurface
                reorderer.reset(new FrameReorderer(ip_period - 1, frame_width, frame_height));
        }
        if (global_flags.x264_video_to_http) {
-               x264_encoder.reset(new X264Encoder(stream_mux));
+               assert(x264_encoder != nullptr);
+       } else {
+               assert(x264_encoder == nullptr);
        }
 
        init_va(va_display);
@@ -1919,7 +1921,6 @@ void QuickSyncEncoderImpl::shutdown()
                frame_queue_nonempty.notify_all();
        }
        encode_thread.join();
-       x264_encoder.reset();
        {
                unique_lock<mutex> lock(storage_task_queue_mutex);
                storage_thread_should_quit = true;
@@ -2171,8 +2172,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, AudioEncoder *stream_audio_encoder)
-       : impl(new QuickSyncEncoderImpl(filename, surface, va_display, width, height, stream_mux, stream_audio_encoder)) {}
+QuickSyncEncoder::QuickSyncEncoder(const std::string &filename, QSurface *surface, const string &va_display, int width, int height, Mux *stream_mux, AudioEncoder *stream_audio_encoder, X264Encoder *x264_encoder)
+       : impl(new QuickSyncEncoderImpl(filename, surface, va_display, width, height, stream_mux, stream_audio_encoder, x264_encoder)) {}
 
 // Must be defined here because unique_ptr<> destructor needs to know the impl.
 QuickSyncEncoder::~QuickSyncEncoder() {}
index 9ec7c85b88a28e76777b8474ec6449fdd61eceaa..40bf15e90904bdb682906e7f130e2a33ef184f08 100644 (file)
@@ -40,13 +40,14 @@ class AudioEncoder;
 class Mux;
 class QuickSyncEncoderImpl;
 class QSurface;
+class X264Encoder;
 
 // This is just a pimpl, because including anything X11-related in a .h file
 // tends to trip up Qt. All the real logic is in QuickSyncEncoderImpl, defined in the
 // .cpp file.
 class QuickSyncEncoder {
 public:
-        QuickSyncEncoder(const std::string &filename, QSurface *surface, const std::string &va_display, int width, int height, Mux *stream_mux, AudioEncoder *stream_audio_encoder);
+        QuickSyncEncoder(const std::string &filename, QSurface *surface, const std::string &va_display, int width, int height, Mux *stream_mux, AudioEncoder *stream_audio_encoder, X264Encoder *x264_encoder);
         ~QuickSyncEncoder();
 
        void add_audio(int64_t pts, std::vector<float> audio);
index 0df3b4ffe66c2bf8019be319233faa010c3796f8..25765291a890a3de3eb294ed236d4ff01d160899 100644 (file)
@@ -9,6 +9,7 @@
 #include "httpd.h"
 #include "timebase.h"
 #include "quicksync_encoder.h"
+#include "x264_encoder.h"
 
 using namespace std;
 
@@ -45,8 +46,12 @@ VideoEncoder::VideoEncoder(QSurface *surface, const std::string &va_display, int
        }
        stream_audio_encoder->add_mux(stream_mux.get());
 
+       if (global_flags.x264_video_to_http) {
+               x264_encoder.reset(new X264Encoder(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(), stream_audio_encoder.get()));
+       quicksync_encoder.reset(new QuickSyncEncoder(filename, surface, va_display, width, height, stream_mux.get(), stream_audio_encoder.get(), x264_encoder.get()));
 }
 
 VideoEncoder::~VideoEncoder()
@@ -60,7 +65,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(), stream_audio_encoder.get()));
+       quicksync_encoder.reset(new QuickSyncEncoder(filename, surface, va_display, width, height, stream_mux.get(), stream_audio_encoder.get(), x264_encoder.get()));
 }
 
 void VideoEncoder::add_audio(int64_t pts, std::vector<float> audio)
index bf203f1438cbc2b1a2138fb1764fc576fa8b93c7..81c48992f8c7620289e83abc458dd6e7ddbaf2ad 100644 (file)
@@ -18,6 +18,7 @@
 class HTTPD;
 class QSurface;
 class QuickSyncEncoder;
+class X264Encoder;
 
 class VideoEncoder : public KeyFrameSignalReceiver {
 public:
@@ -49,6 +50,7 @@ private:
 
        std::unique_ptr<Mux> stream_mux;  // To HTTP.
        std::unique_ptr<AudioEncoder> stream_audio_encoder;
+       std::unique_ptr<X264Encoder> x264_encoder;  // nullptr if not using x264.
 
        // While Mux object is constructing, <stream_mux_writing_header> is true,
        // and the header is being collected into stream_mux_header.