ICodec: fix free avcodec in destructor

Close and free avcodec in destructor only if AVCodecContext and AVCodec
are not NULL.
StreamTranscoder: clean constructor in case of generator essence

* Cast only one time (for video or audio cases).
* Use reference when cast (it was not the case for video).