From ee1587a71a96c592688d33b26365eb3811181eaa Mon Sep 17 00:00:00 2001 From: Michel Promonet Date: Sun, 31 Dec 2023 17:05:57 +0100 Subject: [PATCH] move build of encoded image --- inc/EncodedVideoFrameBuffer.h | 25 +++++++++++++++++-------- inc/NullEncoder.h | 17 ++++------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/inc/EncodedVideoFrameBuffer.h b/inc/EncodedVideoFrameBuffer.h index 558f13d4..b215e96d 100644 --- a/inc/EncodedVideoFrameBuffer.h +++ b/inc/EncodedVideoFrameBuffer.h @@ -21,13 +21,22 @@ class EncodedVideoI420Buffer : public webrtc::I420BufferInterface : m_width(width), m_height(height), m_encoded_data(encoded_data), m_frameType(frameType) {} virtual int width() const { return m_width; } virtual int height() const { return m_height; } - virtual const uint8_t *DataY() const { return m_encoded_data->data(); } + virtual const uint8_t *DataY() const { return NULL; } virtual const uint8_t *DataU() const { return NULL; } virtual const uint8_t *DataV() const { return NULL; } - virtual int StrideY() const { return m_encoded_data->size(); } + virtual int StrideY() const { return 0; } virtual int StrideU() const { return 0; } virtual int StrideV() const { return 0; } - webrtc::VideoFrameType getFrameType() const { return m_frameType; } + + webrtc::EncodedImage getEncodedImage(uint32_t rtptime, int ntptime ) const { + webrtc::EncodedImage encoded_image; + encoded_image.SetEncodedData(webrtc::EncodedImageBuffer::Create(m_encoded_data->data(), m_encoded_data->size())); + encoded_image._frameType = m_frameType; + encoded_image.SetAtTargetQuality(true); + encoded_image.SetRtpTimestamp(rtptime); + encoded_image.ntp_time_ms_ = ntptime; + return encoded_image; + } private: const int m_width; @@ -40,13 +49,13 @@ class EncodedVideoFrameBuffer : public webrtc::VideoFrameBuffer { public: EncodedVideoFrameBuffer(int width, int height, const rtc::scoped_refptr &encoded_data, webrtc::VideoFrameType frameType) - : buffer_(new rtc::RefCountedObject(width, height, encoded_data, frameType)) {} + : m_buffer(new rtc::RefCountedObject(width, height, encoded_data, frameType)) {} virtual Type type() const { return webrtc::VideoFrameBuffer::Type::kNative; } virtual rtc::scoped_refptr ToI420() { return webrtc::I420Buffer::Create(width(), height()); } - virtual int width() const { return buffer_->width(); } - virtual int height() const { return buffer_->height(); } - const webrtc::I420BufferInterface *GetI420() const final { return buffer_.get(); } + virtual int width() const { return m_buffer->width(); } + virtual int height() const { return m_buffer->height(); } + const webrtc::I420BufferInterface *GetI420() const final { return m_buffer.get(); } private: - rtc::scoped_refptr buffer_; + rtc::scoped_refptr m_buffer; }; diff --git a/inc/NullEncoder.h b/inc/NullEncoder.h index 85d43082..5a25b78b 100644 --- a/inc/NullEncoder.h +++ b/inc/NullEncoder.h @@ -48,20 +48,11 @@ class NullEncoder : public webrtc::VideoEncoder { return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; } - // compute frametype + // get webrtc::EncodedImage EncodedVideoI420Buffer* encodedBuffer = (EncodedVideoI420Buffer*)buffer->GetI420(); - const uint8_t* data = encodedBuffer->DataY(); - size_t dataSize = encodedBuffer->StrideY(); - webrtc::VideoFrameType frameType = encodedBuffer->getFrameType(); + webrtc::EncodedImage encoded_image = encodedBuffer->getEncodedImage(frame.timestamp(), frame.ntp_time_ms()); - // build webrtc::EncodedImage - webrtc::EncodedImage encoded_image; - encoded_image.SetEncodedData(webrtc::EncodedImageBuffer::Create(data, dataSize)); - encoded_image.SetRtpTimestamp(frame.timestamp()); - encoded_image.ntp_time_ms_ = frame.ntp_time_ms(); - encoded_image._frameType = frameType; - - RTC_LOG(LS_VERBOSE) << "EncodedImage " << frame.id() << " " << encoded_image._frameType << " " << buffer->width() << "x" << buffer->height() << " " << buffer->GetI420()->StrideY(); + RTC_LOG(LS_VERBOSE) << "EncodedImage " << frame.id() << " " << encoded_image.FrameType() << " " << buffer->width() << "x" << buffer->height(); // forward to callback webrtc::CodecSpecificInfo codec_specific; @@ -73,7 +64,7 @@ class NullEncoder : public webrtc::VideoEncoder { } webrtc::EncodedImageCallback::Result result = m_encoded_image_callback->OnEncodedImage(encoded_image, &codec_specific); if (result.error == webrtc::EncodedImageCallback::Result::ERROR_SEND_FAILED) { - RTC_LOG(LS_ERROR) << "Error in parsing EncodedImage " << frame.id() << " " << encoded_image._frameType << " " << buffer->width() << "x" << buffer->height() << " " << buffer->GetI420()->StrideY(); + RTC_LOG(LS_ERROR) << "Error in parsing EncodedImage " << frame.id() << " " << encoded_image._frameType << " " << buffer->width() << "x" << buffer->height(); } return WEBRTC_VIDEO_CODEC_OK; }