Skip to content

Commit

Permalink
libhb: fix build with --enable-qsv
Browse files Browse the repository at this point in the history
Convert qsv_livav.[ch] to be built within libhb.

Convert other files to use qsv_libav.h in place of libavcodec/qsv.h

Don't attempt to build libav with QSV support (not available in unpatched release/11 branch).

QSV-accelerated decoding is broken, so disable it for the time being.
  • Loading branch information
twalker314 authored and jstebbins committed Dec 17, 2016
1 parent ac6c1ab commit 5b48deb
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 75 deletions.
7 changes: 4 additions & 3 deletions contrib/ffmpeg/module.defs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ ifeq (none,$(FFMPEG.GCC.O))
FFMPEG.CONFIGURE.extra += --disable-optimizations
endif

ifeq (1,$(FEATURE.qsv))
FFMPEG.CONFIGURE.extra += --enable-qsv
endif
## not supported in release/11 branch without our patch
## ifeq (1,$(FEATURE.qsv))
## FFMPEG.CONFIGURE.extra += --enable-qsv
## endif

## enable compile verbosity
FFMPEG.BUILD.extra = V=1
Expand Down
2 changes: 1 addition & 1 deletion libhb/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ typedef enum
#include "libavutil/channel_layout.h"

#ifdef USE_QSV
#include "libavcodec/qsv.h"
#include "qsv_libav.h"
#endif

struct hb_buffer_list_s
Expand Down
2 changes: 1 addition & 1 deletion libhb/fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "hb.h"
#include "openclwrapper.h"
#ifdef USE_QSV
#include "libavcodec/qsv.h"
#include "qsv_libav.h"
#endif

#ifndef SYS_DARWIN
Expand Down
2 changes: 1 addition & 1 deletion libhb/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "hbffmpeg.h"
#include "extras/cl.h"
#ifdef USE_QSV
#include "libavcodec/qsv.h"
#include "qsv_libav.h"
#endif

/***********************************************************************
Expand Down
14 changes: 11 additions & 3 deletions libhb/qsv_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,9 +912,17 @@ const char* hb_qsv_decode_get_codec_name(enum AVCodecID codec_id)

int hb_qsv_decode_is_enabled(hb_job_t *job)
{
return ((job != NULL && job->qsv.decode) &&
(job->vcodec & HB_VCODEC_QSV_MASK) &&
(job->title->video_decode_support & HB_DECODE_SUPPORT_QSV));
/*
* XXX: we haven't yet adjusted our QSV decoder wrapper to use libav's new
* QSV-accelerated decoder, and our old custom QSV-accelerated decoder
* for libav hasn't been updated to work with newer libav releases, so
* we can't use QSV-accelerated decoding at all for the time being.
*
* return ((job != NULL && job->qsv.decode) &&
* (job->vcodec & HB_VCODEC_QSV_MASK) &&
* (job->title->video_decode_support & HB_DECODE_SUPPORT_QSV));
*/
return 0;
}

int hb_qsv_copyframe_is_slow(int encoder)
Expand Down
2 changes: 1 addition & 1 deletion libhb/qsv_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "hb.h"
#include "hbffmpeg.h"
#include "libavcodec/qsv.h"
#include "qsv_filter.h"
#include "qsv_libav.h"

struct hb_filter_private_s
{
Expand Down
2 changes: 1 addition & 1 deletion libhb/qsv_filter_pp.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "hb.h"
#include "hbffmpeg.h"
#include "libavcodec/qsv.h"
#include "qsv_filter_pp.h"
#include "qsv_filter.h"
#include "qsv_libav.h"
#include "qsv_memory.h"


Expand Down
52 changes: 6 additions & 46 deletions libhb/qsv_libav.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\* ********************************************************************* */

#include "qsv.h"
#ifdef USE_QSV

#include "avcodec.h"
#include "internal.h"
#include "hbffmpeg.h"
#include "qsv_libav.h"

int av_qsv_get_free_encode_task(av_qsv_list * tasks)
{
Expand Down Expand Up @@ -62,16 +62,12 @@ int av_qsv_get_free_sync(av_qsv_space * space, av_qsv_context * qsv)
return i;
}
}
#if HAVE_THREADS
if (++counter >= AV_QSV_REPEAT_NUM_DEFAULT) {
#endif
av_log(NULL, AV_LOG_FATAL, "not enough to have %d sync point(s) allocated\n",
space->sync_num);
break;
#if HAVE_THREADS
}
av_qsv_sleep(5);
#endif
}
return ret;
}
Expand Down Expand Up @@ -101,16 +97,12 @@ int av_qsv_get_free_surface(av_qsv_space * space, av_qsv_context * qsv,
return i;
}
}
#if HAVE_THREADS
if (++counter >= AV_QSV_REPEAT_NUM_DEFAULT) {
#endif
av_log(NULL, AV_LOG_FATAL,
"not enough to have %d surface(s) allocated\n", up);
break;
#if HAVE_THREADS
}
av_qsv_sleep(5);
#endif
}
return ret;
}
Expand Down Expand Up @@ -193,9 +185,7 @@ void av_qsv_stage_clean(av_qsv_stage ** stage)
void av_qsv_add_context_usage(av_qsv_context * qsv, int is_threaded)
{
int is_active = 0;
#if HAVE_THREADS
int mut_ret = 0;
#endif

is_active = ff_qsv_atomic_inc(&qsv->is_context_active);
if (is_active == 1) {
Expand All @@ -204,7 +194,6 @@ void av_qsv_add_context_usage(av_qsv_context * qsv, int is_threaded)

qsv->dts_seq = av_qsv_list_init(is_threaded);

#if HAVE_THREADS
if (is_threaded) {
qsv->qts_seq_mutex = av_mallocz(sizeof(pthread_mutex_t));
if (qsv->qts_seq_mutex){
Expand All @@ -214,7 +203,6 @@ void av_qsv_add_context_usage(av_qsv_context * qsv, int is_threaded)
}

} else
#endif
qsv->qts_seq_mutex = 0;
}
}
Expand All @@ -223,9 +211,7 @@ int av_qsv_context_clean(av_qsv_context * qsv)
{
int is_active = 0;
mfxStatus sts = MFX_ERR_NONE;
#if HAVE_THREADS
int mut_ret = 0;
#endif

is_active = ff_qsv_atomic_dec(&qsv->is_context_active);

Expand All @@ -239,16 +225,12 @@ int av_qsv_context_clean(av_qsv_context * qsv)

av_qsv_list_close(&qsv->dts_seq);
}
#if HAVE_THREADS
if (qsv->qts_seq_mutex) {
mut_ret = pthread_mutex_destroy(qsv->qts_seq_mutex);
if(mut_ret)
av_log(NULL, AV_LOG_ERROR, "pthread_mutex_destroy issue[%d] at %s\n", mut_ret,__FUNCTION__);
#endif
qsv->qts_seq_mutex = 0;
#if HAVE_THREADS
}
#endif

if (qsv->pipes)
av_qsv_pipe_list_clean(&qsv->pipes);
Expand Down Expand Up @@ -360,18 +342,14 @@ void av_qsv_dts_ordered_insert(av_qsv_context * qsv, int start, int end,
av_qsv_dts *cur_dts = 0;
av_qsv_dts *new_dts = 0;
int i = 0;
#if HAVE_THREADS
int mut_ret = 0;
#endif


#if HAVE_THREADS
if (iter == 0 && qsv->qts_seq_mutex){
mut_ret = pthread_mutex_lock(qsv->qts_seq_mutex);
if(mut_ret)
av_log(NULL, AV_LOG_ERROR, "pthread_mutex_lock issue[%d] at %s\n",mut_ret, __FUNCTION__);
}
#endif

if (end == 0)
end = av_qsv_list_count(qsv->dts_seq);
Expand All @@ -395,51 +373,41 @@ void av_qsv_dts_ordered_insert(av_qsv_context * qsv, int start, int end,
} else if (cur_dts->dts == dts)
break;
}
#if HAVE_THREADS
if (iter == 0 && qsv->qts_seq_mutex){
mut_ret = pthread_mutex_unlock(qsv->qts_seq_mutex);
if(mut_ret)
av_log(NULL, AV_LOG_ERROR, "pthread_mutex_unlock issue[%d] at %s\n",mut_ret, __FUNCTION__);
}
#endif
}

void av_qsv_dts_pop(av_qsv_context * qsv)
{
av_qsv_dts *item = 0;
#if HAVE_THREADS
int mut_ret = 0;
#endif

#if HAVE_THREADS
if (qsv && qsv->qts_seq_mutex){
mut_ret = pthread_mutex_lock(qsv->qts_seq_mutex);
if(mut_ret)
av_log(NULL, AV_LOG_ERROR, "pthread_mutex_lock issue[%d] at %s\n",mut_ret, __FUNCTION__);
}
#endif

if (av_qsv_list_count(qsv->dts_seq)) {
item = av_qsv_list_item(qsv->dts_seq, 0);
av_qsv_list_rem(qsv->dts_seq, item);
av_free(item);
}
#if HAVE_THREADS
if (qsv && qsv->qts_seq_mutex){
mut_ret = pthread_mutex_unlock(qsv->qts_seq_mutex);
if(mut_ret)
av_log(NULL, AV_LOG_ERROR, "pthread_mutex_lock issue[%d] at %s\n",mut_ret, __FUNCTION__);
}
#endif
}


av_qsv_list *av_qsv_list_init(int is_threaded)
{
av_qsv_list *l;
#if HAVE_THREADS
int mut_ret;
#endif

l = av_mallocz(sizeof(av_qsv_list));
if (!l)
Expand All @@ -449,7 +417,6 @@ av_qsv_list *av_qsv_list_init(int is_threaded)
return 0;
l->items_alloc = AV_QSV_JOB_SIZE_DEFAULT;

#if HAVE_THREADS
if (is_threaded) {
l->mutex = av_mallocz(sizeof(pthread_mutex_t));
if (l->mutex){
Expand All @@ -464,7 +431,6 @@ av_qsv_list *av_qsv_list_init(int is_threaded)
av_log(NULL, AV_LOG_ERROR, "pthread_mutex_init issue[%d] at %s\n",mut_ret, __FUNCTION__);
}
} else
#endif
l->mutex = 0;
return l;
}
Expand Down Expand Up @@ -566,47 +532,39 @@ void av_qsv_list_insert(av_qsv_list * l, int pos, void *p)
void av_qsv_list_close(av_qsv_list ** _l)
{
av_qsv_list *l = *_l;
#if HAVE_THREADS
int mut_ret;
#endif

av_qsv_list_lock(l);

av_free(l->items);

#if HAVE_THREADS
if (l->mutex){
mut_ret = pthread_mutex_unlock(l->mutex);
if( mut_ret )
av_log(NULL, AV_LOG_ERROR, "pthread_mutex_unlock issue[%d] at %s\n",mut_ret, __FUNCTION__);
mut_ret = pthread_mutex_destroy(&l->mutex);
mut_ret = pthread_mutexattr_destroy(&l->mta);
}
#endif
av_freep(_l);
}

int av_qsv_list_lock(av_qsv_list *l){
int ret = 0;
#if HAVE_THREADS
if (l->mutex){
ret = pthread_mutex_lock(l->mutex);
if( ret )
av_log(NULL, AV_LOG_ERROR, "pthread_mutex_lock issue[%d] at %s\n",ret, __FUNCTION__);
}
#endif
return ret;
}

int av_qsv_list_unlock(av_qsv_list *l){
int ret = 0;
#if HAVE_THREADS
if (l->mutex){
ret = pthread_mutex_unlock(l->mutex);
if( ret )
av_log(NULL, AV_LOG_ERROR, "pthread_mutex_unlock issue[%d] at %s\n",ret, __FUNCTION__);
}
#endif
return ret;
}

Expand Down Expand Up @@ -643,4 +601,6 @@ void av_qsv_wait_on_sync(av_qsv_context *qsv, av_qsv_stage *stage)
break;
}
}
}
}

#endif // USE_QSV
20 changes: 3 additions & 17 deletions libhb/qsv_libav.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\* ********************************************************************* */

#ifndef AVCODEC_QSV_H
#define AVCODEC_QSV_H
#ifndef HB_QSV_LIBAV_H
#define HB_QSV_LIBAV_H

/**
* @file
Expand Down Expand Up @@ -120,11 +120,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "libavutil/mem.h"
#include "libavutil/time.h"

#ifdef HAVE_AV_CONFIG_H
#include "config.h"
#endif

#if HAVE_THREADS
#if defined (__GNUC__)
#include <pthread.h>
#define ff_qsv_atomic_inc(ptr) __sync_add_and_fetch(ptr,1)
Expand All @@ -138,13 +133,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif
#define ff_qsv_atomic_inc(ptr) InterlockedIncrement(ptr)
#define ff_qsv_atomic_dec(ptr) InterlockedDecrement (ptr)
#else
// targeting only for MinGW or MSVC
#endif

#else
#define ff_qsv_atomic_inc(ptr) ((*ptr)++)
#define ff_qsv_atomic_dec(ptr) ((*ptr)--)
#endif


Expand Down Expand Up @@ -202,9 +190,7 @@ typedef enum AV_QSV_STAGE_TYPE {
typedef struct av_qsv_list {
// practically pthread_mutex_t
void *mutex;
#if HAVE_THREADS
pthread_mutexattr_t mta;
#endif

void **items;
int items_alloc;
Expand Down Expand Up @@ -491,4 +477,4 @@ void *av_qsv_list_item(av_qsv_list *, int);

/* @} */

#endif //AVCODEC_QSV_H
#endif // HB_QSV_LIBAV_H
2 changes: 1 addition & 1 deletion libhb/qsv_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef QSV_MEMORY_H
#define QSV_MEMORY_H

#include "libavcodec/qsv.h"
#include "mfx/mfxplugin.h"
#include "qsv_libav.h"

typedef struct{

Expand Down

0 comments on commit 5b48deb

Please sign in to comment.