radeon/vcn: move header related algorithm to vcn_enc
authorBoyuan Zhang <boyuan.zhang@amd.com>
Tue, 30 Oct 2018 18:14:35 +0000 (14:14 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 3 Jul 2019 19:51:12 +0000 (15:51 -0400)
Signed-off-by: Boyuan Zhang <boyuan.zhang@amd.com>
Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/gallium/drivers/radeon/radeon_vcn_enc.c
src/gallium/drivers/radeon/radeon_vcn_enc.h
src/gallium/drivers/radeon/radeon_vcn_enc_1_2.c

index 868f94731268fb423c888270b92069c6f42c6fdd..5eb5f406882cd5185cc5e630ba37c01ff2a0416b 100644 (file)
@@ -38,6 +38,8 @@
 #include "radeon_video.h"
 #include "radeon_vcn_enc.h"
 
+static const unsigned index_to_shifts[4] = {24, 16, 8, 0};
+
 static void radeon_vcn_enc_get_param(struct radeon_encoder *enc, struct pipe_picture_desc *picture)
 {
    if (u_reduce_video_profile(picture->profile) == PIPE_VIDEO_FORMAT_MPEG4_AVC) {
@@ -359,3 +361,123 @@ void radeon_enc_add_buffer(struct radeon_encoder *enc, struct pb_buffer *buf,
        RADEON_ENC_CS(addr >> 32);
        RADEON_ENC_CS(addr);
 }
+
+void radeon_enc_set_emulation_prevention(struct radeon_encoder *enc, bool set)
+{
+       if (set != enc->emulation_prevention) {
+               enc->emulation_prevention = set;
+               enc->num_zeros = 0;
+       }
+}
+
+void radeon_enc_output_one_byte(struct radeon_encoder *enc, unsigned char byte)
+{
+       if (enc->byte_index == 0)
+               enc->cs->current.buf[enc->cs->current.cdw] = 0;
+       enc->cs->current.buf[enc->cs->current.cdw] |= ((unsigned int)(byte) << index_to_shifts[enc->byte_index]);
+       enc->byte_index++;
+
+       if (enc->byte_index >= 4) {
+               enc->byte_index = 0;
+               enc->cs->current.cdw++;
+       }
+}
+
+void radeon_enc_emulation_prevention(struct radeon_encoder *enc, unsigned char byte)
+{
+       if(enc->emulation_prevention) {
+               if((enc->num_zeros >= 2) && ((byte == 0x00) || (byte == 0x01) || (byte == 0x03))) {
+            radeon_enc_output_one_byte(enc, 0x03);
+            enc->bits_output += 8;
+            enc->num_zeros = 0;
+        }
+        enc->num_zeros = (byte == 0 ? (enc->num_zeros + 1) : 0);
+    }
+}
+
+void radeon_enc_code_fixed_bits(struct radeon_encoder *enc, unsigned int value, unsigned int num_bits)
+{
+       unsigned int bits_to_pack = 0;
+
+       while(num_bits > 0) {
+               unsigned int value_to_pack = value & (0xffffffff >> (32 - num_bits));
+               bits_to_pack = num_bits > (32 - enc->bits_in_shifter) ? (32 - enc->bits_in_shifter) : num_bits;
+
+               if (bits_to_pack < num_bits)
+                       value_to_pack = value_to_pack >> (num_bits - bits_to_pack);
+
+               enc->shifter |= value_to_pack << (32 - enc->bits_in_shifter - bits_to_pack);
+               num_bits -= bits_to_pack;
+               enc->bits_in_shifter += bits_to_pack;
+
+               while(enc->bits_in_shifter >= 8) {
+                       unsigned char output_byte = (unsigned char)(enc->shifter >> 24);
+                       enc->shifter <<= 8;
+                       radeon_enc_emulation_prevention(enc, output_byte);
+                       radeon_enc_output_one_byte(enc, output_byte);
+                       enc->bits_in_shifter -= 8;
+                       enc->bits_output += 8;
+               }
+       }
+}
+
+void radeon_enc_reset(struct radeon_encoder *enc)
+{
+       enc->emulation_prevention = false;
+       enc->shifter = 0;
+       enc->bits_in_shifter = 0;
+       enc->bits_output = 0;
+       enc->num_zeros = 0;
+       enc->byte_index = 0;
+}
+
+void radeon_enc_byte_align(struct radeon_encoder *enc)
+{
+       unsigned int num_padding_zeros = (32 - enc->bits_in_shifter) % 8;
+
+       if (num_padding_zeros > 0)
+               radeon_enc_code_fixed_bits(enc, 0, num_padding_zeros);
+}
+
+void radeon_enc_flush_headers(struct radeon_encoder *enc)
+{
+       if (enc->bits_in_shifter != 0) {
+               unsigned char output_byte = (unsigned char)(enc->shifter >> 24);
+               radeon_enc_emulation_prevention(enc, output_byte);
+               radeon_enc_output_one_byte(enc, output_byte);
+               enc->bits_output += enc->bits_in_shifter;
+               enc->shifter = 0;
+               enc->bits_in_shifter = 0;
+               enc->num_zeros = 0;
+       }
+
+       if (enc->byte_index > 0) {
+               enc->cs->current.cdw++;
+               enc->byte_index = 0;
+       }
+}
+
+void radeon_enc_code_ue(struct radeon_encoder *enc, unsigned int value)
+{
+       int x = -1;
+       unsigned int ue_code = value + 1;
+       value += 1;
+
+       while (value) {
+               value = (value >> 1);
+               x += 1;
+       }
+
+       unsigned int ue_length = (x << 1) + 1;
+       radeon_enc_code_fixed_bits(enc, ue_code, ue_length);
+}
+
+void radeon_enc_code_se(struct radeon_encoder *enc, int value)
+{
+       unsigned int v = 0;
+
+       if (value != 0)
+               v = (value < 0 ? ((unsigned int)(0 - value) << 1) : (((unsigned int)(value) << 1) - 1));
+
+       radeon_enc_code_ue(enc, v);
+}
index 5fa516167d90d402768b443335c01b049250070f..15f12c66155b3f349aaa57f9124e619fab067fe1 100644 (file)
@@ -500,6 +500,26 @@ void radeon_enc_add_buffer(struct radeon_encoder *enc, struct pb_buffer *buf,
                           enum radeon_bo_usage usage, enum radeon_bo_domain domain,
                           signed offset);
 
+void radeon_enc_set_emulation_prevention(struct radeon_encoder *enc, bool set);
+
+void radeon_enc_output_one_byte(struct radeon_encoder *enc, unsigned char byte);
+
+void radeon_enc_emulation_prevention(struct radeon_encoder *enc,
+                                    unsigned char byte);
+
+void radeon_enc_code_fixed_bits(struct radeon_encoder *enc, unsigned int value,
+                               unsigned int num_bits);
+
+void radeon_enc_reset(struct radeon_encoder *enc);
+
+void radeon_enc_byte_align(struct radeon_encoder *enc);
+
+void radeon_enc_flush_headers(struct radeon_encoder *enc);
+
+void radeon_enc_code_ue(struct radeon_encoder *enc, unsigned int value);
+
+void radeon_enc_code_se(struct radeon_encoder *enc, int value);
+
 void radeon_enc_1_2_init(struct radeon_encoder *enc);
 
 #endif  // _RADEON_VCN_ENC_H
index 75082092ca34c644045418a5387222a6a9aa3d22..6efb10d96fcc38ddd3031ed802a94b67e3e06a7a 100644 (file)
 #include "radeon_video.h"
 #include "radeon_vcn_enc.h"
 
-static const unsigned index_to_shifts[4] = {24, 16, 8, 0};
-
-static void radeon_enc_set_emulation_prevention(struct radeon_encoder *enc, bool set)
-{
-       if (set != enc->emulation_prevention) {
-               enc->emulation_prevention = set;
-               enc->num_zeros = 0;
-       }
-}
-
-static void radeon_enc_output_one_byte(struct radeon_encoder *enc, unsigned char byte)
-{
-       if (enc->byte_index == 0)
-               enc->cs->current.buf[enc->cs->current.cdw] = 0;
-       enc->cs->current.buf[enc->cs->current.cdw] |= ((unsigned int)(byte) << index_to_shifts[enc->byte_index]);
-       enc->byte_index++;
-
-       if (enc->byte_index >= 4) {
-               enc->byte_index = 0;
-               enc->cs->current.cdw++;
-       }
-}
-
-static void radeon_enc_emulation_prevention(struct radeon_encoder *enc, unsigned char byte)
-{
-       if(enc->emulation_prevention) {
-               if((enc->num_zeros >= 2) && ((byte == 0x00) || (byte == 0x01) || (byte == 0x03))) {
-            radeon_enc_output_one_byte(enc, 0x03);
-            enc->bits_output += 8;
-            enc->num_zeros = 0;
-        }
-        enc->num_zeros = (byte == 0 ? (enc->num_zeros + 1) : 0);
-    }
-}
-
-static void radeon_enc_code_fixed_bits(struct radeon_encoder *enc, unsigned int value, unsigned int num_bits)
-{
-       unsigned int bits_to_pack = 0;
-
-       while(num_bits > 0) {
-               unsigned int value_to_pack = value & (0xffffffff >> (32 - num_bits));
-               bits_to_pack = num_bits > (32 - enc->bits_in_shifter) ? (32 - enc->bits_in_shifter) : num_bits;
-
-               if (bits_to_pack < num_bits)
-                       value_to_pack = value_to_pack >> (num_bits - bits_to_pack);
-
-               enc->shifter |= value_to_pack << (32 - enc->bits_in_shifter - bits_to_pack);
-               num_bits -= bits_to_pack;
-               enc->bits_in_shifter += bits_to_pack;
-
-               while(enc->bits_in_shifter >= 8) {
-                       unsigned char output_byte = (unsigned char)(enc->shifter >> 24);
-                       enc->shifter <<= 8;
-                       radeon_enc_emulation_prevention(enc, output_byte);
-                       radeon_enc_output_one_byte(enc, output_byte);
-                       enc->bits_in_shifter -= 8;
-                       enc->bits_output += 8;
-               }
-       }
-}
-
-static void radeon_enc_reset(struct radeon_encoder *enc)
-{
-       enc->emulation_prevention = false;
-       enc->shifter = 0;
-       enc->bits_in_shifter = 0;
-       enc->bits_output = 0;
-       enc->num_zeros = 0;
-       enc->byte_index = 0;
-}
-
-static void radeon_enc_byte_align(struct radeon_encoder *enc)
-{
-       unsigned int num_padding_zeros = (32 - enc->bits_in_shifter) % 8;
-
-       if (num_padding_zeros > 0)
-               radeon_enc_code_fixed_bits(enc, 0, num_padding_zeros);
-}
-
-static void radeon_enc_flush_headers(struct radeon_encoder *enc)
-{
-       if (enc->bits_in_shifter != 0) {
-               unsigned char output_byte = (unsigned char)(enc->shifter >> 24);
-               radeon_enc_emulation_prevention(enc, output_byte);
-               radeon_enc_output_one_byte(enc, output_byte);
-               enc->bits_output += enc->bits_in_shifter;
-               enc->shifter = 0;
-               enc->bits_in_shifter = 0;
-               enc->num_zeros = 0;
-       }
-
-       if (enc->byte_index > 0) {
-               enc->cs->current.cdw++;
-               enc->byte_index = 0;
-       }
-}
-
-static void radeon_enc_code_ue(struct radeon_encoder *enc, unsigned int value)
-{
-       int x = -1;
-       unsigned int ue_code = value + 1;
-       value += 1;
-
-       while (value) {
-               value = (value >> 1);
-               x += 1;
-       }
-
-       unsigned int ue_length = (x << 1) + 1;
-       radeon_enc_code_fixed_bits(enc, ue_code, ue_length);
-}
-
-static void radeon_enc_code_se(struct radeon_encoder *enc, int value)
-{
-       unsigned int v = 0;
-
-       if (value != 0)
-               v = (value < 0 ? ((unsigned int)(0 - value) << 1) : (((unsigned int)(value) << 1) - 1));
-
-       radeon_enc_code_ue(enc, v);
-}
-
 static void radeon_enc_session_info(struct radeon_encoder *enc)
 {
        unsigned int interface_version = ((RENCODE_FW_INTERFACE_MAJOR_VERSION << RENCODE_IF_MAJOR_VERSION_SHIFT) |