diff options
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/convert/convert_impl.cpp | 26 | ||||
-rw-r--r-- | host/lib/transport/vrt_packet_handler.hpp | 39 |
2 files changed, 33 insertions, 32 deletions
diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp index 74837cc51..6a5a1465d 100644 --- a/host/lib/convert/convert_impl.cpp +++ b/host/lib/convert/convert_impl.cpp @@ -90,28 +90,22 @@ void uhd::convert::register_converter( /*********************************************************************** * The converter functions **********************************************************************/ -void uhd::convert::io_type_to_otw_type( +const convert::function_type &convert::get_converter_cpu_to_otw( const io_type_t &io_type, const otw_type_t &otw_type, - input_type &input_buffs, - output_type &output_buffs, - size_t nsamps_per_io_buff + size_t num_input_buffs, + size_t num_output_buffs ){ - pred_type pred = make_pred(io_type, otw_type, input_buffs.size(), output_buffs.size()); - fcn_table_type table = get_cpu_to_otw_table(); - function_type fcn = table.at(pred).fcn; - fcn(input_buffs, output_buffs, nsamps_per_io_buff); + pred_type pred = make_pred(io_type, otw_type, num_input_buffs, num_output_buffs); + return get_cpu_to_otw_table().at(pred).fcn; } -void uhd::convert::otw_type_to_io_type( +const convert::function_type &convert::get_converter_otw_to_cpu( const io_type_t &io_type, const otw_type_t &otw_type, - input_type &input_buffs, - output_type &output_buffs, - size_t nsamps_per_io_buff + size_t num_input_buffs, + size_t num_output_buffs ){ - pred_type pred = make_pred(io_type, otw_type, input_buffs.size(), output_buffs.size()); - fcn_table_type table = get_otw_to_cpu_table(); - function_type fcn = table.at(pred).fcn; - fcn(input_buffs, output_buffs, nsamps_per_io_buff); + pred_type pred = make_pred(io_type, otw_type, num_input_buffs, num_output_buffs); + return get_otw_to_cpu_table().at(pred).fcn; } diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp index ab58e3416..0507ae328 100644 --- a/host/lib/transport/vrt_packet_handler.hpp +++ b/host/lib/transport/vrt_packet_handler.hpp @@ -35,6 +35,9 @@ namespace vrt_packet_handler{ +//this may change in the future but its a constant for now +static const size_t OTW_BYTES_PER_SAMP = sizeof(boost::uint32_t); + template <typename T> UHD_INLINE T get_context_code( const boost::uint32_t *vrt_hdr, const uhd::transport::vrt::if_packet_info_t &if_packet_info @@ -145,8 +148,7 @@ template <typename T> UHD_INLINE T get_context_code( size_t offset_bytes, size_t total_samps, uhd::rx_metadata_t &metadata, - const uhd::io_type_t &io_type, - const uhd::otw_type_t &otw_type, + uhd::convert::function_type &converter, double tick_rate, const vrt_unpacker_t &vrt_unpacker, const get_recv_buffs_t &get_recv_buffs, @@ -184,7 +186,7 @@ template <typename T> UHD_INLINE T get_context_code( } //extract the number of samples available to copy - size_t bytes_per_item = otw_type.get_sample_size(); + size_t bytes_per_item = OTW_BYTES_PER_SAMP; size_t nsamps_available = state.size_of_copy_buffs/bytes_per_item; size_t nsamps_to_copy = std::min(total_samps*chans_per_otw_buff, nsamps_available); size_t bytes_to_copy = nsamps_to_copy*bytes_per_item; @@ -200,9 +202,7 @@ template <typename T> UHD_INLINE T get_context_code( //copy-convert the samples from the recv buffer uhd::convert::input_type otw_buffs(1, state.copy_buffs[i]); - uhd::convert::otw_type_to_io_type( - io_type, otw_type, otw_buffs, io_buffs, nsamps_to_copy_per_io_buff - ); + converter(otw_buffs, io_buffs, nsamps_to_copy_per_io_buff); //update the rx copy buffer to reflect the bytes copied state.copy_buffs[i] += bytes_to_copy; @@ -236,6 +236,11 @@ template <typename T> UHD_INLINE T get_context_code( size_t vrt_header_offset_words32 = 0, size_t chans_per_otw_buff = 1 ){ + uhd::convert::function_type converter( + uhd::convert::get_converter_otw_to_cpu( + io_type, otw_type, 1, buffs.size() + )); + switch(recv_mode){ //////////////////////////////////////////////////////////////// @@ -246,7 +251,7 @@ template <typename T> UHD_INLINE T get_context_code( buffs, 0, total_num_samps, metadata, - io_type, otw_type, + converter, tick_rate, vrt_unpacker, get_recv_buffs, @@ -267,7 +272,7 @@ template <typename T> UHD_INLINE T get_context_code( buffs, accum_num_samps*io_type.size, total_num_samps - accum_num_samps, (accum_num_samps == 0)? metadata : tmp_md, //only the first metadata gets kept - io_type, otw_type, + converter, tick_rate, vrt_unpacker, get_recv_buffs, @@ -311,15 +316,14 @@ template <typename T> UHD_INLINE T get_context_code( const size_t offset_bytes, const size_t num_samps, uhd::transport::vrt::if_packet_info_t &if_packet_info, - const uhd::io_type_t &io_type, - const uhd::otw_type_t &otw_type, + uhd::convert::function_type &converter, const vrt_packer_t &vrt_packer, const get_send_buffs_t &get_send_buffs, const size_t vrt_header_offset_words32, const size_t chans_per_otw_buff ){ //load the rest of the if_packet_info in here - if_packet_info.num_payload_words32 = (num_samps*chans_per_otw_buff*otw_type.get_sample_size())/sizeof(boost::uint32_t); + if_packet_info.num_payload_words32 = (num_samps*chans_per_otw_buff*OTW_BYTES_PER_SAMP)/sizeof(boost::uint32_t); if_packet_info.packet_count = state.next_packet_seq; //get send buffers for each channel @@ -340,9 +344,7 @@ template <typename T> UHD_INLINE T get_context_code( //copy-convert the samples into the send buffer uhd::convert::output_type otw_buffs(1, otw_mem); - uhd::convert::io_type_to_otw_type( - io_type, otw_type, io_buffs, otw_buffs, num_samps - ); + converter(io_buffs, otw_buffs, num_samps); //commit the samples to the zero-copy interface size_t num_bytes_total = (vrt_header_offset_words32+if_packet_info.num_packet_words32)*sizeof(boost::uint32_t); @@ -370,6 +372,11 @@ template <typename T> UHD_INLINE T get_context_code( size_t vrt_header_offset_words32 = 0, size_t chans_per_otw_buff = 1 ){ + uhd::convert::function_type converter( + uhd::convert::get_converter_cpu_to_otw( + io_type, otw_type, buffs.size(), 1 + )); + //translate the metadata to vrt if packet info uhd::transport::vrt::if_packet_info_t if_packet_info; if_packet_info.has_sid = false; @@ -405,7 +412,7 @@ template <typename T> UHD_INLINE T get_context_code( buffs_, 0, std::min(total_num_samps_, max_samples_per_packet), if_packet_info, - io_type, otw_type, + converter, vrt_packer, get_send_buffs, vrt_header_offset_words32, @@ -438,7 +445,7 @@ template <typename T> UHD_INLINE T get_context_code( buffs, total_num_samps_sent*io_type.size, std::min(total_num_samps_unsent, max_samples_per_packet), if_packet_info, - io_type, otw_type, + converter, vrt_packer, get_send_buffs, vrt_header_offset_words32, |