Adding //aos/vision/debug:debug_framework.

This will allow easy construction of year-specific debug viewers.
Currently supported source types are:
- blobs over tcp
- jpegs from a camera
- blobs from a log
- a random list of jpegs

Change-Id: I1d73f82f98ca5f60b0135ea0dd588759056e0c40
diff --git a/aos/vision/debug/camera-source.cc b/aos/vision/debug/camera-source.cc
new file mode 100644
index 0000000..ef48a11
--- /dev/null
+++ b/aos/vision/debug/camera-source.cc
@@ -0,0 +1,72 @@
+#include "aos/vision/debug/debug_framework.h"
+
+#include <gdk/gdk.h>
+#include <fstream>
+#include <string>
+
+#include "aos/vision/image/image_stream.h"
+
+namespace aos {
+namespace vision {
+
+class CameraImageSource : public ImageSource {
+ public:
+  void Init(const std::string &jpeg_list_filename,
+            DebugFrameworkInterface *interface) override {
+    // TODO: Get these params from a config file passed in through the
+    // constructor.
+    camera::CameraParams params = {.width = 640 * 2,
+                                   .height = 480 * 2,
+                                   .exposure = 10,
+                                   .brightness = 128,
+                                   .gain = 0,
+                                   .fps = 30};
+    image_stream_.reset(new ImageStream(jpeg_list_filename, params, interface));
+  }
+
+  const char *GetHelpMessage() override {
+    return &R"(
+    format_spec is filename of the camera device.
+    example: camera:/dev/video0
+    This viewer source will stream video from a usb camera of your choice.
+)"[1];
+  }
+
+  class ImageStream : public ImageStreamEvent {
+   public:
+    ImageStream(const std::string &fname, camera::CameraParams params,
+                DebugFrameworkInterface *interface)
+        : ImageStreamEvent(fname, params), interface_(interface) {
+      interface_->Loop()->Add(this);
+
+      interface_->InstallKeyPress([this](uint32_t keyval) {
+        // Takes a picture when you press 'a'.
+        // TODO(parker): Allow setting directory.
+        if (keyval == GDK_KEY_a) {
+          std::ofstream ofs(
+              std::string("/tmp/out_jpegs/test") + std::to_string(i_) + ".jpg",
+              std::ofstream::out);
+          ofs << prev_data_;
+          ofs.close();
+          ++i_;
+        }
+      });
+    }
+    void ProcessImage(DataRef data, aos::monotonic_clock::time_point) override {
+      prev_data_ = std::string(data);
+      interface_->NewJpeg(data);
+    }
+
+   private:
+    int i_ = 0;
+    std::string prev_data_;
+    DebugFrameworkInterface *interface_;
+  };
+
+  std::unique_ptr<ImageStream> image_stream_;
+};
+
+REGISTER_IMAGE_SOURCE("camera", CameraImageSource);
+
+}  // namespace vision
+}  // namespace aos