]> git.sesse.net Git - nageru/blobdiff - nageru/image_input.cpp
IWYU-fix nageru/*.cpp.
[nageru] / nageru / image_input.cpp
index c8b10371b4d381eec9535246f1e216ba6b6f3bb6..316292b15d7ffd01428eb2d7a165834278fe1fc7 100644 (file)
@@ -1,15 +1,32 @@
 #include "image_input.h"
 
+#include <assert.h>
+#include <chrono>
+#include <condition_variable>
+#include <epoxy/egl.h>
 #include <errno.h>
-#include <movit/flat_input.h>
+#include <fcntl.h>
+#include <map>
+#include <memory>
 #include <movit/image_format.h>
 #include <movit/util.h>
+#include <mutex>
+#include <pthread.h>
+#include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <string>
+#include <sys/stat.h>
+#include <thread>
+#include <time.h>
+#include <utility>
+#include <vector>
 
 extern "C" {
+#include <libavcodec/codec.h>
+#include <libavcodec/codec_par.h>
 #include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
 #include <libavutil/avutil.h>
@@ -21,26 +38,21 @@ extern "C" {
 #include <libswscale/swscale.h>
 }
 
-#include <epoxy/egl.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <cstddef>
-#include <functional>
-#include <mutex>
-#include <thread>
-#include <utility>
-#include <vector>
-
+#include "ffmpeg_util.h"
 #include "shared/context.h"
 #include "shared/ffmpeg_raii.h"
-#include "ffmpeg_util.h"
-#include "flags.h"
+#include "shared/ref_counted_texture.h"
+#include "tweaked_inputs.h"
 
 struct SwsContext;
 
 using namespace std;
 
+ImageInput::ImageInput()
+       : sRGBSwitchingFlatInput({movit::COLORSPACE_sRGB, movit::GAMMA_sRGB}, movit::FORMAT_RGBA_POSTMULTIPLIED_ALPHA,
+                                GL_UNSIGNED_BYTE, 1280, 720)  // Resolution will be overwritten.
+{}
+
 ImageInput::ImageInput(const string &filename)
        : sRGBSwitchingFlatInput({movit::COLORSPACE_sRGB, movit::GAMMA_sRGB}, movit::FORMAT_RGBA_POSTMULTIPLIED_ALPHA,
                                 GL_UNSIGNED_BYTE, 1280, 720),  // Resolution will be overwritten.
@@ -66,6 +78,7 @@ void ImageInput::set_gl_state(GLuint glsl_program_num, const string& prefix, uns
        // is mostly there to save startup time, not RAM).
        {
                lock_guard<mutex> lock(all_images_lock);
+               assert(all_images.count(pathname));
                if (all_images[pathname] != current_image) {
                        current_image = all_images[pathname];
                        set_texture_num(*current_image->tex);
@@ -120,7 +133,7 @@ shared_ptr<const ImageInput::Image> ImageInput::load_image_raw(const string &pat
                fprintf(stderr, "%s: Cannot fill codec parameters\n", pathname.c_str());
                return nullptr;
        }
-       AVCodec *codec = avcodec_find_decoder(codecpar->codec_id);
+       const AVCodec *codec = avcodec_find_decoder(codecpar->codec_id);
        if (codec == nullptr) {
                fprintf(stderr, "%s: Cannot find decoder\n", pathname.c_str());
                return nullptr;
@@ -137,17 +150,14 @@ shared_ptr<const ImageInput::Image> ImageInput::load_image_raw(const string &pat
        AVFrameWithDeleter frame = av_frame_alloc_unique();
        bool eof = false;
        do {
-               AVPacket pkt;
-               unique_ptr<AVPacket, decltype(av_packet_unref)*> pkt_cleanup(
-                       &pkt, av_packet_unref);
-               av_init_packet(&pkt);
-               pkt.data = nullptr;
-               pkt.size = 0;
-               if (av_read_frame(format_ctx.get(), &pkt) == 0) {
-                       if (pkt.stream_index != stream_index) {
+               AVPacketWithDeleter pkt = av_packet_alloc_unique();
+               pkt->data = nullptr;
+               pkt->size = 0;
+               if (av_read_frame(format_ctx.get(), pkt.get()) == 0) {
+                       if (pkt->stream_index != stream_index) {
                                continue;
                        }
-                       if (avcodec_send_packet(codec_ctx.get(), &pkt) < 0) {
+                       if (avcodec_send_packet(codec_ctx.get(), pkt.get()) < 0) {
                                fprintf(stderr, "%s: Cannot send packet to codec.\n", pathname.c_str());
                                return nullptr;
                        }
@@ -222,7 +232,7 @@ shared_ptr<const ImageInput::Image> ImageInput::load_image_raw(const string &pat
        glBindTexture(GL_TEXTURE_2D, 0);
        check_error();
 
-       shared_ptr<Image> image(new Image{unsigned(frame->width), unsigned(frame->height), RefCountedTexture(new GLuint(tex)), last_modified});
+       shared_ptr<Image> image(new Image{unsigned(frame->width), unsigned(frame->height), UniqueTexture(new GLuint(tex)), last_modified});
        return image;
 }
 
@@ -288,6 +298,15 @@ void ImageInput::update_thread_func(QSurface *surface)
        }
 }
 
+void ImageInput::switch_image(const string &pathname)
+{
+#ifndef NDEBUG
+       lock_guard<mutex> lock(all_images_lock);
+       assert(all_images.count(pathname));
+#endif
+       this->pathname = pathname;
+}
+
 void ImageInput::start_update_thread(QSurface *surface)
 {
        update_thread = thread(update_thread_func, surface);