code: def _notify_caps(self, pad, args):
          
          # The sink has started to receive data, so the stream is ready.
          # This also is our opportunity to read information about the
          # stream.
          self.got_caps = True
          info = pad.get_current_caps().get_structure(0)
  
          # Stream attributes.
          self.channels = info.get_int('channels')[1]
          self.samplerate = info.get_int('rate')[1]
  
          # Query duration.
          success, length = pad.get_peer().query_duration(Gst.Format.TIME)
          if success:
              self.duration = length / 1000000000
          else:
              self.read_exc = MetadataMissingError('duration not available')
  
          # Allow constructor to complete.
          self.ready_sem.release()
docs: The callback for the sinkpad's "notify::caps" signal.