mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
[fix] fix the function which converts yuv420p into nv12
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include "log.h"
|
||||
|
||||
#define SAVE_RECEIVED_AV1_STREAM 0
|
||||
#define SAVE_DECODED_NV12_STREAM 1
|
||||
#define SAVE_DECODED_NV12_STREAM 0
|
||||
|
||||
#include "libyuv.h"
|
||||
|
||||
@@ -33,8 +33,17 @@ void NullFreeCallback(const uint8_t *buffer, void *opaque) {}
|
||||
void Yuv420pToNv12(unsigned char *SrcY, unsigned char *SrcU,
|
||||
unsigned char *SrcV, int y_stride, int uv_stride,
|
||||
unsigned char *Dst, int Width, int Height) {
|
||||
libyuv::I420ToNV12(SrcY, y_stride, SrcU, uv_stride, SrcV, uv_stride, Dst,
|
||||
Width, Dst + Width * Height, Width / 2, Width, Height);
|
||||
for (int i = 0; i < Height; i++) {
|
||||
memcpy(Dst + i * Width, SrcY + i * y_stride, Width);
|
||||
}
|
||||
|
||||
unsigned char *DstUV = Dst + Width * Height;
|
||||
for (int i = 0; i < Height / 2; i++) {
|
||||
for (int j = 0; j < Width / 2; j++) {
|
||||
DstUV[i * Width + 2 * j] = SrcU[i * uv_stride + j];
|
||||
DstUV[i * Width + 2 * j + 1] = SrcV[i * uv_stride + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dav1dAv1Decoder::Dav1dAv1Decoder() {}
|
||||
@@ -163,58 +172,23 @@ int Dav1dAv1Decoder::Decode(
|
||||
nv12_frame_->SetHeight(frame_height_);
|
||||
}
|
||||
|
||||
// if (1) {
|
||||
// Yuv420pToNv12((unsigned char *)dav1d_picture.data[0],
|
||||
// (unsigned char *)dav1d_picture.data[1],
|
||||
// (unsigned char *)dav1d_picture.data[2],
|
||||
// dav1d_picture.stride[0], dav1d_picture.stride[1],
|
||||
// (unsigned char *)nv12_frame_->Buffer(), frame_width_,
|
||||
// frame_height_);
|
||||
// } else {
|
||||
// libyuv::I420ToNV12(
|
||||
// (const uint8_t *)dav1d_picture.data[0], dav1d_picture.stride[0],
|
||||
// (const uint8_t *)dav1d_picture.data[1], dav1d_picture.stride[1] / 2,
|
||||
// (const uint8_t *)dav1d_picture.data[2], dav1d_picture.stride[1] / 2,
|
||||
// (uint8_t *)nv12_frame_->Buffer(), frame_width_,
|
||||
// (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_);
|
||||
if (0) {
|
||||
Yuv420pToNv12((unsigned char *)dav1d_picture.data[0],
|
||||
(unsigned char *)dav1d_picture.data[1],
|
||||
(unsigned char *)dav1d_picture.data[2],
|
||||
dav1d_picture.stride[0], dav1d_picture.stride[1],
|
||||
(unsigned char *)nv12_frame_->Buffer(), frame_width_,
|
||||
frame_height_);
|
||||
} else {
|
||||
libyuv::I420ToNV12(
|
||||
(const uint8_t *)dav1d_picture.data[0], dav1d_picture.stride[0],
|
||||
(const uint8_t *)dav1d_picture.data[1], dav1d_picture.stride[1],
|
||||
(const uint8_t *)dav1d_picture.data[2], dav1d_picture.stride[1],
|
||||
(uint8_t *)nv12_frame_->Buffer(), frame_width_,
|
||||
(uint8_t *)nv12_frame_->Buffer() + frame_width_ * frame_height_,
|
||||
frame_width_, frame_width_, frame_height_);
|
||||
}
|
||||
|
||||
// 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_);
|
||||
|
||||
if (SAVE_DECODED_NV12_STREAM) {
|
||||
|
||||
@@ -339,7 +339,6 @@ int AomAv1Encoder::Encode(const XVideoFrame *video_frame,
|
||||
// LOG_INFO("Encoded frame qp = {}", qp);
|
||||
|
||||
if (on_encoded_image) {
|
||||
LOG_ERROR("enc {}x{}", video_frame->width, video_frame->height);
|
||||
on_encoded_image((char *)encoded_frame_, encoded_frame_size_,
|
||||
frame_type);
|
||||
if (SAVE_ENCODED_AV1_STREAM) {
|
||||
|
||||
Reference in New Issue
Block a user