How to calculate $\int_0^\pi \frac{\cos^4(x)}{1+\sin^2(x)}dx$ using contour integrals How do I go about calculating $\int_0^\pi \frac{\cos^4(x)}{1+\sin^2(x)}dx$ using contour integrals?

Suppose we seek to evaluate
$$J = \int_0^{\pi} \frac{\cos^4 x}{1+\sin^2 x} dx
= \frac{1}{2} \int_0^{2\pi} \frac{\cos^4 x}{1+\sin^2 x} dx.$$
Put  $z   =  \exp(ix)$  so  that   $dz  =  i\exp(ix)   dx$  and  hence
$\frac{dz}{iz} = dx$ to obtain
$$\frac{1}{2} \int_{|z|=1}
\frac{(z+1/z)^4/2^4}{1+(z-1/z)^2/(2i)^2} \frac{dz}{iz}
\\ = -\frac{1}{8} \int_{|z|=1}
\frac{(z^2+1)^4}{-4z^2+(z^2-1)^2} \frac{dz}{iz^3}
\\ = \frac{i}{8} \int_{|z|=1}
\frac{(z^2+1)^4}{(z^2-1)^2-4z^2} \frac{z\; dz}{z^4}.$$
Now put  $w=z^2$ so that  $z\; dz =  \frac{1}{2} \; dw$ and  note that
this loops around  the origin twice so that we  must multiply a single
loop by two to get
$$2\times \frac{i}{8} \int_{|w|=1}
\frac{(w+1)^4}{(w-1)^2-4w} \frac{1}{2} \frac{dw}{w^2}
\\ = \frac{i}{8} \int_{|w|=1}
\frac{(w+1)^4}{w^2-6w+1} \frac{dw}{w^2}.$$
In  addition to the  double pole  at $w=0=\rho$  there are  two simple
poles here at
$$\rho_{0,1} = 3 \pm 2\sqrt{2}$$
and clearly  $\rho_1$ is the only  one inside the contour. 
Converting to partial fractions we get
$$\frac{64}{w^2-6w+1} + 1 + \frac{10}{w} + \frac{1}{w^2}.$$ 
Hence the non-zero contribution comes from
$$\frac{64}{w^2-6w+1} + \frac{10}{w}.$$ 
The first term yields
$$\mathrm{Res}_{w=\rho_1} 
\frac{64}{w^2-6w+1} = 
\left. \frac{64}{2w-6} \right|_{w=\rho_1}
\\ = \frac{64}{-4\times\sqrt{2}}
= -\frac{16}{\sqrt{2}} = -8\sqrt{2}.$$
The second  term produces $10$  by inspection. Collecting
everything we have
$$2\pi i \times \frac{i}{8}
\times(10 - 8\sqrt{2})
= \frac{\pi}{4} (8\sqrt{2}-10)$$
or
$$\bbox[5px,border:2px solid #00A000]{
\frac{\pi}{2}(4\sqrt{2}-5).}$$
