delete duplicate file, set thread_count for multi threaded mjpeg decoding

This commit is contained in:
veejay
2023-09-16 19:25:58 +02:00
parent 4a6322c46b
commit 9f4b8f0a10
24 changed files with 114 additions and 190 deletions

View File

@@ -7,9 +7,9 @@ MAINTAINERCLEANFILES = Makefile.in
AM_CPPFLAGS = -I$(top_srcdir) -I$(includedir) \
-I$(top_srcdir)/thirdparty
AM_CPPFLAGS += $(FFMPEG_CFLAGS) $(PIXBUF_CFLAGS) $(LIBQUICKTIME_CFLAGS)
AM_CPPFLAGS += $(FFMPEG_CFLAGS) $(PIXBUF_CFLAGS) $(LIBQUICKTIME_CFLAGS) $(VEEJAYCORE_CFLAGS)
VJEL_LIB_FILE = libel.la
noinst_LTLIBRARIES = $(VJEL_LIB_FILE)
libel_la_SOURCES = vj-mmap.c elcache.c avilib.c lav_io.c vj-dv.c rawdv.c pixbuf.c vj-avcodec.c vj-el.c
libel_la_SOURCES = avhelper.c vj-mmap.c elcache.c avilib.c lav_io.c vj-dv.c rawdv.c pixbuf.c vj-avcodec.c vj-el.c

View File

@@ -1,87 +0,0 @@
#ifndef AVCOMMON_H
#define AVCOMMON_H
#include <libavutil/version.h>
#define LIBAVUTIL_VERSION_CHECK( a, b, c, d, e ) \
( (LIBAVUTIL_VERSION_MICRO < 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT( a, b, c ) ) || \
(LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT( a, d, e ) ) )
#if LIBAVUTIL_VERSION_CHECK(51,45,0,74,100)
#ifndef PIX_FMT_YUVA422P
#define PIX_FMT_YUVA422P AV_PIX_FMT_YUVA422P
#endif
#ifndef PIX_FMT_YUVA444P
#define PIX_FMT_YUVA444P AV_PIX_FMT_YUVA444P
#endif
#ifndef PIX_FMT_YUVA420P
#define PIX_FMT_YUVA420P AV_PIX_FMT_YUVA420P
#endif
#ifndef PIX_FMT_YUV422P
#define PIX_FMT_YUV422P AV_PIX_FMT_YUV422P
#endif
#ifndef PIX_FMT_YUV420P
#define PIX_FMT_YUV420P AV_PIX_FMT_YUV420P
#endif
#ifndef PIX_FMT_YUVJ420P
#define PIX_FMT_YUVJ420P AV_PIX_FMT_YUVJ420P
#endif
#ifndef PIX_FMT_YUV444P
#define PIX_FMT_YUV444P AV_PIX_FMT_YUV444P
#endif
#ifndef PIX_FMT_RGB24
#define PIX_FMT_RGB24 AV_PIX_FMT_RGB24
#endif
#ifndef PIX_FMT_YUVJ444P
#define PIX_FMT_YUVJ444P AV_PIX_FMT_YUVJ444P
#endif
#ifndef PIX_FMT_YUVJ422P
#define PIX_FMT_YUVJ422P AV_PIX_FMT_YUVJ422P
#endif
#ifndef PIX_FMT_RGB32
#define PIX_FMT_RGB32 AV_PIX_FMT_RGB32
#endif
#ifndef PIX_FMT_BGR32
#define PIX_FMT_BGR32 AV_PIX_FMT_BGR32
#endif
#ifndef PIX_FMT_RGBA
#define PIX_FMT_RGBA AV_PIX_FMT_RGBA
#endif
#ifndef PIX_FMT_BGRA
#define PIX_FMT_BGRA AV_PIX_FMT_BGRA
#endif
#ifndef PIX_FMT_BGR24
#define PIX_FMT_BGR24 AV_PIX_FMT_BGR24
#endif
#ifndef PIX_FMT_GRAY8
#define PIX_FMT_GRAY8 AV_PIX_FMT_GRAY8
#endif
#ifndef PIX_FMT_RB32_1
#define PIX_FMT_RGB32_1 AV_PIX_FMT_RGB32_1
#endif
#ifndef PIX_FMT_YUYV422
#define PIX_FMT_YUYV422 AV_PIX_FMT_YUYV422
#endif
#ifndef PIX_FMT_UYVY422
#define PIX_FMT_UYVY422 AV_PIX_FMT_UYVY422
#endif
#ifndef PIX_FMT_ARGB
#define PIX_FMT_ARGB AV_PIX_FMT_ARGB
#endif
#ifndef PIX_FMT_ABGR
#define PIX_FMT_ABGR AV_PIX_FMT_ABGR
#endif
#ifndef PIX_FMT_YUV411P
#define PIX_FMT_YUV411P AV_PIX_FMT_YUV411P
#endif
#ifndef CODEC_FLAG_QSCALE
#define CODEC_FLAG_QSCALE AV_CODEC_FLAG_QSCALE
#endif
#ifndef CODEC_CAP_TRUNCATED
#define CODEC_CAP_TRUNCATED AV_CODEC_CAP_TRUNCATED
#endif
#ifndef CODEC_FLAG_TRUNCATED
#define CODEC_FLAG_TRUNCATED AV_CODEC_FLAG_TRUNCATED
#endif
#endif
#endif

View File

@@ -24,6 +24,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdint.h>
#include <veejaycore/defs.h>
#include <veejaycore/vj-msg.h>
#include <veejaycore/vjmem.h>
#include <libvje/vje.h>
@@ -33,7 +35,7 @@
#include <libavcodec/version.h>
#include <libavformat/avformat.h>
#include <libavformat/version.h>
#include <libel/avhelper.h>
#include <veejaycore/avhelper.h>
#include <libel/av.h>
#include <veejaycore/hash.h>
@@ -138,6 +140,26 @@ static int key_compare(const void *key1, const void *key2)
return ((const int) key1 == (const int) key2 ? 0 : 1);
}
static int avhelper_set_num_decoders() {
int n_threads = 0;
char *num_decode_threads = getenv( "VEEJAY_NUM_DECODE_THREADS" );
if( num_decode_threads ) {
n_threads = atoi(num_decode_threads);
}
else {
veejay_msg(VEEJAY_MSG_DEBUG, "env VEEJAY_NUM_DECODE_THREADS not set!");
int n = task_num_cpus();
if( n > 1 )
n_threads = 2;
if( n > 3 )
n_threads = 4;
}
veejay_msg(VEEJAY_MSG_DEBUG, "Using %d decoding threads (ffmpeg)", n_threads);
return n_threads;
}
int avhelper_get_codec_by_id(int id)
{
int i;
@@ -254,6 +276,14 @@ void *avhelper_get_mjpeg_decoder(VJFrame *output) {
#if LIBAVCODEC_BUILD > 5400
x->codec_ctx = avcodec_alloc_context3(x->codec);
int n_threads = avhelper_set_num_decoders();
if( n_threads > 0 ) {
x->codec_ctx->thread_count = n_threads;
x->codec_ctx->thread_type = FF_THREAD_FRAME;
}
if ( avcodec_open2( x->codec_ctx, x->codec, NULL ) < 0 )
#else
x->codec_ctx = avcodec_alloc_context();
@@ -504,6 +534,14 @@ further:
}
#if LIBAVCODEC_BUILD > 5400
int n_threads = avhelper_set_num_decoders();
if( n_threads > 0 ) {
x->codec_ctx->thread_count = n_threads;
x->codec_ctx->thread_type = FF_THREAD_FRAME;
}
if ( avcodec_open2( x->codec_ctx, x->codec, NULL ) < 0 )
#else
if ( avcodec_open( x->codec_ctx, x->codec ) < 0 )

View File

@@ -1,73 +0,0 @@
/* veejay - Linux VeeJay
* (C) 2002-2015 Niels Elburg <nwelburg@gmail.com>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details//.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef AVHELPER_H
#define AVHELPER_H
#define CODEC_ID_YUV420 999
#define CODEC_ID_YUV422 998
#define CODEC_ID_YUV422F 997
#define CODEC_ID_YUV420F 996
#define CODEC_ID_YUVLZO 900
// This is not a library, it is a collection of helper functions for various purposes
void *avhelper_alloc_frame();
int avhelper_get_codec_by_id(int id);
int avhelper_get_codec_by_key( int key );
void *avhelper_get_codec_ctx( void *ptr );
void *avhelper_get_codec( void *ptr );
void avhelper_close_decoder( void *ptr );
int avhelper_decode_video( void *ptr, uint8_t *data, int len);
void avhelper_rescale_video(void *ptr, uint8_t *dst[4]);
void *avhelper_get_decoder( const char *filename, int dst_pixfmt, int dst_width, int dst_height );
void *avhelper_get_stream_decoder( const char *filename, int dst_pixfmt, int dst_width, int dst_height );
VJFrame *avhelper_get_decoded_video(void *ptr);
void avhelper_free_context(AVCodecContext **avctx);
void avhelper_frame_unref(AVFrame *ptr);
void *avhelper_get_mjpeg_decoder(VJFrame *output_info);
int avhelper_get_frame( void *decoder, int *got_picture );
VJFrame *avhelper_get_input_frame( void *ptr );
VJFrame *avhelper_get_output_frame( void *ptr);
int avhelper_recv_decode( void *decoder, int *got_picture );
int avhelper_recv_frame_packet( void *decoder );
int avhelper_decode_video_buffer( void *ptr, uint8_t *data, int len );
double avhelper_get_spvf( void *decoder );
#endif

View File

@@ -49,8 +49,8 @@
#include <veejaycore/vims.h>
#include <veejaycore/lzo.h>
#include <veejaycore/vjmem.h>
#include <libel/avcommon.h>
#include <libel/avhelper.h>
#include <veejaycore/avcommon.h>
#include <veejaycore/avhelper.h>
#define QUICKTIME_MJPG_TAG 0x6d6a7067
extern int get_ffmpeg_pixfmt(int p);

View File

@@ -35,7 +35,7 @@
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <veejaycore/yuvconv.h>
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
#define RUP8(num)(((num)+8)&~8)
typedef struct

View File

@@ -37,8 +37,8 @@
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libel/av.h>
#include <libel/avhelper.h>
#include <libel/avcommon.h>
#include <veejaycore/avhelper.h>
#include <veejaycore/avcommon.h>
//from gst-ffmpeg, round up a number
#define GEN_MASK(x) ((1<<(x))-1)
@@ -180,6 +180,29 @@ static vj_encoder *vj_avcodec_new_encoder( int id, VJFrame *frame, char *filenam
#endif
#if LIBAVCODEC_BUILD > 5400
e->context = avcodec_alloc_context3(e->codec);
int n_threads = 0;
char *num_decode_threads = getenv( "VEEJAY_NUM_DECODE_THREADS" );
if( num_decode_threads ) {
n_threads = atoi(num_decode_threads);
}
else {
veejay_msg(VEEJAY_MSG_DEBUG, "env VEEJAY_NUM_DECODE_THREADS not set!");
int n = task_num_cpus();
if( n > 1 )
n_threads = 2;
if( n > 3 )
n_threads = 4;
}
veejay_msg(VEEJAY_MSG_DEBUG, "Using %d decoding threads (ffmpeg)", n_threads);
if( n_threads > 0 ) {
e->context->thread_count = n_threads;
e->context->thread_type = FF_THREAD_FRAME;
}
#else
e->context = avcodec_alloc_context();
#endif

View File

@@ -28,7 +28,7 @@
#include <libvje/vje.h>
#include <libel/vj-dv.h>
#include <libel/vj-avcodec.h>
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
#include <veejaycore/yuvconv.h>
#include <string.h>

View File

@@ -38,7 +38,7 @@
#include <libel/vj-avcodec.h>
#include <libel/elcache.h>
#include <libel/pixbuf.h>
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
#include <limits.h>
#include <veejaycore/mpegconsts.h>
#include <veejaycore/mpegtimecode.h>
@@ -47,7 +47,7 @@
#include <libavutil/avutil.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libel/avhelper.h>
#include <veejaycore/avhelper.h>
#include <libel/av.h>
#include <veejaycore/vj-task.h>
#include <veejaycore/lzo.h>

View File

@@ -40,7 +40,7 @@
#define V_BITS 24
#include <libplugger/freeframe-loader.h>
#include <libvje/vje.h>
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
typedef struct
{

View File

@@ -43,7 +43,7 @@
#include <libplugger/defaults.h>
#include <libplugger/specs/frei0r.h>
#include <libplugger/frei0r-loader.h>
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
#define RUP8(num)(((num)+8)&~8)
#define _VJ_MAX_PARAMS 32

View File

@@ -46,7 +46,7 @@
#include <libplugger/utility.h>
#include <libplugger/livido-loader.h>
#include <libsubsample/subsample.h>
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
#include <veejay/vj-shm.h>
#include <veejaycore/vims.h>
#define LIVIDO_COPY 1

View File

@@ -78,8 +78,8 @@
#include <libavutil/avutil.h>
#include <libavcodec/avcodec.h>
#include <libel/av.h>
#include <libel/avhelper.h>
#include <libel/avcommon.h>
#include <veejaycore/avhelper.h>
#include <veejaycore/avcommon.h>
#define RUP8(num)(((num)+8)&~8)
//#include <pthread.h>
@@ -578,6 +578,29 @@ static int v4l2_setup_avcodec_capture( v4l2info *v, int wid, int hei, int codec_
#if LIBAVCODEC_BUILD > 5400
v->c = avcodec_alloc_context3( v->codec );
int n_threads = 0;
char *num_decode_threads = getenv( "VEEJAY_NUM_DECODE_THREADS" );
if( num_decode_threads ) {
n_threads = atoi(num_decode_threads);
}
else {
veejay_msg(VEEJAY_MSG_DEBUG, "env VEEJAY_NUM_DECODE_THREADS not set!");
int n = task_num_cpus();
if( n > 1 )
n_threads = 2;
if( n > 3 )
n_threads = 4;
}
veejay_msg(VEEJAY_MSG_DEBUG, "Using %d decoding threads (ffmpeg)", n_threads);
if( n_threads > 0 ) {
v->c->thread_count = n_threads;
v->c->thread_type = FF_THREAD_FRAME;
}
#else
v->c = avcodec_alloc_context();
#endif

View File

@@ -33,8 +33,8 @@
#include <libstream/vj-avformat.h>
#include <time.h>
#include <veejaycore/yuvconv.h>
#include <libel/avcommon.h>
#include <libel/avhelper.h>
#include <veejaycore/avcommon.h>
#include <veejaycore/avhelper.h>
typedef struct
{

View File

@@ -32,8 +32,8 @@
#include <libstream/vj-net.h>
#include <time.h>
#include <veejaycore/yuvconv.h>
#include <libel/avcommon.h>
#include <libel/avhelper.h>
#include <veejaycore/avcommon.h>
#include <veejaycore/avhelper.h>
#include <libvje/effects/common.h>
typedef struct

View File

@@ -40,7 +40,7 @@
#include <veejaycore/vj-msg.h>
#include <veejaycore/vims.h>
#include <libavutil/pixfmt.h>
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
#include <libstream/vj-vloopback.h>
#include <libvje/effects/common.h>

View File

@@ -29,7 +29,7 @@
#include <libavutil/avutil.h>
#include "../effects/common.h"
#include "../libel/pixbuf.h"
#include "../libel/avcommon.h"
#include <veejaycore/avcommon.h>
#include <veejaycore/vjmem.h>
#include <veejaycore/vj-msg.h>
#include "shapewipe.h"

View File

@@ -84,7 +84,7 @@
#include <veejay/vj-sdl.h>
#include <libel/vj-avcodec.h>
#include <libel/pixbuf.h>
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
#include <veejaycore/vj-client.h>
#ifdef HAVE_JACK
#include <veejay/vj-jack.h>

View File

@@ -42,7 +42,7 @@
#ifdef HAVE_GL
#include <veejay/gl.h>
#endif
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
typedef struct
{

View File

@@ -44,7 +44,7 @@
#include <libvje/vje.h>
#include <veejaycore/yuvconv.h>
#include <libavutil/pixfmt.h>
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <pthread.h>

View File

@@ -43,7 +43,7 @@
#include <veejay/vj-sdl.h>
#include <libsamplerec/samplerecord.h>
#include <libel/pixbuf.h>
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
#include <veejay/vj-misc.h>
#include <veejaycore/vj-task.h>
#include <veejaycore/lzo.h>

View File

@@ -36,7 +36,7 @@
#include <libel/vj-avcodec.h>
#include <veejaycore/yuvconv.h>
#include <veejay/libveejay.h>
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
#include <string.h>
#include <stdlib.h>

View File

@@ -40,7 +40,7 @@
#include <libavutil/pixfmt.h>
#include <libavutil/avutil.h>
#include <libplugger/specs/livido.h>
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
#include <veejay/vj-shm.h>
#define HEADER_LENGTH 4096
#ifndef PATH_MAX

View File

@@ -43,7 +43,7 @@
#include <veejay/vj-viewport-cfg.h>
#include <veejay/vj-viewport.h>
#include <math.h>
#include <libel/avcommon.h>
#include <veejaycore/avcommon.h>
#define X0 0
#define Y0 1