Ejemplo n.º 1
0
    def compress(self, uncomp_pkt):
        """ Compress the given uncompressed packet

        Keyword arguments:
        uncomp_pkt -- the uncompressed packet (str)

        Return tuple (return_code, compressed_packet):
        status   -- a value among ROHC_STATUS_*
        comp_pkt -- the compressed packet (str) or None wrt status_code
        """

        status = ROHC_STATUS_ERROR

        timestamp = rohc_ts(0, 0)

        # create the input buffer for the uncompressed packet
        if isinstance(uncomp_pkt, bytes) is not True:
            raise TypeError("compress(): argument 'uncomp_pkt' shall be "\
                            "'bytes' not '%s'" % type(uncomp_pkt))
        uncomp_pkt_len = len(uncomp_pkt)
        buf_uncomp = rohc_buf(uncomp_pkt, uncomp_pkt_len, timestamp)
        if buf_uncomp is None:
            return (status, None)

        # create the output buffer for the compressed ROHC packet
        buf_comp = rohc_buf(self._buf, 0, timestamp)
        if buf_comp is None:
            return (status, None)

        # compress the uncompressed packet into one ROHC packet
        status = rohc_compress4(self.comp, buf_uncomp, buf_comp)
        if status != ROHC_STATUS_OK:
            return (status, None)

        return (status, self._buf[:buf_comp.len])
Ejemplo n.º 2
0
    def compress(self, uncomp_pkt):
        """ Compress the given uncompressed packet

        Keyword arguments:
        uncomp_pkt -- the uncompressed packet (str)

        Return tuple (return_code, compressed_packet):
        status   -- a value among ROHC_STATUS_*
        comp_pkt -- the compressed packet (str) or None wrt status_code
        """

        status = ROHC_STATUS_ERROR

        timestamp = rohc_ts(0, 0)

        # create the input buffer for the uncompressed packet
        if isinstance(uncomp_pkt, bytes) is not True:
            raise TypeError("compress(): argument 'uncomp_pkt' shall be "\
                            "'bytes' not '%s'" % type(uncomp_pkt))
        uncomp_pkt_len = len(uncomp_pkt)
        buf_uncomp = rohc_buf(uncomp_pkt, uncomp_pkt_len, timestamp)
        if buf_uncomp is None:
            return (status, None)

        # create the output buffer for the compressed ROHC packet
        buf_comp = rohc_buf(self._buf, 0, timestamp)
        if buf_comp is None:
            return (status, None)

        # compress the uncompressed packet into one ROHC packet
        status = rohc_compress4(self.comp, buf_uncomp, buf_comp)
        if status != ROHC_STATUS_OK:
            return (status, None)

        return (status, self._buf[:buf_comp.len])
Ejemplo n.º 3
0
    def decompress(self, comp_pkt):
        """ Decompress the given compressed ROHC packet

        Keyword arguments:
        comp_pkt -- the compressed ROHC packet (str)

        Return tuple:
        status           -- a value among ROHC_STATUS_*
        decomp_pkt       -- the decompressed packet (str) or None wrt status_code
        feedback_recv    -- the feedback (str) received with the compressed packet
        feedback_to_send -- the feedback (str) to send with the associated compressor
        """

        status = ROHC_STATUS_ERROR
        timestamp = rohc_ts(0, 0)

        # create the input buffer for the compressed ROHC packet
        if isinstance(comp_pkt, bytes) is not True:
            raise TypeError("compress(): argument 'comp_pkt' shall be "\
                            "'bytes' not '%s'" % type(comp_pkt))
        comp_pkt_len = len(comp_pkt)
        buf_comp = rohc_buf(comp_pkt, comp_pkt_len, timestamp)
        if buf_comp is None:
            return (status, None, None, None)

        # create the output buffer for the decompressed packet
        buf_decomp = rohc_buf(self._buf1, 0, timestamp)
        if buf_decomp is None:
            return (status, None, None, None)

        # create the buffers for feedbacks
        buf_feedback_recv = rohc_buf(self._buf2, 0, timestamp)
        if buf_feedback_recv is None:
            return (status, None, None, None)
        buf_feedback_to_send = rohc_buf(self._buf3, 0, timestamp)
        if buf_feedback_to_send is None:
            return (status, None, None, None)

        # decompress the ROHC packet
        status = rohc_decompress3(self.decomp, buf_comp, buf_decomp, \
                                  buf_feedback_recv, buf_feedback_to_send)
        if status != ROHC_STATUS_OK:
            return (status, None, None, None)

        return (status, self._buf1[:buf_decomp.len], \
                self._buf2[:buf_feedback_recv.len], \
                self._buf3[:buf_feedback_to_send.len])
Ejemplo n.º 4
0
    def deliver_feedback(self, feedback):
        """ Deliver the given feedback packet to the ROHC compressor

        Keyword arguments:
        feedback -- the feedback packet to deliver to the ROHC compressor

        Return whether the feedback packet was successfully delivered to the
        ROHC compressor or not (bool).
        """

        timestamp = rohc_ts(0, 0)

        # create the buffer for the feedback data
        if isinstance(feedback, bytes) is not True:
            raise TypeError("compress(): argument 'feedback' shall be "\
                            "'bytes' not '%s'" % type(feedback))
        feedback_len = len(feedback)
        buf_feedback = rohc_buf(feedback, feedback_len, timestamp)
        if buf_feedback is None:
            return False

        return rohc_comp_deliver_feedback2(self.comp, buf_feedback)
Ejemplo n.º 5
0
    def deliver_feedback(self, feedback):
        """ Deliver the given feedback packet to the ROHC compressor

        Keyword arguments:
        feedback -- the feedback packet to deliver to the ROHC compressor

        Return whether the feedback packet was successfully delivered to the
        ROHC compressor or not (bool).
        """

        timestamp = rohc_ts(0, 0)

        # create the buffer for the feedback data
        if isinstance(feedback, bytes) is not True:
            raise TypeError("compress(): argument 'feedback' shall be "\
                            "'bytes' not '%s'" % type(feedback))
        feedback_len = len(feedback)
        buf_feedback = rohc_buf(feedback, feedback_len, timestamp)
        if buf_feedback is None:
            return False

        return rohc_comp_deliver_feedback2(self.comp, buf_feedback)