Skip to content

Commit

Permalink
move build of encoded image
Browse files Browse the repository at this point in the history
  • Loading branch information
mpromonet committed Dec 31, 2023
1 parent 4708e3a commit ee1587a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
25 changes: 17 additions & 8 deletions inc/EncodedVideoFrameBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,13 +49,13 @@ class EncodedVideoFrameBuffer : public webrtc::VideoFrameBuffer
{
public:
EncodedVideoFrameBuffer(int width, int height, const rtc::scoped_refptr<webrtc::EncodedImageBufferInterface> &encoded_data, webrtc::VideoFrameType frameType)
: buffer_(new rtc::RefCountedObject<EncodedVideoI420Buffer>(width, height, encoded_data, frameType)) {}
: m_buffer(new rtc::RefCountedObject<EncodedVideoI420Buffer>(width, height, encoded_data, frameType)) {}
virtual Type type() const { return webrtc::VideoFrameBuffer::Type::kNative; }
virtual rtc::scoped_refptr<webrtc::I420BufferInterface> 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<EncodedVideoI420Buffer> buffer_;
rtc::scoped_refptr<EncodedVideoI420Buffer> m_buffer;
};
17 changes: 4 additions & 13 deletions inc/NullEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit ee1587a

Please sign in to comment.