X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=quicksync_encoder.cpp;h=4e974223d15def72a9d348a2a4eb94039077d0e2;hb=402b3d36c13bb04e9a2f690c5c12d8f85d6dc415;hp=5bba54632907216d79fcc6801f1c8299e85eb56f;hpb=319b807ceede52e45cf07f712259b1a42ec3cc54;p=nageru diff --git a/quicksync_encoder.cpp b/quicksync_encoder.cpp index 5bba546..4e97422 100644 --- a/quicksync_encoder.cpp +++ b/quicksync_encoder.cpp @@ -1,18 +1,17 @@ -//#include "sysdeps.h" #include "quicksync_encoder.h" -#include +#include // Must be above the Xlib includes. #include + #include -#include #include #include #include -#include +#include #include #include #include -#include +#include #include #include #include @@ -20,24 +19,40 @@ #include #include #include +#include #include +#include #include #include #include #include +#include #include #include #include +extern "C" { + +#include +#include +#include +#include + +} // namespace + #include "audio_encoder.h" #include "context.h" #include "defs.h" +#include "disk_space_estimator.h" +#include "ffmpeg_raii.h" #include "flags.h" #include "mux.h" +#include "ref_counted_frame.h" #include "timebase.h" #include "x264_encoder.h" using namespace std; +using namespace std::placeholders; class QOpenGLContext; class QSurface; @@ -194,7 +209,7 @@ FrameReorderer::Frame FrameReorderer::get_first_frame() class QuickSyncEncoderImpl { public: - QuickSyncEncoderImpl(const std::string &filename, movit::ResourcePool *resource_pool, QSurface *surface, const string &va_display, int width, int height, AVOutputFormat *oformat, X264Encoder *x264_encoder); + QuickSyncEncoderImpl(const std::string &filename, movit::ResourcePool *resource_pool, QSurface *surface, const string &va_display, int width, int height, AVOutputFormat *oformat, X264Encoder *x264_encoder, DiskSpaceEstimator *disk_space_estimator); ~QuickSyncEncoderImpl(); void add_audio(int64_t pts, vector audio); bool begin_frame(GLuint *y_tex, GLuint *cbcr_tex); @@ -343,6 +358,8 @@ private: int frame_height; int frame_width_mbaligned; int frame_height_mbaligned; + + DiskSpaceEstimator *disk_space_estimator; }; // Supposedly vaRenderPicture() is supposed to destroy the buffer implicitly, @@ -1716,12 +1733,8 @@ int QuickSyncEncoderImpl::deinit_va() return 0; } -namespace { - -} // namespace - -QuickSyncEncoderImpl::QuickSyncEncoderImpl(const std::string &filename, movit::ResourcePool *resource_pool, QSurface *surface, const string &va_display, int width, int height, AVOutputFormat *oformat, X264Encoder *x264_encoder) - : current_storage_frame(0), resource_pool(resource_pool), surface(surface), x264_encoder(x264_encoder), frame_width(width), frame_height(height) +QuickSyncEncoderImpl::QuickSyncEncoderImpl(const std::string &filename, movit::ResourcePool *resource_pool, QSurface *surface, const string &va_display, int width, int height, AVOutputFormat *oformat, X264Encoder *x264_encoder, DiskSpaceEstimator *disk_space_estimator) + : current_storage_frame(0), resource_pool(resource_pool), surface(surface), x264_encoder(x264_encoder), frame_width(width), frame_height(height), disk_space_estimator(disk_space_estimator) { file_audio_encoder.reset(new AudioEncoder(AUDIO_OUTPUT_CODEC_NAME, DEFAULT_AUDIO_OUTPUT_BIT_RATE, oformat)); open_output_file(filename); @@ -1943,7 +1956,8 @@ void QuickSyncEncoderImpl::open_output_file(const std::string &filename) string video_extradata = ""; // FIXME: See other comment about global headers. AVCodecParametersWithDeleter audio_codecpar = file_audio_encoder->get_codec_parameters(); - file_mux.reset(new Mux(avctx, frame_width, frame_height, Mux::CODEC_H264, video_extradata, audio_codecpar.get(), TIMEBASE)); + file_mux.reset(new Mux(avctx, frame_width, frame_height, Mux::CODEC_H264, video_extradata, audio_codecpar.get(), TIMEBASE, + std::bind(&DiskSpaceEstimator::report_write, disk_space_estimator, filename, _1))); } void QuickSyncEncoderImpl::encode_thread_func() @@ -2148,8 +2162,8 @@ void QuickSyncEncoderImpl::encode_frame(QuickSyncEncoderImpl::PendingFrame frame } // Proxy object. -QuickSyncEncoder::QuickSyncEncoder(const std::string &filename, movit::ResourcePool *resource_pool, QSurface *surface, const string &va_display, int width, int height, AVOutputFormat *oformat, X264Encoder *x264_encoder) - : impl(new QuickSyncEncoderImpl(filename, resource_pool, surface, va_display, width, height, oformat, x264_encoder)) {} +QuickSyncEncoder::QuickSyncEncoder(const std::string &filename, movit::ResourcePool *resource_pool, QSurface *surface, const string &va_display, int width, int height, AVOutputFormat *oformat, X264Encoder *x264_encoder, DiskSpaceEstimator *disk_space_estimator) + : impl(new QuickSyncEncoderImpl(filename, resource_pool, surface, va_display, width, height, oformat, x264_encoder, disk_space_estimator)) {} // Must be defined here because unique_ptr<> destructor needs to know the impl. QuickSyncEncoder::~QuickSyncEncoder() {}