You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
  3. *
  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
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "video/video_stream_decoder.h"
  11. #include "modules/video_coding/video_receiver2.h"
  12. #include "rtc_base/checks.h"
  13. #include "video/receive_statistics_proxy.h"
  14. namespace webrtc {
  15. VideoStreamDecoder::VideoStreamDecoder(
  16. VideoReceiver2* video_receiver,
  17. ReceiveStatisticsProxy* receive_statistics_proxy,
  18. rtc::VideoSinkInterface<VideoFrame>* incoming_video_stream)
  19. : video_receiver_(video_receiver),
  20. receive_stats_callback_(receive_statistics_proxy),
  21. incoming_video_stream_(incoming_video_stream) {
  22. RTC_DCHECK(video_receiver_);
  23. video_receiver_->RegisterReceiveCallback(this);
  24. }
  25. VideoStreamDecoder::~VideoStreamDecoder() {
  26. // Note: There's an assumption at this point that the decoder thread is
  27. // *not* running. If it was, then there could be a race for each of these
  28. // callbacks.
  29. // Unset all the callback pointers that we set in the ctor.
  30. video_receiver_->RegisterReceiveCallback(nullptr);
  31. }
  32. // Do not acquire the lock of |video_receiver_| in this function. Decode
  33. // callback won't necessarily be called from the decoding thread. The decoding
  34. // thread may have held the lock when calling VideoDecoder::Decode, Reset, or
  35. // Release. Acquiring the same lock in the path of decode callback can deadlock.
  36. int32_t VideoStreamDecoder::FrameToRender(VideoFrame& video_frame,
  37. absl::optional<uint8_t> qp,
  38. int32_t decode_time_ms,
  39. VideoContentType content_type) {
  40. receive_stats_callback_->OnDecodedFrame(video_frame, qp, decode_time_ms,
  41. content_type);
  42. incoming_video_stream_->OnFrame(video_frame);
  43. return 0;
  44. }
  45. void VideoStreamDecoder::OnDroppedFrames(uint32_t frames_dropped) {
  46. receive_stats_callback_->OnDroppedFrames(frames_dropped);
  47. }
  48. void VideoStreamDecoder::OnIncomingPayloadType(int payload_type) {
  49. receive_stats_callback_->OnIncomingPayloadType(payload_type);
  50. }
  51. void VideoStreamDecoder::OnDecoderImplementationName(
  52. const char* implementation_name) {
  53. receive_stats_callback_->OnDecoderImplementationName(implementation_name);
  54. }
  55. } // namespace webrtc