def get_buffer(self, bytes): '''Fill and return an OpenAL buffer''' frames = ctypes.c_uint(bytes / self.bytes_per_frame) flags = ctypes.c_uint() buffer = (ctypes.c_byte * bytes)() audio_buffer_list = AudioBufferList() audio_buffer_list.mNumberBuffers = 1 audio_buffer_list.mBuffers[0].mNumberChannels = self.channels audio_buffer_list.mBuffers[0].mDataByteSize = bytes audio_buffer_list.mBuffers[0].mData = \ ctypes.cast(buffer, ctypes.c_void_p) result = quicktime.MovieAudioExtractionFillBuffer( self.extraction_session_ref, ctypes.byref(frames), ctypes.byref(audio_buffer_list), ctypes.byref(flags)) _oscheck(result) if frames.value == 0: return None size = audio_buffer_list.mBuffers[0].mDataByteSize albuffer = openal.buffer_pool.get(self.time) al.alBufferData(albuffer, self.format, audio_buffer_list.mBuffers[0].mData, size, int(self.sample_rate)) self.time += self.seconds_per_byte * size return albuffer
def chain(self, this, buffer): timestamp = buffer.contents.timestamp * 0.000000001 albuffer = openal.buffer_pool.get(timestamp) size = buffer.contents.size al.alBufferData(albuffer, self.format, buffer.contents.data, size, self.rate) gst.gst_mini_object_unref(buffer) self.element._add_buffer(albuffer, size / self.bytes_per_second) return gstreamer.GST_FLOW_OK