X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fquicksync_encoder.cpp;h=75b13b899a0cee05e109ef5b53764f82ebeb767b;hb=5d6ba6daaffcddb3aaf1e3c39f80ab4447c0e074;hp=e22bab39aa9827283d72df23cb2c4338b68c551f;hpb=0c7201c2d136870ea8c5fe205bee21207369312c;p=nageru diff --git a/nageru/quicksync_encoder.cpp b/nageru/quicksync_encoder.cpp index e22bab3..75b13b8 100644 --- a/nageru/quicksync_encoder.cpp +++ b/nageru/quicksync_encoder.cpp @@ -40,7 +40,7 @@ extern "C" { #include #include #include -#include +#include } // namespace @@ -713,14 +713,11 @@ void QuickSyncEncoderImpl::enable_zerocopy_if_possible() if (global_flags.x264_video_to_disk) { // Quick Sync is entirely disabled. use_zerocopy = false; - } else if (global_flags.uncompressed_video_to_http) { - fprintf(stderr, "Disabling zerocopy H.264 encoding due to --http-uncompressed-video.\n"); - use_zerocopy = false; } else if (global_flags.x264_video_to_http) { - fprintf(stderr, "Disabling zerocopy H.264 encoding due to --http-x264-video.\n"); + use_zerocopy = false; + } else if (global_flags.av1_video_to_http) { use_zerocopy = false; } else if (!global_flags.v4l_output_device.empty()) { - fprintf(stderr, "Disabling zerocopy H.264 encoding due to --v4l-output.\n"); use_zerocopy = false; } else { use_zerocopy = true; @@ -903,7 +900,7 @@ int QuickSyncEncoderImpl::setup_encode() gl_surfaces[i].y_tex = resource_pool->create_2d_texture(GL_R8, 1, 1); gl_surfaces[i].cbcr_tex = resource_pool->create_2d_texture(GL_RG8, 1, 1); } else { - size_t bytes_per_pixel = (global_flags.x264_bit_depth > 8) ? 2 : 1; + size_t bytes_per_pixel = (global_flags.bit_depth > 8) ? 2 : 1; // Generate a PBO to read into. It doesn't necessarily fit 1:1 with the VA-API // buffers, due to potentially differing pitch. @@ -1341,8 +1338,8 @@ void QuickSyncEncoderImpl::save_codeddata(GLSurface *surf, storage_task task) if (file_mux) { file_mux->add_packet(pkt, task.pts + global_delay(), task.dts + global_delay()); } - if (!global_flags.uncompressed_video_to_http && - !global_flags.x264_video_to_http) { + if (!global_flags.x264_video_to_http && + !global_flags.av1_video_to_http) { stream_mux->add_packet(pkt, task.pts + global_delay(), task.dts + global_delay()); } } @@ -1352,6 +1349,7 @@ void QuickSyncEncoderImpl::save_codeddata(GLSurface *surf, storage_task task) // this is weird. but it seems to put a new frame onto the queue void QuickSyncEncoderImpl::storage_task_enqueue(storage_task task) { + assert(task.pts >= task.dts); lock_guard lock(storage_task_queue_mutex); storage_task_queue.push(move(task)); storage_task_queue_changed.notify_all(); @@ -1435,8 +1433,8 @@ void QuickSyncEncoderImpl::release_gl_resources() has_released_gl_resources = true; } -QuickSyncEncoderImpl::QuickSyncEncoderImpl(const std::string &filename, 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) +QuickSyncEncoderImpl::QuickSyncEncoderImpl(const std::string &filename, ResourcePool *resource_pool, QSurface *surface, const string &va_display, int width, int height, const AVOutputFormat *oformat, VideoCodecInterface *http_encoder, VideoCodecInterface *disk_encoder, DiskSpaceEstimator *disk_space_estimator) + : current_storage_frame(0), resource_pool(resource_pool), surface(surface), http_encoder(http_encoder), disk_encoder(disk_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); @@ -1448,9 +1446,13 @@ QuickSyncEncoderImpl::QuickSyncEncoderImpl(const std::string &filename, Resource //print_input(); if (global_flags.x264_video_to_http || global_flags.x264_video_to_disk) { - assert(x264_encoder != nullptr); + assert(http_encoder != nullptr); + assert(disk_encoder != nullptr); + } else if (global_flags.av1_video_to_http) { + assert(http_encoder != nullptr); } else { - assert(x264_encoder == nullptr); + assert(http_encoder == nullptr); + assert(disk_encoder == nullptr); } enable_zerocopy_if_possible(); @@ -1625,7 +1627,7 @@ RefCountedGLsync QuickSyncEncoderImpl::end_frame() assert(!is_shutdown); if (!use_zerocopy) { - GLenum type = global_flags.x264_bit_depth > 8 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE; + GLenum type = global_flags.bit_depth > 8 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE; GLSurface *surf; { lock_guard lock(storage_task_queue_mutex); @@ -1731,7 +1733,7 @@ void QuickSyncEncoderImpl::open_output_file(const std::string &filename) string video_extradata; // FIXME: See other comment about global headers. if (global_flags.x264_video_to_disk) { - video_extradata = x264_encoder->get_global_headers(); + video_extradata = disk_encoder->get_global_headers(); } current_file_mux_metrics.reset(); @@ -1747,7 +1749,7 @@ void QuickSyncEncoderImpl::open_output_file(const std::string &filename) metric_current_file_start_time_seconds = get_timestamp_for_metrics(); if (global_flags.x264_video_to_disk) { - x264_encoder->add_mux(file_mux.get()); + disk_encoder->add_mux(file_mux.get()); } } @@ -1852,19 +1854,6 @@ void QuickSyncEncoderImpl::encode_remaining_frames_as_p(int encoding_frame_num, } } -void QuickSyncEncoderImpl::add_packet_for_uncompressed_frame(int64_t pts, int64_t duration, const uint8_t *data) -{ - AVPacket pkt; - memset(&pkt, 0, sizeof(pkt)); - pkt.buf = nullptr; - pkt.data = const_cast(data); - pkt.size = frame_width * frame_height * 2; - pkt.stream_index = 0; - pkt.flags = AV_PKT_FLAG_KEY; - pkt.duration = duration; - stream_mux->add_packet(pkt, pts, pts); -} - void memcpy_with_pitch(uint8_t *dst, const uint8_t *src, size_t src_width, size_t dst_pitch, size_t height) { if (src_width == dst_pitch) { @@ -1907,10 +1896,10 @@ void QuickSyncEncoderImpl::pass_frame(QuickSyncEncoderImpl::PendingFrame frame, assert(surf != nullptr); } uint8_t *data = reinterpret_cast(surf->y_ptr); - if (global_flags.uncompressed_video_to_http) { - add_packet_for_uncompressed_frame(pts, duration, data); - } else if (global_flags.x264_video_to_http || global_flags.x264_video_to_disk) { - x264_encoder->add_frame(pts, duration, frame.ycbcr_coefficients, data, received_ts); + if (http_encoder != nullptr) { + http_encoder->add_frame(pts, duration, frame.ycbcr_coefficients, data, received_ts); + } if (disk_encoder != nullptr && disk_encoder != http_encoder) { + disk_encoder->add_frame(pts, duration, frame.ycbcr_coefficients, data, received_ts); } if (v4l_output != nullptr) { @@ -2012,8 +2001,8 @@ void QuickSyncEncoderImpl::encode_frame(QuickSyncEncoderImpl::PendingFrame frame } // Proxy object. -QuickSyncEncoder::QuickSyncEncoder(const std::string &filename, 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)) {} +QuickSyncEncoder::QuickSyncEncoder(const std::string &filename, ResourcePool *resource_pool, QSurface *surface, const string &va_display, int width, int height, const AVOutputFormat *oformat, VideoCodecInterface *http_encoder, VideoCodecInterface *disk_encoder, DiskSpaceEstimator *disk_space_estimator) + : impl(new QuickSyncEncoderImpl(filename, resource_pool, surface, va_display, width, height, oformat, http_encoder, disk_encoder, disk_space_estimator)) {} // Must be defined here because unique_ptr<> destructor needs to know the impl. QuickSyncEncoder::~QuickSyncEncoder() {}