Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(590)

Side by Side Diff: ppapi/examples/video_encode/video_encode.cc

Issue 1187193006: ppapi: VideoEncoder: improve accuracy of encoding tick (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « native_client_sdk/src/examples/api/video_encode/video_encode.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <math.h> 5 #include <math.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm>
9 #include <iostream> 10 #include <iostream>
10 #include <map> 11 #include <map>
11 #include <sstream> 12 #include <sstream>
12 #include <vector> 13 #include <vector>
13 14
14 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/c/ppb_console.h" 16 #include "ppapi/c/ppb_console.h"
16 #include "ppapi/cpp/input_event.h" 17 #include "ppapi/cpp/input_event.h"
17 #include "ppapi/cpp/instance.h" 18 #include "ppapi/cpp/instance.h"
18 #include "ppapi/cpp/media_stream_video_track.h" 19 #include "ppapi/cpp/media_stream_video_track.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 PP_VideoFrame_Format frame_format_; 170 PP_VideoFrame_Format frame_format_;
170 171
171 pp::Size requested_size_; 172 pp::Size requested_size_;
172 pp::Size frame_size_; 173 pp::Size frame_size_;
173 pp::Size encoder_size_; 174 pp::Size encoder_size_;
174 uint32_t encoded_frames_; 175 uint32_t encoded_frames_;
175 176
176 pp::VideoFrame current_track_frame_; 177 pp::VideoFrame current_track_frame_;
177 178
178 IVFWriter ivf_writer_; 179 IVFWriter ivf_writer_;
180
181 PP_Time last_encode_tick_;
179 }; 182 };
180 183
181 VideoEncoderInstance::VideoEncoderInstance(PP_Instance instance, 184 VideoEncoderInstance::VideoEncoderInstance(PP_Instance instance,
182 pp::Module* module) 185 pp::Module* module)
183 : pp::Instance(instance), 186 : pp::Instance(instance),
184 is_encoding_(false), 187 is_encoding_(false),
185 callback_factory_(this), 188 callback_factory_(this),
186 #if defined(USE_VP8_INSTEAD_OF_H264) 189 #if defined(USE_VP8_INSTEAD_OF_H264)
187 video_profile_(PP_VIDEOPROFILE_VP8_ANY), 190 video_profile_(PP_VIDEOPROFILE_VP8_ANY),
188 #else 191 #else
189 video_profile_(PP_VIDEOPROFILE_H264MAIN), 192 video_profile_(PP_VIDEOPROFILE_H264MAIN),
190 #endif 193 #endif
191 frame_format_(PP_VIDEOFRAME_FORMAT_I420), 194 frame_format_(PP_VIDEOFRAME_FORMAT_I420),
192 encoded_frames_(0) { 195 encoded_frames_(0),
196 last_encode_tick_(0) {
193 InitializeVideoProfiles(); 197 InitializeVideoProfiles();
194 ProbeEncoder(); 198 ProbeEncoder();
195 } 199 }
196 200
197 VideoEncoderInstance::~VideoEncoderInstance() { 201 VideoEncoderInstance::~VideoEncoderInstance() {
198 } 202 }
199 203
200 void VideoEncoderInstance::AddVideoProfile(PP_VideoProfile profile, 204 void VideoEncoderInstance::AddVideoProfile(PP_VideoProfile profile,
201 const std::string& profile_str) { 205 const std::string& profile_str) {
202 profile_to_string_.insert(std::make_pair(profile, profile_str)); 206 profile_to_string_.insert(std::make_pair(profile, profile_str));
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 336
333 if (encoder_size_ != frame_size_) 337 if (encoder_size_ != frame_size_)
334 ConfigureTrack(); 338 ConfigureTrack();
335 else { 339 else {
336 StartTrackFrames(); 340 StartTrackFrames();
337 ScheduleNextEncode(); 341 ScheduleNextEncode();
338 } 342 }
339 } 343 }
340 344
341 void VideoEncoderInstance::ScheduleNextEncode() { 345 void VideoEncoderInstance::ScheduleNextEncode() {
346 PP_Time now = pp::Module::Get()->core()->GetTime();
342 pp::Module::Get()->core()->CallOnMainThread( 347 pp::Module::Get()->core()->CallOnMainThread(
343 1000 / 30, 348 std::min(std::max(now - last_encode_tick_, 0.0), 1000.0 / 30),
344 callback_factory_.NewCallback(&VideoEncoderInstance::GetEncoderFrameTick), 349 callback_factory_.NewCallback(&VideoEncoderInstance::GetEncoderFrameTick),
345 0); 350 0);
351 last_encode_tick_ = now;
346 } 352 }
347 353
348 void VideoEncoderInstance::GetEncoderFrameTick(int32_t result) { 354 void VideoEncoderInstance::GetEncoderFrameTick(int32_t result) {
349 if (is_encoding_) { 355 if (is_encoding_) {
350 if (!current_track_frame_.is_null()) { 356 if (!current_track_frame_.is_null()) {
351 pp::VideoFrame frame = current_track_frame_; 357 pp::VideoFrame frame = current_track_frame_;
352 current_track_frame_.detach(); 358 current_track_frame_.detach();
353 GetEncoderFrame(frame); 359 GetEncoderFrame(frame);
354 } 360 }
355 ScheduleNextEncode(); 361 ScheduleNextEncode();
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 } 576 }
571 577
572 } // anonymous namespace 578 } // anonymous namespace
573 579
574 namespace pp { 580 namespace pp {
575 // Factory function for your specialization of the Module object. 581 // Factory function for your specialization of the Module object.
576 Module* CreateModule() { 582 Module* CreateModule() {
577 return new VideoEncoderModule(); 583 return new VideoEncoderModule();
578 } 584 }
579 } // namespace pp 585 } // namespace pp
OLDNEW
« no previous file with comments | « native_client_sdk/src/examples/api/video_encode/video_encode.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698