#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_video.h"
-#include "util/vl_vlc.h"
struct pipe_video_codec *
d3d12_video_create_decoder(struct pipe_context *context, const struct pipe_video_codec *codec)
}
}
-///
-/// Returns the number of bytes starting from [buf.data() + buffsetOffset] where the _targetCode_ is found
-/// Returns -1 if start code not found
-///
-int
-d3d12_video_decoder_get_next_startcode_offset(std::vector<uint8_t> &buf,
- unsigned int bufferOffset,
- unsigned int targetCode,
- unsigned int targetCodeBitSize,
- unsigned int numBitsToSearchIntoBuffer)
-{
- struct vl_vlc vlc = { 0 };
-
- // Shorten the buffer to be [buffetOffset, endOfBuf)
- unsigned int bufSize = buf.size() - bufferOffset;
- uint8_t *bufPtr = buf.data();
- bufPtr += bufferOffset;
-
- /* search the first numBitsToSearchIntoBuffer bytes for a startcode */
- vl_vlc_init(&vlc, 1, (const void *const *) &bufPtr, &bufSize);
- for (uint i = 0; i < numBitsToSearchIntoBuffer && vl_vlc_bits_left(&vlc) >= targetCodeBitSize; ++i) {
- if (vl_vlc_peekbits(&vlc, targetCodeBitSize) == targetCode)
- return i;
- vl_vlc_eatbits(&vlc, 8); // Stride is 8 bits = 1 byte
- vl_vlc_fillbits(&vlc);
- }
-
- return -1;
-}
-
void
d3d12_video_decoder_store_converted_dxva_picparams_from_pipe_input(
struct d3d12_video_decoder *codec, // input argument, current decoder
uint64_t DXVAStructSize);
void
d3d12_video_decoder_prepare_dxva_slices_control(struct d3d12_video_decoder *pD3D12Dec, struct pipe_picture_desc *picture);
-int
-d3d12_video_decoder_get_next_startcode_offset(std::vector<uint8_t> &buf,
- unsigned int bufferOffset,
- unsigned int targetCode,
- unsigned int targetCodeBitSize,
- unsigned int numBitsToSearchIntoBuffer);
///
/// d3d12_video_decoder functions ends
assert(vecOutSliceControlBuffers.size() == TotalSlicesDXVAArrayByteSize);
}
-bool
-d3d12_video_decoder_get_next_slice_size_and_offset_h264(std::vector<uint8_t> &buf,
- unsigned int bufferOffset,
- uint32_t &outSliceSize,
- uint32_t &outSliceOffset)
-{
- // Search the rest of the full frame buffer after the offset
- uint numBitsToSearchIntoBuffer = buf.size() - bufferOffset;
- int currentSlicePosition = d3d12_video_decoder_get_next_startcode_offset(buf,
- bufferOffset,
- DXVA_H264_START_CODE,
- DXVA_H264_START_CODE_LEN_BITS,
- numBitsToSearchIntoBuffer);
-
- // Return false now if we didn't find a next slice based on the bufferOffset parameter
- if (currentSlicePosition < 0) {
- return false;
- } else {
- // Save the absolute buffer offset until the next slice in the output param
- outSliceOffset = currentSlicePosition + bufferOffset;
-
- // Found a next NALU, make sure it's a slice:
- d3d12_video_decoder_nal_unit_type_h264 naluType =
- (d3d12_video_decoder_nal_unit_type_h264)(buf[outSliceOffset + (DXVA_H264_START_CODE_LEN_BITS / 8)] & 0x1F);
-
- bool isNaluSliceType = (naluType == type_slice) || (naluType == type_slice_part_A) ||
- (naluType == type_slice_part_B) || (naluType == type_slice_part_C) ||
- (naluType == type_slice_IDR) || (naluType == type_slice_aux) ||
- (naluType == type_slice_layer_ext);
-
- if (!isNaluSliceType) {
- // We found a NALU, but it's not a slice
- return false;
- } else {
- // We did find a next slice based on the bufferOffset parameter
-
- // Skip current start code, to get the slice after this, to calculate its size
- bufferOffset += (DXVA_H264_START_CODE_LEN_BITS / 8 /*convert bits to bytes*/);
- numBitsToSearchIntoBuffer = buf.size() - bufferOffset;
-
- int c_signedStartCodeLen = (DXVA_H264_START_CODE_LEN_BITS / 8 /*convert bits to bytes*/);
- int nextSlicePosition = c_signedStartCodeLen // Takes into account the skipped start code
- + d3d12_video_decoder_get_next_startcode_offset(buf,
- bufferOffset,
- DXVA_H264_START_CODE,
- DXVA_H264_START_CODE_LEN_BITS,
- numBitsToSearchIntoBuffer);
-
- if (nextSlicePosition <
- c_signedStartCodeLen) // if no slice found, d3d12_video_decoder_get_next_startcode_offset returns - 1
- {
- // This means currentSlicePosition points to the last slice in the buffer
- outSliceSize = buf.size() - outSliceOffset;
- } else {
- // This means there are more slices after the one pointed by currentSlicePosition
- outSliceSize = nextSlicePosition - currentSlicePosition;
- }
- return true;
- }
- }
-}
-
static void
d3d12_video_decoder_log_pic_entry_h264(DXVA_PicEntry_H264 &picEntry)
{