Skip to content

Commit

Permalink
refactor ugly cut&paste code
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@8267 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Dec 22, 2014
1 parent a84fc1e commit eb1d3ba
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/xpra/codecs/dec_avcodec2/decoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ cdef extern from "libavcodec/version.h":
int LIBAVCODEC_VERSION_MINOR
int LIBAVCODEC_VERSION_MICRO

#why can't we define this inside the avcodec.h section? (beats me)
ctypedef unsigned int AVCodecID

cdef extern from "libavcodec/avcodec.h":

int AV_PIX_FMT_YUV420P
Expand All @@ -63,16 +66,13 @@ cdef extern from "libavcodec/avcodec.h":

int CODEC_FLAG2_FAST


ctypedef struct AVFrame:
uint8_t **data
int *linesize
int format
void *opaque
ctypedef struct AVCodec:
pass
ctypedef struct AVCodecID:
pass
ctypedef struct AVDictionary:
pass
ctypedef struct AVPacket:
Expand Down Expand Up @@ -310,28 +310,21 @@ cdef class Decoder:

avcodec_register_all()

cdef AVCodecID CodecID
if self.encoding=="h264":
self.codec = avcodec_find_decoder(AV_CODEC_ID_H264)
if self.codec==NULL:
log.error("codec H264 not found!")
return False
CodecID = AV_CODEC_ID_H264
elif self.encoding=="h265":
self.codec = avcodec_find_decoder(AV_CODEC_ID_H265)
if self.codec==NULL:
log.error("codec H265 (HEVC) not found!")
return False
CodecID = AV_CODEC_ID_H265
elif self.encoding=="vp8":
self.codec = avcodec_find_decoder(AV_CODEC_ID_VP8)
if self.codec==NULL:
log.error("codec VP8 not found!")
return False
CodecID = AV_CODEC_ID_VP8
elif self.encoding=="vp9":
self.codec = avcodec_find_decoder(AV_CODEC_ID_VP8)
if self.codec==NULL:
log.error("codec VP8 not found!")
return False
CodecID = AV_CODEC_ID_VP9
else:
raise Exception("invalid codec; %s" % self.encoding)
self.codec = avcodec_find_decoder(CodecID)
if self.codec==NULL:
log.error("codec %s not found!" % self.encoding)
return False

#from here on, we have to call clean_decoder():
self.codec_ctx = avcodec_alloc_context3(self.codec)
Expand Down

0 comments on commit eb1d3ba

Please sign in to comment.