media: vidtv: simplify NIT write function
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 24 Nov 2020 09:37:12 +0000 (10:37 +0100)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 26 Nov 2020 07:05:24 +0000 (08:05 +0100)
- pass struct vidtv_psi_nit_write_args as a pointer;
- avoid initializing struct fields multiple times.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/test-drivers/vidtv/vidtv_mux.c
drivers/media/test-drivers/vidtv/vidtv_psi.c
drivers/media/test-drivers/vidtv/vidtv_psi.h

index ff1c7c58683827afb8901076a51a930bedb0c5e3..77d691f4ff922e018d5536a7d1fb78af278c9e15 100644 (file)
@@ -204,7 +204,7 @@ static u32 vidtv_mux_push_si(struct vidtv_mux *m)
        nit_args.offset             = m->mux_buf_offset;
        nit_args.continuity_counter = &nit_ctx->cc;
 
-       m->mux_buf_offset += vidtv_psi_nit_write_into(nit_args);
+       m->mux_buf_offset += vidtv_psi_nit_write_into(&nit_args);
 
        eit_args.offset             = m->mux_buf_offset;
        eit_args.continuity_counter = &eit_ctx->cc;
index f8cfcd7f42d32dccc50c3d589b739bca0f73c6d7..b03e235b0a678cae124e1a057ee1fefd7251f8f5 100644 (file)
@@ -1647,53 +1647,60 @@ free_nit:
        return NULL;
 }
 
-u32 vidtv_psi_nit_write_into(struct vidtv_psi_nit_write_args args)
+u32 vidtv_psi_nit_write_into(struct vidtv_psi_nit_write_args *args)
 {
-       struct vidtv_psi_desc *table_descriptor     = args.nit->descriptor;
-       struct vidtv_psi_table_transport *transport = args.nit->transport;
+       struct header_write_args h_args = {
+               .dest_buf           = args->buf,
+               .dest_offset        = args->offset,
+               .h                  = &args->nit->header,
+               .pid                = VIDTV_NIT_PID,
+               .dest_buf_sz        = args->buf_sz,
+       };
+       struct psi_write_args psi_args  = {
+               .dest_buf           = args->buf,
+               .from               = &args->nit->bitfield,
+               .len                = sizeof_field(struct vidtv_psi_table_nit, bitfield),
+               .pid                = VIDTV_NIT_PID,
+               .new_psi_section    = false,
+               .is_crc             = false,
+               .dest_buf_sz        = args->buf_sz,
+       };
+       struct desc_write_args d_args   = {
+               .dest_buf           = args->buf,
+               .pid                = VIDTV_NIT_PID,
+               .dest_buf_sz        = args->buf_sz,
+       };
+       struct crc32_write_args c_args  = {
+               .dest_buf           = args->buf,
+               .pid                = VIDTV_NIT_PID,
+               .dest_buf_sz        = args->buf_sz,
+       };
+       struct vidtv_psi_desc *table_descriptor     = args->nit->descriptor;
+       struct vidtv_psi_table_transport *transport = args->nit->transport;
        struct vidtv_psi_desc *transport_descriptor;
-       struct header_write_args h_args = {};
-       struct psi_write_args psi_args  = {};
-       struct desc_write_args d_args   = {};
-       struct crc32_write_args c_args  = {};
        u32 crc = INITIAL_CRC;
        u32 nbytes = 0;
 
-       vidtv_psi_nit_table_update_sec_len(args.nit);
+       vidtv_psi_nit_table_update_sec_len(args->nit);
 
-       h_args.dest_buf           = args.buf;
-       h_args.dest_offset        = args.offset;
-       h_args.h                  = &args.nit->header;
-       h_args.pid                = VIDTV_NIT_PID;
-       h_args.continuity_counter = args.continuity_counter;
-       h_args.dest_buf_sz        = args.buf_sz;
+       h_args.continuity_counter = args->continuity_counter;
        h_args.crc                = &crc;
 
        nbytes += vidtv_psi_table_header_write_into(&h_args);
 
        /* write the bitfield */
-       psi_args.dest_buf = args.buf;
-       psi_args.from     = &args.nit->bitfield;
-       psi_args.len      = sizeof_field(struct vidtv_psi_table_nit, bitfield);
 
-       psi_args.dest_offset        = args.offset + nbytes;
-       psi_args.pid                = VIDTV_NIT_PID;
-       psi_args.new_psi_section    = false;
-       psi_args.continuity_counter = args.continuity_counter;
-       psi_args.is_crc             = false;
-       psi_args.dest_buf_sz        = args.buf_sz;
+       psi_args.dest_offset        = args->offset + nbytes;
+       psi_args.continuity_counter = args->continuity_counter;
        psi_args.crc                = &crc;
 
        nbytes += vidtv_psi_ts_psi_write_into(&psi_args);
 
        while (table_descriptor) {
                /* write the descriptors, if any */
-               d_args.dest_buf           = args.buf;
-               d_args.dest_offset        = args.offset + nbytes;
+               d_args.dest_offset        = args->offset + nbytes;
                d_args.desc               = table_descriptor;
-               d_args.pid                = VIDTV_NIT_PID;
-               d_args.continuity_counter = args.continuity_counter;
-               d_args.dest_buf_sz        = args.buf_sz;
+               d_args.continuity_counter = args->continuity_counter;
                d_args.crc                = &crc;
 
                nbytes += vidtv_psi_desc_write_into(&d_args);
@@ -1702,21 +1709,19 @@ u32 vidtv_psi_nit_write_into(struct vidtv_psi_nit_write_args args)
        }
 
        /* write the second bitfield */
-       psi_args.dest_buf = args.buf;
-       psi_args.from = &args.nit->bitfield2;
+       psi_args.from = &args->nit->bitfield2;
        psi_args.len = sizeof_field(struct vidtv_psi_table_nit, bitfield2);
-       psi_args.dest_offset = args.offset + nbytes;
-       psi_args.pid = VIDTV_NIT_PID;
+       psi_args.dest_offset = args->offset + nbytes;
 
        nbytes += vidtv_psi_ts_psi_write_into(&psi_args);
 
+       psi_args.len  = sizeof_field(struct vidtv_psi_table_transport, transport_id) +
+                       sizeof_field(struct vidtv_psi_table_transport, network_id)   +
+                       sizeof_field(struct vidtv_psi_table_transport, bitfield);
        while (transport) {
                /* write the transport sections, if any */
                psi_args.from = transport;
-               psi_args.len  = sizeof_field(struct vidtv_psi_table_transport, transport_id) +
-                               sizeof_field(struct vidtv_psi_table_transport, network_id)   +
-                               sizeof_field(struct vidtv_psi_table_transport, bitfield);
-               psi_args.dest_offset = args.offset + nbytes;
+               psi_args.dest_offset = args->offset + nbytes;
 
                nbytes += vidtv_psi_ts_psi_write_into(&psi_args);
 
@@ -1724,12 +1729,9 @@ u32 vidtv_psi_nit_write_into(struct vidtv_psi_nit_write_args args)
 
                while (transport_descriptor) {
                        /* write the transport descriptors, if any */
-                       d_args.dest_buf           = args.buf;
-                       d_args.dest_offset        = args.offset + nbytes;
+                       d_args.dest_offset        = args->offset + nbytes;
                        d_args.desc               = transport_descriptor;
-                       d_args.pid                = VIDTV_NIT_PID;
-                       d_args.continuity_counter = args.continuity_counter;
-                       d_args.dest_buf_sz        = args.buf_sz;
+                       d_args.continuity_counter = args->continuity_counter;
                        d_args.crc                = &crc;
 
                        nbytes += vidtv_psi_desc_write_into(&d_args);
@@ -1740,12 +1742,9 @@ u32 vidtv_psi_nit_write_into(struct vidtv_psi_nit_write_args args)
                transport = transport->next;
        }
 
-       c_args.dest_buf           = args.buf;
-       c_args.dest_offset        = args.offset + nbytes;
+       c_args.dest_offset        = args->offset + nbytes;
        c_args.crc                = cpu_to_be32(crc);
-       c_args.pid                = VIDTV_NIT_PID;
-       c_args.continuity_counter = args.continuity_counter;
-       c_args.dest_buf_sz        = args.buf_sz;
+       c_args.continuity_counter = args->continuity_counter;
 
        /* Write the CRC32 at the end */
        nbytes += table_section_crc32_write_into(&c_args);
index e3913fbe7832856dcfb1b59d7685d4c6f1eb8a3a..8e366ea44ccacd748ce0ceec4d1d342aab0b7d03 100644 (file)
@@ -709,7 +709,7 @@ struct vidtv_psi_nit_write_args {
  * equal to the size of the NIT, since more space is needed for TS headers during TS
  * encapsulation.
  */
-u32 vidtv_psi_nit_write_into(struct vidtv_psi_nit_write_args args);
+u32 vidtv_psi_nit_write_into(struct vidtv_psi_nit_write_args *args);
 
 void vidtv_psi_nit_table_destroy(struct vidtv_psi_table_nit *nit);