From b681e575356f56d89b0e5d8545163e4e3ee12e44 Mon Sep 17 00:00:00 2001 From: melpon Date: Sat, 20 Apr 2024 16:23:18 +0900 Subject: [PATCH] =?UTF-8?q?AV1=20=E3=81=AE=E3=82=B5=E3=82=A4=E3=83=9E?= =?UTF-8?q?=E3=83=AB=E3=82=AD=E3=83=A3=E3=82=B9=E3=83=88=E3=81=8C=E3=81=A1?= =?UTF-8?q?=E3=82=83=E3=82=93=E3=81=A8=E5=8B=95=E3=81=8F=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 4 +++- examples/sumomo/fake_capturer.cpp | 6 ++++-- examples/sumomo/mac_capturer.mm | 3 +++ examples/sumomo/v4l2_capturer.cpp | 2 ++ include/sorac/types.hpp | 3 +++ src/aom_av1_video_encoder.cpp | 10 ++++++---- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 627d8a5..f1161fd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -103,6 +103,8 @@ "recorder.h": "c", "__mutex_base": "cpp", "sorac.h": "c", - "soracp.json.c.h": "c" + "soracp.json.c.h": "c", + "complex": "cpp", + "cfenv": "cpp" } } \ No newline at end of file diff --git a/examples/sumomo/fake_capturer.cpp b/examples/sumomo/fake_capturer.cpp index fa659f9..99cd8b0 100644 --- a/examples/sumomo/fake_capturer.cpp +++ b/examples/sumomo/fake_capturer.cpp @@ -48,16 +48,17 @@ class FakeCapturer : public SumomoCapturer { std::uniform_int_distribution dist(0, width_ * height_ - 1); sorac::VideoFrame frame; frame.timestamp = timestamp; + frame.frame_number = ++frame_number_; if (format_ == SUMOMO_FAKE_CAPTURER_FORMAT_I420) { frame.i420_buffer = sorac::VideoFrameBufferI420::Create(width_, height_); - for (int i = 0; i < width_ / 100; i++) { + for (int i = 0; i < width_ / 10; i++) { frame.i420_buffer->y[dist(*engine_)] = 0xff; } } else if (format_ == SUMOMO_FAKE_CAPTURER_FORMAT_NV12) { frame.nv12_buffer = sorac::VideoFrameBufferNV12::Create(width_, height_); - for (int i = 0; i < width_ / 100; i++) { + for (int i = 0; i < width_ / 10; i++) { frame.nv12_buffer->y[dist(*engine_)] = 0xff; } } @@ -73,6 +74,7 @@ class FakeCapturer : public SumomoCapturer { int width_; int height_; int fps_; + int frame_number_ = 0; SumomoFakeCapturerFormat format_; std::function callback_; SteadyFrameThread th_; diff --git a/examples/sumomo/mac_capturer.mm b/examples/sumomo/mac_capturer.mm index a17a264..d931845 100644 --- a/examples/sumomo/mac_capturer.mm +++ b/examples/sumomo/mac_capturer.mm @@ -48,6 +48,7 @@ @implementation SumomoMacCapturer { std::function _callback; BOOL _willBeRunning; dispatch_queue_t _frameQueue; + int _frameNumber; } - (instancetype)initWithCallback: @@ -64,6 +65,7 @@ - (instancetype)initWithCallback: _videoDataOutput = [[AVCaptureVideoDataOutput alloc] init]; _willBeRunning = NO; _frameQueue = nil; + _frameNumber = 0; NSSet* supportedPixelFormats = [NSSet setWithObjects:@(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange), @@ -283,6 +285,7 @@ - (void)captureOutput:(AVCaptureOutput*)captureOutput (int64_t)(CMTimeGetSeconds( CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) * kMicrosecondsPerSecond)); + frame.frame_number = ++_frameNumber; frame.nv12_buffer = sorac::VideoFrameBufferNV12::Create(width, height); frame.base_width = width; frame.base_height = height; diff --git a/examples/sumomo/v4l2_capturer.cpp b/examples/sumomo/v4l2_capturer.cpp index 6fc1af9..2308e4c 100644 --- a/examples/sumomo/v4l2_capturer.cpp +++ b/examples/sumomo/v4l2_capturer.cpp @@ -229,6 +229,7 @@ class V4L2Capturer : public SumomoCapturer { frame.timestamp = sorac::get_current_time(); frame.base_width = width_; frame.base_height = height_; + frame.frame_number = ++frame_number_; callback_(frame); if (ioctl(device_fd_, VIDIOC_QBUF, &buf) < 0) { @@ -267,6 +268,7 @@ class V4L2Capturer : public SumomoCapturer { int width_; int height_; int fps_; + int frame_number_ = 0; int device_fd_ = -1; std::atomic quit_; diff --git a/include/sorac/types.hpp b/include/sorac/types.hpp index 163794e..87074e7 100644 --- a/include/sorac/types.hpp +++ b/include/sorac/types.hpp @@ -45,6 +45,9 @@ struct VideoFrame { int height() const { return i420_buffer != nullptr ? i420_buffer->height : nv12_buffer->height; } + // サイマルキャストで DD を利用する時にフレーム番号を全体で同じにする必要があるため + // ここにフレーム番号を持たせる + int frame_number; }; struct EncodedImage { diff --git a/src/aom_av1_video_encoder.cpp b/src/aom_av1_video_encoder.cpp index 2a0517b..60f9bc9 100644 --- a/src/aom_av1_video_encoder.cpp +++ b/src/aom_av1_video_encoder.cpp @@ -172,8 +172,6 @@ class AomAv1VideoEncoder : public VideoEncoder { SET_PARAM(AV1E_SET_ENABLE_TX64, 0); SET_PARAM(AV1E_SET_MAX_REFERENCE_FRAMES, 3); - frame_number_ = 0; - return true; } @@ -272,17 +270,21 @@ class AomAv1VideoEncoder : public VideoEncoder { delta_frame_template.frameDiffs = {1}; ctx.structure.templates = {key_frame_template, delta_frame_template}; ctx.activeChains[0] = true; - ctx.descriptor.frameNumber = ++frame_number_; + ctx.descriptor.frameNumber = frame.frame_number; if (is_key_frame) { ctx.descriptor.dependencyTemplate = key_frame_template; } else { ctx.descriptor.dependencyTemplate = delta_frame_template; + ctx.descriptor.dependencyTemplate.frameDiffs = {frame.frame_number - + prev_frame_number_}; } ctx.descriptor.structureAttached = is_key_frame; encoded.dependency_descriptor_context = std::make_shared< rtc::RtpPacketizationConfig::DependencyDescriptorContext>(ctx); + prev_frame_number_ = frame.frame_number; + callback_(encoded); } @@ -341,7 +343,7 @@ class AomAv1VideoEncoder : public VideoEncoder { aom_codec_enc_cfg_t cfg_; aom_image_t* frame_for_encode_ = nullptr; int64_t timestamp_ = 0; - int frame_number_ = 0; + int prev_frame_number_ = 0; std::function callback_;