diff options
author | lionel.g.landwerlin <lionel.g.landwerlin@intel.com> | 2015-07-14 08:57:32 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-14 15:58:00 +0000 |
commit | 0141e7812a6a7b6b24b7b4df25bf5d4a1bc8c348 (patch) | |
tree | cec3eed2548d68079fbc81f1ea24e3c58302ce68 /ppapi/examples | |
parent | 0c5a55a6a377689f2c2450fc56f9919a03621d71 (diff) | |
download | chromium_src-0141e7812a6a7b6b24b7b4df25bf5d4a1bc8c348.zip chromium_src-0141e7812a6a7b6b24b7b4df25bf5d4a1bc8c348.tar.gz chromium_src-0141e7812a6a7b6b24b7b4df25bf5d4a1bc8c348.tar.bz2 |
ppapi: VideoEncoder: augment precision of the IVF container
Use millisecond timestamps in the IVF container rather than having
1.0/30 units of time. This prevents a drift in the replay of the
video because the recorder might not schedule frames at exactly
33.3333ms.
BUG=503153
TEST=record a 2 minutes vp8 video using the video encoder NaCl SDK and verify the produced video last exactly 2 minutes
Review URL: https://codereview.chromium.org/1226203010
Cr-Commit-Position: refs/heads/master@{#338694}
Diffstat (limited to 'ppapi/examples')
-rw-r--r-- | ppapi/examples/video_encode/video_encode.cc | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/ppapi/examples/video_encode/video_encode.cc b/ppapi/examples/video_encode/video_encode.cc index 229c30d..12e5280 100644 --- a/ppapi/examples/video_encode/video_encode.cc +++ b/ppapi/examples/video_encode/video_encode.cc @@ -7,6 +7,7 @@ #include <string.h> #include <algorithm> +#include <deque> #include <iostream> #include <map> #include <sstream> @@ -86,7 +87,7 @@ uint32_t IVFWriter::WriteFileHeader(uint8_t* mem, PutLE32(mem + 8, fourcc('V', 'P', '8', '0')); // fourcc PutLE16(mem + 12, static_cast<uint16_t>(width)); // width PutLE16(mem + 14, static_cast<uint16_t>(height)); // height - PutLE32(mem + 16, 30); // rate + PutLE32(mem + 16, 1000); // rate PutLE32(mem + 20, 1); // scale PutLE32(mem + 24, 0xffffffff); // length PutLE32(mem + 28, 0); // unused @@ -179,6 +180,8 @@ class VideoEncoderInstance : public pp::Instance { pp::Size encoder_size_; uint32_t encoded_frames_; + std::deque<uint64_t> frames_timestamps_; + pp::VideoFrame current_track_frame_; IVFWriter ivf_writer_; @@ -311,6 +314,7 @@ void VideoEncoderInstance::OnEncoderProbed( void VideoEncoderInstance::StartEncoder() { video_encoder_ = pp::VideoEncoder(this); + frames_timestamps_.clear(); int32_t error = video_encoder_.Initialize( frame_format_, frame_size_, video_profile_, 2000000, @@ -428,6 +432,8 @@ int32_t VideoEncoderInstance::CopyVideoFrame(pp::VideoFrame dest, } void VideoEncoderInstance::EncodeFrame(const pp::VideoFrame& frame) { + frames_timestamps_.push_back( + static_cast<uint64_t>(frame.GetTimestamp() * 1000)); video_encoder_.Encode( frame, PP_FALSE, callback_factory_.NewCallback(&VideoEncoderInstance::OnEncodeDone)); @@ -555,10 +561,11 @@ void VideoEncoderInstance::PostDataMessage(const void* buffer, uint32_t size) { size + ivf_writer_.GetFrameHeaderSize()); data_ptr = static_cast<uint8_t*>(array_buffer.Map()); } - data_offset = frame_offset + - ivf_writer_.WriteFrameHeader(data_ptr + frame_offset, - encoded_frames_, - size); + uint64_t timestamp = frames_timestamps_.front(); + frames_timestamps_.pop_front(); + data_offset = + frame_offset + + ivf_writer_.WriteFrameHeader(data_ptr + frame_offset, timestamp, size); } else { array_buffer = pp::VarArrayBuffer(size); data_ptr = static_cast<uint8_t*>(array_buffer.Map()); |