diff --git a/src/hwenc_jetson/jetson_h264_encoder.cpp b/src/hwenc_jetson/jetson_h264_encoder.cpp index 97dec05f..c1e2753c 100644 --- a/src/hwenc_jetson/jetson_h264_encoder.cpp +++ b/src/hwenc_jetson/jetson_h264_encoder.cpp @@ -450,8 +450,8 @@ bool JetsonH264Encoder::EncodeFinishedCallback(struct v4l2_buffer* v4l2_buf, } params = std::move(frame_params_.front()); frame_params_.pop(); - } while (params->timestamp < pts); - if (params->timestamp != pts) { + } while (params->timestamp_us < pts); + if (params->timestamp_us != pts) { RTC_LOG(LS_WARNING) << __FUNCTION__ << "Frame parameter is not found. SkipFrame pts:" << pts; @@ -463,7 +463,7 @@ bool JetsonH264Encoder::EncodeFinishedCallback(struct v4l2_buffer* v4l2_buf, encoded_image_._encodedHeight = params->height; encoded_image_.capture_time_ms_ = params->render_time_ms; encoded_image_.ntp_time_ms_ = params->ntp_time_ms; - encoded_image_.SetTimestamp(pts * 90 / rtc::kNumMicrosecsPerMillisec); // timestamp resolution is 90 kHz + encoded_image_.SetTimestamp(params->timestamp_rtp); encoded_image_.rotation_ = params->rotation; encoded_image_.SetColorSpace(params->color_space); @@ -598,8 +598,8 @@ int32_t JetsonH264Encoder::Encode( frame_params_.push(absl::make_unique( frame_buffer->width(), frame_buffer->height(), input_frame.render_time_ms(), input_frame.ntp_time_ms(), - input_frame.timestamp_us(), input_frame.rotation(), - input_frame.color_space())); + input_frame.timestamp_us(), input_frame.timestamp(), + input_frame.rotation(), input_frame.color_space())); } struct v4l2_buffer v4l2_buf; diff --git a/src/hwenc_jetson/jetson_h264_encoder.h b/src/hwenc_jetson/jetson_h264_encoder.h index 802f934e..91a592e3 100644 --- a/src/hwenc_jetson/jetson_h264_encoder.h +++ b/src/hwenc_jetson/jetson_h264_encoder.h @@ -52,14 +52,16 @@ class JetsonH264Encoder : public webrtc::VideoEncoder { int32_t h, int64_t rtms, int64_t ntpms, - int64_t ts, + int64_t tsus, + int64_t rtpts, webrtc::VideoRotation r, absl::optional c) : width(w), height(h), render_time_ms(rtms), ntp_time_ms(ntpms), - timestamp(ts), + timestamp_us(tsus), + timestamp_rtp(rtpts), rotation(r), color_space(c) {} @@ -67,7 +69,8 @@ class JetsonH264Encoder : public webrtc::VideoEncoder { int32_t height; int64_t render_time_ms; int64_t ntp_time_ms; - int64_t timestamp; + int64_t timestamp_us; + int64_t timestamp_rtp; webrtc::VideoRotation rotation; absl::optional color_space; }; diff --git a/src/hwenc_mmal/mmal_h264_encoder.cpp b/src/hwenc_mmal/mmal_h264_encoder.cpp index b3df7247..f2dc192e 100644 --- a/src/hwenc_mmal/mmal_h264_encoder.cpp +++ b/src/hwenc_mmal/mmal_h264_encoder.cpp @@ -280,8 +280,8 @@ void MMALH264Encoder::EncoderOutputCallback(MMAL_PORT_T* port, } params = std::move(frame_params_.front()); frame_params_.pop(); - } while (params->timestamp < buffer->pts); - if (params->timestamp != buffer->pts) { + } while (params->timestamp_us < buffer->pts); + if (params->timestamp_us != buffer->pts) { RTC_LOG(LS_WARNING) << __FUNCTION__ << "Frame parameter is not found. SkipFrame pts:" << buffer->pts; @@ -293,7 +293,7 @@ void MMALH264Encoder::EncoderOutputCallback(MMAL_PORT_T* port, encoded_image_._encodedHeight = params->height; encoded_image_.capture_time_ms_ = params->render_time_ms; encoded_image_.ntp_time_ms_ = params->ntp_time_ms; - encoded_image_.SetTimestamp(buffer->pts); + encoded_image_.SetTimestamp(params->timestamp_rtp); encoded_image_.rotation_ = params->rotation; encoded_image_.SetColorSpace(params->color_space); @@ -431,13 +431,13 @@ int32_t MMALH264Encoder::Encode( frame_params_.push(absl::make_unique( frame_buffer->width(), frame_buffer->height(), input_frame.render_time_ms(), input_frame.ntp_time_ms(), - input_frame.timestamp(), input_frame.rotation(), - input_frame.color_space())); + input_frame.timestamp_us(), input_frame.timestamp(), + input_frame.rotation(), input_frame.color_space())); } MMAL_BUFFER_HEADER_T* buffer; if ((buffer = mmal_queue_get(encoder_pool_in_->queue)) != nullptr) { - buffer->pts = buffer->dts = input_frame.timestamp(); + buffer->pts = buffer->dts = input_frame.timestamp_us(); buffer->offset = 0; buffer->flags = MMAL_BUFFER_HEADER_FLAG_FRAME; if (frame_buffer->type() == webrtc::VideoFrameBuffer::Type::kNative) { diff --git a/src/hwenc_mmal/mmal_h264_encoder.h b/src/hwenc_mmal/mmal_h264_encoder.h index d8f1469f..39fa5546 100644 --- a/src/hwenc_mmal/mmal_h264_encoder.h +++ b/src/hwenc_mmal/mmal_h264_encoder.h @@ -60,14 +60,16 @@ class MMALH264Encoder : public webrtc::VideoEncoder { int32_t h, int64_t rtms, int64_t ntpms, - int64_t ts, + int64_t tsus, + int64_t rtpts, webrtc::VideoRotation r, absl::optional c) : width(w), height(h), render_time_ms(rtms), ntp_time_ms(ntpms), - timestamp(ts), + timestamp_us(tsus), + timestamp_rtp(rtpts), rotation(r), color_space(c) {} @@ -75,7 +77,8 @@ class MMALH264Encoder : public webrtc::VideoEncoder { int32_t height; int64_t render_time_ms; int64_t ntp_time_ms; - int64_t timestamp; + int64_t timestamp_us; + int64_t timestamp_rtp; webrtc::VideoRotation rotation; absl::optional color_space; };