| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 namespace webrtc { | 25 namespace webrtc { |
| 26 namespace vcm { | 26 namespace vcm { |
| 27 | 27 |
| 28 VideoReceiver::VideoReceiver(Clock* clock, EventFactory* event_factory) | 28 VideoReceiver::VideoReceiver(Clock* clock, EventFactory* event_factory) |
| 29 : clock_(clock), | 29 : clock_(clock), |
| 30 process_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), | 30 process_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
| 31 _receiveCritSect(CriticalSectionWrapper::CreateCriticalSection()), | 31 _receiveCritSect(CriticalSectionWrapper::CreateCriticalSection()), |
| 32 _timing(clock_), | 32 _timing(clock_), |
| 33 _receiver(&_timing, clock_, event_factory), | 33 _receiver(&_timing, clock_, event_factory), |
| 34 _decodedFrameCallback(_timing, clock_), | 34 _decodedFrameCallback(&_timing, clock_), |
| 35 _frameTypeCallback(NULL), | 35 _frameTypeCallback(NULL), |
| 36 _receiveStatsCallback(NULL), | 36 _receiveStatsCallback(NULL), |
| 37 _decoderTimingCallback(NULL), | 37 _decoderTimingCallback(NULL), |
| 38 _packetRequestCallback(NULL), | 38 _packetRequestCallback(NULL), |
| 39 render_buffer_callback_(NULL), | 39 render_buffer_callback_(NULL), |
| 40 _decoder(NULL), | 40 _decoder(NULL), |
| 41 #ifdef DEBUG_DECODER_BIT_STREAM | 41 #ifdef DEBUG_DECODER_BIT_STREAM |
| 42 _bitStreamBeforeDecoder(NULL), | 42 _bitStreamBeforeDecoder(NULL), |
| 43 #endif | 43 #endif |
| 44 _frameFromFile(), | 44 _frameFromFile(), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 77 } |
| 78 | 78 |
| 79 if (_decoderTimingCallback != NULL) { | 79 if (_decoderTimingCallback != NULL) { |
| 80 int decode_ms; | 80 int decode_ms; |
| 81 int max_decode_ms; | 81 int max_decode_ms; |
| 82 int current_delay_ms; | 82 int current_delay_ms; |
| 83 int target_delay_ms; | 83 int target_delay_ms; |
| 84 int jitter_buffer_ms; | 84 int jitter_buffer_ms; |
| 85 int min_playout_delay_ms; | 85 int min_playout_delay_ms; |
| 86 int render_delay_ms; | 86 int render_delay_ms; |
| 87 _timing.GetTimings(&decode_ms, | 87 _timing.GetTimings(&decode_ms, &max_decode_ms, ¤t_delay_ms, |
| 88 &max_decode_ms, | 88 &target_delay_ms, &jitter_buffer_ms, |
| 89 ¤t_delay_ms, | 89 &min_playout_delay_ms, &render_delay_ms); |
| 90 &target_delay_ms, | 90 _decoderTimingCallback->OnDecoderTiming( |
| 91 &jitter_buffer_ms, | 91 decode_ms, max_decode_ms, current_delay_ms, target_delay_ms, |
| 92 &min_playout_delay_ms, | 92 jitter_buffer_ms, min_playout_delay_ms, render_delay_ms); |
| 93 &render_delay_ms); | |
| 94 _decoderTimingCallback->OnDecoderTiming(decode_ms, | |
| 95 max_decode_ms, | |
| 96 current_delay_ms, | |
| 97 target_delay_ms, | |
| 98 jitter_buffer_ms, | |
| 99 min_playout_delay_ms, | |
| 100 render_delay_ms); | |
| 101 } | 93 } |
| 102 | 94 |
| 103 // Size of render buffer. | 95 // Size of render buffer. |
| 104 if (render_buffer_callback_) { | 96 if (render_buffer_callback_) { |
| 105 int buffer_size_ms = _receiver.RenderBufferSizeMs(); | 97 int buffer_size_ms = _receiver.RenderBufferSizeMs(); |
| 106 render_buffer_callback_->RenderBufferSizeMs(buffer_size_ms); | 98 render_buffer_callback_->RenderBufferSizeMs(buffer_size_ms); |
| 107 } | 99 } |
| 108 } | 100 } |
| 109 | 101 |
| 110 // Key frame requests | 102 // Key frame requests |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 // Should be called as often as possible to get the most out of the decoder. | 270 // Should be called as often as possible to get the most out of the decoder. |
| 279 int32_t VideoReceiver::Decode(uint16_t maxWaitTimeMs) { | 271 int32_t VideoReceiver::Decode(uint16_t maxWaitTimeMs) { |
| 280 int64_t nextRenderTimeMs; | 272 int64_t nextRenderTimeMs; |
| 281 bool prefer_late_decoding = false; | 273 bool prefer_late_decoding = false; |
| 282 { | 274 { |
| 283 CriticalSectionScoped cs(_receiveCritSect); | 275 CriticalSectionScoped cs(_receiveCritSect); |
| 284 prefer_late_decoding = _codecDataBase.PrefersLateDecoding(); | 276 prefer_late_decoding = _codecDataBase.PrefersLateDecoding(); |
| 285 } | 277 } |
| 286 | 278 |
| 287 VCMEncodedFrame* frame = _receiver.FrameForDecoding( | 279 VCMEncodedFrame* frame = _receiver.FrameForDecoding( |
| 288 maxWaitTimeMs, nextRenderTimeMs, prefer_late_decoding); | 280 maxWaitTimeMs, &nextRenderTimeMs, prefer_late_decoding); |
| 289 | 281 |
| 290 if (frame == NULL) { | 282 if (frame == NULL) { |
| 291 return VCM_FRAME_NOT_READY; | 283 return VCM_FRAME_NOT_READY; |
| 292 } else { | 284 } else { |
| 293 CriticalSectionScoped cs(_receiveCritSect); | 285 CriticalSectionScoped cs(_receiveCritSect); |
| 294 | 286 |
| 295 // If this frame was too late, we should adjust the delay accordingly | 287 // If this frame was too late, we should adjust the delay accordingly |
| 296 _timing.UpdateCurrentDelay(frame->RenderTimeMs(), | 288 _timing.UpdateCurrentDelay(frame->RenderTimeMs(), |
| 297 clock_->TimeInMilliseconds()); | 289 clock_->TimeInMilliseconds()); |
| 298 | 290 |
| 299 if (pre_decode_image_callback_) { | 291 if (pre_decode_image_callback_) { |
| 300 EncodedImage encoded_image(frame->EncodedImage()); | 292 EncodedImage encoded_image(frame->EncodedImage()); |
| 301 int qp = -1; | 293 int qp = -1; |
| 302 if (qp_parser_.GetQp(*frame, &qp)) { | 294 if (qp_parser_.GetQp(*frame, &qp)) { |
| 303 encoded_image.qp_ = qp; | 295 encoded_image.qp_ = qp; |
| 304 } | 296 } |
| 305 pre_decode_image_callback_->Encoded( | 297 pre_decode_image_callback_->Encoded(encoded_image, frame->CodecSpecific(), |
| 306 encoded_image, frame->CodecSpecific(), NULL); | 298 NULL); |
| 307 } | 299 } |
| 308 | 300 |
| 309 #ifdef DEBUG_DECODER_BIT_STREAM | 301 #ifdef DEBUG_DECODER_BIT_STREAM |
| 310 if (_bitStreamBeforeDecoder != NULL) { | 302 if (_bitStreamBeforeDecoder != NULL) { |
| 311 // Write bit stream to file for debugging purposes | 303 // Write bit stream to file for debugging purposes |
| 312 if (fwrite( | 304 if (fwrite(frame->Buffer(), 1, frame->Length(), |
| 313 frame->Buffer(), 1, frame->Length(), _bitStreamBeforeDecoder) != | 305 _bitStreamBeforeDecoder) != frame->Length()) { |
| 314 frame->Length()) { | |
| 315 return -1; | 306 return -1; |
| 316 } | 307 } |
| 317 } | 308 } |
| 318 #endif | 309 #endif |
| 319 const int32_t ret = Decode(*frame); | 310 const int32_t ret = Decode(*frame); |
| 320 _receiver.ReleaseFrame(frame); | 311 _receiver.ReleaseFrame(frame); |
| 321 frame = NULL; | 312 frame = NULL; |
| 322 if (ret != VCM_OK) { | 313 if (ret != VCM_OK) { |
| 323 return ret; | 314 return ret; |
| 324 } | 315 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 352 } | 343 } |
| 353 _scheduleKeyRequest = false; | 344 _scheduleKeyRequest = false; |
| 354 } else { | 345 } else { |
| 355 return VCM_MISSING_CALLBACK; | 346 return VCM_MISSING_CALLBACK; |
| 356 } | 347 } |
| 357 return VCM_OK; | 348 return VCM_OK; |
| 358 } | 349 } |
| 359 | 350 |
| 360 // Must be called from inside the receive side critical section. | 351 // Must be called from inside the receive side critical section. |
| 361 int32_t VideoReceiver::Decode(const VCMEncodedFrame& frame) { | 352 int32_t VideoReceiver::Decode(const VCMEncodedFrame& frame) { |
| 362 TRACE_EVENT_ASYNC_STEP1("webrtc", | 353 TRACE_EVENT_ASYNC_STEP1("webrtc", "Video", frame.TimeStamp(), "Decode", |
| 363 "Video", | 354 "type", frame.FrameType()); |
| 364 frame.TimeStamp(), | |
| 365 "Decode", | |
| 366 "type", | |
| 367 frame.FrameType()); | |
| 368 // Change decoder if payload type has changed | 355 // Change decoder if payload type has changed |
| 369 _decoder = _codecDataBase.GetDecoder(frame, &_decodedFrameCallback); | 356 _decoder = _codecDataBase.GetDecoder(frame, &_decodedFrameCallback); |
| 370 if (_decoder == NULL) { | 357 if (_decoder == NULL) { |
| 371 return VCM_NO_CODEC_REGISTERED; | 358 return VCM_NO_CODEC_REGISTERED; |
| 372 } | 359 } |
| 373 // Decode a frame | 360 // Decode a frame |
| 374 int32_t ret = _decoder->Decode(frame, clock_->TimeInMilliseconds()); | 361 int32_t ret = _decoder->Decode(frame, clock_->TimeInMilliseconds()); |
| 375 | 362 |
| 376 // Check for failed decoding, run frame type request callback if needed. | 363 // Check for failed decoding, run frame type request callback if needed. |
| 377 bool request_key_frame = false; | 364 bool request_key_frame = false; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } | 405 } |
| 419 | 406 |
| 420 // Register possible receive codecs, can be called multiple times | 407 // Register possible receive codecs, can be called multiple times |
| 421 int32_t VideoReceiver::RegisterReceiveCodec(const VideoCodec* receiveCodec, | 408 int32_t VideoReceiver::RegisterReceiveCodec(const VideoCodec* receiveCodec, |
| 422 int32_t numberOfCores, | 409 int32_t numberOfCores, |
| 423 bool requireKeyFrame) { | 410 bool requireKeyFrame) { |
| 424 CriticalSectionScoped cs(_receiveCritSect); | 411 CriticalSectionScoped cs(_receiveCritSect); |
| 425 if (receiveCodec == NULL) { | 412 if (receiveCodec == NULL) { |
| 426 return VCM_PARAMETER_ERROR; | 413 return VCM_PARAMETER_ERROR; |
| 427 } | 414 } |
| 428 if (!_codecDataBase.RegisterReceiveCodec( | 415 if (!_codecDataBase.RegisterReceiveCodec(receiveCodec, numberOfCores, |
| 429 receiveCodec, numberOfCores, requireKeyFrame)) { | 416 requireKeyFrame)) { |
| 430 return -1; | 417 return -1; |
| 431 } | 418 } |
| 432 return 0; | 419 return 0; |
| 433 } | 420 } |
| 434 | 421 |
| 435 // Get current received codec | 422 // Get current received codec |
| 436 int32_t VideoReceiver::ReceiveCodec(VideoCodec* currentReceiveCodec) const { | 423 int32_t VideoReceiver::ReceiveCodec(VideoCodec* currentReceiveCodec) const { |
| 437 CriticalSectionScoped cs(_receiveCritSect); | 424 CriticalSectionScoped cs(_receiveCritSect); |
| 438 if (currentReceiveCodec == NULL) { | 425 if (currentReceiveCodec == NULL) { |
| 439 return VCM_PARAMETER_ERROR; | 426 return VCM_PARAMETER_ERROR; |
| 440 } | 427 } |
| 441 return _codecDataBase.ReceiveCodec(currentReceiveCodec) ? 0 : -1; | 428 return _codecDataBase.ReceiveCodec(currentReceiveCodec) ? 0 : -1; |
| 442 } | 429 } |
| 443 | 430 |
| 444 // Get current received codec | 431 // Get current received codec |
| 445 VideoCodecType VideoReceiver::ReceiveCodec() const { | 432 VideoCodecType VideoReceiver::ReceiveCodec() const { |
| 446 CriticalSectionScoped cs(_receiveCritSect); | 433 CriticalSectionScoped cs(_receiveCritSect); |
| 447 return _codecDataBase.ReceiveCodec(); | 434 return _codecDataBase.ReceiveCodec(); |
| 448 } | 435 } |
| 449 | 436 |
| 450 // Incoming packet from network parsed and ready for decode, non blocking. | 437 // Incoming packet from network parsed and ready for decode, non blocking. |
| 451 int32_t VideoReceiver::IncomingPacket(const uint8_t* incomingPayload, | 438 int32_t VideoReceiver::IncomingPacket(const uint8_t* incomingPayload, |
| 452 size_t payloadLength, | 439 size_t payloadLength, |
| 453 const WebRtcRTPHeader& rtpInfo) { | 440 const WebRtcRTPHeader& rtpInfo) { |
| 454 if (rtpInfo.frameType == kVideoFrameKey) { | 441 if (rtpInfo.frameType == kVideoFrameKey) { |
| 455 TRACE_EVENT1("webrtc", | 442 TRACE_EVENT1("webrtc", "VCM::PacketKeyFrame", "seqnum", |
| 456 "VCM::PacketKeyFrame", | |
| 457 "seqnum", | |
| 458 rtpInfo.header.sequenceNumber); | 443 rtpInfo.header.sequenceNumber); |
| 459 } | 444 } |
| 460 if (incomingPayload == NULL) { | 445 if (incomingPayload == NULL) { |
| 461 // The jitter buffer doesn't handle non-zero payload lengths for packets | 446 // The jitter buffer doesn't handle non-zero payload lengths for packets |
| 462 // without payload. | 447 // without payload. |
| 463 // TODO(holmer): We should fix this in the jitter buffer. | 448 // TODO(holmer): We should fix this in the jitter buffer. |
| 464 payloadLength = 0; | 449 payloadLength = 0; |
| 465 } | 450 } |
| 466 const VCMPacket packet(incomingPayload, payloadLength, rtpInfo); | 451 const VCMPacket packet(incomingPayload, payloadLength, rtpInfo); |
| 467 int32_t ret = _receiver.InsertPacket(packet, rtpInfo.type.Video.width, | 452 int32_t ret = _receiver.InsertPacket(packet, rtpInfo.type.Video.width, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 486 } | 471 } |
| 487 | 472 |
| 488 // The estimated delay caused by rendering, defaults to | 473 // The estimated delay caused by rendering, defaults to |
| 489 // kDefaultRenderDelayMs = 10 ms | 474 // kDefaultRenderDelayMs = 10 ms |
| 490 int32_t VideoReceiver::SetRenderDelay(uint32_t timeMS) { | 475 int32_t VideoReceiver::SetRenderDelay(uint32_t timeMS) { |
| 491 _timing.set_render_delay(timeMS); | 476 _timing.set_render_delay(timeMS); |
| 492 return VCM_OK; | 477 return VCM_OK; |
| 493 } | 478 } |
| 494 | 479 |
| 495 // Current video delay | 480 // Current video delay |
| 496 int32_t VideoReceiver::Delay() const { return _timing.TargetVideoDelay(); } | 481 int32_t VideoReceiver::Delay() const { |
| 482 return _timing.TargetVideoDelay(); |
| 483 } |
| 497 | 484 |
| 498 uint32_t VideoReceiver::DiscardedPackets() const { | 485 uint32_t VideoReceiver::DiscardedPackets() const { |
| 499 return _receiver.DiscardedPackets(); | 486 return _receiver.DiscardedPackets(); |
| 500 } | 487 } |
| 501 | 488 |
| 502 int VideoReceiver::SetReceiverRobustnessMode( | 489 int VideoReceiver::SetReceiverRobustnessMode( |
| 503 ReceiverRobustness robustnessMode, | 490 ReceiverRobustness robustnessMode, |
| 504 VCMDecodeErrorMode decode_error_mode) { | 491 VCMDecodeErrorMode decode_error_mode) { |
| 505 CriticalSectionScoped cs(_receiveCritSect); | 492 CriticalSectionScoped cs(_receiveCritSect); |
| 506 switch (robustnessMode) { | 493 switch (robustnessMode) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 _receiver.SetDecodeErrorMode(decode_error_mode); | 529 _receiver.SetDecodeErrorMode(decode_error_mode); |
| 543 } | 530 } |
| 544 | 531 |
| 545 void VideoReceiver::SetNackSettings(size_t max_nack_list_size, | 532 void VideoReceiver::SetNackSettings(size_t max_nack_list_size, |
| 546 int max_packet_age_to_nack, | 533 int max_packet_age_to_nack, |
| 547 int max_incomplete_time_ms) { | 534 int max_incomplete_time_ms) { |
| 548 if (max_nack_list_size != 0) { | 535 if (max_nack_list_size != 0) { |
| 549 CriticalSectionScoped process_cs(process_crit_sect_.get()); | 536 CriticalSectionScoped process_cs(process_crit_sect_.get()); |
| 550 max_nack_list_size_ = max_nack_list_size; | 537 max_nack_list_size_ = max_nack_list_size; |
| 551 } | 538 } |
| 552 _receiver.SetNackSettings( | 539 _receiver.SetNackSettings(max_nack_list_size, max_packet_age_to_nack, |
| 553 max_nack_list_size, max_packet_age_to_nack, max_incomplete_time_ms); | 540 max_incomplete_time_ms); |
| 554 } | 541 } |
| 555 | 542 |
| 556 int VideoReceiver::SetMinReceiverDelay(int desired_delay_ms) { | 543 int VideoReceiver::SetMinReceiverDelay(int desired_delay_ms) { |
| 557 return _receiver.SetMinReceiverDelay(desired_delay_ms); | 544 return _receiver.SetMinReceiverDelay(desired_delay_ms); |
| 558 } | 545 } |
| 559 | 546 |
| 560 void VideoReceiver::RegisterPreDecodeImageCallback( | 547 void VideoReceiver::RegisterPreDecodeImageCallback( |
| 561 EncodedImageCallback* observer) { | 548 EncodedImageCallback* observer) { |
| 562 CriticalSectionScoped cs(_receiveCritSect); | 549 CriticalSectionScoped cs(_receiveCritSect); |
| 563 pre_decode_image_callback_ = observer; | 550 pre_decode_image_callback_ = observer; |
| 564 } | 551 } |
| 565 | 552 |
| 566 } // namespace vcm | 553 } // namespace vcm |
| 567 } // namespace webrtc | 554 } // namespace webrtc |
| OLD | NEW |