  Transit observations in Ly-alpha of HD209458b and HD189733b revealed
signatures of neutral hydrogen escaping the planets. We present a 3D particle
model of the dynamics of the escaping atoms, and calculate theoretical Ly-alpha
absorption line profiles, which can be directly compared with the absorption
observed in the blue wing of the line. For HD209458b the observed velocities of
the escaping atoms up to -130km/s are naturally explained by radiation-pressure
acceleration. The observations are well-fitted with an ionizing flux of about
3-4 times solar and a hydrogen escape rate in the range 10^9-10^11g/s, in
agreement with theoretical predictions. For HD189733b absorption by neutral
hydrogen was observed in 2011 in the velocity range -230 to -140km/s. These
velocities are higher than for HD209458b and require an additional acceleration
mechanism for the escaping hydrogen atoms, which could be interactions with
stellar wind protons. We constrain the stellar wind (temperature ~3x10^4K,
velocity 200+-20km/s and density in the range 10^3-10^7/cm3) as well as the
escape rate (4x10^8-10^11g/s) and ionizing flux (6-23 times solar). We also
reveal the existence of an 'escape-limited' saturation regime in which most of
the escaping gas interacts with the stellar protons. In this regime, which
occurs at proton densities above ~3x10^5/cm3, the amplitude of the absorption
signature is limited by the escape rate and does not depend on the wind
density. The non-detection of escaping hydrogen in earlier observations in 2010
can be explained by the suppression of the stellar wind at that time, or an
escape rate of about an order of magnitude lower than in 2011. For both
planets, best-fit simulations show that the escaping atmosphere has the shape
of a cometary tail.
