コード例 #1
0
    def __init__(self, config):

        import sys

        try:
            self.codec = ffi.dlopen('./librtpsbc.so')
        except:
            print 'Exception:', sys.exc_info()[0]

        self.config = ffi.new('sbc_t *')
        self.ts = ffi.new('unsigned int *', 0)
        self.seq_num = ffi.new('unsigned int *', 0)
        self._init_sbc_config(config)
        self.codec.sbc_init(self.config, 0)
コード例 #2
0
    def __init__(self, config):

        import sys

        try:
            self.codec = ffi.verify(b'#include "rtpsbc.h"',
                                    libraries=[b'rtpsbc'],
                                    ext_package=b'rtpsbc')
        except:
            print 'Exception:', sys.exc_info()[0]

        self.config = ffi.new('sbc_t *')
        self.ts = ffi.new('unsigned int *', 0)
        self.seq_num = ffi.new('unsigned int *', 0)
        self._init_sbc_config(config)
        self.codec.sbc_init(self.config, 0)
コード例 #3
0
ファイル: codecs.py プロジェクト: liamw9534/bt-manager
    def __init__(self, config):

        import sys

        try:
            self.codec = ffi.verify(b'#include "rtpsbc.h"',
                                    libraries=[b'rtpsbc'],
                                    ext_package=b'rtpsbc')
        except:
            print 'Exception:', sys.exc_info()[0]

        self.config = ffi.new('sbc_t *')
        self.ts = ffi.new('unsigned int *', 0)
        self.seq_num = ffi.new('unsigned int *', 0)
        self._init_sbc_config(config)
        self.codec.sbc_init(self.config, 0)
コード例 #4
0
ファイル: codecs.py プロジェクト: MoralCode/sonos-bt-speaker
    def __init__(self, config):

        import sys

        so_path = './librtpsbc.so'
        if platform.machine() == 'aarch64':
            so_path = './librtpsbc_aarch64.so'

        try:
            self.codec = ffi.dlopen(so_path)
        except Exception as e:
            print('Exception:' + str(sys.exc_info()[0]))
            print(str(e))

        self.config = ffi.new('sbc_t *')
        self.ts = ffi.new('unsigned int *', 0)
        self.seq_num = ffi.new('unsigned int *', 0)
        self._init_sbc_config(config)
        self.codec.sbc_init(self.config, 0)
コード例 #5
0
    def encode(self, fd, mtu, data):
        """
        Encode the supplied data (byte array) and write to
        the media transport file descriptor encapsulated
        as RTP packets.  The encoder will calculate the
        required number of SBC frames and encapsulate as
        RTP to fit the MTU size.

        :param int fd: Media transport file descriptor
        :param int mtu: Media transport MTU size as returned
            when the media transport was acquired.
        :param array{byte} data: Data to encode and send
            over the media transport.
        :return:
        """
        self.codec.rtp_sbc_encode_to_fd(self.config, ffi.new('char[]', data),
                                        len(data), mtu, self.ts, self.seq_num,
                                        fd)
コード例 #6
0
    def decode(self, fd, mtu, max_len=2560):
        """
        Read the media transport descriptor, depay
        the RTP payload and decode the SBC frames into
        a byte array.  The maximum number of bytes to
        be returned may be passed as an argument and all
        available bytes are returned to the caller.

        :param int fd: Media transport file descriptor
        :param int mtu: Media transport MTU size as returned
            when the media transport was acquired.
        :param int max_len: Optional.  Set maximum number of
            bytes to read.
        :return data: Decoded data bytes as an array.
        :rtype: array{byte}
        """
        output_buffer = ffi.new('char[]', max_len)
        sz = self.codec.rtp_sbc_decode_from_fd(self.config, output_buffer,
                                               max_len, mtu, fd)
        return ffi.buffer(output_buffer[0:sz])
コード例 #7
0
ファイル: codecs.py プロジェクト: liamw9534/bt-manager
    def decode(self, fd, mtu, max_len=2560):
        """
        Read the media transport descriptor, depay
        the RTP payload and decode the SBC frames into
        a byte array.  The maximum number of bytes to
        be returned may be passed as an argument and all
        available bytes are returned to the caller.

        :param int fd: Media transport file descriptor
        :param int mtu: Media transport MTU size as returned
            when the media transport was acquired.
        :param int max_len: Optional.  Set maximum number of
            bytes to read.
        :return data: Decoded data bytes as an array.
        :rtype: array{byte}
        """
        output_buffer = ffi.new('char[]', max_len)
        sz = self.codec.rtp_sbc_decode_from_fd(self.config,
                                               output_buffer,
                                               max_len,
                                               mtu,
                                               fd)
        return ffi.buffer(output_buffer[0:sz])
コード例 #8
0
ファイル: codecs.py プロジェクト: liamw9534/bt-manager
    def encode(self, fd, mtu, data):
        """
        Encode the supplied data (byte array) and write to
        the media transport file descriptor encapsulated
        as RTP packets.  The encoder will calculate the
        required number of SBC frames and encapsulate as
        RTP to fit the MTU size.

        :param int fd: Media transport file descriptor
        :param int mtu: Media transport MTU size as returned
            when the media transport was acquired.
        :param array{byte} data: Data to encode and send
            over the media transport.
        :return:
        """
        self.codec.rtp_sbc_encode_to_fd(self.config,
                                        ffi.new('char[]',
                                                data),
                                        len(data),
                                        mtu,
                                        self.ts,
                                        self.seq_num,
                                        fd)