---
description: >-
  IReader's job is to be able to load data from a frame source into a
  FrameStruct for each frame type in the frame source
---

# IReaders

`IReader`s interface with the frame source and create `FrameStruct`s.

Based on the config yaml the Sensor Stream Server will create an `IReader` to pull data and create `FrameStructs`.

If you want to [add a new sensor interface](../how-to-extend-sensor-stream-pipe/add-new-frame-source), you will need to make an implementation of the `IReader` interface that can pull data from the hardware and create a `FrameStruct`.

### [IReader Interface](https://github.com/moetsi/Sensor-Stream-Pipe/blob/master/readers/ireader.h)

```
#pragma once

#include "../structs/frame_struct.hpp"

class IReader {

public:
  virtual ~IReader() {}

  virtual std::vector<std::shared_ptr<FrameStruct>> GetCurrentFrame() = 0;

  virtual std::vector<unsigned int> GetType() = 0;

  virtual bool HasNextFrame() = 0;

  virtual void NextFrame() = 0;

  virtual void Reset() = 0;

  virtual void GoToFrame(unsigned int frame_id) = 0;

  virtual unsigned int GetCurrentFrameId() = 0;

  virtual unsigned int GetFps() = 0;
};
```

## How IReader is interacted with by Sensor Stream Server

* Sensor Stream Server is what uses the IReader
* When Sensor Stream Server is started it reads the config.yaml to understand reader\_type
  * frames
    * which can then be MultiImageReader or ImageReader based on the parameter "path"
  * video
  * kinect
    * takes in parameters to build new ExtendedAzureConfig
  * iphone
* **It then creates an IReader using the parameters**
* **It then asks for "GetType()" which the IReader will respond with and array of types**
  * 0 - color
  * 1- depth
  * 2 - ir
  * 3 - confidence (iphone)
  * IReader knows how to respond based on the parameters it was passed when built
* That will create IEncoders for each type
* **It then asks for "GetFps()"**
  * IReader knows how to respond based on the parameters it was passed when built
* **It then calls "GetCurrentFrame()" which gets provides a frame struct**
  * This is then encoded by the associated encoders
* **It then calls HasNextFrame() and then NextFrame(), otherwise it calls Reset()**

### Available IReader Implementations

* [ImageReader](https://github.com/moetsi/Sensor-Stream-Pipe/blob/master/readers/image_reader.cc)
* [MultiImageReader](https://github.com/moetsi/Sensor-Stream-Pipe/blob/master/readers/multi_image_reader.cc)
* [VideoFileReader](https://github.com/moetsi/Sensor-Stream-Pipe/blob/master/readers/video_file_reader.cc)
* [KinectReader](https://github.com/moetsi/Sensor-Stream-Pipe/blob/master/readers/kinect_reader.cc)
* [IPhoneReader](https://github.com/moetsi/Sensor-Stream-Pipe/blob/master/readers/iphone_reader.mm)
* OAK-D (coming soon!)
