Skip to content

Commit

Permalink
#137 に関連してタイムスタンプの取り扱いを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
tnoho committed Mar 9, 2020
1 parent 13a8629 commit b02ea79
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/hwenc_jetson/jetson_h264_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -598,8 +598,8 @@ int32_t JetsonH264Encoder::Encode(
frame_params_.push(absl::make_unique<FrameParams>(
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;
Expand Down
9 changes: 6 additions & 3 deletions src/hwenc_jetson/jetson_h264_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,25 @@ 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<webrtc::ColorSpace> 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) {}

int32_t width;
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<webrtc::ColorSpace> color_space;
};
Expand Down
12 changes: 6 additions & 6 deletions src/hwenc_mmal/mmal_h264_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -431,13 +431,13 @@ int32_t MMALH264Encoder::Encode(
frame_params_.push(absl::make_unique<FrameParams>(
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) {
Expand Down
9 changes: 6 additions & 3 deletions src/hwenc_mmal/mmal_h264_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,25 @@ 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<webrtc::ColorSpace> 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) {}

int32_t width;
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<webrtc::ColorSpace> color_space;
};
Expand Down

0 comments on commit b02ea79

Please sign in to comment.