streamtools: refactor output/scaler drivers to their own directories
[jpcrr.git] / streamtools / output-drv / rawrgbx.cpp
blob59fed4f6151f9481e784c3bcf3f6fe2946aaa177
1 #include "output-drv.hpp"
2 #include <iostream>
3 #include <fstream>
4 #include <stdexcept>
5 #include <string>
7 namespace
9 class output_driver_rawrgbx : public output_driver
11 public:
12 output_driver_rawrgbx(const std::string& filename)
14 if(filename != "-")
15 out = new std::ofstream(filename.c_str(), std::ios_base::binary);
16 else
17 out = &std::cout;
18 if(!*out)
19 throw std::runtime_error("Unable to open output file");
20 set_video_callback<output_driver_rawrgbx>(*this, &output_driver_rawrgbx::video_callback);
23 ~output_driver_rawrgbx()
25 if(out != &std::cout)
26 delete out;
29 void ready()
31 const video_settings& v = get_video_settings();
32 framesize = 4 * v.get_width() * v.get_height();
35 void video_callback(uint64_t timestamp, const uint8_t* raw_rgbx_data)
37 out->write((const char*)raw_rgbx_data, framesize);
38 if(!*out)
39 throw std::runtime_error("Error writing frame to file");
41 private:
42 std::ostream* out;
43 size_t framesize;
46 class output_driver_rawrgbx_factory : output_driver_factory
48 public:
49 output_driver_rawrgbx_factory()
50 : output_driver_factory("rawrgbx")
54 output_driver& make(const std::string& type, const std::string& name, const std::string& parameters)
56 if(parameters != "")
57 throw std::runtime_error("rawrgbx output does not take parameters");
58 return *new output_driver_rawrgbx(name);
60 } factory;