root / host / include / uhd / stream.hpp @ 0946176f
History | View | Annotate | Download (6.5 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2011 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
#ifndef INCLUDED_UHD_STREAM_HPP
|
| 19 |
#define INCLUDED_UHD_STREAM_HPP
|
| 20 |
|
| 21 |
#include <uhd/config.hpp> |
| 22 |
#include <uhd/types/metadata.hpp> |
| 23 |
#include <uhd/types/ref_vector.hpp> |
| 24 |
#include <boost/utility.hpp> |
| 25 |
#include <boost/shared_ptr.hpp> |
| 26 |
#include <vector> |
| 27 |
#include <string> |
| 28 |
|
| 29 |
namespace uhd{
|
| 30 |
|
| 31 |
/*!
|
| 32 |
* A struct of parameters to construct a streamer.
|
| 33 |
*
|
| 34 |
* Note:
|
| 35 |
* Not all combinations of CPU and OTW format have conversion support.
|
| 36 |
* You may however write and register your own conversion routines.
|
| 37 |
*/
|
| 38 |
struct UHD_API stream_args_t{
|
| 39 |
|
| 40 |
//! Convenience constructor for streamer args
|
| 41 |
stream_args_t( |
| 42 |
const std::string &cpu = "", |
| 43 |
const std::string &otw = "" |
| 44 |
){
|
| 45 |
cpu_format = cpu; |
| 46 |
otw_format = otw; |
| 47 |
} |
| 48 |
|
| 49 |
/*!
|
| 50 |
* The CPU format is a string that describes the format of host memory.
|
| 51 |
* Common CPU formats are:
|
| 52 |
* - fc32 - complex<float>
|
| 53 |
* - fc64 - complex<double>
|
| 54 |
* - sc16 - complex<int16_t>
|
| 55 |
* - sc8 - complex<int8_t>
|
| 56 |
* - f32 - float
|
| 57 |
* - f64 - double
|
| 58 |
* - s16 - int16_t
|
| 59 |
* - s8 - int8_t
|
| 60 |
*/
|
| 61 |
std::string cpu_format;
|
| 62 |
|
| 63 |
/*!
|
| 64 |
* The OTW format is a string that describes the format over-the-wire.
|
| 65 |
* Common OTW format are:
|
| 66 |
* - sc16 - Q16 I16
|
| 67 |
* - sc8 - Q8_1 I8_1 Q8_0 I8_0
|
| 68 |
* - s16 - R16_1 R16_0
|
| 69 |
* - s8 - R8_3 R8_2 R8_1 R8_0
|
| 70 |
*/
|
| 71 |
std::string otw_format;
|
| 72 |
|
| 73 |
/*!
|
| 74 |
* The args parameter is currently unused. Leave it blank.
|
| 75 |
* The intention is that a user with a custom DSP design
|
| 76 |
* may want to pass args and do something special with it.
|
| 77 |
*/
|
| 78 |
std::string args;
|
| 79 |
|
| 80 |
/*!
|
| 81 |
* The channels is a list of channel numbers.
|
| 82 |
* Leave this blank to default to channel 0.
|
| 83 |
* Set channels for a multi-channel application.
|
| 84 |
* Channel mapping depends on the front-end selection.
|
| 85 |
*/
|
| 86 |
std::vector<size_t> channels; |
| 87 |
}; |
| 88 |
|
| 89 |
/*!
|
| 90 |
* The RX streamer is the host interface to receiving samples.
|
| 91 |
* It represents the layer between the samples on the host
|
| 92 |
* and samples inside the device's receive DSP processing.
|
| 93 |
*/
|
| 94 |
class UHD_API rx_streamer : boost::noncopyable{ |
| 95 |
public:
|
| 96 |
typedef boost::shared_ptr<rx_streamer> sptr;
|
| 97 |
|
| 98 |
//! Get the number of channels associated with this streamer
|
| 99 |
virtual size_t get_num_channels(void) const = 0; |
| 100 |
|
| 101 |
//! Get the max number of samples per buffer per packet
|
| 102 |
virtual size_t get_max_num_samps(void) const = 0; |
| 103 |
|
| 104 |
//! Typedef for a pointer to a single, or a collection of recv buffers
|
| 105 |
typedef ref_vector<void *> buffs_type; |
| 106 |
|
| 107 |
/*!
|
| 108 |
* Receive buffers containing samples described by the metadata.
|
| 109 |
*
|
| 110 |
* Receive handles fragmentation as follows:
|
| 111 |
* If the buffer has insufficient space to hold all samples
|
| 112 |
* that were received in a single packet over-the-wire,
|
| 113 |
* then the buffer will be completely filled and the implementation
|
| 114 |
* will hold a pointer into the remaining portion of the packet.
|
| 115 |
* Subsequent calls will load from the remainder of the packet,
|
| 116 |
* and will flag the metadata to show that this is a fragment.
|
| 117 |
* The next call to receive, after the remainder becomes exahausted,
|
| 118 |
* will perform an over-the-wire receive as usual.
|
| 119 |
* See the rx metadata fragment flags and offset fields for details.
|
| 120 |
*
|
| 121 |
* This is a blocking call and will not return until the number
|
| 122 |
* of samples returned have been written into each buffer.
|
| 123 |
* Under a timeout condition, the number of samples returned
|
| 124 |
* may be less than the number of samples specified.
|
| 125 |
*
|
| 126 |
* \param buffs a vector of writable memory to fill with samples
|
| 127 |
* \param nsamps_per_buff the size of each buffer in number of samples
|
| 128 |
* \param metadata data to fill describing the buffer
|
| 129 |
* \param timeout the timeout in seconds to wait for a packet
|
| 130 |
* \return the number of samples received or 0 on error
|
| 131 |
*/
|
| 132 |
virtual size_t recv(
|
| 133 |
const buffs_type &buffs,
|
| 134 |
const size_t nsamps_per_buff,
|
| 135 |
rx_metadata_t &metadata, |
| 136 |
double timeout = 0.1 |
| 137 |
) = 0;
|
| 138 |
}; |
| 139 |
|
| 140 |
/*!
|
| 141 |
* The TX streamer is the host interface to transmitting samples.
|
| 142 |
* It represents the layer between the samples on the host
|
| 143 |
* and samples inside the device's transmit DSP processing.
|
| 144 |
*/
|
| 145 |
class UHD_API tx_streamer : boost::noncopyable{ |
| 146 |
public:
|
| 147 |
typedef boost::shared_ptr<tx_streamer> sptr;
|
| 148 |
|
| 149 |
//! Get the number of channels associated with this streamer
|
| 150 |
virtual size_t get_num_channels(void) const = 0; |
| 151 |
|
| 152 |
//! Get the max number of samples per buffer per packet
|
| 153 |
virtual size_t get_max_num_samps(void) const = 0; |
| 154 |
|
| 155 |
//! Typedef for a pointer to a single, or a collection of send buffers
|
| 156 |
typedef ref_vector<const void *> buffs_type; |
| 157 |
|
| 158 |
/*!
|
| 159 |
* Send buffers containing samples described by the metadata.
|
| 160 |
*
|
| 161 |
* Send handles fragmentation as follows:
|
| 162 |
* If the buffer has more items than the maximum per packet,
|
| 163 |
* the send method will fragment the samples across several packets.
|
| 164 |
* Send will respect the burst flags when fragmenting to ensure
|
| 165 |
* that start of burst can only be set on the first fragment and
|
| 166 |
* that end of burst can only be set on the final fragment.
|
| 167 |
*
|
| 168 |
* This is a blocking call and will not return until the number
|
| 169 |
* of samples returned have been read out of each buffer.
|
| 170 |
* Under a timeout condition, the number of samples returned
|
| 171 |
* may be less than the number of samples specified.
|
| 172 |
*
|
| 173 |
* \param buffs a vector of read-only memory containing samples
|
| 174 |
* \param nsamps_per_buff the number of samples to send, per buffer
|
| 175 |
* \param metadata data describing the buffer's contents
|
| 176 |
* \param timeout the timeout in seconds to wait on a packet
|
| 177 |
* \return the number of samples sent
|
| 178 |
*/
|
| 179 |
virtual size_t send(
|
| 180 |
const buffs_type &buffs,
|
| 181 |
const size_t nsamps_per_buff,
|
| 182 |
const tx_metadata_t &metadata,
|
| 183 |
double timeout = 0.1 |
| 184 |
) = 0;
|
| 185 |
}; |
| 186 |
|
| 187 |
} //namespace uhd
|
| 188 |
|
| 189 |
#endif /* INCLUDED_UHD_STREAM_HPP */ |