OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 VideoProcessing* vp_; | 78 VideoProcessing* vp_; |
79 }; | 79 }; |
80 | 80 |
81 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 81 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
82 const std::vector<uint32_t>& ssrcs, | 82 const std::vector<uint32_t>& ssrcs, |
83 ProcessThread* module_process_thread, | 83 ProcessThread* module_process_thread, |
84 SendStatisticsProxy* stats_proxy, | 84 SendStatisticsProxy* stats_proxy, |
85 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 85 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
86 OveruseFrameDetector* overuse_detector, | 86 OveruseFrameDetector* overuse_detector, |
87 PacedSender* pacer, | 87 PacedSender* pacer, |
88 PayloadRouter* payload_router) | 88 PayloadRouter* payload_router, |
| 89 EncodedImageCallback* post_encode_callback) |
89 : number_of_cores_(number_of_cores), | 90 : number_of_cores_(number_of_cores), |
90 ssrcs_(ssrcs), | 91 ssrcs_(ssrcs), |
91 vp_(VideoProcessing::Create()), | 92 vp_(VideoProcessing::Create()), |
92 qm_callback_(new QMVideoSettingsCallback(vp_.get())), | 93 qm_callback_(new QMVideoSettingsCallback(vp_.get())), |
93 vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), | 94 vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), |
94 this, | 95 this, |
95 qm_callback_.get())), | 96 qm_callback_.get())), |
96 stats_proxy_(stats_proxy), | 97 stats_proxy_(stats_proxy), |
97 pre_encode_callback_(pre_encode_callback), | 98 pre_encode_callback_(pre_encode_callback), |
98 overuse_detector_(overuse_detector), | 99 overuse_detector_(overuse_detector), |
99 pacer_(pacer), | 100 pacer_(pacer), |
100 send_payload_router_(payload_router), | 101 send_payload_router_(payload_router), |
| 102 post_encode_callback_(post_encode_callback), |
101 time_of_last_frame_activity_ms_(0), | 103 time_of_last_frame_activity_ms_(0), |
102 encoder_config_(), | 104 encoder_config_(), |
103 min_transmit_bitrate_bps_(0), | 105 min_transmit_bitrate_bps_(0), |
104 last_observed_bitrate_bps_(0), | 106 last_observed_bitrate_bps_(0), |
105 network_is_transmitting_(true), | 107 network_is_transmitting_(true), |
106 encoder_paused_(false), | 108 encoder_paused_(false), |
107 encoder_paused_and_dropped_frame_(false), | 109 encoder_paused_and_dropped_frame_(false), |
108 time_last_intra_request_ms_(ssrcs.size(), -1), | 110 time_last_intra_request_ms_(ssrcs.size(), -1), |
109 module_process_thread_(module_process_thread), | 111 module_process_thread_(module_process_thread), |
110 has_received_sli_(false), | 112 has_received_sli_(false), |
111 picture_id_sli_(0), | 113 picture_id_sli_(0), |
112 has_received_rpsi_(false), | 114 has_received_rpsi_(false), |
113 picture_id_rpsi_(0), | 115 picture_id_rpsi_(0), |
114 video_suspended_(false) { | 116 video_suspended_(false) { |
115 module_process_thread_->RegisterModule(vcm_.get()); | 117 module_process_thread_->RegisterModule(vcm_.get()); |
116 } | 118 } |
117 | 119 |
118 bool ViEEncoder::Init() { | 120 bool ViEEncoder::Init() { |
119 vp_->EnableTemporalDecimation(true); | 121 vp_->EnableTemporalDecimation(true); |
120 | 122 |
121 // Enable/disable content analysis: off by default for now. | 123 // Enable/disable content analysis: off by default for now. |
122 vp_->EnableContentAnalysis(false); | 124 vp_->EnableContentAnalysis(false); |
123 | 125 |
| 126 vcm_->RegisterPostEncodeImageCallback(this); |
| 127 |
| 128 // TODO(perkj): Remove |RegisterTransportCallback| as soon as we don't use |
| 129 // VCMPacketizationCallback::OnEncoderImplementationName. |
124 if (vcm_->RegisterTransportCallback(this) != 0) { | 130 if (vcm_->RegisterTransportCallback(this) != 0) { |
125 return false; | 131 return false; |
126 } | 132 } |
127 if (vcm_->RegisterSendStatisticsCallback(this) != 0) { | 133 if (vcm_->RegisterSendStatisticsCallback(this) != 0) { |
128 return false; | 134 return false; |
129 } | 135 } |
130 return true; | 136 return true; |
131 } | 137 } |
132 | 138 |
133 VideoCodingModule* ViEEncoder::vcm() const { | 139 VideoCodingModule* ViEEncoder::vcm() const { |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 protection_mode = nack ? kProtectionNack : kProtectionNone; | 402 protection_mode = nack ? kProtectionNack : kProtectionNone; |
397 } | 403 } |
398 vcm_->SetVideoProtection(protection_mode, true); | 404 vcm_->SetVideoProtection(protection_mode, true); |
399 } | 405 } |
400 | 406 |
401 void ViEEncoder::OnSetRates(uint32_t bitrate_bps, int framerate) { | 407 void ViEEncoder::OnSetRates(uint32_t bitrate_bps, int framerate) { |
402 if (stats_proxy_) | 408 if (stats_proxy_) |
403 stats_proxy_->OnSetRates(bitrate_bps, framerate); | 409 stats_proxy_->OnSetRates(bitrate_bps, framerate); |
404 } | 410 } |
405 | 411 |
406 int32_t ViEEncoder::SendData(const uint8_t payload_type, | 412 void ViEEncoder::OnEncoderImplementationName(const char* implementation_name) { |
407 const EncodedImage& encoded_image, | 413 if (stats_proxy_) |
408 const RTPFragmentationHeader* fragmentation_header, | 414 stats_proxy_->OnEncoderImplementationName(implementation_name); |
409 const RTPVideoHeader* rtp_video_hdr) { | 415 } |
| 416 |
| 417 int32_t ViEEncoder::Encoded(const EncodedImage& encoded_image, |
| 418 const CodecSpecificInfo* codec_specific_info, |
| 419 const RTPFragmentationHeader* fragmentation) { |
410 RTC_DCHECK(send_payload_router_); | 420 RTC_DCHECK(send_payload_router_); |
411 | 421 |
412 { | 422 { |
413 rtc::CritScope lock(&data_cs_); | 423 rtc::CritScope lock(&data_cs_); |
414 time_of_last_frame_activity_ms_ = TickTime::MillisecondTimestamp(); | 424 time_of_last_frame_activity_ms_ = TickTime::MillisecondTimestamp(); |
415 } | 425 } |
416 | 426 |
417 if (stats_proxy_) | 427 if (post_encode_callback_) { |
418 stats_proxy_->OnSendEncodedImage(encoded_image, rtp_video_hdr); | 428 post_encode_callback_->Encoded(encoded_image, codec_specific_info, |
| 429 fragmentation); |
| 430 } |
419 | 431 |
420 bool success = send_payload_router_->RoutePayload( | 432 if (stats_proxy_) { |
421 encoded_image._frameType, payload_type, encoded_image._timeStamp, | 433 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); |
422 encoded_image.capture_time_ms_, encoded_image._buffer, | 434 } |
423 encoded_image._length, fragmentation_header, rtp_video_hdr); | 435 int success = send_payload_router_->Encoded( |
| 436 encoded_image, codec_specific_info, fragmentation); |
424 overuse_detector_->FrameSent(encoded_image._timeStamp); | 437 overuse_detector_->FrameSent(encoded_image._timeStamp); |
425 | 438 |
426 if (kEnableFrameRecording) { | 439 if (kEnableFrameRecording) { |
427 int layer = rtp_video_hdr->simulcastIdx; | 440 int layer = codec_specific_info->codecType == kVideoCodecVP8 |
| 441 ? codec_specific_info->codecSpecific.VP8.simulcastIdx |
| 442 : 0; |
428 IvfFileWriter* file_writer; | 443 IvfFileWriter* file_writer; |
429 { | 444 { |
430 rtc::CritScope lock(&data_cs_); | 445 rtc::CritScope lock(&data_cs_); |
431 if (file_writers_[layer] == nullptr) { | 446 if (file_writers_[layer] == nullptr) { |
432 std::ostringstream oss; | 447 std::ostringstream oss; |
433 oss << "send_bitstream_ssrc"; | 448 oss << "send_bitstream_ssrc"; |
434 for (uint32_t ssrc : ssrcs_) | 449 for (uint32_t ssrc : ssrcs_) |
435 oss << "_" << ssrc; | 450 oss << "_" << ssrc; |
436 oss << "_layer" << layer << ".ivf"; | 451 oss << "_layer" << layer << ".ivf"; |
437 file_writers_[layer] = | 452 file_writers_[layer] = |
438 IvfFileWriter::Open(oss.str(), rtp_video_hdr->codec); | 453 IvfFileWriter::Open(oss.str(), codec_specific_info->codecType); |
439 } | 454 } |
440 file_writer = file_writers_[layer].get(); | 455 file_writer = file_writers_[layer].get(); |
441 } | 456 } |
442 if (file_writer) { | 457 if (file_writer) { |
443 bool ok = file_writer->WriteFrame(encoded_image); | 458 bool ok = file_writer->WriteFrame(encoded_image); |
444 RTC_DCHECK(ok); | 459 RTC_DCHECK(ok); |
445 } | 460 } |
446 } | 461 } |
447 | 462 |
448 return success ? 0 : -1; | 463 return success; |
449 } | |
450 | |
451 void ViEEncoder::OnEncoderImplementationName( | |
452 const char* implementation_name) { | |
453 if (stats_proxy_) | |
454 stats_proxy_->OnEncoderImplementationName(implementation_name); | |
455 } | 464 } |
456 | 465 |
457 int32_t ViEEncoder::SendStatistics(const uint32_t bit_rate, | 466 int32_t ViEEncoder::SendStatistics(const uint32_t bit_rate, |
458 const uint32_t frame_rate) { | 467 const uint32_t frame_rate) { |
459 if (stats_proxy_) | 468 if (stats_proxy_) |
460 stats_proxy_->OnOutgoingRate(frame_rate, bit_rate); | 469 stats_proxy_->OnOutgoingRate(frame_rate, bit_rate); |
461 return 0; | 470 return 0; |
462 } | 471 } |
463 | 472 |
464 void ViEEncoder::OnReceivedSLI(uint32_t /*ssrc*/, | 473 void ViEEncoder::OnReceivedSLI(uint32_t /*ssrc*/, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 | 533 |
525 if (!video_suspension_changed) | 534 if (!video_suspension_changed) |
526 return; | 535 return; |
527 // Video suspend-state changed, inform codec observer. | 536 // Video suspend-state changed, inform codec observer. |
528 LOG(LS_INFO) << "Video suspend state changed " << video_is_suspended | 537 LOG(LS_INFO) << "Video suspend state changed " << video_is_suspended |
529 << " for ssrc " << ssrcs_[0]; | 538 << " for ssrc " << ssrcs_[0]; |
530 if (stats_proxy_) | 539 if (stats_proxy_) |
531 stats_proxy_->OnSuspendChange(video_is_suspended); | 540 stats_proxy_->OnSuspendChange(video_is_suspended); |
532 } | 541 } |
533 | 542 |
534 void ViEEncoder::RegisterPostEncodeImageCallback( | |
535 EncodedImageCallback* post_encode_callback) { | |
536 vcm_->RegisterPostEncodeImageCallback(post_encode_callback); | |
537 } | |
538 | |
539 QMVideoSettingsCallback::QMVideoSettingsCallback(VideoProcessing* vpm) | 543 QMVideoSettingsCallback::QMVideoSettingsCallback(VideoProcessing* vpm) |
540 : vp_(vpm) { | 544 : vp_(vpm) { |
541 } | 545 } |
542 | 546 |
543 QMVideoSettingsCallback::~QMVideoSettingsCallback() { | 547 QMVideoSettingsCallback::~QMVideoSettingsCallback() { |
544 } | 548 } |
545 | 549 |
546 int32_t QMVideoSettingsCallback::SetVideoQMSettings( | 550 int32_t QMVideoSettingsCallback::SetVideoQMSettings( |
547 const uint32_t frame_rate, | 551 const uint32_t frame_rate, |
548 const uint32_t width, | 552 const uint32_t width, |
549 const uint32_t height) { | 553 const uint32_t height) { |
550 return vp_->SetTargetResolution(width, height, frame_rate); | 554 return vp_->SetTargetResolution(width, height, frame_rate); |
551 } | 555 } |
552 | 556 |
553 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { | 557 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { |
554 vp_->SetTargetFramerate(frame_rate); | 558 vp_->SetTargetFramerate(frame_rate); |
555 } | 559 } |
556 | 560 |
557 } // namespace webrtc | 561 } // namespace webrtc |
OLD | NEW |