[fix] find out dav1d decode error

This commit is contained in:
dijunkun
2024-10-15 17:36:18 +08:00
parent 9a6def32fd
commit 6e622b4ab2
2 changed files with 58 additions and 27 deletions

View File

@@ -2,8 +2,8 @@
#include "log.h" #include "log.h"
#define SAVE_RECEIVED_AV1_STREAM 1 #define SAVE_RECEIVED_AV1_STREAM 0
#define SAVE_DECODED_NV12_STREAM 0 #define SAVE_DECODED_NV12_STREAM 1
#include "libyuv.h" #include "libyuv.h"
@@ -31,14 +31,10 @@ class ScopedDav1dData {
void NullFreeCallback(const uint8_t *buffer, void *opaque) {} void NullFreeCallback(const uint8_t *buffer, void *opaque) {}
void Yuv420pToNv12(unsigned char *SrcY, unsigned char *SrcU, void Yuv420pToNv12(unsigned char *SrcY, unsigned char *SrcU,
unsigned char *SrcV, unsigned char *Dst, int Width, unsigned char *SrcV, int y_stride, int uv_stride,
int Height) { unsigned char *Dst, int Width, int Height) {
memcpy(Dst, SrcY, Width * Height); libyuv::I420ToNV12(SrcY, y_stride, SrcU, uv_stride, SrcV, uv_stride, Dst,
unsigned char *DstU = Dst + Width * Height; Width, Dst + Width * Height, Width / 2, Width, Height);
for (int i = 0; i < Width * Height / 4; i++) {
(*DstU++) = (*SrcU++);
(*DstU++) = (*SrcV++);
}
} }
Dav1dAv1Decoder::Dav1dAv1Decoder() {} Dav1dAv1Decoder::Dav1dAv1Decoder() {}
@@ -167,22 +163,58 @@ int Dav1dAv1Decoder::Decode(
nv12_frame_->SetHeight(frame_height_); nv12_frame_->SetHeight(frame_height_);
} }
if (0) { // if (1) {
Yuv420pToNv12((unsigned char *)dav1d_picture.data[0], // Yuv420pToNv12((unsigned char *)dav1d_picture.data[0],
(unsigned char *)dav1d_picture.data[1], // (unsigned char *)dav1d_picture.data[1],
(unsigned char *)dav1d_picture.data[2], // (unsigned char *)dav1d_picture.data[2],
(unsigned char *)nv12_frame_->Buffer(), frame_width_, // dav1d_picture.stride[0], dav1d_picture.stride[1],
frame_height_); // (unsigned char *)nv12_frame_->Buffer(), frame_width_,
} else { // frame_height_);
libyuv::I420ToNV12( // } else {
(const uint8_t *)dav1d_picture.data[0], dav1d_picture.p.w, // libyuv::I420ToNV12(
(const uint8_t *)dav1d_picture.data[1], dav1d_picture.p.w / 2, // (const uint8_t *)dav1d_picture.data[0], dav1d_picture.stride[0],
(const uint8_t *)dav1d_picture.data[2], dav1d_picture.p.w / 2, // (const uint8_t *)dav1d_picture.data[1], dav1d_picture.stride[1] / 2,
(uint8_t *)nv12_frame_->Buffer(), frame_width_, // (const uint8_t *)dav1d_picture.data[2], dav1d_picture.stride[1] / 2,
(uint8_t *)nv12_frame_->Buffer() + frame_width_ * frame_height_, // (uint8_t *)nv12_frame_->Buffer(), frame_width_,
frame_width_, frame_width_, frame_height_); // (uint8_t *)nv12_frame_->Buffer() + frame_width_ * frame_height_,
// frame_width_ / 2, frame_width_, frame_height_);
// }
size_t y_size = frame_width_ * frame_height_;
size_t u_size = frame_width_ * frame_height_ / 4;
size_t v_size = frame_width_ * frame_height_ / 4;
for (int i = 0; i < frame_height_; i++) {
memcpy((void *)(nv12_frame_->Buffer() + i * frame_width_),
(uint8_t *)(dav1d_picture.data[0]) + i * dav1d_picture.stride[0],
frame_width_);
} }
// for (int i = 0; i < frame_height_ / 2; i++) {
// memcpy((void *)(nv12_frame_->Buffer() + y_size + i * (frame_width_ / 2)),
// (uint8_t *)(dav1d_picture.data[1]) + i * dav1d_picture.stride[1],
// frame_width_ / 2);
// }
uint8_t *uv_plane = (uint8_t *)nv12_frame_->Buffer() + y_size;
for (int i = 0; i < frame_height_ / 2; i++) {
for (int j = 0; j < frame_width_ / 2; j++) {
uv_plane[i * frame_width_ + 2 * j] =
((uint8_t *)(dav1d_picture.data[1]))[i * dav1d_picture.stride[1] + j];
uv_plane[i * frame_width_ + 2 * j + 1] =
((uint8_t *)(dav1d_picture.data[2]))[i * dav1d_picture.stride[1] + j];
}
}
for (int i = 0; i < frame_height_ / 2; i++) {
memcpy((void *)(nv12_frame_->Buffer() + y_size + u_size +
i * (frame_width_ / 2)),
(uint8_t *)(dav1d_picture.data[2]) + i * dav1d_picture.stride[1],
frame_width_ / 2);
}
LOG_ERROR("{}x{}", dav1d_picture.stride[0], dav1d_picture.stride[1]);
on_receive_decoded_frame(*nv12_frame_); on_receive_decoded_frame(*nv12_frame_);
if (SAVE_DECODED_NV12_STREAM) { if (SAVE_DECODED_NV12_STREAM) {

View File

@@ -6,7 +6,7 @@
#include "log.h" #include "log.h"
#define SAVE_RECEIVED_NV12_STREAM 0 #define SAVE_RECEIVED_NV12_STREAM 0
#define SAVE_ENCODED_AV1_STREAM 1 #define SAVE_ENCODED_AV1_STREAM 0
#define SET_ENCODER_PARAM_OR_RETURN_ERROR(param_id, param_value) \ #define SET_ENCODER_PARAM_OR_RETURN_ERROR(param_id, param_value) \
do { \ do { \
@@ -25,8 +25,6 @@ constexpr int kLagInFrames = 0; // No look ahead.
constexpr int kRtpTicksPerSecond = 90000; constexpr int kRtpTicksPerSecond = 90000;
constexpr double kMinimumFrameRate = 1.0; constexpr double kMinimumFrameRate = 1.0;
constexpr uint8_t kObuSizePresentBit = 0b0'0000'010;
static aom_superblock_size_t GetSuperblockSize(int width, int height, static aom_superblock_size_t GetSuperblockSize(int width, int height,
int threads) { int threads) {
int resolution = width * height; int resolution = width * height;
@@ -341,6 +339,7 @@ int AomAv1Encoder::Encode(const XVideoFrame *video_frame,
// LOG_INFO("Encoded frame qp = {}", qp); // LOG_INFO("Encoded frame qp = {}", qp);
if (on_encoded_image) { if (on_encoded_image) {
LOG_ERROR("enc {}x{}", video_frame->width, video_frame->height);
on_encoded_image((char *)encoded_frame_, encoded_frame_size_, on_encoded_image((char *)encoded_frame_, encoded_frame_size_,
frame_type); frame_type);
if (SAVE_ENCODED_AV1_STREAM) { if (SAVE_ENCODED_AV1_STREAM) {