| OLD | NEW |
| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 PP_VideoFrame_Format frame_format_; | 169 PP_VideoFrame_Format frame_format_; |
| 169 | 170 |
| 170 pp::Size requested_size_; | 171 pp::Size requested_size_; |
| 171 pp::Size frame_size_; | 172 pp::Size frame_size_; |
| 172 pp::Size encoder_size_; | 173 pp::Size encoder_size_; |
| 173 uint32_t encoded_frames_; | 174 uint32_t encoded_frames_; |
| 174 | 175 |
| 175 pp::VideoFrame current_track_frame_; | 176 pp::VideoFrame current_track_frame_; |
| 176 | 177 |
| 177 IVFWriter ivf_writer_; | 178 IVFWriter ivf_writer_; |
| 179 |
| 180 PP_Time last_encode_tick_; |
| 178 }; | 181 }; |
| 179 | 182 |
| 180 VideoEncoderInstance::VideoEncoderInstance(PP_Instance instance, | 183 VideoEncoderInstance::VideoEncoderInstance(PP_Instance instance, |
| 181 pp::Module* module) | 184 pp::Module* module) |
| 182 : pp::Instance(instance), | 185 : pp::Instance(instance), |
| 183 is_encoding_(false), | 186 is_encoding_(false), |
| 184 callback_factory_(this), | 187 callback_factory_(this), |
| 185 #if defined(USE_VP8_INSTEAD_OF_H264) | 188 #if defined(USE_VP8_INSTEAD_OF_H264) |
| 186 video_profile_(PP_VIDEOPROFILE_VP8_ANY), | 189 video_profile_(PP_VIDEOPROFILE_VP8_ANY), |
| 187 #else | 190 #else |
| 188 video_profile_(PP_VIDEOPROFILE_H264MAIN), | 191 video_profile_(PP_VIDEOPROFILE_H264MAIN), |
| 189 #endif | 192 #endif |
| 190 frame_format_(PP_VIDEOFRAME_FORMAT_I420), | 193 frame_format_(PP_VIDEOFRAME_FORMAT_I420), |
| 191 encoded_frames_(0) { | 194 encoded_frames_(0), |
| 195 last_encode_tick_(0) { |
| 192 InitializeVideoProfiles(); | 196 InitializeVideoProfiles(); |
| 193 ProbeEncoder(); | 197 ProbeEncoder(); |
| 194 } | 198 } |
| 195 | 199 |
| 196 VideoEncoderInstance::~VideoEncoderInstance() { | 200 VideoEncoderInstance::~VideoEncoderInstance() { |
| 197 } | 201 } |
| 198 | 202 |
| 199 void VideoEncoderInstance::AddVideoProfile(PP_VideoProfile profile, | 203 void VideoEncoderInstance::AddVideoProfile(PP_VideoProfile profile, |
| 200 const std::string& profile_str) { | 204 const std::string& profile_str) { |
| 201 profile_to_string_.insert(std::make_pair(profile, profile_str)); | 205 profile_to_string_.insert(std::make_pair(profile, profile_str)); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 331 |
| 328 if (encoder_size_ != frame_size_) | 332 if (encoder_size_ != frame_size_) |
| 329 ConfigureTrack(); | 333 ConfigureTrack(); |
| 330 else { | 334 else { |
| 331 StartTrackFrames(); | 335 StartTrackFrames(); |
| 332 ScheduleNextEncode(); | 336 ScheduleNextEncode(); |
| 333 } | 337 } |
| 334 } | 338 } |
| 335 | 339 |
| 336 void VideoEncoderInstance::ScheduleNextEncode() { | 340 void VideoEncoderInstance::ScheduleNextEncode() { |
| 341 PP_Time now = pp::Module::Get()->core()->GetTime(); |
| 337 pp::Module::Get()->core()->CallOnMainThread( | 342 pp::Module::Get()->core()->CallOnMainThread( |
| 338 1000 / 30, | 343 std::min(std::max(now - last_encode_tick_, 0.0), 1000.0 / 30), |
| 339 callback_factory_.NewCallback(&VideoEncoderInstance::GetEncoderFrameTick), | 344 callback_factory_.NewCallback(&VideoEncoderInstance::GetEncoderFrameTick), |
| 340 0); | 345 0); |
| 346 last_encode_tick_ = now; |
| 341 } | 347 } |
| 342 | 348 |
| 343 void VideoEncoderInstance::GetEncoderFrameTick(int32_t result) { | 349 void VideoEncoderInstance::GetEncoderFrameTick(int32_t result) { |
| 344 if (is_encoding_) { | 350 if (is_encoding_) { |
| 345 if (!current_track_frame_.is_null()) { | 351 if (!current_track_frame_.is_null()) { |
| 346 pp::VideoFrame frame = current_track_frame_; | 352 pp::VideoFrame frame = current_track_frame_; |
| 347 current_track_frame_.detach(); | 353 current_track_frame_.detach(); |
| 348 GetEncoderFrame(frame); | 354 GetEncoderFrame(frame); |
| 349 } | 355 } |
| 350 ScheduleNextEncode(); | 356 ScheduleNextEncode(); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 } | 569 } |
| 564 | 570 |
| 565 } // anonymous namespace | 571 } // anonymous namespace |
| 566 | 572 |
| 567 namespace pp { | 573 namespace pp { |
| 568 // Factory function for your specialization of the Module object. | 574 // Factory function for your specialization of the Module object. |
| 569 Module* CreateModule() { | 575 Module* CreateModule() { |
| 570 return new VideoEncoderModule(); | 576 return new VideoEncoderModule(); |
| 571 } | 577 } |
| 572 } // namespace pp | 578 } // namespace pp |
| OLD | NEW |