From b563b8903fa84bb7fd62d7d0b84b70cb26843dbf Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 2 Dec 2018 00:34:15 +0100 Subject: [PATCH] Combine the Nageru and Futatabi files that are identical. --- futatabi/httpd.cpp | 2 +- futatabi/jpeg_frame_view.cpp | 2 +- futatabi/main.cpp | 4 +- futatabi/mainwindow.cpp | 2 +- futatabi/meson.build | 6 +- futatabi/player.cpp | 2 +- futatabi/vaapi_jpeg_decoder.cpp | 2 +- meson.build | 24 +++++++ nageru/audio_encoder.h | 2 +- nageru/decklink_capture.cpp | 2 +- nageru/ffmpeg_capture.cpp | 2 +- nageru/ffmpeg_capture.h | 2 +- nageru/ffmpeg_raii.cpp | 77 -------------------- nageru/ffmpeg_raii.h | 80 --------------------- nageru/httpd.cpp | 2 +- nageru/image_input.cpp | 2 +- nageru/input_mapping_dialog.cpp | 2 +- nageru/mainwindow.cpp | 2 +- nageru/memcpy_interleaved.h | 11 --- nageru/meson.build | 28 +------- nageru/metacube2.cpp | 60 ---------------- nageru/metacube2.h | 71 ------------------ nageru/midi_mapping_dialog.cpp | 2 +- nageru/post_to_main_thread.h | 16 ----- nageru/quicksync_encoder.cpp | 2 +- nageru/video_encoder.cpp | 2 +- {futatabi => shared}/ffmpeg_raii.cpp | 0 {futatabi => shared}/ffmpeg_raii.h | 0 {futatabi => shared}/memcpy_interleaved.cpp | 0 {futatabi => shared}/memcpy_interleaved.h | 0 shared/meson.build | 7 ++ {futatabi => shared}/metacube2.cpp | 0 {futatabi => shared}/metacube2.h | 0 {futatabi => shared}/post_to_main_thread.h | 0 34 files changed, 55 insertions(+), 361 deletions(-) delete mode 100644 nageru/ffmpeg_raii.cpp delete mode 100644 nageru/ffmpeg_raii.h delete mode 100644 nageru/memcpy_interleaved.h delete mode 100644 nageru/metacube2.cpp delete mode 100644 nageru/metacube2.h delete mode 100644 nageru/post_to_main_thread.h rename {futatabi => shared}/ffmpeg_raii.cpp (100%) rename {futatabi => shared}/ffmpeg_raii.h (100%) rename {futatabi => shared}/memcpy_interleaved.cpp (100%) rename {futatabi => shared}/memcpy_interleaved.h (100%) create mode 100644 shared/meson.build rename {futatabi => shared}/metacube2.cpp (100%) rename {futatabi => shared}/metacube2.h (100%) rename {futatabi => shared}/post_to_main_thread.h (100%) diff --git a/futatabi/httpd.cpp b/futatabi/httpd.cpp index 36d2874..c9399d8 100644 --- a/futatabi/httpd.cpp +++ b/futatabi/httpd.cpp @@ -15,7 +15,7 @@ extern "C" { } #include "defs.h" -#include "metacube2.h" +#include "shared/metacube2.h" struct MHD_Connection; struct MHD_Response; diff --git a/futatabi/jpeg_frame_view.cpp b/futatabi/jpeg_frame_view.cpp index 3d3383f..283ff67 100644 --- a/futatabi/jpeg_frame_view.cpp +++ b/futatabi/jpeg_frame_view.cpp @@ -2,7 +2,7 @@ #include "defs.h" #include "jpeg_destroyer.h" -#include "post_to_main_thread.h" +#include "shared/post_to_main_thread.h" #include "video_stream.h" #include "ycbcr_converter.h" diff --git a/futatabi/main.cpp b/futatabi/main.cpp index e0518af..14bc12a 100644 --- a/futatabi/main.cpp +++ b/futatabi/main.cpp @@ -23,14 +23,14 @@ extern "C" { #include "context.h" #include "defs.h" #include "disk_space_estimator.h" -#include "ffmpeg_raii.h" +#include "shared/ffmpeg_raii.h" #include "flags.h" #include "frame_on_disk.h" #include "frame.pb.h" #include "httpd.h" #include "mainwindow.h" #include "player.h" -#include "post_to_main_thread.h" +#include "shared/post_to_main_thread.h" #include "ref_counted_gl_sync.h" #include "timebase.h" #include "ui_mainwindow.h" diff --git a/futatabi/mainwindow.cpp b/futatabi/mainwindow.cpp index dd3c827..b9dee27 100644 --- a/futatabi/mainwindow.cpp +++ b/futatabi/mainwindow.cpp @@ -5,7 +5,7 @@ #include "flags.h" #include "frame_on_disk.h" #include "player.h" -#include "post_to_main_thread.h" +#include "shared/post_to_main_thread.h" #include "timebase.h" #include "ui_mainwindow.h" diff --git a/futatabi/meson.build b/futatabi/meson.build index fdcc446..d9ec0c3 100644 --- a/futatabi/meson.build +++ b/futatabi/meson.build @@ -34,8 +34,8 @@ moc_files = qt5.preprocess( srcs = ['flow.cpp', 'gpu_timers.cpp'] # All the other files. -srcs += ['ffmpeg_raii.cpp', 'main.cpp', 'player.cpp', 'httpd.cpp', 'mux.cpp', 'metacube2.cpp', 'video_stream.cpp', 'context.cpp', 'chroma_subsampler.cpp'] -srcs += ['vaapi_jpeg_decoder.cpp', 'memcpy_interleaved.cpp', 'db.cpp', 'disk_space_estimator.cpp', 'ycbcr_converter.cpp', 'flags.cpp'] +srcs += ['main.cpp', 'player.cpp', 'httpd.cpp', 'mux.cpp', 'video_stream.cpp', 'context.cpp', 'chroma_subsampler.cpp'] +srcs += ['vaapi_jpeg_decoder.cpp', 'db.cpp', 'disk_space_estimator.cpp', 'ycbcr_converter.cpp', 'flags.cpp'] srcs += ['mainwindow.cpp', 'jpeg_frame_view.cpp', 'clip_list.cpp', 'frame_on_disk.cpp'] srcs += moc_files srcs += proto_generated @@ -57,7 +57,7 @@ bin2h_gen = generator(bin2h, \ shader_srcs = bin2h_gen.process(shaders) srcs += shader_srcs -executable('futatabi', srcs, dependencies: [qt5deps, libjpegdep, movitdep, libmicrohttpddep, protobufdep, sqlite3dep, vax11dep, vadrmdep, x11dep, libavformatdep, libavcodecdep, libavutildep, libswscaledep]) +executable('futatabi', srcs, dependencies: [shareddep, qt5deps, libjpegdep, movitdep, libmicrohttpddep, protobufdep, sqlite3dep, vax11dep, vadrmdep, x11dep, libavformatdep, libavcodecdep, libavutildep, libswscaledep], link_with: shared) executable('flow', 'flow_main.cpp', 'flow.cpp', 'gpu_timers.cpp', shader_srcs, dependencies: [epoxydep, sdl2dep, sdl2_imagedep]) executable('eval', 'eval.cpp', 'util.cpp') executable('vis', 'vis.cpp', 'util.cpp') diff --git a/futatabi/player.cpp b/futatabi/player.cpp index b0e862d..918b61d 100644 --- a/futatabi/player.cpp +++ b/futatabi/player.cpp @@ -3,7 +3,7 @@ #include "clip_list.h" #include "context.h" #include "defs.h" -#include "ffmpeg_raii.h" +#include "shared/ffmpeg_raii.h" #include "frame_on_disk.h" #include "httpd.h" #include "jpeg_frame_view.h" diff --git a/futatabi/vaapi_jpeg_decoder.cpp b/futatabi/vaapi_jpeg_decoder.cpp index 12db78b..2cd2f00 100644 --- a/futatabi/vaapi_jpeg_decoder.cpp +++ b/futatabi/vaapi_jpeg_decoder.cpp @@ -2,7 +2,7 @@ #include "jpeg_destroyer.h" #include "jpeg_frame.h" -#include "memcpy_interleaved.h" +#include "shared/memcpy_interleaved.h" #include #include diff --git a/meson.build b/meson.build index 8357005..7146fb8 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,15 @@ project('nageru', 'cpp', default_options: ['buildtype=debugoptimized']) +cxx = meson.get_compiler('cpp') + +# Use lld if we can; it links a lot faster than ld.bfd or gold. +code = '''#include +int main() { printf("Hello, world!\n"); return 0; } +''' +if cxx.links(code, args: '-fuse-ld=lld', name: 'check for LLD') + add_project_link_arguments('-fuse-ld=lld') +endif + # Add the right MOVIT_SHADER_DIR definition. r = run_command('pkg-config', '--variable=shaderdir', 'movit') if r.returncode() != 0 @@ -7,5 +17,19 @@ if r.returncode() != 0 endif add_project_arguments('-DMOVIT_SHADER_DIR="' + r.stdout().strip() + '"', language: 'cpp') +# DeckLink has these issues, and we include it from various places. +if cxx.has_argument('-Wno-non-virtual-dtor') + add_project_arguments('-Wno-non-virtual-dtor', language: 'cpp') +endif + +# FFmpeg has a lot of deprecated APIs whose replacements are not available +# in Debian stable, so we suppress these warnings. +if cxx.has_argument('-Wno-deprecated-declarations') + add_project_arguments('-Wno-deprecated-declarations', language: 'cpp') +endif + +top_include = include_directories('.') + +subdir('shared') subdir('nageru') subdir('futatabi') diff --git a/nageru/audio_encoder.h b/nageru/audio_encoder.h index 93adbaf..d28d7ee 100644 --- a/nageru/audio_encoder.h +++ b/nageru/audio_encoder.h @@ -15,7 +15,7 @@ extern "C" { #include } -#include "ffmpeg_raii.h" +#include "shared/ffmpeg_raii.h" class Mux; diff --git a/nageru/decklink_capture.cpp b/nageru/decklink_capture.cpp index 881e181..7e56271 100644 --- a/nageru/decklink_capture.cpp +++ b/nageru/decklink_capture.cpp @@ -21,7 +21,7 @@ #include "bmusb/bmusb.h" #include "decklink_util.h" #include "flags.h" -#include "memcpy_interleaved.h" +#include "shared/memcpy_interleaved.h" #include "v210_converter.h" #define FRAME_SIZE (8 << 20) // 8 MB. diff --git a/nageru/ffmpeg_capture.cpp b/nageru/ffmpeg_capture.cpp index 7bd9278..2ecdf64 100644 --- a/nageru/ffmpeg_capture.cpp +++ b/nageru/ffmpeg_capture.cpp @@ -28,7 +28,7 @@ extern "C" { #include #include "bmusb/bmusb.h" -#include "ffmpeg_raii.h" +#include "shared/ffmpeg_raii.h" #include "ffmpeg_util.h" #include "flags.h" #include "image_input.h" diff --git a/nageru/ffmpeg_capture.h b/nageru/ffmpeg_capture.h index 8a513df..31e94ab 100644 --- a/nageru/ffmpeg_capture.h +++ b/nageru/ffmpeg_capture.h @@ -38,7 +38,7 @@ extern "C" { } #include "bmusb/bmusb.h" -#include "ffmpeg_raii.h" +#include "shared/ffmpeg_raii.h" #include "ref_counted_frame.h" #include "quittable_sleeper.h" diff --git a/nageru/ffmpeg_raii.cpp b/nageru/ffmpeg_raii.cpp deleted file mode 100644 index 746e03d..0000000 --- a/nageru/ffmpeg_raii.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "ffmpeg_raii.h" - -extern "C" { -#include -#include -#include -#include -#include -} - -using namespace std; - -// AVFormatContext - -void avformat_close_input_unique::operator() (AVFormatContext *format_ctx) const -{ - avformat_close_input(&format_ctx); -} - -AVFormatContextWithCloser avformat_open_input_unique( - const char *pathname, AVInputFormat *fmt, - AVDictionary **options) -{ - return avformat_open_input_unique(pathname, fmt, options, AVIOInterruptCB{ nullptr, nullptr }); -} - -AVFormatContextWithCloser avformat_open_input_unique( - const char *pathname, AVInputFormat *fmt, - AVDictionary **options, - const AVIOInterruptCB &interrupt_cb) -{ - AVFormatContext *format_ctx = avformat_alloc_context(); - format_ctx->interrupt_callback = interrupt_cb; - if (avformat_open_input(&format_ctx, pathname, fmt, options) != 0) { - format_ctx = nullptr; - } - return AVFormatContextWithCloser(format_ctx); -} - -// AVCodecContext - -void avcodec_free_context_unique::operator() (AVCodecContext *codec_ctx) const -{ - avcodec_free_context(&codec_ctx); -} - -AVCodecContextWithDeleter avcodec_alloc_context3_unique(const AVCodec *codec) -{ - return AVCodecContextWithDeleter(avcodec_alloc_context3(codec)); -} - - -// AVCodecParameters - -void avcodec_parameters_free_unique::operator() (AVCodecParameters *codec_par) const -{ - avcodec_parameters_free(&codec_par); -} - -// AVFrame - -void av_frame_free_unique::operator() (AVFrame *frame) const -{ - av_frame_free(&frame); -} - -AVFrameWithDeleter av_frame_alloc_unique() -{ - return AVFrameWithDeleter(av_frame_alloc()); -} - -// SwsContext - -void sws_free_context_unique::operator() (SwsContext *context) const -{ - sws_freeContext(context); -} diff --git a/nageru/ffmpeg_raii.h b/nageru/ffmpeg_raii.h deleted file mode 100644 index 33d2334..0000000 --- a/nageru/ffmpeg_raii.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef _FFMPEG_RAII_H -#define _FFMPEG_RAII_H 1 - -// Some helpers to make RAII versions of FFmpeg objects. -// The cleanup functions don't interact all that well with unique_ptr, -// so things get a bit messy and verbose, but overall it's worth it to ensure -// we never leak things by accident in error paths. -// -// This does not cover any of the types that can actually be declared as -// a unique_ptr with no helper functions for deleter. - -#include - -struct AVCodec; -struct AVCodecContext; -struct AVCodecParameters; -struct AVDictionary; -struct AVFormatContext; -struct AVFrame; -struct AVInputFormat; -struct SwsContext; -typedef struct AVIOInterruptCB AVIOInterruptCB; - -// AVFormatContext -struct avformat_close_input_unique { - void operator() (AVFormatContext *format_ctx) const; -}; - -typedef std::unique_ptr - AVFormatContextWithCloser; - -AVFormatContextWithCloser avformat_open_input_unique( - const char *pathname, AVInputFormat *fmt, - AVDictionary **options); - -AVFormatContextWithCloser avformat_open_input_unique( - const char *pathname, AVInputFormat *fmt, - AVDictionary **options, - const AVIOInterruptCB &interrupt_cb); - - -// AVCodecContext -struct avcodec_free_context_unique { - void operator() (AVCodecContext *ctx) const; -}; - -typedef std::unique_ptr - AVCodecContextWithDeleter; - -AVCodecContextWithDeleter avcodec_alloc_context3_unique(const AVCodec *codec); - - -// AVCodecParameters -struct avcodec_parameters_free_unique { - void operator() (AVCodecParameters *codec_par) const; -}; - -typedef std::unique_ptr - AVCodecParametersWithDeleter; - - -// AVFrame -struct av_frame_free_unique { - void operator() (AVFrame *frame) const; -}; - -typedef std::unique_ptr - AVFrameWithDeleter; - -AVFrameWithDeleter av_frame_alloc_unique(); - -// SwsContext -struct sws_free_context_unique { - void operator() (SwsContext *context) const; -}; - -typedef std::unique_ptr - SwsContextWithDeleter; - -#endif // !defined(_FFMPEG_RAII_H) diff --git a/nageru/httpd.cpp b/nageru/httpd.cpp index f644176..842952f 100644 --- a/nageru/httpd.cpp +++ b/nageru/httpd.cpp @@ -15,7 +15,7 @@ extern "C" { } #include "defs.h" -#include "metacube2.h" +#include "shared/metacube2.h" #include "metrics.h" struct MHD_Connection; diff --git a/nageru/image_input.cpp b/nageru/image_input.cpp index 2bf4a23..5f69570 100644 --- a/nageru/image_input.cpp +++ b/nageru/image_input.cpp @@ -30,7 +30,7 @@ extern "C" { #include #include -#include "ffmpeg_raii.h" +#include "shared/ffmpeg_raii.h" #include "ffmpeg_util.h" #include "flags.h" diff --git a/nageru/input_mapping_dialog.cpp b/nageru/input_mapping_dialog.cpp index 23e8895..b456515 100644 --- a/nageru/input_mapping_dialog.cpp +++ b/nageru/input_mapping_dialog.cpp @@ -22,7 +22,7 @@ #include "alsa_pool.h" #include "defs.h" -#include "post_to_main_thread.h" +#include "shared/post_to_main_thread.h" #include "ui_input_mapping.h" using namespace std; diff --git a/nageru/mainwindow.cpp b/nageru/mainwindow.cpp index b542c10..05e41eb 100644 --- a/nageru/mainwindow.cpp +++ b/nageru/mainwindow.cpp @@ -61,7 +61,7 @@ #include "midi_mapping_dialog.h" #include "mixer.h" #include "nonlinear_fader.h" -#include "post_to_main_thread.h" +#include "shared/post_to_main_thread.h" #include "ui_audio_expanded_view.h" #include "ui_audio_miniview.h" #include "ui_display.h" diff --git a/nageru/memcpy_interleaved.h b/nageru/memcpy_interleaved.h deleted file mode 100644 index a7f8994..0000000 --- a/nageru/memcpy_interleaved.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _MEMCPY_INTERLEAVED_H -#define _MEMCPY_INTERLEAVED_H 1 - -#include -#include - -// Copies every other byte from src to dest1 and dest2. -// TODO: Support stride. -void memcpy_interleaved(uint8_t *dest1, uint8_t *dest2, const uint8_t *src, size_t n); - -#endif // !defined(_MEMCPY_INTERLEAVED_H) diff --git a/nageru/meson.build b/nageru/meson.build index 70d5ab7..6d984e8 100644 --- a/nageru/meson.build +++ b/nageru/meson.build @@ -2,15 +2,6 @@ qt5 = import('qt5') protoc = find_program('protoc') cxx = meson.get_compiler('cpp') -# Use lld if we can; it links a lot faster than ld.bfd or gold. -nageru_link_args = [] -code = '''#include -int main() { printf("Hello, world!\n"); return 0; } -''' -if cxx.links(code, args: '-fuse-ld=lld', name: 'check for LLD') - nageru_link_args += '-fuse-ld=lld' -endif - embedded_bmusb = get_option('embedded_bmusb') alsadep = dependency('alsa') @@ -38,7 +29,7 @@ x264dep = dependency('x264') zitaresamplerdep = cxx.find_library('zita-resampler') srcs = [] -nageru_deps = [qt5deps, libjpegdep, movitdep, libmicrohttpddep, protobufdep, +nageru_deps = [shareddep, qt5deps, libjpegdep, movitdep, libmicrohttpddep, protobufdep, vax11dep, vadrmdep, x11dep, libavformatdep, libavresampledep, libavcodecdep, libavutildep, libswscaledep, libusbdep, luajitdep, dldep, x264dep, alsadep, zitaresamplerdep, qcustomplotdep, threaddep] @@ -50,17 +41,6 @@ nageru_install_rpath = '' kaeru_link_with = [] kaeru_extra_deps = [] -# DeckLink has these issues, and we include it from various places. -if cxx.has_argument('-Wno-non-virtual-dtor') - add_project_arguments('-Wno-non-virtual-dtor', language: 'cpp') -endif - -# FFmpeg has a lot of deprecated APIs whose replacements are not available -# in Debian stable, so we suppress these warnings. -if cxx.has_argument('-Wno-deprecated-declarations') - add_project_arguments('-Wno-deprecated-declarations', language: 'cpp') -endif - # CEF. exe_dir = join_paths(get_option('prefix'), 'lib/nageru') cef_dir = get_option('cef_dir') @@ -186,7 +166,7 @@ srcs += ['chroma_subsampler.cpp', 'v210_converter.cpp', 'mixer.cpp', 'pbo_frame_ # Streaming and encoding objects (largely the set that is shared between Nageru and Kaeru). stream_srcs = ['quicksync_encoder.cpp', 'x264_encoder.cpp', 'x264_dynamic.cpp', 'x264_speed_control.cpp', 'video_encoder.cpp', - 'metacube2.cpp', 'mux.cpp', 'audio_encoder.cpp', 'ffmpeg_raii.cpp', 'ffmpeg_util.cpp', 'httpd.cpp', 'ffmpeg_capture.cpp', + 'mux.cpp', 'audio_encoder.cpp', 'ffmpeg_util.cpp', 'httpd.cpp', 'ffmpeg_capture.cpp', 'print_latency.cpp', 'basic_stats.cpp', 'ref_counted_frame.cpp'] stream = static_library('stream', stream_srcs, dependencies: nageru_deps, include_directories: nageru_include_dirs) nageru_link_with += stream @@ -217,7 +197,6 @@ executable('nageru', 'main.cpp', dependencies: nageru_deps, include_directories: nageru_include_dirs, link_with: nageru_link_with, - link_args: nageru_link_args, build_rpath: nageru_build_rpath, install_rpath: nageru_install_rpath, install: true, @@ -230,11 +209,10 @@ executable('kaeru', 'kaeru.cpp', dependencies: [nageru_deps, kaeru_extra_deps], include_directories: nageru_include_dirs, link_with: [stream, aux, kaeru_link_with], - link_args: nageru_link_args, install: true) # Audio mixer microbenchmark. -executable('benchmark_audio_mixer', 'benchmark_audio_mixer.cpp', dependencies: nageru_deps, include_directories: nageru_include_dirs, link_args: nageru_link_args, link_with: [audio, aux]) +executable('benchmark_audio_mixer', 'benchmark_audio_mixer.cpp', dependencies: nageru_deps, include_directories: nageru_include_dirs, link_with: [audio, aux]) # These are needed for a default run. data_files = ['theme.lua', 'simple.lua', 'bg.jpeg', 'akai_midimix.midimapping'] diff --git a/nageru/metacube2.cpp b/nageru/metacube2.cpp deleted file mode 100644 index 6b68132..0000000 --- a/nageru/metacube2.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Implementation of Metacube2 utility functions. - * - * Note: This file is meant to compile as both C and C++, for easier inclusion - * in other projects. - */ - -#include "metacube2.h" - -#include -#include - -/* - * https://www.ece.cmu.edu/~koopman/pubs/KoopmanCRCWebinar9May2012.pdf - * recommends this for messages as short as ours (see table at page 34). - */ -#define METACUBE2_CRC_POLYNOMIAL 0x8FDB - -/* Semi-random starting value to make sure all-zero won't pass. */ -#define METACUBE2_CRC_START 0x1234 - -/* This code is based on code generated by pycrc. */ -uint16_t metacube2_compute_crc(const struct metacube2_block_header *hdr) -{ - static const int data_len = sizeof(hdr->size) + sizeof(hdr->flags); - const uint8_t *data = (uint8_t *)&hdr->size; - uint16_t crc = METACUBE2_CRC_START; - int i, j; - - for (i = 0; i < data_len; ++i) { - uint8_t c = data[i]; - for (j = 0; j < 8; j++) { - int bit = crc & 0x8000; - crc = (crc << 1) | ((c >> (7 - j)) & 0x01); - if (bit) { - crc ^= METACUBE2_CRC_POLYNOMIAL; - } - } - } - - /* Finalize. */ - for (i = 0; i < 16; i++) { - int bit = crc & 0x8000; - crc = crc << 1; - if (bit) { - crc ^= METACUBE2_CRC_POLYNOMIAL; - } - } - - /* - * Invert the checksum for metadata packets, so that clients that - * don't understand metadata will ignore it as broken. There will - * probably be logging, but apart from that, it's harmless. - */ - if (ntohs(hdr->flags) & METACUBE_FLAGS_METADATA) { - crc ^= 0xffff; - } - - return crc; -} diff --git a/nageru/metacube2.h b/nageru/metacube2.h deleted file mode 100644 index 4f232c8..0000000 --- a/nageru/metacube2.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef _METACUBE2_H -#define _METACUBE2_H - -/* - * Definitions for the Metacube2 protocol, used to communicate with Cubemap. - * - * Note: This file is meant to compile as both C and C++, for easier inclusion - * in other projects. - */ - -#include - -#define METACUBE2_SYNC "cube!map" /* 8 bytes long. */ -#define METACUBE_FLAGS_HEADER 0x1 -#define METACUBE_FLAGS_NOT_SUITABLE_FOR_STREAM_START 0x2 - -/* - * Metadata packets; should not be counted as data, but rather - * parsed (or ignored if you don't understand them). - * - * Metadata packets start with a uint64_t (network byte order) - * that describe the type; the rest is defined by the type. - */ -#define METACUBE_FLAGS_METADATA 0x4 - -struct metacube2_block_header { - char sync[8]; /* METACUBE2_SYNC */ - uint32_t size; /* Network byte order. Does not include header. */ - uint16_t flags; /* Network byte order. METACUBE_FLAGS_*. */ - uint16_t csum; /* Network byte order. CRC16 of size and flags. - If METACUBE_FLAGS_METADATA is set, inverted - so that older clients will ignore it as broken. */ -}; - -uint16_t metacube2_compute_crc(const struct metacube2_block_header *hdr); - -/* - * Set by the encoder, and can be measured for latency purposes (e.g., if the - * network can't keep up, the latency will tend to increase. - */ -#define METACUBE_METADATA_TYPE_ENCODER_TIMESTAMP 0x1 - -struct metacube2_timestamp_packet { - uint64_t type; /* METACUBE_METADATA_TYPE_ENCODER_TIMESTAMP, in network byte order. */ - - /* - * Time since the UTC epoch. Basically a struct timespec. - * Both are in network byte order. - */ - uint64_t tv_sec; - uint64_t tv_nsec; -}; - -/* - * Sent before a block to mark its presentation timestamp (ie., counts - * only for the next Metacube block). Used so that the reflector can know - * the length (in seconds) of fragments. - */ -#define METACUBE_METADATA_TYPE_NEXT_BLOCK_PTS 0x2 - -struct metacube2_pts_packet { - uint64_t type; /* METACUBE_METADATA_TYPE_NEXT_BLOCK_PTS, in network byte order. */ - - /* The timestamp of the first packet in the next block, in network byte order. */ - int64_t pts; - - /* Timebase "pts" is expressed in, as a fraction. Network byte order. */ - uint64_t timebase_num, timebase_den; -}; - -#endif /* !defined(_METACUBE_H) */ diff --git a/nageru/midi_mapping_dialog.cpp b/nageru/midi_mapping_dialog.cpp index 05508e4..a3286b4 100644 --- a/nageru/midi_mapping_dialog.cpp +++ b/nageru/midi_mapping_dialog.cpp @@ -20,7 +20,7 @@ #include "midi_mapper.h" #include "midi_mapping.pb.h" -#include "post_to_main_thread.h" +#include "shared/post_to_main_thread.h" #include "ui_midi_mapping.h" class QObject; diff --git a/nageru/post_to_main_thread.h b/nageru/post_to_main_thread.h deleted file mode 100644 index 0462c7b..0000000 --- a/nageru/post_to_main_thread.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _POST_TO_MAIN_THREAD_H -#define _POST_TO_MAIN_THREAD_H 1 - -#include -#include -#include - -// http://stackoverflow.com/questions/21646467/how-to-execute-a-functor-in-a-given-thread-in-qt-gcd-style -template -static inline void post_to_main_thread(F &&fun) -{ - QObject signalSource; - QObject::connect(&signalSource, &QObject::destroyed, qApp, std::move(fun)); -} - -#endif // !defined(_POST_TO_MAIN_THREAD_H) diff --git a/nageru/quicksync_encoder.cpp b/nageru/quicksync_encoder.cpp index 5200ce6..c4f8aef 100644 --- a/nageru/quicksync_encoder.cpp +++ b/nageru/quicksync_encoder.cpp @@ -48,7 +48,7 @@ extern "C" { #include "context.h" #include "defs.h" #include "disk_space_estimator.h" -#include "ffmpeg_raii.h" +#include "shared/ffmpeg_raii.h" #include "flags.h" #include "mux.h" #include "print_latency.h" diff --git a/nageru/video_encoder.cpp b/nageru/video_encoder.cpp index 6344b8c..42247e9 100644 --- a/nageru/video_encoder.cpp +++ b/nageru/video_encoder.cpp @@ -13,7 +13,7 @@ extern "C" { #include "audio_encoder.h" #include "defs.h" -#include "ffmpeg_raii.h" +#include "shared/ffmpeg_raii.h" #include "flags.h" #include "httpd.h" #include "mux.h" diff --git a/futatabi/ffmpeg_raii.cpp b/shared/ffmpeg_raii.cpp similarity index 100% rename from futatabi/ffmpeg_raii.cpp rename to shared/ffmpeg_raii.cpp diff --git a/futatabi/ffmpeg_raii.h b/shared/ffmpeg_raii.h similarity index 100% rename from futatabi/ffmpeg_raii.h rename to shared/ffmpeg_raii.h diff --git a/futatabi/memcpy_interleaved.cpp b/shared/memcpy_interleaved.cpp similarity index 100% rename from futatabi/memcpy_interleaved.cpp rename to shared/memcpy_interleaved.cpp diff --git a/futatabi/memcpy_interleaved.h b/shared/memcpy_interleaved.h similarity index 100% rename from futatabi/memcpy_interleaved.h rename to shared/memcpy_interleaved.h diff --git a/shared/meson.build b/shared/meson.build new file mode 100644 index 0000000..09bf990 --- /dev/null +++ b/shared/meson.build @@ -0,0 +1,7 @@ + +srcs = ['memcpy_interleaved.cpp', 'metacube2.cpp', 'ffmpeg_raii.cpp'] +shared = static_library('shared', srcs, include_directories: top_include) +shareddep = declare_dependency( + include_directories: top_include, + link_with: shared, + sources: srcs) diff --git a/futatabi/metacube2.cpp b/shared/metacube2.cpp similarity index 100% rename from futatabi/metacube2.cpp rename to shared/metacube2.cpp diff --git a/futatabi/metacube2.h b/shared/metacube2.h similarity index 100% rename from futatabi/metacube2.h rename to shared/metacube2.h diff --git a/futatabi/post_to_main_thread.h b/shared/post_to_main_thread.h similarity index 100% rename from futatabi/post_to_main_thread.h rename to shared/post_to_main_thread.h -- 2.39.2