|
| 1 | +diff --git a/video/video_receive_stream2.cc b/video/video_receive_stream2.cc |
| 2 | +index ea4b474a..cb11023b 100644 |
| 3 | +--- a/video/video_receive_stream2.cc |
| 4 | ++++ b/video/video_receive_stream2.cc |
| 5 | +@@ -105,6 +105,31 @@ namespace { |
| 6 | + constexpr TimeDelta kMinBaseMinimumDelay = TimeDelta::Zero(); |
| 7 | + constexpr TimeDelta kMaxBaseMinimumDelay = TimeDelta::Seconds(10); |
| 8 | + |
| 9 | ++uint getTotalVideoDecoders() { |
| 10 | ++ FileWrapper file_wrapper = FileWrapper::OpenReadOnly("/dev/shm/chromium-video-decoders"); |
| 11 | ++ if (file_wrapper.is_open()) { |
| 12 | ++ char buf[256]; |
| 13 | ++ file_wrapper.Read(buf, sizeof(buf)); |
| 14 | ++ file_wrapper.Close(); |
| 15 | ++ return (uint)atoi(buf); |
| 16 | ++ } |
| 17 | ++ return 0; |
| 18 | ++} |
| 19 | ++ |
| 20 | ++void updateTotalVideoDecoders(int value) { |
| 21 | ++ char buf[256]; |
| 22 | ++ uint total_video_decoders = getTotalVideoDecoders(); |
| 23 | ++ snprintf(buf, sizeof(buf), "%u", std::max<uint>(0, total_video_decoders + value)); |
| 24 | ++ |
| 25 | ++ FileWrapper file_wrapper = FileWrapper::OpenWriteOnly("/dev/shm/chromium-video-decoders"); |
| 26 | ++ if (!file_wrapper.is_open()) { |
| 27 | ++ RTC_LOG(LS_ERROR) << "total video decoders file cannot be opened: /dev/shm/chromium-video-decoders"; |
| 28 | ++ return; |
| 29 | ++ } |
| 30 | ++ file_wrapper.Write(buf, strlen(buf)); |
| 31 | ++ file_wrapper.Close(); |
| 32 | ++} |
| 33 | ++ |
| 34 | + // Concrete instance of RecordableEncodedFrame wrapping needed content |
| 35 | + // from EncodedFrame. |
| 36 | + class WebRtcRecordableEncodedFrame : public RecordableEncodedFrame { |
| 37 | +@@ -182,7 +207,7 @@ class NullVideoDecoder : public VideoDecoder { |
| 38 | + |
| 39 | + int32_t Decode(const EncodedImage& input_image, |
| 40 | + int64_t render_time_ms) override { |
| 41 | +- RTC_LOG(LS_ERROR) << "The NullVideoDecoder doesn't support decoding."; |
| 42 | ++ RTC_LOG(LS_WARNING) << "The NullVideoDecoder doesn't support decoding."; |
| 43 | + return WEBRTC_VIDEO_CODEC_OK; |
| 44 | + } |
| 45 | + |
| 46 | +@@ -394,6 +419,20 @@ void VideoReceiveStream2::Start() { |
| 47 | + renderer = this; |
| 48 | + } |
| 49 | + |
| 50 | ++ // Check if we should create video decoders. |
| 51 | ++ enable_video_decoders_ = true; |
| 52 | ++ std::string max_video_decoders = env_.field_trials().Lookup("WebRTC-MaxVideoDecoders"); |
| 53 | ++ if (!max_video_decoders.empty()) { |
| 54 | ++ uint video_decoders = getTotalVideoDecoders(); |
| 55 | ++ uint max_decoders = (uint)atoi(max_video_decoders.c_str()); |
| 56 | ++ RTC_LOG(LS_ERROR) << "WebRTC-MaxVideoDecoders: " << video_decoders << "/" << max_decoders; |
| 57 | ++ if (video_decoders >= max_decoders) { |
| 58 | ++ enable_video_decoders_ = false; |
| 59 | ++ } |
| 60 | ++ } |
| 61 | ++ if (enable_video_decoders_) |
| 62 | ++ updateTotalVideoDecoders(1); |
| 63 | ++ |
| 64 | + for (const Decoder& decoder : config_.decoders) { |
| 65 | + VideoDecoder::Settings settings; |
| 66 | + settings.set_codec_type( |
| 67 | +@@ -472,6 +511,9 @@ void VideoReceiveStream2::Stop() { |
| 68 | + stats_proxy_.DecoderThreadStopped(); |
| 69 | + |
| 70 | + UpdateHistograms(); |
| 71 | ++ |
| 72 | ++ if (enable_video_decoders_) |
| 73 | ++ updateTotalVideoDecoders(-1); |
| 74 | + } |
| 75 | + |
| 76 | + // TODO(bugs.webrtc.org/11993): Make these calls on the network thread. |
| 77 | +@@ -563,8 +605,9 @@ void VideoReceiveStream2::CreateAndRegisterExternalDecoder( |
| 78 | + const Decoder& decoder) { |
| 79 | + TRACE_EVENT0("webrtc", |
| 80 | + "VideoReceiveStream2::CreateAndRegisterExternalDecoder"); |
| 81 | +- std::unique_ptr<VideoDecoder> video_decoder = |
| 82 | +- config_.decoder_factory->Create(env_, decoder.video_format); |
| 83 | ++ std::unique_ptr<VideoDecoder> video_decoder = enable_video_decoders_ ? |
| 84 | ++ config_.decoder_factory->Create(env_, decoder.video_format) : |
| 85 | ++ nullptr; |
| 86 | + // If we still have no valid decoder, we have to create a "Null" decoder |
| 87 | + // that ignores all calls. The reason we can get into this state is that the |
| 88 | + // old decoder factory interface doesn't have a way to query supported |
| 89 | +diff --git a/video/video_receive_stream2.h b/video/video_receive_stream2.h |
| 90 | +index a07bd08f..0aa6a3f6 100644 |
| 91 | +--- a/video/video_receive_stream2.h |
| 92 | ++++ b/video/video_receive_stream2.h |
| 93 | +@@ -298,6 +298,7 @@ class VideoReceiveStream2 |
| 94 | + RtpStreamsSynchronizer rtp_stream_sync_; |
| 95 | + |
| 96 | + std::unique_ptr<VideoStreamBufferController> buffer_; |
| 97 | ++ bool enable_video_decoders_; |
| 98 | + |
| 99 | + // `receiver_controller_` is valid from when RegisterWithTransport is invoked |
| 100 | + // until UnregisterFromTransport. |
0 commit comments