decoder multithreading
This commit is contained in:
		@ -21,7 +21,7 @@ from .frame import Frame
 | 
			
		||||
class Decoder:
 | 
			
		||||
    __slots__ = '_context'
 | 
			
		||||
 | 
			
		||||
    def __init__(self, stream):
 | 
			
		||||
    def __init__(self, stream, thread_count):
 | 
			
		||||
        self._context = libav.codec_alloc_context(stream.codec)
 | 
			
		||||
        if not self._context:
 | 
			
		||||
            raise MemoryError
 | 
			
		||||
@ -29,6 +29,9 @@ class Decoder:
 | 
			
		||||
        if errcode < 0:
 | 
			
		||||
            libav.codec_free_context(self._context)
 | 
			
		||||
            raise Exception("Failed to set context parameters")
 | 
			
		||||
        if thread_count > 1:
 | 
			
		||||
            self._context.contents.thread_count = thread_count
 | 
			
		||||
            self._context.contents.thread_type = libav.FF_THREAD_FRAME
 | 
			
		||||
        errcode = libav.codec_open(self._context, stream.codec)
 | 
			
		||||
        if errcode < 0:
 | 
			
		||||
            libav.codec_free_context(self._context)
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user