# automatically generated by the FlatBuffers compiler, do not modify

# namespace: foxglove

import flatbuffers
from flatbuffers.compat import import_numpy
np = import_numpy()

# A single frame of a compressed video bitstream
class CompressedVideo(object):
    __slots__ = ['_tab']

    @classmethod
    def GetRootAs(cls, buf, offset=0):
        n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
        x = CompressedVideo()
        x.Init(buf, n + offset)
        return x

    @classmethod
    def GetRootAsCompressedVideo(cls, buf, offset=0):
        """This method is deprecated. Please switch to GetRootAs."""
        return cls.GetRootAs(buf, offset)
    # CompressedVideo
    def Init(self, buf, pos):
        self._tab = flatbuffers.table.Table(buf, pos)

    # Timestamp of video frame
    # CompressedVideo
    def Timestamp(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            x = o + self._tab.Pos
            from .Time import Time
            obj = Time()
            obj.Init(self._tab.Bytes, x)
            return obj
        return None

    # Frame of reference for the video.
    # 
    # The origin of the frame is the optical center of the camera. +x points to the right in the video, +y points down, and +z points into the plane of the video.
    # CompressedVideo
    def FrameId(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

    # Compressed video frame data.
    # 
    # For packet-based video codecs this data must begin and end on packet boundaries (no partial packets), and must contain enough video packets to decode exactly one image (either a keyframe or delta frame). Note: Foxglove does not support video streams that include B frames because they require lookahead.
    # 
    # Specifically, the requirements for different `format` values are:
    # 
    # - `h264`
    #   - Use Annex B formatted data
    #   - Each CompressedVideo message should contain enough NAL units to decode exactly one video frame
    #   - Each message containing a key frame (IDR) must also include a SPS NAL unit
    # 
    # - `h265` (HEVC)
    #   - Use Annex B formatted data
    #   - Each CompressedVideo message should contain enough NAL units to decode exactly one video frame
    #   - Each message containing a key frame (IRAP) must also include relevant VPS/SPS/PPS NAL units
    # 
    # - `vp9`
    #   - Each CompressedVideo message should contain exactly one video frame
    # 
    # - `av1`
    #   - Use the "Low overhead bitstream format" (section 5.2)
    #   - Each CompressedVideo message should contain enough OBUs to decode exactly one video frame
    #   - Each message containing a key frame must also include a Sequence Header OBU
    # CompressedVideo
    def Data(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
        if o != 0:
            a = self._tab.Vector(o)
            return self._tab.Get(flatbuffers.number_types.Uint8Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 1))
        return 0

    # CompressedVideo
    def DataAsNumpy(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
        if o != 0:
            return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Uint8Flags, o)
        return 0

    # CompressedVideo
    def DataLength(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # CompressedVideo
    def DataIsNone(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
        return o == 0

    # Video format.
    # 
    # Supported values: `h264`, `h265`, `vp9`, `av1`.
    # 
    # Note: compressed video support is subject to hardware limitations and patent licensing, so not all encodings may be supported on all platforms. See more about [H.265 support](https://caniuse.com/hevc), [VP9 support](https://caniuse.com/webm), and [AV1 support](https://caniuse.com/av1).
    # CompressedVideo
    def Format(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

def CompressedVideoStart(builder): builder.StartObject(4)
def Start(builder):
    return CompressedVideoStart(builder)
def CompressedVideoAddTimestamp(builder, timestamp): builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(timestamp), 0)
def AddTimestamp(builder, timestamp):
    return CompressedVideoAddTimestamp(builder, timestamp)
def CompressedVideoAddFrameId(builder, frameId): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(frameId), 0)
def AddFrameId(builder, frameId):
    return CompressedVideoAddFrameId(builder, frameId)
def CompressedVideoAddData(builder, data): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(data), 0)
def AddData(builder, data):
    return CompressedVideoAddData(builder, data)
def CompressedVideoStartDataVector(builder, numElems): return builder.StartVector(1, numElems, 1)
def StartDataVector(builder, numElems):
    return CompressedVideoStartDataVector(builder, numElems)
def CompressedVideoAddFormat(builder, format): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(format), 0)
def AddFormat(builder, format):
    return CompressedVideoAddFormat(builder, format)
def CompressedVideoEnd(builder): return builder.EndObject()
def End(builder):
    return CompressedVideoEnd(builder)