def libvlc_media_player_set_xwindow(p_mi, drawable):
'''Set an X Window System drawable where the media player should render its
video output. The call takes effect when the playback starts. If it is
already started, it might need to be stopped before changes apply.
If LibVLC was built without X11 output support, then this function has no
effects.
By default, LibVLC will capture input events on the video rendering area.
Use L{libvlc_video_set_mouse_input}() and L{libvlc_video_set_key_input}() to
disable that and deliver events to the parent window / to the application
instead. By design, the X11 protocol delivers input events to only one
recipient.
@warning
The application must call the XInitThreads() function from Xlib before
L{libvlc_new}(), and before any call to XOpenDisplay() directly or via any
other library. Failure to call XInitThreads() will seriously impede LibVLC
performance. Calling XOpenDisplay() before XInitThreads() will eventually
crash the process. That is a limitation of Xlib.
@param p_mi: media player.
@param drawable: X11 window ID @note The specified identifier must correspond to an existing Input/Output class X11 window. Pixmaps are B{not} currently supported. The default X11 server is assumed, i.e. that specified in the DISPLAY environment variable. @warning LibVLC can deal with invalid X11 handle errors, however some display drivers (EGL, GLX, VA and/or VDPAU) can unfortunately not. Thus the window handle must remain valid until playback is stopped, otherwise the process may abort or crash.
@bug No more than one window handle per media player instance can be specified. If the media has multiple simultaneously active video tracks, extra tracks will be rendered into external windows beyond the control of the application.
'''
f = _Cfunctions.get('libvlc_media_player_set_xwindow', None) or \
_Cfunction('libvlc_media_player_set_xwindow', ((1,), (1,),), None,
None, MediaPlayer, ctypes.c_uint32)
return f(p_mi, drawable)
python类c_uint32()的实例源码
def GetLogMessage(self, level, msgid):
tick = ctypes.c_uint32()
tv_sec = ctypes.c_uint32()
tv_nsec = ctypes.c_uint32()
if self._GetLogMessage is not None:
maxsz = len(self._log_read_buffer)-1
sz = self._GetLogMessage(level, msgid,
self._log_read_buffer, maxsz,
ctypes.byref(tick),
ctypes.byref(tv_sec),
ctypes.byref(tv_nsec))
if sz and sz <= maxsz:
self._log_read_buffer[sz] = '\x00'
return self._log_read_buffer.value, tick.value, tv_sec.value, tv_nsec.value
elif self._loading_error is not None and level == 0:
return self._loading_error, 0, 0, 0
return None
def TraceThreadProc(self):
"""
Return a list of traces, corresponding to the list of required idx
"""
while self.PLCStatus == "Started":
tick = ctypes.c_uint32()
size = ctypes.c_uint32()
buff = ctypes.c_void_p()
TraceBuffer = None
if self.PLClibraryLock.acquire(False):
if self._GetDebugData(ctypes.byref(tick),
ctypes.byref(size),
ctypes.byref(buff)) == 0:
if size.value:
TraceBuffer = ctypes.string_at(buff.value, size.value)
self._FreeDebugData()
self.PLClibraryLock.release()
if TraceBuffer is not None:
self._TracesPush((tick.value, TraceBuffer))
self._TracesAutoSuspend()
self._TracesFlush()
def set_register(self, register_name, value):
"""
Writes a CPU register.
@param int, str, or CPURegister(IntEnum) register_name: CPU register to write.
@param int value: Value to write.
"""
if not self._is_u32(value):
raise ValueError('The value parameter must be an unsigned 32-bit value.')
if not self._is_enum(register_name, CpuRegister):
raise ValueError('Parameter register_name must be of type int, str or CpuRegister enumeration.')
register_name = self._decode_enum(register_name, CpuRegister)
if register_name is None:
raise ValueError('Parameter register_name must be of type int, str or CpuRegister enumeration.')
register_name = ctypes.c_int(register_name.value)
value = ctypes.c_uint32(value)
self.jlink.JLINKARM_WriteReg(register_name, value)
def get_register(self, register_name):
"""
Reads a CPU register.
@param int, str, or CPURegister(IntEnum) register_name: CPU register to read.
@return int: Value read.
"""
if not self._is_enum(register_name, CpuRegister):
raise ValueError('Parameter register_name must be of type int, str or CpuRegister enumeration.')
register_name = self._decode_enum(register_name, CpuRegister)
if register_name is None:
raise ValueError('Parameter register_name must be of type int, str or CpuRegister enumeration.')
register_name = ctypes.c_int(register_name.value)
#value = ctypes.c_uint32()
return self.jlink.JLINKARM_ReadReg(register_name)
def write(self, addr, data):
"""
Writes data from the array into the device starting at the given address.
@param int addr: Start address of the memory block to write.
@param sequence data: Data to write. Any type that implements the sequence API (i.e. string, list, bytearray...) is valid as input.
"""
if not self._is_u32(addr):
raise ValueError('The addr parameter must be an unsigned 32-bit value.')
if not self._is_valid_buf(data):
raise ValueError('The data parameter must be a sequence type with at least one item.')
addr = ctypes.c_uint32(addr)
data_len = ctypes.c_uint32(len(data))
data = (ctypes.c_uint8 * data_len.value)(*data)
self.jlink.JLINKARM_WriteMem(addr, data_len, ctypes.byref(data))
def read(self, addr, data_len):
"""
Reads data_len bytes from the device starting at the given address.
@param int addr: Start address of the memory block to read.
@param int data_len: Number of bytes to read.
@return [int]: List of values read.
"""
if not self._is_u32(addr):
raise ValueError('The addr parameter must be an unsigned 32-bit value.')
if not self._is_u32(data_len):
raise ValueError('The data_len parameter must be an unsigned 32-bit value.')
addr = ctypes.c_uint32(addr)
data_len = ctypes.c_uint32(data_len)
data = (ctypes.c_uint8 * data_len.value)()
self.jlink.JLINKARM_ReadMem(addr, data_len, ctypes.byref(data))
return bytes(data)
def friend_delete(self, friend_number):
"""
Remove a friend from the friend list.
This does not notify the friend of their deletion. After calling this function, this client will appear offline
to the friend and no communication can occur between the two.
:param friend_number: Friend number for the friend to be deleted.
:return: True on success.
"""
tox_err_friend_delete = c_int()
result = Tox.libtoxcore.tox_friend_delete(self._tox_pointer, c_uint32(friend_number),
byref(tox_err_friend_delete))
tox_err_friend_delete = tox_err_friend_delete.value
if tox_err_friend_delete == TOX_ERR_FRIEND_DELETE['OK']:
return bool(result)
elif tox_err_friend_delete == TOX_ERR_FRIEND_DELETE['FRIEND_NOT_FOUND']:
raise ArgumentError('There was no friend with the given friend number. No friends were deleted.')
# -----------------------------------------------------------------------------------------------------------------
# Friend list queries
# -----------------------------------------------------------------------------------------------------------------
def self_get_friend_list(self, friend_list=None):
"""
Copy a list of valid friend numbers into an array.
Call tox_self_get_friend_list_size to determine the number of elements to allocate.
:param friend_list: pointer (c_char_p) to a memory region with enough space to hold the friend list. If this
parameter is None, this function allocates memory for the friend list.
:return: friend list
"""
friend_list_size = self.self_get_friend_list_size()
if friend_list is None:
friend_list = create_string_buffer(sizeof(c_uint32) * friend_list_size)
friend_list = POINTER(c_uint32)(friend_list)
Tox.libtoxcore.tox_self_get_friend_list(self._tox_pointer, friend_list)
return friend_list[0:friend_list_size]
def friend_get_public_key(self, friend_number, public_key=None):
"""
Copies the Public Key associated with a given friend number to a byte array.
:param friend_number: The friend number you want the Public Key of.
:param public_key: pointer (c_char_p) to a memory region of at least TOX_PUBLIC_KEY_SIZE bytes. If this
parameter is None, this function allocates memory for Tox Public Key.
:return: Tox Public Key
"""
if public_key is None:
public_key = create_string_buffer(TOX_PUBLIC_KEY_SIZE)
tox_err_friend_get_public_key = c_int()
Tox.libtoxcore.tox_friend_get_public_key(self._tox_pointer, c_uint32(friend_number), public_key,
byref(tox_err_friend_get_public_key))
tox_err_friend_get_public_key = tox_err_friend_get_public_key.value
if tox_err_friend_get_public_key == TOX_ERR_FRIEND_GET_PUBLIC_KEY['OK']:
return bin_to_string(public_key, TOX_PUBLIC_KEY_SIZE)
elif tox_err_friend_get_public_key == TOX_ERR_FRIEND_GET_PUBLIC_KEY['FRIEND_NOT_FOUND']:
raise ArgumentError('No friend with the given number exists on the friend list.')
def friend_get_name_size(self, friend_number):
"""
Return the length of the friend's name. If the friend number is invalid, the return value is unspecified.
The return value is equal to the `length` argument received by the last `friend_name` callback.
"""
tox_err_friend_query = c_int()
result = Tox.libtoxcore.tox_friend_get_name_size(self._tox_pointer, c_uint32(friend_number),
byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return result
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
' the `_self_` variants of these functions, which have no effect when a parameter is'
' NULL, these functions return an error in that case.')
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['FRIEND_NOT_FOUND']:
raise ArgumentError('The friend_number did not designate a valid friend.')
def callback_friend_name(self, callback, user_data):
"""
Set the callback for the `friend_name` event. Pass None to unset.
This event is triggered when a friend changes their name.
:param callback: Python function. Should take pointer (c_void_p) to Tox object,
The friend number (c_uint32) of the friend whose name changed,
A byte array (c_char_p) containing the same data as tox_friend_get_name would write to its `name` parameter,
A value (c_size_t) equal to the return value of tox_friend_get_name_size,
pointer (c_void_p) to user_data
:param user_data: pointer (c_void_p) to user data
"""
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_char_p, c_size_t, c_void_p)
self.friend_name_cb = c_callback(callback)
Tox.libtoxcore.tox_callback_friend_name(self._tox_pointer, self.friend_name_cb, user_data)
def friend_get_status_message_size(self, friend_number):
"""
Return the length of the friend's status message. If the friend number is invalid, the return value is SIZE_MAX.
:return: length of the friend's status message
"""
tox_err_friend_query = c_int()
result = Tox.libtoxcore.tox_friend_get_status_message_size(self._tox_pointer, c_uint32(friend_number),
byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return result
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
' the `_self_` variants of these functions, which have no effect when a parameter is'
' NULL, these functions return an error in that case.')
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['FRIEND_NOT_FOUND']:
raise ArgumentError('The friend_number did not designate a valid friend.')
def friend_get_status(self, friend_number):
"""
Return the friend's user status (away/busy/...). If the friend number is invalid, the return value is
unspecified.
The status returned is equal to the last status received through the `friend_status` callback.
:return: TOX_USER_STATUS
"""
tox_err_friend_query = c_int()
result = Tox.libtoxcore.tox_friend_get_status(self._tox_pointer, c_uint32(friend_number),
byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return result
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
' the `_self_` variants of these functions, which have no effect when a parameter is'
' NULL, these functions return an error in that case.')
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['FRIEND_NOT_FOUND']:
raise ArgumentError('The friend_number did not designate a valid friend.')
def friend_get_connection_status(self, friend_number):
"""
Check whether a friend is currently connected to this client.
The result of this function is equal to the last value received by the `friend_connection_status` callback.
:param friend_number: The friend number for which to query the connection status.
:return: the friend's connection status (TOX_CONNECTION) as it was received through the
`friend_connection_status` event.
"""
tox_err_friend_query = c_int()
result = Tox.libtoxcore.tox_friend_get_connection_status(self._tox_pointer, c_uint32(friend_number),
byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return result
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
' the `_self_` variants of these functions, which have no effect when a parameter is'
' NULL, these functions return an error in that case.')
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['FRIEND_NOT_FOUND']:
raise ArgumentError('The friend_number did not designate a valid friend.')
def callback_friend_connection_status(self, callback, user_data):
"""
Set the callback for the `friend_connection_status` event. Pass NULL to unset.
This event is triggered when a friend goes offline after having been online, or when a friend goes online.
This callback is not called when adding friends. It is assumed that when adding friends, their connection status
is initially offline.
:param callback: Python function. Should take pointer (c_void_p) to Tox object,
The friend number (c_uint32) of the friend whose connection status changed,
The result of calling tox_friend_get_connection_status (TOX_CONNECTION) on the passed friend_number,
pointer (c_void_p) to user_data
:param user_data: pointer (c_void_p) to user data
"""
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_int, c_void_p)
self.friend_connection_status_cb = c_callback(callback)
Tox.libtoxcore.tox_callback_friend_connection_status(self._tox_pointer,
self.friend_connection_status_cb, c_void_p(user_data))
def friend_get_typing(self, friend_number):
"""
Check whether a friend is currently typing a message.
:param friend_number: The friend number for which to query the typing status.
:return: true if the friend is typing.
"""
tox_err_friend_query = c_int()
result = Tox.libtoxcore.tox_friend_get_typing(self._tox_pointer, c_uint32(friend_number),
byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return bool(result)
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
' the `_self_` variants of these functions, which have no effect when a parameter is'
' NULL, these functions return an error in that case.')
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['FRIEND_NOT_FOUND']:
raise ArgumentError('The friend_number did not designate a valid friend.')
def self_set_typing(self, friend_number, typing):
"""
Set the client's typing status for a friend.
The client is responsible for turning it on or off.
:param friend_number: The friend to which the client is typing a message.
:param typing: The typing status. True means the client is typing.
:return: True on success.
"""
tox_err_set_typing = c_int()
result = Tox.libtoxcore.tox_self_set_typing(self._tox_pointer, c_uint32(friend_number),
c_bool(typing), byref(tox_err_set_typing))
tox_err_set_typing = tox_err_set_typing.value
if tox_err_set_typing == TOX_ERR_SET_TYPING['OK']:
return bool(result)
elif tox_err_set_typing == TOX_ERR_SET_TYPING['FRIEND_NOT_FOUND']:
raise ArgumentError('The friend number did not designate a valid friend.')
def callback_friend_read_receipt(self, callback, user_data):
"""
Set the callback for the `friend_read_receipt` event. Pass None to unset.
This event is triggered when the friend receives the message sent with tox_friend_send_message with the
corresponding message ID.
:param callback: Python function. Should take pointer (c_void_p) to Tox object,
The friend number (c_uint32) of the friend who received the message,
The message ID (c_uint32) as returned from tox_friend_send_message corresponding to the message sent,
pointer (c_void_p) to user_data
:param user_data: pointer (c_void_p) to user data
"""
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint32, c_void_p)
self.friend_read_receipt_cb = c_callback(callback)
Tox.libtoxcore.tox_callback_friend_read_receipt(self._tox_pointer,
self.friend_read_receipt_cb, c_void_p(user_data))
# -----------------------------------------------------------------------------------------------------------------
# Receiving private messages and friend requests
# -----------------------------------------------------------------------------------------------------------------
def callback_friend_message(self, callback, user_data):
"""
Set the callback for the `friend_message` event. Pass None to unset.
This event is triggered when a message from a friend is received.
:param callback: Python function. Should take pointer (c_void_p) to Tox object,
The friend number (c_uint32) of the friend who sent the message,
Message type (TOX_MESSAGE_TYPE),
The message data (c_char_p) they sent,
The size (c_size_t) of the message byte array.
pointer (c_void_p) to user_data
:param user_data: pointer (c_void_p) to user data
"""
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_int, c_char_p, c_size_t, c_void_p)
self.friend_message_cb = c_callback(callback)
Tox.libtoxcore.tox_callback_friend_message(self._tox_pointer, self.friend_message_cb, c_void_p(user_data))
# -----------------------------------------------------------------------------------------------------------------
# File transmission: common between sending and receiving
# -----------------------------------------------------------------------------------------------------------------