Skip to content

Commit

Permalink
avconv: Generic device setup
Browse files Browse the repository at this point in the history
Not yet enabled for any hwaccels.
  • Loading branch information
fhvwy committed Mar 20, 2017
1 parent b7487f4 commit d2e6dd3
Show file tree
Hide file tree
Showing 5 changed files with 452 additions and 6 deletions.
3 changes: 2 additions & 1 deletion avtools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ PROGS += $(AVPROGS)
AVBASENAMES = avconv avplay avprobe
ALLAVPROGS = $(AVBASENAMES:%=%$(EXESUF))

OBJS-avconv += avtools/avconv_opt.o avtools/avconv_filter.o
OBJS-avconv += avtools/avconv_opt.o avtools/avconv_filter.o \
avtools/avconv_hw.o
OBJS-avconv-$(CONFIG_LIBMFX) += avtools/avconv_qsv.o
OBJS-avconv-$(CONFIG_VAAPI) += avtools/avconv_vaapi.o
OBJS-avconv-$(CONFIG_VDA) += avtools/avconv_vda.o
Expand Down
22 changes: 22 additions & 0 deletions avtools/avconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,17 @@ static int init_input_stream(int ist_index, char *error, int error_len)

if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0))
av_dict_set(&ist->decoder_opts, "threads", "auto", 0);

ret = hw_device_setup_for_decode(ist);
if (ret < 0) {
char errbuf[128];
av_strerror(ret, errbuf, sizeof(errbuf));
snprintf(error, error_len, "Device setup failed for "
"decoder on input stream #%d:%d : %s",
ist->file_index, ist->st->index, errbuf);
return ret;
}

if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) {
char errbuf[128];
if (ret == AVERROR_EXPERIMENTAL)
Expand Down Expand Up @@ -2046,6 +2057,16 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len)
ost->enc_ctx->hw_frames_ctx = av_buffer_ref(ost->filter->filter->inputs[0]->hw_frames_ctx);
if (!ost->enc_ctx->hw_frames_ctx)
return AVERROR(ENOMEM);
} else {
ret = hw_device_setup_for_encode(ost);
if (ret < 0) {
char errbuf[128];
av_strerror(ret, errbuf, sizeof(errbuf));
snprintf(error, error_len, "Device setup failed for "
"encoder on output stream #%d:%d : %s",
ost->file_index, ost->index, errbuf);
return ret;
}
}

if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) {
Expand Down Expand Up @@ -2795,6 +2816,7 @@ static int transcode(void)
}

av_buffer_unref(&hw_device_ctx);
hw_device_free_all();

/* finished ! */
ret = 0;
Expand Down
17 changes: 17 additions & 0 deletions avtools/avconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "libavutil/avutil.h"
#include "libavutil/dict.h"
#include "libavutil/fifo.h"
#include "libavutil/hwcontext.h"
#include "libavutil/pixfmt.h"
#include "libavutil/rational.h"

Expand All @@ -63,8 +64,15 @@ typedef struct HWAccel {
int (*init)(AVCodecContext *s);
enum HWAccelID id;
enum AVPixelFormat pix_fmt;
enum AVHWDeviceType device_type;
} HWAccel;

typedef struct HWDevice {
char *name;
enum AVHWDeviceType type;
AVBufferRef *device_ref;
} HWDevice;

/* select an input stream for an output stream */
typedef struct StreamMap {
int disabled; /* 1 is this mapping is disabled by a negative map */
Expand Down Expand Up @@ -510,4 +518,13 @@ int qsv_transcode_init(OutputStream *ost);
int vaapi_decode_init(AVCodecContext *avctx);
int vaapi_device_init(const char *device);

HWDevice *hw_device_get_by_name(const char *name);
int hw_device_init_from_string(const char *arg, HWDevice **dev);
void hw_device_free_all(void);

int hw_device_setup_for_decode(InputStream *ist);
int hw_device_setup_for_encode(OutputStream *ost);

int hwaccel_decode_init(AVCodecContext *avctx);

#endif /* AVCONV_H */

0 comments on commit d2e6dd3

Please sign in to comment.