Changeset 276223 in webkit
- Timestamp:
- Apr 18, 2021, 12:10:05 AM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
GPUProcess/webrtc/LibWebRTCCodecsProxy.h (modified) (1 diff)
-
GPUProcess/webrtc/LibWebRTCCodecsProxy.mm (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r276222 r276223 1 2021-04-18 Chris Dumez <cdumez@apple.com> 2 3 Update LibWebRTCCodecsProxy to use a Lock 4 https://bugs.webkit.org/show_bug.cgi?id=224728 5 6 Reviewed by Darin Adler. 7 8 Update LibWebRTCCodecsProxy to use a Lock, instead of a std::atomic<bool> that 9 has to be kept up to date. I think this simplifies the code a bit. Adding / Removing 10 encoder / decoder is not very hot code as far as I know and there will very rarely 11 be contention since allowsExitUnderMemoryPressure() is only called on memory pressure. 12 13 m_encoder / m_decoder are still always modified from the background thread. However, we 14 now check from the main thread if they are empty by locking. 15 16 * GPUProcess/webrtc/LibWebRTCCodecsProxy.h: 17 * GPUProcess/webrtc/LibWebRTCCodecsProxy.mm: 18 (WebKit::LibWebRTCCodecsProxy::close): 19 (WebKit::LibWebRTCCodecsProxy::createH264Decoder): 20 (WebKit::LibWebRTCCodecsProxy::createH265Decoder): 21 (WebKit::LibWebRTCCodecsProxy::createVP9Decoder): 22 (WebKit::LibWebRTCCodecsProxy::releaseDecoder): 23 (WebKit::LibWebRTCCodecsProxy::decodeFrame): 24 (WebKit::LibWebRTCCodecsProxy::setFrameSize): 25 (WebKit::LibWebRTCCodecsProxy::createEncoder): 26 (WebKit::LibWebRTCCodecsProxy::releaseEncoder): 27 (WebKit::LibWebRTCCodecsProxy::initializeEncoder): 28 (WebKit::LibWebRTCCodecsProxy::encodeFrame): 29 (WebKit::LibWebRTCCodecsProxy::setEncodeRates): 30 (WebKit::LibWebRTCCodecsProxy::allowsExitUnderMemoryPressure const): 31 (WebKit::LibWebRTCCodecsProxy::updateHasEncodersOrDecoders): Deleted. 32 1 33 2021-04-17 Chris Dumez <cdumez@apple.com> 2 34 -
trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h
r276222 r276223 83 83 void setEncodeRates(RTCEncoderIdentifier, uint32_t bitRate, uint32_t frameRate); 84 84 85 void updateHasEncodersOrDecoders();86 87 85 CFDictionaryRef ioSurfacePixelBufferCreationOptions(IOSurfaceRef); 88 86 89 87 GPUConnectionToWebProcess& m_gpuConnectionToWebProcess; 88 89 mutable Lock m_lock; 90 90 HashMap<RTCDecoderIdentifier, webrtc::LocalDecoder> m_decoders; 91 91 HashMap<RTCEncoderIdentifier, webrtc::LocalEncoder> m_encoders; 92 std::atomic<bool> m_hasEncodersOrDecoders;93 92 94 93 Ref<WorkQueue> m_queue; -
trunk/Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm
r276222 r276223 63 63 64 64 dispatchToThread([this, protectedThis = makeRef(*this)] { 65 auto locker = holdLock(m_lock); 65 66 auto decoders = WTFMove(m_decoders); 66 67 for (auto decoder : decoders.values()) … … 74 75 void LibWebRTCCodecsProxy::createH264Decoder(RTCDecoderIdentifier identifier) 75 76 { 77 ASSERT(!isMainRunLoop()); 78 auto locker = holdLock(m_lock); 76 79 ASSERT(!m_decoders.contains(identifier)); 77 80 m_decoders.add(identifier, webrtc::createLocalH264Decoder(makeBlockPtr([connection = makeRef(m_gpuConnectionToWebProcess.connection()), identifier](CVPixelBufferRef pixelBuffer, uint32_t timeStampNs, uint32_t timeStamp) { … … 79 82 connection->send(Messages::LibWebRTCCodecs::CompletedDecoding { identifier, timeStamp, *sample }, 0); 80 83 }).get())); 81 updateHasEncodersOrDecoders();82 84 } 83 85 84 86 void LibWebRTCCodecsProxy::createH265Decoder(RTCDecoderIdentifier identifier) 85 87 { 88 ASSERT(!isMainRunLoop()); 89 auto locker = holdLock(m_lock); 86 90 ASSERT(!m_decoders.contains(identifier)); 87 91 m_decoders.add(identifier, webrtc::createLocalH265Decoder(makeBlockPtr([connection = makeRef(m_gpuConnectionToWebProcess.connection()), identifier](CVPixelBufferRef pixelBuffer, uint32_t timeStampNs, uint32_t timeStamp) { … … 89 93 connection->send(Messages::LibWebRTCCodecs::CompletedDecoding { identifier, timeStamp, *sample }, 0); 90 94 }).get())); 91 updateHasEncodersOrDecoders();92 95 } 93 96 94 97 void LibWebRTCCodecsProxy::createVP9Decoder(RTCDecoderIdentifier identifier) 95 98 { 99 ASSERT(!isMainRunLoop()); 100 auto locker = holdLock(m_lock); 96 101 ASSERT(!m_decoders.contains(identifier)); 97 102 m_decoders.add(identifier, webrtc::createLocalVP9Decoder(makeBlockPtr([connection = makeRef(m_gpuConnectionToWebProcess.connection()), identifier](CVPixelBufferRef pixelBuffer, uint32_t timeStampNs, uint32_t timeStamp) { … … 99 104 connection->send(Messages::LibWebRTCCodecs::CompletedDecoding { identifier, timeStamp, *sample }, 0); 100 105 }).get())); 101 updateHasEncodersOrDecoders();102 106 } 103 107 104 108 void LibWebRTCCodecsProxy::releaseDecoder(RTCDecoderIdentifier identifier) 105 109 { 110 ASSERT(!isMainRunLoop()); 111 auto locker = holdLock(m_lock); 106 112 ASSERT(m_decoders.contains(identifier)); 107 if (auto decoder = m_decoders.take(identifier)) {113 if (auto decoder = m_decoders.take(identifier)) 108 114 webrtc::releaseLocalDecoder(decoder); 109 updateHasEncodersOrDecoders();110 }111 115 } 112 116 113 117 void LibWebRTCCodecsProxy::decodeFrame(RTCDecoderIdentifier identifier, uint32_t timeStamp, const IPC::DataReference& data) 114 118 { 119 ASSERT(!isMainRunLoop()); 115 120 ASSERT(m_decoders.contains(identifier)); 116 121 auto decoder = m_decoders.get(identifier); … … 124 129 void LibWebRTCCodecsProxy::setFrameSize(RTCDecoderIdentifier identifier, uint16_t width, uint16_t height) 125 130 { 131 ASSERT(!isMainRunLoop()); 126 132 ASSERT(m_decoders.contains(identifier)); 127 133 auto decoder = m_decoders.get(identifier); … … 134 140 void LibWebRTCCodecsProxy::createEncoder(RTCEncoderIdentifier identifier, const String& formatName, const Vector<std::pair<String, String>>& parameters, bool useLowLatency) 135 141 { 142 ASSERT(!isMainRunLoop()); 143 auto locker = holdLock(m_lock); 136 144 ASSERT(!m_encoders.contains(identifier)); 137 145 … … 145 153 webrtc::setLocalEncoderLowLatency(encoder, useLowLatency); 146 154 m_encoders.add(identifier, encoder); 147 updateHasEncodersOrDecoders();148 155 } 149 156 150 157 void LibWebRTCCodecsProxy::releaseEncoder(RTCEncoderIdentifier identifier) 151 158 { 159 ASSERT(!isMainRunLoop()); 160 auto locker = holdLock(m_lock); 152 161 ASSERT(m_encoders.contains(identifier)); 153 if (auto encoder = m_encoders.take(identifier)) {162 if (auto encoder = m_encoders.take(identifier)) 154 163 webrtc::releaseLocalEncoder(encoder); 155 updateHasEncodersOrDecoders();156 }157 164 } 158 165 159 166 void LibWebRTCCodecsProxy::initializeEncoder(RTCEncoderIdentifier identifier, uint16_t width, uint16_t height, unsigned startBitrate, unsigned maxBitrate, unsigned minBitrate, uint32_t maxFramerate) 160 167 { 168 ASSERT(!isMainRunLoop()); 161 169 ASSERT(m_encoders.contains(identifier)); 162 170 auto encoder = m_encoders.get(identifier); … … 185 193 void LibWebRTCCodecsProxy::encodeFrame(RTCEncoderIdentifier identifier, WebCore::RemoteVideoSample&& sample, uint32_t timeStamp, bool shouldEncodeAsKeyFrame) 186 194 { 195 ASSERT(!isMainRunLoop()); 187 196 ASSERT(m_encoders.contains(identifier)); 188 197 auto encoder = m_encoders.get(identifier); … … 201 210 void LibWebRTCCodecsProxy::setEncodeRates(RTCEncoderIdentifier identifier, uint32_t bitRate, uint32_t frameRate) 202 211 { 212 ASSERT(!isMainRunLoop()); 203 213 auto encoder = m_encoders.get(identifier); 204 214 if (!encoder) … … 208 218 } 209 219 210 void LibWebRTCCodecsProxy::updateHasEncodersOrDecoders()211 {212 m_hasEncodersOrDecoders = !m_encoders.isEmpty() || !m_decoders.isEmpty();213 }214 215 220 bool LibWebRTCCodecsProxy::allowsExitUnderMemoryPressure() const 216 221 { 217 return !m_hasEncodersOrDecoders; 222 ASSERT(isMainRunLoop()); 223 auto locker = holdLock(m_lock); 224 return m_encoders.isEmpty() && m_decoders.isEmpty(); 218 225 } 219 226
Note:
See TracChangeset
for help on using the changeset viewer.