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