ffmpeg-devel
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
May 2018
- 114 participants
- 325 discussions
I apologize in advance for the formatting of this message. My mail
configuration impeded my efforts to use ‘—send-email’.
This commit did pass 'make fate’ though the use of these changes requires
decklink hardware so I did not add any new fate tests. By default the new
optional behavior is skipped for old behavior.
---
libavdevice/decklink_common.cpp | 30 -----------------------------
libavdevice/decklink_common.h | 42 ++++++++++++++++++++++++++++++
+++++++++++
libavdevice/decklink_common_c.h | 1 +
libavdevice/decklink_dec.cpp | 19 +++++++++++++++++++
libavdevice/decklink_dec_c.c | 9 +++++++++
5 files changed, 71 insertions(+), 30 deletions(-)
diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.
cpp
index d8cced7c74..aab9d85b94 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -77,36 +77,6 @@ static IDeckLinkIterator
*decklink_create_iterator(AVFormatContext
*avctx)
return iter;
}
-#ifdef _WIN32
-static char *dup_wchar_to_utf8(wchar_t *w)
-{
- char *s = NULL;
- int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
- s = (char *) av_malloc(l);
- if (s)
- WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
- return s;
-}
-#define DECKLINK_STR OLECHAR *
-#define DECKLINK_STRDUP dup_wchar_to_utf8
-#define DECKLINK_FREE(s) SysFreeString(s)
-#elif defined(__APPLE__)
-static char *dup_cfstring_to_utf8(CFStringRef w)
-{
- char s[256];
- CFStringGetCString(w, s, 255, kCFStringEncodingUTF8);
- return av_strdup(s);
-}
-#define DECKLINK_STR const __CFString *
-#define DECKLINK_STRDUP dup_cfstring_to_utf8
-#define DECKLINK_FREE(s) CFRelease(s)
-#else
-#define DECKLINK_STR const char *
-#define DECKLINK_STRDUP av_strdup
-/* free() is needed for a string returned by the DeckLink SDL. */
-#define DECKLINK_FREE(s) free((void *) s)
-#endif
-
HRESULT ff_decklink_get_display_name(IDeckLink *This, const char
**displayName)
{
DECKLINK_STR tmpDisplayName;
diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index 57ee7d1d68..8c5f8e9f06 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -34,6 +34,36 @@
#define DECKLINK_BOOL bool
#endif
+#ifdef _WIN32
+static char *dup_wchar_to_utf8(wchar_t *w)
+{
+ char *s = NULL;
+ int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
+ s = (char *) av_malloc(l);
+ if (s)
+ WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
+ return s;
+}
+#define DECKLINK_STR OLECHAR *
+#define DECKLINK_STRDUP dup_wchar_to_utf8
+#define DECKLINK_FREE(s) SysFreeString(s)
+#elif defined(__APPLE__)
+static char *dup_cfstring_to_utf8(CFStringRef w)
+{
+ char s[256];
+ CFStringGetCString(w, s, 255, kCFStringEncodingUTF8);
+ return av_strdup(s);
+}
+#define DECKLINK_STR const __CFString *
+#define DECKLINK_STRDUP dup_cfstring_to_utf8
+#define DECKLINK_FREE(s) CFRelease(s)
+#else
+#define DECKLINK_STR const char *
+#define DECKLINK_STRDUP av_strdup
+/* free() is needed for a string returned by the DeckLink SDL. */
+#define DECKLINK_FREE(s) free((void *) s)
+#endif
+
class decklink_output_callback;
class decklink_input_callback;
@@ -64,6 +94,7 @@ struct decklink_ctx {
BMDDisplayMode bmd_mode;
BMDVideoConnection video_input;
BMDAudioConnection audio_input;
+ BMDTimecodeFormat tc_format;
int bmd_width;
int bmd_height;
int bmd_field_dominance;
@@ -140,6 +171,17 @@ static const BMDVideoConnection
decklink_video_connection_map[] = {
bmdVideoConnectionSVideo,
};
+static const BMDTimecodeFormat decklink_timecode_format_map[] = {
+ (BMDTimecodeFormat)0,
+ bmdTimecodeRP188VITC1,
+ bmdTimecodeRP188VITC2,
+ bmdTimecodeRP188LTC,
+ bmdTimecodeRP188Any,
+ bmdTimecodeVITC,
+ bmdTimecodeVITCField2,
+ bmdTimecodeSerial,
+};
+
HRESULT ff_decklink_get_display_name(IDeckLink *This, const char
**displayName);
int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t
direction);
int ff_decklink_set_format(AVFormatContext *avctx, int width, int height,
int tb_num, int tb_den, enum AVFieldOrder field_order, decklink_direction_t
direction = DIRECTION_OUT, int num = 0);
diff --git a/libavdevice/decklink_common_c.h b/libavdevice/decklink_common_
c.h
index 08e9f9bbd5..32a5d70ee1 100644
--- a/libavdevice/decklink_common_c.h
+++ b/libavdevice/decklink_common_c.h
@@ -50,6 +50,7 @@ struct decklink_cctx {
DecklinkPtsSource video_pts_source;
int audio_input;
int video_input;
+ int tc_format;
int draw_bars;
char *format_code;
int raw_format;
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 510637676c..818235bfa6 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -726,6 +726,23 @@ HRESULT decklink_input_callback::
VideoInputFrameArrived(
no_video = 0;
}
+ // Handle Timecode (if requested)
+ if (ctx->tc_format && !(av_dict_get(ctx->video_st->metadata,
"timecode", NULL, 0)) && !no_video) {
+ IDeckLinkTimecode *timecode;
+ if (videoFrame->GetTimecode(ctx->tc_format, &timecode) ==
S_OK) {
+ DECKLINK_STR timecodeString = NULL;
+ timecode->GetString(&timecodeString);
+ const char* tc = DECKLINK_STRDUP(timecodeString);
+ if (!(av_dict_set(&ctx->video_st->metadata, "timecode",
tc, 0)))
+ av_log(avctx, AV_LOG_ERROR, "Unable to set
timecode\n");
+ if (timecodeString)
+ DECKLINK_FREE(timecodeString);
+ timecode->Release();
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "Unable to find timecode.\n");
+ }
+ }
+
pkt.pts = get_pkt_pts(videoFrame, audioFrame, wallclock,
abs_wallclock, ctx->video_pts_source, ctx->video_st->time_base,
&initial_video_pts, cctx->copyts);
pkt.dts = pkt.pts;
@@ -939,6 +956,8 @@ av_cold int ff_decklink_read_header(AVFormatContext
*avctx)
ctx->teletext_lines = cctx->teletext_lines;
ctx->preroll = cctx->preroll;
ctx->duplex_mode = cctx->duplex_mode;
+ if (cctx->tc_format > 0 && (unsigned int)cctx->tc_format <
FF_ARRAY_ELEMS(decklink_timecode_format_map))
+ ctx->tc_format = decklink_timecode_format_map[cctx->tc_format];
if (cctx->video_input > 0 && (unsigned int)cctx->video_input <
FF_ARRAY_ELEMS(decklink_video_connection_map))
ctx->video_input = decklink_video_connection_map[cctx->video_input];
if (cctx->audio_input > 0 && (unsigned int)cctx->audio_input <
FF_ARRAY_ELEMS(decklink_audio_connection_map))
diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c
index 47018dc681..6ab3819375 100644
--- a/libavdevice/decklink_dec_c.c
+++ b/libavdevice/decklink_dec_c.c
@@ -48,6 +48,15 @@ static const AVOption options[] = {
{ "unset", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = 0}, 0, 0, DEC, "duplex_mode"},
{ "half", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = 1}, 0, 0, DEC, "duplex_mode"},
{ "full", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = 2}, 0, 0, DEC, "duplex_mode"},
+ { "timecode_format", "timecode format", OFFSET(tc_format),
AV_OPT_TYPE_INT, { .i64 = 0}, 0, 7, DEC, "tc_format"},
+ { "none", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = 0}, 0, 0, DEC, "tc_format"},
+ { "rp188vitc", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = 1}, 0, 0, DEC, "tc_format"},
+ { "rp188vitc2", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = 2}, 0, 0, DEC, "tc_format"},
+ { "rp188ltc", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = 3}, 0, 0, DEC, "tc_format"},
+ { "rp188any", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = 4}, 0, 0, DEC, "tc_format"},
+ { "vitc", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = 5}, 0, 0, DEC, "tc_format"},
+ { "vitc2", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = 6}, 0, 0, DEC, "tc_format"},
+ { "serial", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = 7}, 0, 0, DEC, "tc_format"},
{ "video_input", "video input", OFFSET(video_input),
AV_OPT_TYPE_INT, { .i64 = 0}, 0, 6, DEC, "video_input"},
{ "unset", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = 0}, 0, 0, DEC, "video_input"},
{ "sdi", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = 1}, 0, 0, DEC, "video_input"},
--
2.16.2
5
45
[PATCH]lavc/aarch64/h264_init_aarch64: Fix weight function prototypes
by Carl Eugen Hoyos 13 Jul '18
by Carl Eugen Hoyos 13 Jul '18
13 Jul '18
Hi!
Attached patch fixes a warning when compiling for aarch64, fate passes.
Please comment, Carl Eugen
1
1
>From 7056d06412214bd601afb4b423d20ab6100e6ac5 Mon Sep 17 00:00:00 2001
From: palich2000 <y.palich.t(a)gmail.com>
Date: Fri, 2 Mar 2018 11:48:22 +0000
Subject: [PATCH] https://trac.ffmpeg.org/ticket/7030 fix
---
libavcodec/qsvenc_h264.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
index 09e4c0e..5f60675 100644
--- a/libavcodec/qsvenc_h264.c
+++ b/libavcodec/qsvenc_h264.c
@@ -34,6 +34,7 @@
#include "qsv.h"
#include "qsv_internal.h"
#include "qsvenc.h"
+#include "hwaccel.h"
typedef struct QSVH264EncContext {
AVClass *class;
@@ -169,6 +170,16 @@ static const AVCodecDefault qsv_enc_defaults[] = {
{ NULL },
};
+#define HWACCEL_QSV(codec) \
+ HW_CONFIG_HWACCEL(1, 1, 1, QSV, QSV, ff_ ## codec ##
_qsv_hwaccel)
+
+const AVHWAccel ff_h264_qsv_hwaccel = {
+ .name = "h264_qsv",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_H264,
+ .pix_fmt = AV_PIX_FMT_QSV
+};
+
AVCodec ff_h264_qsv_encoder = {
.name = "h264_qsv",
.long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC /
MPEG-4 part 10 (Intel Quick Sync Video acceleration)"),
@@ -186,5 +197,9 @@ AVCodec ff_h264_qsv_encoder = {
.priv_class = &class,
.defaults = qsv_enc_defaults,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
+ .hw_configs = (const AVCodecHWConfigInternal*[]) {
+ HWACCEL_QSV(h264),
+ NULL
+ },
.wrapper_name = "qsv",
};
--
1.8.3.1
5
12
03 Jul '18
- Parse schm atom to get different encryption schemes.
- Allow senc atom to appear in track fragments.
- Allow 16-byte IVs.
- Allow constant IVs (specified in tenc).
- Allow only tenc to specify encryption (i.e. no senc/saiz/saio).
- Use sample descriptor to detect clear fragments.
This doesn't support:
- Different sample descriptor holding different encryption info.
- Only first sample descriptor can be encrypted.
- Encrypted sample groups (i.e. seig).
- Non-'cenc' encryption scheme when using -decryption_key.
This removes support for saio/saiz atoms, but it was incorrect before.
A follow-up change will add correct support for those.
Signed-off-by: Jacob Trimble <modmaker(a)google.com>
---
libavformat/isom.h | 20 +-
libavformat/mov.c | 404 +++++++++++++++++++++------------
libavutil/aes_ctr.c | 11 +-
libavutil/aes_ctr.h | 4 +-
libavutil/encryption_info.c | 17 ++
libavutil/encryption_info.h | 6 +
libavutil/tests/aes_ctr.c | 2 +-
tests/fate/mov.mak | 8 +
tests/ref/fate/mov-frag-encrypted | 57 +++++
tests/ref/fate/mov-tenc-only-encrypted | 57 +++++
10 files changed, 426 insertions(+), 160 deletions(-)
create mode 100644 tests/ref/fate/mov-frag-encrypted
create mode 100644 tests/ref/fate/mov-tenc-only-encrypted
diff --git a/libavformat/isom.h b/libavformat/isom.h
index 65676fb0f5..3794b1f0fd 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -27,6 +27,7 @@
#include <stddef.h>
#include <stdint.h>
+#include "libavutil/encryption_info.h"
#include "libavutil/mastering_display_metadata.h"
#include "libavutil/spherical.h"
#include "libavutil/stereo3d.h"
@@ -108,12 +109,20 @@ typedef struct MOVSbgp {
unsigned int index;
} MOVSbgp;
+typedef struct MOVEncryptionIndex {
+ // Individual encrypted samples. If there are no elements, then the default
+ // settings will be used.
+ unsigned int nb_encrypted_samples;
+ AVEncryptionInfo **encrypted_samples;
+} MOVEncryptionIndex;
+
typedef struct MOVFragmentStreamInfo {
int id;
int64_t sidx_pts;
int64_t first_tfra_pts;
int64_t tfdt_dts;
int index_entry;
+ MOVEncryptionIndex *encryption_index;
} MOVFragmentStreamInfo;
typedef struct MOVFragmentIndexItem {
@@ -214,15 +223,10 @@ typedef struct MOVStreamContext {
int has_sidx; // If there is an sidx entry for this stream.
struct {
- int use_subsamples;
- uint8_t* auxiliary_info;
- uint8_t* auxiliary_info_end;
- uint8_t* auxiliary_info_pos;
- uint8_t auxiliary_info_default_size;
- uint8_t* auxiliary_info_sizes;
- size_t auxiliary_info_sizes_count;
- int64_t auxiliary_info_index;
struct AVAESCTR* aes_ctr;
+ unsigned int per_sample_iv_size; // Either 0, 8, or 16.
+ AVEncryptionInfo *default_encrypted_sample;
+ MOVEncryptionIndex *encryption_index;
} cenc;
} MOVStreamContext;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 22faecfc17..eb3fb71e2a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1324,6 +1324,7 @@ static int update_frag_index(MOVContext *c, int64_t offset)
frag_stream_info[i].tfdt_dts = AV_NOPTS_VALUE;
frag_stream_info[i].first_tfra_pts = AV_NOPTS_VALUE;
frag_stream_info[i].index_entry = -1;
+ frag_stream_info[i].encryption_index = NULL;
}
if (index < c->frag_index.nb_items)
@@ -5710,117 +5711,224 @@ static int mov_read_frma(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0;
}
-static int mov_read_senc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+/**
+ * Gets the current encryption info and associated current stream context. If
+ * we are parsing a track fragment, this will return the specific encryption
+ * info for this fragment; otherwise this will return the global encryption
+ * info for the current stream.
+ */
+static int get_current_encryption_info(MOVContext *c, MOVEncryptionIndex **encryption_index, MOVStreamContext **sc)
{
+ MOVFragmentStreamInfo *frag_stream_info;
AVStream *st;
- MOVStreamContext *sc;
- size_t auxiliary_info_size;
+ int i;
- if (c->decryption_key_len == 0 || c->fc->nb_streams < 1)
- return 0;
+ frag_stream_info = get_current_frag_stream_info(&c->frag_index);
+ if (frag_stream_info) {
+ for (i = 0; i < c->fc->nb_streams; i++) {
+ if (c->fc->streams[i]->id == frag_stream_info->id) {
+ st = c->fc->streams[i];
+ break;
+ }
+ }
+ if (i == c->fc->nb_streams)
+ return 0;
+ *sc = st->priv_data;
- st = c->fc->streams[c->fc->nb_streams - 1];
- sc = st->priv_data;
+ if (!frag_stream_info->encryption_index) {
+ frag_stream_info->encryption_index = av_mallocz(sizeof(MOVEncryptionIndex));
+ if (!frag_stream_info->encryption_index)
+ return AVERROR(ENOMEM);
+ }
+ *encryption_index = frag_stream_info->encryption_index;
+ return 1;
+ } else {
+ // No current track fragment, using stream level encryption info.
- if (sc->cenc.aes_ctr) {
- av_log(c->fc, AV_LOG_ERROR, "duplicate senc atom\n");
- return AVERROR_INVALIDDATA;
+ if (c->fc->nb_streams < 1)
+ return 0;
+ st = c->fc->streams[c->fc->nb_streams - 1];
+ *sc = st->priv_data;
+
+ if (!(*sc)->cenc.encryption_index) {
+ (*sc)->cenc.encryption_index = av_mallocz(sizeof(MOVEncryptionIndex));
+ if (!(*sc)->cenc.encryption_index)
+ return AVERROR(ENOMEM);
+ }
+
+ *encryption_index = (*sc)->cenc.encryption_index;
+ return 1;
}
+}
- avio_r8(pb); /* version */
- sc->cenc.use_subsamples = avio_rb24(pb) & 0x02; /* flags */
+static int mov_read_sample_encryption_info(MOVContext *c, AVIOContext *pb, MOVStreamContext *sc, AVEncryptionInfo **sample, int use_subsamples)
+{
+ int i;
+ unsigned int subsample_count;
+ AVSubsampleEncryptionInfo *subsamples;
- avio_rb32(pb); /* entries */
+ *sample = av_encryption_info_clone(sc->cenc.default_encrypted_sample);
+ if (!*sample)
+ return AVERROR(ENOMEM);
- if (atom.size < 8 || atom.size > FFMIN(INT_MAX, SIZE_MAX)) {
- av_log(c->fc, AV_LOG_ERROR, "senc atom size %"PRId64" invalid\n", atom.size);
- return AVERROR_INVALIDDATA;
+ if (sc->cenc.per_sample_iv_size != 0) {
+ if (avio_read(pb, (*sample)->iv, sc->cenc.per_sample_iv_size) != sc->cenc.per_sample_iv_size) {
+ av_log(c->fc, AV_LOG_ERROR, "failed to read the initialization vector");
+ return AVERROR_INVALIDDATA;
+ }
}
- /* save the auxiliary info as is */
- auxiliary_info_size = atom.size - 8;
+ if (use_subsamples) {
+ subsample_count = avio_rb16(pb);
- sc->cenc.auxiliary_info = av_malloc(auxiliary_info_size);
- if (!sc->cenc.auxiliary_info) {
- return AVERROR(ENOMEM);
+ subsamples = av_realloc((*sample)->subsamples, sizeof(AVSubsampleEncryptionInfo) * subsample_count);
+ if (!subsamples) {
+ av_encryption_info_free(*sample);
+ return AVERROR(ENOMEM);
+ }
+ (*sample)->subsamples = subsamples;
+ (*sample)->subsample_count = subsample_count;
+
+ for (i = 0; i < subsample_count; i++) {
+ (*sample)->subsamples[i].bytes_of_clear_data = avio_rb16(pb);
+ (*sample)->subsamples[i].bytes_of_protected_data = avio_rb32(pb);
+ }
}
- sc->cenc.auxiliary_info_end = sc->cenc.auxiliary_info + auxiliary_info_size;
- sc->cenc.auxiliary_info_pos = sc->cenc.auxiliary_info;
- sc->cenc.auxiliary_info_index = 0;
+ return 0;
+}
- if (avio_read(pb, sc->cenc.auxiliary_info, auxiliary_info_size) != auxiliary_info_size) {
- av_log(c->fc, AV_LOG_ERROR, "failed to read the auxiliary info");
- return AVERROR_INVALIDDATA;
+static int mov_read_senc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+ MOVEncryptionIndex *encryption_index;
+ MOVStreamContext *sc;
+ int use_subsamples, ret;
+ unsigned int sample_count, i;
+
+ ret = get_current_encryption_info(c, &encryption_index, &sc);
+ if (ret != 1)
+ return ret;
+
+ if (encryption_index->nb_encrypted_samples) {
+ // This can happen if we have both saio/saiz and senc atoms.
+ av_log(c->fc, AV_LOG_DEBUG, "ignoring duplicate encryption info in senc\n");
+ return 0;
}
- /* initialize the cipher */
- sc->cenc.aes_ctr = av_aes_ctr_alloc();
- if (!sc->cenc.aes_ctr) {
+ avio_r8(pb); /* version */
+ use_subsamples = avio_rb24(pb) & 0x02; /* flags */
+
+ sample_count = avio_rb32(pb);
+
+ encryption_index->encrypted_samples = av_mallocz_array(sizeof(AVEncryptionInfo*), sample_count);
+ if (!encryption_index->encrypted_samples) {
return AVERROR(ENOMEM);
}
+ encryption_index->nb_encrypted_samples = sample_count;
- return av_aes_ctr_init(sc->cenc.aes_ctr, c->decryption_key);
+ for (i = 0; i < sample_count; i++) {
+ ret = mov_read_sample_encryption_info(c, pb, sc, &encryption_index->encrypted_samples[i], use_subsamples);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
}
-static int mov_read_saiz(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+static int mov_read_schm(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
AVStream *st;
MOVStreamContext *sc;
- size_t data_size;
- int atom_header_size;
- int flags;
- if (c->decryption_key_len == 0 || c->fc->nb_streams < 1)
+ if (c->fc->nb_streams < 1)
return 0;
-
- st = c->fc->streams[c->fc->nb_streams - 1];
+ st = c->fc->streams[c->fc->nb_streams-1];
sc = st->priv_data;
- if (sc->cenc.auxiliary_info_sizes || sc->cenc.auxiliary_info_default_size) {
- av_log(c->fc, AV_LOG_ERROR, "duplicate saiz atom\n");
- return AVERROR_INVALIDDATA;
+ if (sc->pseudo_stream_id != 0) {
+ av_log(c->fc, AV_LOG_ERROR, "schm boxes are only supported in first sample descriptor\n");
+ return AVERROR_PATCHWELCOME;
}
- atom_header_size = 9;
-
- avio_r8(pb); /* version */
- flags = avio_rb24(pb);
+ if (atom.size < 8)
+ return AVERROR_INVALIDDATA;
- if ((flags & 0x01) != 0) {
- atom_header_size += 8;
+ avio_rb32(pb); /* version and flags */
- avio_rb32(pb); /* info type */
- avio_rb32(pb); /* info type param */
+ if (!sc->cenc.default_encrypted_sample) {
+ sc->cenc.default_encrypted_sample = av_encryption_info_alloc(0, 16, 16);
+ if (!sc->cenc.default_encrypted_sample) {
+ return AVERROR(ENOMEM);
+ }
}
- sc->cenc.auxiliary_info_default_size = avio_r8(pb);
- avio_rb32(pb); /* entries */
+ sc->cenc.default_encrypted_sample->scheme = avio_rl32(pb);
+ return 0;
+}
- if (atom.size <= atom_header_size) {
+static int mov_read_tenc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+ AVStream *st;
+ MOVStreamContext *sc;
+ unsigned int version, pattern, is_protected, iv_size;
+
+ if (c->fc->nb_streams < 1)
return 0;
+ st = c->fc->streams[c->fc->nb_streams-1];
+ sc = st->priv_data;
+
+ if (sc->pseudo_stream_id != 0) {
+ av_log(c->fc, AV_LOG_ERROR, "tenc atom are only supported in first sample descriptor\n");
+ return AVERROR_PATCHWELCOME;
}
- if (atom.size > FFMIN(INT_MAX, SIZE_MAX)) {
- av_log(c->fc, AV_LOG_ERROR, "saiz atom auxiliary_info_sizes size %"PRId64" invalid\n", atom.size);
- return AVERROR_INVALIDDATA;
+ if (!sc->cenc.default_encrypted_sample) {
+ sc->cenc.default_encrypted_sample = av_encryption_info_alloc(0, 16, 16);
+ if (!sc->cenc.default_encrypted_sample) {
+ return AVERROR(ENOMEM);
+ }
}
- /* save the auxiliary info sizes as is */
- data_size = atom.size - atom_header_size;
+ if (atom.size < 20)
+ return AVERROR_INVALIDDATA;
- sc->cenc.auxiliary_info_sizes = av_malloc(data_size);
- if (!sc->cenc.auxiliary_info_sizes) {
- return AVERROR(ENOMEM);
- }
+ version = avio_r8(pb); /* version */
+ avio_rb24(pb); /* flags */
- sc->cenc.auxiliary_info_sizes_count = data_size;
+ avio_r8(pb); /* reserved */
+ pattern = avio_r8(pb);
+
+ if (version > 0) {
+ sc->cenc.default_encrypted_sample->crypt_byte_block = pattern >> 4;
+ sc->cenc.default_encrypted_sample->skip_byte_block = pattern & 0xf;
+ }
- if (avio_read(pb, sc->cenc.auxiliary_info_sizes, data_size) != data_size) {
- av_log(c->fc, AV_LOG_ERROR, "failed to read the auxiliary info sizes");
+ is_protected = avio_r8(pb);
+ if (is_protected && !sc->cenc.encryption_index) {
+ // The whole stream should be by-default encrypted.
+ sc->cenc.encryption_index = av_mallocz(sizeof(MOVEncryptionIndex));
+ if (!sc->cenc.encryption_index)
+ return AVERROR(ENOMEM);
+ }
+ sc->cenc.per_sample_iv_size = avio_r8(pb);
+ if (avio_read(pb, sc->cenc.default_encrypted_sample->key_id, 16) != 16) {
+ av_log(c->fc, AV_LOG_ERROR, "failed to read the default key ID");
return AVERROR_INVALIDDATA;
}
+ if (is_protected && !sc->cenc.per_sample_iv_size) {
+ iv_size = avio_r8(pb);
+ if (iv_size != 8 && iv_size != 16) {
+ av_log(c->fc, AV_LOG_ERROR, "invalid default_constant_IV_size in tenc atom\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (avio_read(pb, sc->cenc.default_encrypted_sample->iv, iv_size) != iv_size) {
+ av_log(c->fc, AV_LOG_ERROR, "failed to read the default IV");
+ return AVERROR_INVALIDDATA;
+ }
+ }
+
return 0;
}
@@ -5861,108 +5969,103 @@ static int mov_read_dfla(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0;
}
-static int mov_seek_auxiliary_info(MOVContext *c, MOVStreamContext *sc, int64_t index)
+static int cenc_decrypt(MOVContext *c, MOVStreamContext *sc, AVEncryptionInfo *sample, uint8_t *input, int size)
{
- size_t auxiliary_info_seek_offset = 0;
- int i;
-
- if (sc->cenc.auxiliary_info_default_size) {
- auxiliary_info_seek_offset = (size_t)sc->cenc.auxiliary_info_default_size * index;
- } else if (sc->cenc.auxiliary_info_sizes) {
- if (index > sc->cenc.auxiliary_info_sizes_count) {
- av_log(c, AV_LOG_ERROR, "current sample %"PRId64" greater than the number of auxiliary info sample sizes %"SIZE_SPECIFIER"\n",
- index, sc->cenc.auxiliary_info_sizes_count);
- return AVERROR_INVALIDDATA;
- }
-
- for (i = 0; i < index; i++) {
- auxiliary_info_seek_offset += sc->cenc.auxiliary_info_sizes[i];
- }
- }
+ int i, ret;
- if (auxiliary_info_seek_offset > sc->cenc.auxiliary_info_end - sc->cenc.auxiliary_info) {
- av_log(c, AV_LOG_ERROR, "auxiliary info offset %"SIZE_SPECIFIER" greater than auxiliary info size %"SIZE_SPECIFIER"\n",
- auxiliary_info_seek_offset, (size_t)(sc->cenc.auxiliary_info_end - sc->cenc.auxiliary_info));
- return AVERROR_INVALIDDATA;
+ if (sample->scheme != MKTAG('c','e','n','c') || sample->crypt_byte_block != 0 || sample->skip_byte_block != 0) {
+ av_log(c->fc, AV_LOG_ERROR, "Only the 'cenc' encryption scheme is supported\n");
+ return AVERROR_PATCHWELCOME;
}
- sc->cenc.auxiliary_info_pos = sc->cenc.auxiliary_info + auxiliary_info_seek_offset;
- sc->cenc.auxiliary_info_index = index;
- return 0;
-}
-
-static int cenc_filter(MOVContext *c, MOVStreamContext *sc, int64_t index, uint8_t *input, int size)
-{
- uint32_t encrypted_bytes;
- uint16_t subsample_count;
- uint16_t clear_bytes;
- uint8_t* input_end = input + size;
- int ret;
+ if (!sc->cenc.aes_ctr) {
+ /* initialize the cipher */
+ sc->cenc.aes_ctr = av_aes_ctr_alloc();
+ if (!sc->cenc.aes_ctr) {
+ return AVERROR(ENOMEM);
+ }
- if (index != sc->cenc.auxiliary_info_index) {
- ret = mov_seek_auxiliary_info(c, sc, index);
+ ret = av_aes_ctr_init(sc->cenc.aes_ctr, c->decryption_key);
if (ret < 0) {
return ret;
}
}
- /* read the iv */
- if (AES_CTR_IV_SIZE > sc->cenc.auxiliary_info_end - sc->cenc.auxiliary_info_pos) {
- av_log(c->fc, AV_LOG_ERROR, "failed to read iv from the auxiliary info\n");
- return AVERROR_INVALIDDATA;
- }
-
- av_aes_ctr_set_iv(sc->cenc.aes_ctr, sc->cenc.auxiliary_info_pos);
- sc->cenc.auxiliary_info_pos += AES_CTR_IV_SIZE;
+ av_aes_ctr_set_full_iv(sc->cenc.aes_ctr, sample->iv);
- if (!sc->cenc.use_subsamples)
+ if (!sample->subsample_count)
{
/* decrypt the whole packet */
av_aes_ctr_crypt(sc->cenc.aes_ctr, input, input, size);
return 0;
}
- /* read the subsample count */
- if (sizeof(uint16_t) > sc->cenc.auxiliary_info_end - sc->cenc.auxiliary_info_pos) {
- av_log(c->fc, AV_LOG_ERROR, "failed to read subsample count from the auxiliary info\n");
- return AVERROR_INVALIDDATA;
- }
-
- subsample_count = AV_RB16(sc->cenc.auxiliary_info_pos);
- sc->cenc.auxiliary_info_pos += sizeof(uint16_t);
-
- for (; subsample_count > 0; subsample_count--)
+ for (i = 0; i < sample->subsample_count; i++)
{
- if (6 > sc->cenc.auxiliary_info_end - sc->cenc.auxiliary_info_pos) {
- av_log(c->fc, AV_LOG_ERROR, "failed to read subsample from the auxiliary info\n");
- return AVERROR_INVALIDDATA;
- }
-
- /* read the number of clear / encrypted bytes */
- clear_bytes = AV_RB16(sc->cenc.auxiliary_info_pos);
- sc->cenc.auxiliary_info_pos += sizeof(uint16_t);
- encrypted_bytes = AV_RB32(sc->cenc.auxiliary_info_pos);
- sc->cenc.auxiliary_info_pos += sizeof(uint32_t);
-
- if ((uint64_t)clear_bytes + encrypted_bytes > input_end - input) {
+ if (sample->subsamples[i].bytes_of_clear_data + sample->subsamples[i].bytes_of_protected_data > size) {
av_log(c->fc, AV_LOG_ERROR, "subsample size exceeds the packet size left\n");
return AVERROR_INVALIDDATA;
}
/* skip the clear bytes */
- input += clear_bytes;
+ input += sample->subsamples[i].bytes_of_clear_data;
+ size -= sample->subsamples[i].bytes_of_clear_data;
/* decrypt the encrypted bytes */
- av_aes_ctr_crypt(sc->cenc.aes_ctr, input, input, encrypted_bytes);
- input += encrypted_bytes;
+ av_aes_ctr_crypt(sc->cenc.aes_ctr, input, input, sample->subsamples[i].bytes_of_protected_data);
+ input += sample->subsamples[i].bytes_of_protected_data;
+ size -= sample->subsamples[i].bytes_of_protected_data;
}
- if (input < input_end) {
+ if (size > 0) {
av_log(c->fc, AV_LOG_ERROR, "leftover packet bytes after subsample processing\n");
return AVERROR_INVALIDDATA;
}
- sc->cenc.auxiliary_info_index++;
+ return 0;
+}
+
+static int cenc_filter(MOVContext *mov, MOVStreamContext *sc, AVPacket *pkt, int current_index)
+{
+ MOVFragmentStreamInfo *frag_stream_info;
+ MOVEncryptionIndex *encryption_index;
+ AVEncryptionInfo *encrypted_sample;
+ int encrypted_index;
+
+ frag_stream_info = get_current_frag_stream_info(&mov->frag_index);
+ encrypted_index = current_index;
+ encryption_index = NULL;
+ if (frag_stream_info) {
+ // Note this only supports encryption info in the first sample descriptor.
+ if (mov->fragment.stsd_id == 1) {
+ if (frag_stream_info->encryption_index) {
+ encrypted_index = current_index - frag_stream_info->index_entry;
+ encryption_index = frag_stream_info->encryption_index;
+ } else {
+ encryption_index = sc->cenc.encryption_index;
+ }
+ }
+ } else {
+ encryption_index = sc->cenc.encryption_index;
+ }
+
+ if (encryption_index) {
+ if (!encryption_index->nb_encrypted_samples) {
+ // Full-sample encryption with default settings.
+ encrypted_sample = sc->cenc.default_encrypted_sample;
+ } else if (encrypted_index >= 0 && encrypted_index < encryption_index->nb_encrypted_samples) {
+ // Per-sample setting override.
+ encrypted_sample = encryption_index->encrypted_samples[encrypted_index];
+ } else {
+ av_log(mov->fc, AV_LOG_ERROR, "Incorrect number of samples in encryption info\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (mov->decryption_key) {
+ return cenc_decrypt(mov, sc, encrypted_sample, pkt->data, pkt->size);
+ }
+ }
+
return 0;
}
@@ -6091,7 +6194,9 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
{ MKTAG('s','i','n','f'), mov_read_default },
{ MKTAG('f','r','m','a'), mov_read_frma },
{ MKTAG('s','e','n','c'), mov_read_senc },
-{ MKTAG('s','a','i','z'), mov_read_saiz },
+{ MKTAG('s','c','h','m'), mov_read_schm },
+{ MKTAG('s','c','h','i'), mov_read_default },
+{ MKTAG('t','e','n','c'), mov_read_tenc },
{ MKTAG('d','f','L','a'), mov_read_dfla },
{ MKTAG('s','t','3','d'), mov_read_st3d }, /* stereoscopic 3D video box */
{ MKTAG('s','v','3','d'), mov_read_sv3d }, /* spherical video box */
@@ -6477,6 +6582,16 @@ static int mov_read_timecode_track(AVFormatContext *s, AVStream *st)
return 0;
}
+static void mov_free_encryption_index(MOVEncryptionIndex **index) {
+ int i;
+ if (!index || !*index) return;
+ for (i = 0; i < (*index)->nb_encrypted_samples; i++) {
+ av_encryption_info_free((*index)->encrypted_samples[i]);
+ }
+ av_freep(&(*index)->encrypted_samples);
+ av_freep(index);
+}
+
static int mov_read_close(AVFormatContext *s)
{
MOVContext *mov = s->priv_data;
@@ -6519,8 +6634,8 @@ static int mov_read_close(AVFormatContext *s)
av_freep(&sc->extradata);
av_freep(&sc->extradata_size);
- av_freep(&sc->cenc.auxiliary_info);
- av_freep(&sc->cenc.auxiliary_info_sizes);
+ mov_free_encryption_index(&sc->cenc.encryption_index);
+ av_encryption_info_free(sc->cenc.default_encrypted_sample);
av_aes_ctr_free(sc->cenc.aes_ctr);
av_freep(&sc->stereo3d);
@@ -6545,6 +6660,10 @@ static int mov_read_close(AVFormatContext *s)
av_freep(&mov->bitrates);
for (i = 0; i < mov->frag_index.nb_items; i++) {
+ MOVFragmentStreamInfo *frag = mov->frag_index.item[i].stream_info;
+ if (frag) {
+ mov_free_encryption_index(&frag->encryption_index);
+ }
av_freep(&mov->frag_index.item[i].stream_info);
}
av_freep(&mov->frag_index.item);
@@ -7115,12 +7234,9 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
if (mov->aax_mode)
aax_filter(pkt->data, pkt->size, mov);
- if (sc->cenc.aes_ctr) {
- ret = cenc_filter(mov, sc, current_index, pkt->data, pkt->size);
- if (ret) {
- return ret;
- }
- }
+ ret = cenc_filter(mov, sc, pkt, current_index);
+ if (ret < 0)
+ return ret;
return 0;
}
diff --git a/libavutil/aes_ctr.c b/libavutil/aes_ctr.c
index e9c568fe0d..6ed69c8e10 100644
--- a/libavutil/aes_ctr.c
+++ b/libavutil/aes_ctr.c
@@ -38,10 +38,9 @@ struct AVAESCTR *av_aes_ctr_alloc(void)
return av_mallocz(sizeof(struct AVAESCTR));
}
-void av_aes_ctr_set_iv(struct AVAESCTR *a, const uint8_t* iv)
+void av_aes_ctr_set_full_iv(struct AVAESCTR *a, const uint8_t* iv)
{
- memcpy(a->counter, iv, AES_CTR_IV_SIZE);
- memset(a->counter + AES_CTR_IV_SIZE, 0, sizeof(a->counter) - AES_CTR_IV_SIZE);
+ memcpy(a->counter, iv, sizeof(a->counter));
a->block_offset = 0;
}
@@ -52,12 +51,14 @@ const uint8_t* av_aes_ctr_get_iv(struct AVAESCTR *a)
void av_aes_ctr_set_random_iv(struct AVAESCTR *a)
{
- uint32_t iv[2];
+ uint32_t iv[4];
iv[0] = av_get_random_seed();
iv[1] = av_get_random_seed();
+ iv[2] = 0;
+ iv[3] = 0;
- av_aes_ctr_set_iv(a, (uint8_t*)iv);
+ av_aes_ctr_set_full_iv(a, (uint8_t*)iv);
}
int av_aes_ctr_init(struct AVAESCTR *a, const uint8_t *key)
diff --git a/libavutil/aes_ctr.h b/libavutil/aes_ctr.h
index f596fa6a46..5995b37bec 100644
--- a/libavutil/aes_ctr.h
+++ b/libavutil/aes_ctr.h
@@ -67,9 +67,9 @@ const uint8_t* av_aes_ctr_get_iv(struct AVAESCTR *a);
void av_aes_ctr_set_random_iv(struct AVAESCTR *a);
/**
- * Forcefully change the iv
+ * Forcefully change the "full" 16-byte iv, including the counter
*/
-void av_aes_ctr_set_iv(struct AVAESCTR *a, const uint8_t* iv);
+void av_aes_ctr_set_full_iv(struct AVAESCTR *a, const uint8_t* iv);
/**
* Increment the top 64 bit of the iv (performed after each frame)
diff --git a/libavutil/encryption_info.c b/libavutil/encryption_info.c
index 76796b50ee..ad7ce3656a 100644
--- a/libavutil/encryption_info.c
+++ b/libavutil/encryption_info.c
@@ -59,6 +59,23 @@ AVEncryptionInfo *av_encryption_info_alloc(uint32_t subsample_count, uint32_t ke
return info;
}
+AVEncryptionInfo *av_encryption_info_clone(const AVEncryptionInfo *info)
+{
+ AVEncryptionInfo *ret;
+
+ ret = av_encryption_info_alloc(info->subsample_count, info->key_id_size, info->iv_size);
+ if (!ret)
+ return NULL;
+
+ ret->scheme = info->scheme;
+ ret->crypt_byte_block = info->crypt_byte_block;
+ ret->skip_byte_block = info->skip_byte_block;
+ memcpy(ret->iv, info->iv, info->iv_size);
+ memcpy(ret->key_id, info->key_id, info->key_id_size);
+ memcpy(ret->subsamples, info->subsamples, sizeof(AVSubsampleEncryptionInfo) * info->subsample_count);
+ return ret;
+}
+
void av_encryption_info_free(AVEncryptionInfo *info)
{
if (info) {
diff --git a/libavutil/encryption_info.h b/libavutil/encryption_info.h
index 6c2eee80f6..591ac14957 100644
--- a/libavutil/encryption_info.h
+++ b/libavutil/encryption_info.h
@@ -92,6 +92,12 @@ typedef struct AVEncryptionInfo {
*/
AVEncryptionInfo *av_encryption_info_alloc(uint32_t subsample_count, uint32_t key_id_size, uint32_t iv_size);
+/**
+ * Allocates an AVEncryptionInfo structure with a copy of the given data.
+ * @return The new AVEncryptionInfo structure, or NULL on error.
+ */
+AVEncryptionInfo *av_encryption_info_clone(const AVEncryptionInfo *info);
+
/**
* Frees the given encryption info object. This MUST NOT be used to free the
* side-data data pointer, that should use normal side-data methods.
diff --git a/libavutil/tests/aes_ctr.c b/libavutil/tests/aes_ctr.c
index c5ebeda7ac..00fdb05d13 100644
--- a/libavutil/tests/aes_ctr.c
+++ b/libavutil/tests/aes_ctr.c
@@ -45,7 +45,7 @@ int main (void)
av_aes_ctr_set_random_iv(ae);
iv = av_aes_ctr_get_iv(ae);
- av_aes_ctr_set_iv(ad, iv);
+ av_aes_ctr_set_full_iv(ad, iv);
av_aes_ctr_crypt(ae, tmp, plain, sizeof(tmp));
av_aes_ctr_crypt(ad, tmp, tmp, sizeof(tmp));
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 64f92e9488..90ee06a000 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -6,6 +6,8 @@ FATE_MOV = fate-mov-3elist \
fate-mov-1elist-ends-last-bframe \
fate-mov-2elist-elist1-ends-bframe \
fate-mov-3elist-encrypted \
+ fate-mov-frag-encrypted \
+ fate-mov-tenc-only-encrypted \
fate-mov-invalid-elst-entry-count \
fate-mov-gpmf-remux \
fate-mov-440hz-10ms \
@@ -37,6 +39,12 @@ fate-mov-3elist-1ctts: CMD = framemd5 -i $(TARGET_SAMPLES)/mov/mov-3elist-1ctts.
# Edit list with encryption
fate-mov-3elist-encrypted: CMD = framemd5 -decryption_key 12345678901234567890123456789012 -i $(TARGET_SAMPLES)/mov/mov-3elist-encrypted.mov
+# Fragmented encryption with senc boxes in movie fragments.
+fate-mov-frag-encrypted: CMD = framemd5 -decryption_key 12345678901234567890123456789012 -i $(TARGET_SAMPLES)/mov/mov-frag-encrypted.mp4
+
+# Full-sample encryption and constant IV using only tenc atom (no senc/saio/saiz).
+fate-mov-tenc-only-encrypted: CMD = framemd5 -decryption_key 12345678901234567890123456789012 -i $(TARGET_SAMPLES)/mov/mov-tenc-only-encrypted.mp4
+
# Makes sure that the CTTS is also modified when we fix avindex in mov.c while parsing edit lists.
fate-mov-elist-starts-ctts-2ndsample: CMD = framemd5 -i $(TARGET_SAMPLES)/mov/mov-elist-starts-ctts-2ndsample.mov
diff --git a/tests/ref/fate/mov-frag-encrypted b/tests/ref/fate/mov-frag-encrypted
new file mode 100644
index 0000000000..e6c109b566
--- /dev/null
+++ b/tests/ref/fate/mov-frag-encrypted
@@ -0,0 +1,57 @@
+#format: frame checksums
+#version: 2
+#hash: MD5
+#tb 0: 1/24
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 120x52
+#sar 0: 544/545
+#stream#, dts, pts, duration, size, hash
+0, 0, 0, 1, 9360, 920bdc277a6a31c1daed9aca44b10caf
+0, 1, 1, 1, 9360, f1c0b61fef593de57cb97be7fa846569
+0, 2, 2, 1, 9360, 6ef32d9d4398355aebf6d3fb11d51d3f
+0, 3, 3, 1, 9360, d38fd3ef1e5a92fc109b8dd9eb6dadeb
+0, 4, 4, 1, 9360, 54cc0c8a25d2f14f32663837d5e646f1
+0, 5, 5, 1, 9360, b4b6829726dc3decb8b80ba0c35bcf30
+0, 6, 6, 1, 9360, fca3f941e60a2f0a4ce30d5e0efbec3c
+0, 7, 7, 1, 9360, cda6e26b6c1039ff3d229b262c9210c3
+0, 8, 8, 1, 9360, f0d69255e3a27a8b4ae8a4b7b210929d
+0, 9, 9, 1, 9360, 12cb23dd4e32af9c3b35f943714e3fdd
+0, 10, 10, 1, 9360, 082aaf3216124ddcecb422fe5c832e82
+0, 11, 11, 1, 9360, ff37bb8cd6bd0412a3b3cb45db54afc9
+0, 12, 12, 1, 9360, dfb9085441575732844b6c2f05d5f542
+0, 13, 13, 1, 9360, 0017100feaaa9fc7eacd2447d50d7542
+0, 14, 14, 1, 9360, 4e2f1b8c4e04c59934c2f58541e62613
+0, 15, 15, 1, 9360, 27a44dfea7cd2d30e488194c34ab473c
+0, 16, 16, 1, 9360, fc7b56bd95e990a33cf575d1ef820902
+0, 17, 17, 1, 9360, fa2d1609e69714dffc410e65f3c8b755
+0, 18, 18, 1, 9360, 705d7429f447cb13febe202d567795f2
+0, 19, 19, 1, 9360, 234802ce86e868faaf2cd40a286846ea
+0, 20, 20, 1, 9360, 2f0354b40d211d0a4ade4568bea4f85e
+0, 21, 21, 1, 9360, e96af3b6c0cc931463ca77d6be0f1148
+0, 22, 22, 1, 9360, 04a904d798361959971361401879c7e4
+0, 23, 23, 1, 9360, 2f119642340df6d25362b5590ded46b7
+0, 24, 24, 1, 9360, 5993fca2e60050706f857ac76e48f386
+0, 25, 25, 1, 9360, 2ff3b5775fed3d527bfbbeea786787fe
+0, 26, 26, 1, 9360, 42024dbe23d3fb5b0d8987ae1ce390a8
+0, 27, 27, 1, 9360, d804204f0bd9db5f6a758e2c934d9e38
+0, 28, 28, 1, 9360, e322712e6e34c58ec1a2ab5e2c1e3bfe
+0, 29, 29, 1, 9360, 3975bd1a5f6a6b6260276777f9de611e
+0, 30, 30, 1, 9360, 4388f0412efc6310706a7cdedc859ea9
+0, 31, 31, 1, 9360, b4b9a11b0b86635267345a569640e8d4
+0, 32, 32, 1, 9360, 31879c7b8d6b67a4209ffde786bb8cb4
+0, 33, 33, 1, 9360, 4b6dc02d7c889fe4abd4e013b25f585a
+0, 34, 34, 1, 9360, dc73aae82bd39a1220d1106c8d3e8252
+0, 35, 35, 1, 9360, 54c7dfbd49f312806f6c1a89f7c2c36f
+0, 36, 36, 1, 9360, 150abc64f8994d444a521ea90570443c
+0, 37, 37, 1, 9360, d277cdc7dcadbe0016f2e950459e7ebf
+0, 38, 38, 1, 9360, 2196bf338ead90ea54687b85c73c8229
+0, 39, 39, 1, 9360, 53ce5da5365abc0bd3217dd98e7c465d
+0, 40, 40, 1, 9360, 34ee9832aea55c0c4e6f4381c413c10e
+0, 41, 41, 1, 9360, 1769c7b5849e4681119067a06ac29a4f
+0, 42, 42, 1, 9360, 71f53df739ef283a5184c91ef4b158e8
+0, 43, 43, 1, 9360, d2d394739e9a59c06f0354c16843cb63
+0, 44, 44, 1, 9360, d8e458e92ae29344505a24a3059fc584
+0, 45, 45, 1, 9360, 0f1b11a09911851b798df2ef76253a7f
+0, 46, 46, 1, 9360, 5c4a9f22baecf4e749c0d5c65a4f1007
+0, 47, 47, 1, 9360, 3e2b7e7262fdca08d9d1ef6070125c4b
diff --git a/tests/ref/fate/mov-tenc-only-encrypted b/tests/ref/fate/mov-tenc-only-encrypted
new file mode 100644
index 0000000000..1d57aa6a80
--- /dev/null
+++ b/tests/ref/fate/mov-tenc-only-encrypted
@@ -0,0 +1,57 @@
+#format: frame checksums
+#version: 2
+#hash: MD5
+#tb 0: 1/24
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 1024x436
+#sar 0: 1/1
+#stream#, dts, pts, duration, size, hash
+0, 0, 0, 1, 669696, f48f296a85eda5ba069dc851a3228bef
+0, 1, 1, 1, 669696, a50c5f69bfa3387d49b5bdf738e6529c
+0, 2, 2, 1, 669696, 05061299003760f6a4795b408f72aa31
+0, 3, 3, 1, 669696, 2572119f0b0cdd83f8a7e06252cecd3b
+0, 4, 4, 1, 669696, 29fe6a6bdb4a69018e318886a297f07e
+0, 5, 5, 1, 669696, e8233c7fbaecfbff965c7dfdd3982b1b
+0, 6, 6, 1, 669696, d9259df9880ff5d4a4b38282e67f407b
+0, 7, 7, 1, 669696, 3e8d795195038993503ea9ab6984c915
+0, 8, 8, 1, 669696, bc4e2d253b715a34f85aae1b080e3460
+0, 9, 9, 1, 669696, 09aba8b3a96f53f9268e7420a10bfab6
+0, 10, 10, 1, 669696, 179447977dd580da8b35fb5310a809ca
+0, 11, 11, 1, 669696, 7a0eea9d54577990345f5705ab9882be
+0, 12, 12, 1, 669696, 5bb96eb76f461825740e5938456df759
+0, 13, 13, 1, 669696, bd4ac4a760ead774b9422a27dc071964
+0, 14, 14, 1, 669696, 1cc05f760a9b751fc89e77f2bcc97259
+0, 15, 15, 1, 669696, 825d0dee6f0174ba7102892c7de30b4d
+0, 16, 16, 1, 669696, d26a2ef5267f6bb03c4e1d8514eee0df
+0, 17, 17, 1, 669696, c916ffdeadca76596a8f7fd47914b5ef
+0, 18, 18, 1, 669696, 6e085acfa7fee0658ea0ae6188274c17
+0, 19, 19, 1, 669696, 1e95fa5b3561283f05bf0bd44cb91721
+0, 20, 20, 1, 669696, 37e3d135aba9dfb8b87e441753115374
+0, 21, 21, 1, 669696, 9c398310e8564491de624393c16265ce
+0, 22, 22, 1, 669696, c87209e4d2617bc2ab40a75f455f09da
+0, 23, 23, 1, 669696, 2679c2f8d1d1af21982e245945c1ee60
+0, 24, 24, 1, 669696, 6151ab4781f31c5beb66b356ad547122
+0, 25, 25, 1, 669696, f7ef6293bfb3a6a329061cb6a5ed5a38
+0, 26, 26, 1, 669696, 2f6e666d14dfc407ca0c0f347b13eb08
+0, 27, 27, 1, 669696, 3454fa1730d79b1aa8dbbc865dc150f4
+0, 28, 28, 1, 669696, e93dc683e2453419a0419ab9af0f8f95
+0, 29, 29, 1, 669696, 031eb3154f7f83cf86d42bee66be9cf7
+0, 30, 30, 1, 669696, 1205c36723e88811206c68892d3aaed6
+0, 31, 31, 1, 669696, 7dd7a8a19dcd73b31ddc6a6d0c597a42
+0, 32, 32, 1, 669696, 7c91115368ea2531262a1197468bc3f4
+0, 33, 33, 1, 669696, 3cf6d9ba385e0fff76da33299ed5380c
+0, 34, 34, 1, 669696, 859fc8c3ef049e3c1175a85fb0a90a3d
+0, 35, 35, 1, 669696, 1d09ce6c7027103d99a4d5799f6e72ab
+0, 36, 36, 1, 669696, 3dcb8357408ac88abd734128d8f5dd6f
+0, 37, 37, 1, 669696, 4dafce137a0a5178f6efaec878e64d36
+0, 38, 38, 1, 669696, 44c478f29a1399ed03275a7357f57d48
+0, 39, 39, 1, 669696, 6e9edaac7414c0e14591ac3d4d0b1ac4
+0, 40, 40, 1, 669696, 522e4aaeea0825da27f631a9e690d654
+0, 41, 41, 1, 669696, 85f2502a718440834c40051d30f8a65e
+0, 42, 42, 1, 669696, ae8816f7bd4645ef1a17ee6d09b4c8d2
+0, 43, 43, 1, 669696, 914b006fa92f1eb3e590245749f6810d
+0, 44, 44, 1, 669696, 9406901542e94c429dff46108782ed69
+0, 45, 45, 1, 669696, 324c13641c39eef5c476023e358c0391
+0, 46, 46, 1, 669696, 4058e886e17c22e4eb9da1dd0d6ad891
+0, 47, 47, 1, 669696, 9edf9cd15eea985b42fd1f5035b1d693
--
2.16.0.rc0.223.g4a4ac83678-goog
4
45
23 Jun '18
ticket #5522 output of given samples significantly improved
---
libavcodec/cfhd.c | 181 +++++++++++++++++++++++++++++++++++++++++++-----------
libavcodec/cfhd.h | 9 +++
2 files changed, 155 insertions(+), 35 deletions(-)
diff --git a/libavcodec/cfhd.c b/libavcodec/cfhd.c
index 7ceb803595..051d210355 100644
--- a/libavcodec/cfhd.c
+++ b/libavcodec/cfhd.c
@@ -49,12 +49,15 @@ enum CFHDParam {
SubbandNumber = 48,
Quantization = 53,
ChannelNumber = 62,
+ SampleFlags = 68,
BitsPerComponent = 101,
ChannelWidth = 104,
ChannelHeight = 105,
PrescaleShift = 109,
};
+
+
static av_cold int cfhd_init(AVCodecContext *avctx)
{
CFHDContext *s = avctx->priv_data;
@@ -72,6 +75,13 @@ static void init_plane_defaults(CFHDContext *s)
s->subband_num_actual = 0;
}
+static void init_peak_table_defaults(CFHDContext *s)
+{
+ s->peak.level = 0;
+ s->peak.offset = 0;
+ s->peak.base = NULL;
+}
+
static void init_frame_defaults(CFHDContext *s)
{
s->coded_width = 0;
@@ -86,15 +96,44 @@ static void init_frame_defaults(CFHDContext *s)
s->wavelet_depth = 3;
s->pshift = 1;
s->codebook = 0;
+ s->difference_coding = 0;
+ s->progressive = 0;
init_plane_defaults(s);
+ init_peak_table_defaults(s);
}
/* TODO: merge with VLC tables or use LUT */
-static inline int dequant_and_decompand(int level, int quantisation)
+static inline int dequant_and_decompand(int level, int quantisation, int codebook)
+{
+ if (codebook == 0 || codebook == 1) {
+ int64_t abslevel = abs(level);
+ if (level < 264)
+ return (abslevel + ((768 * abslevel * abslevel * abslevel) / (255 * 255 * 255))) *
+ FFSIGN(level) * quantisation;
+ else
+ return level * quantisation;
+ } else
+ return level * quantisation;
+}
+
+static inline void difference_coding(int16_t *band, int width, int height)
+{
+
+ int i,j;
+ for (i = 0; i < height; i++) {
+ for (j = 1; j < width; j++) {
+ band[j] += band[j-1];
+ }
+ band += width;
+ }
+}
+
+static inline void peak_table(int16_t *band, Peak *peak, int length)
{
- int64_t abslevel = abs(level);
- return (abslevel + ((768 * abslevel * abslevel * abslevel) / (255 * 255 * 255))) *
- FFSIGN(level) * quantisation;
+ int i;
+ for (i = 0; i < length; i++)
+ if (abs(band[i]) > peak->level)
+ band[i] = *(peak->base++);
}
static inline void process_alpha(int16_t *alpha, int width)
@@ -154,6 +193,18 @@ static inline void filter(int16_t *output, ptrdiff_t out_stride,
}
}
+static inline void interlaced_vertical_filter(int16_t *output, int16_t *low, int16_t *high,
+ int width, int linesize, int plane)
+{
+ int i;
+ int16_t even, odd;
+ for (i = 0; i < width; i++) {
+ even = (low[i] - high[i])/2;
+ odd = (low[i] + high[i])/2;
+ output[i] = av_clip_uintp2(even, 10);
+ output[i + linesize] = av_clip_uintp2(odd, 10);
+ }
+}
static void horiz_filter(int16_t *output, int16_t *low, int16_t *high,
int width)
{
@@ -295,6 +346,9 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
uint16_t data = bytestream2_get_be16(&gb);
if (abs_tag8 >= 0x60 && abs_tag8 <= 0x6f) {
av_log(avctx, AV_LOG_DEBUG, "large len %x\n", ((tagu & 0xff) << 16) | data);
+ } else if (tag == SampleFlags) {
+ av_log(avctx, AV_LOG_DEBUG, "Progressive?%"PRIu16"\n", data);
+ s->progressive = data & 0x0001;
} else if (tag == ImageWidth) {
av_log(avctx, AV_LOG_DEBUG, "Width %"PRIu16"\n", data);
s->coded_width = data;
@@ -393,6 +447,8 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
}
av_log(avctx, AV_LOG_DEBUG, "Transform-type? %"PRIu16"\n", data);
} else if (abstag >= 0x4000 && abstag <= 0x40ff) {
+ if (abstag == 0x4001)
+ s->peak.level = 0;
av_log(avctx, AV_LOG_DEBUG, "Small chunk length %d %s\n", data * 4, tag < 0 ? "optional" : "required");
bytestream2_skipu(&gb, data * 4);
} else if (tag == 23) {
@@ -450,7 +506,8 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
s->codebook = data;
av_log(avctx, AV_LOG_DEBUG, "Codebook %i\n", s->codebook);
} else if (tag == 72) {
- s->codebook = data;
+ s->codebook = data & 0xf;
+ s->difference_coding = (data >> 4) & 1;
av_log(avctx, AV_LOG_DEBUG, "Other codebook? %i\n", s->codebook);
} else if (tag == 70) {
av_log(avctx, AV_LOG_DEBUG, "Subsampling or bit-depth flag? %i\n", data);
@@ -477,6 +534,19 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
} else if (tag == -85) {
av_log(avctx, AV_LOG_DEBUG, "Cropped height %"PRIu16"\n", data);
s->cropped_height = data;
+ } else if (tag == -75) {
+ s->peak.offset &= ~0xffff;
+ s->peak.offset |= (data & 0xffff);
+ s->peak.base = (int16_t *) gb.buffer;
+ s->peak.level = 0;
+ } else if (tag == -76) {
+ s->peak.offset &= 0xffff;
+ s->peak.offset |= (data & 0xffff)<<16;
+ s->peak.base = (int16_t *) gb.buffer;
+ s->peak.level = 0;
+ } else if (tag == -74 && s->peak.offset) {
+ s->peak.level = data;
+ s->peak.base += s->peak.offset / 2 - 2;
} else
av_log(avctx, AV_LOG_DEBUG, "Unknown tag %i data %x\n", tag, data);
@@ -594,10 +664,15 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
if (count > expected)
break;
- coeff = dequant_and_decompand(level, s->quantisation);
+ coeff = dequant_and_decompand(level, s->quantisation, 0);
for (i = 0; i < run; i++)
*coeff_data++ = coeff;
}
+ if (s->peak.level)
+ peak_table(coeff_data - expected, &s->peak, expected);
+ if (s->difference_coding)
+ difference_coding(s->plane[s->channel_num].subband[s->subband_num_actual], highpass_width, highpass_height);
+
} else {
while (1) {
UPDATE_CACHE(re, &s->gb);
@@ -613,10 +688,15 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
if (count > expected)
break;
- coeff = dequant_and_decompand(level, s->quantisation);
+ coeff = dequant_and_decompand(level, s->quantisation, s->codebook);
for (i = 0; i < run; i++)
*coeff_data++ = coeff;
}
+ if (s->peak.level)
+ peak_table(coeff_data - expected, &s->peak, expected);
+ if (s->difference_coding)
+ difference_coding(s->plane[s->channel_num].subband[s->subband_num_actual], highpass_width, highpass_height);
+
}
CLOSE_READER(re, &s->gb);
}
@@ -784,37 +864,68 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
}
av_log(avctx, AV_LOG_DEBUG, "Level 3 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
+ if (s->progressive) {
+ low = s->plane[plane].subband[0];
+ high = s->plane[plane].subband[8];
+ output = s->plane[plane].l_h[6];
+ for (i = 0; i < lowpass_width; i++) {
+ vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
+ low++;
+ high++;
+ output++;
+ }
- low = s->plane[plane].subband[0];
- high = s->plane[plane].subband[8];
- output = s->plane[plane].l_h[6];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ low = s->plane[plane].subband[7];
+ high = s->plane[plane].subband[9];
+ output = s->plane[plane].l_h[7];
+ for (i = 0; i < lowpass_width; i++) {
+ vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
+ low++;
+ high++;
+ output++;
+ }
- low = s->plane[plane].subband[7];
- high = s->plane[plane].subband[9];
- output = s->plane[plane].l_h[7];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dst = (int16_t *)pic->data[act_plane];
+ low = s->plane[plane].l_h[6];
+ high = s->plane[plane].l_h[7];
+ for (i = 0; i < lowpass_height * 2; i++) {
+ horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
+ low += lowpass_width;
+ high += lowpass_width;
+ dst += pic->linesize[act_plane] / 2;
+ }
+ } else {
+ av_log(avctx, AV_LOG_DEBUG, "interlaced frame ? %d", pic->interlaced_frame);
+ pic->interlaced_frame = 1;
+ low = s->plane[plane].subband[0];
+ high = s->plane[plane].subband[7];
+ output = s->plane[plane].l_h[6];
+ for (i = 0; i < lowpass_height; i++) {
+ horiz_filter(output, low, high, lowpass_width);
+ low += lowpass_width;
+ high += lowpass_width;
+ output += lowpass_width * 2;
+ }
- dst = (int16_t *)pic->data[act_plane];
- low = s->plane[plane].l_h[6];
- high = s->plane[plane].l_h[7];
- for (i = 0; i < lowpass_height * 2; i++) {
- horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
- if (act_plane == 3)
- process_alpha(dst, lowpass_width * 2);
- low += lowpass_width;
- high += lowpass_width;
- dst += pic->linesize[act_plane] / 2;
+ low = s->plane[plane].subband[8];
+ high = s->plane[plane].subband[9];
+ output = s->plane[plane].l_h[7];
+ for (i = 0; i < lowpass_height; i++) {
+ horiz_filter(output, low, high, lowpass_width);
+ low += lowpass_width;
+ high += lowpass_width;
+ output += lowpass_width * 2;
+ }
+
+ dst = (int16_t *)pic->data[act_plane];
+ low = s->plane[plane].l_h[6];
+ high = s->plane[plane].l_h[7];
+ for (i = 0; i < lowpass_height; i++) {
+ interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane);
+ low += lowpass_width * 2;
+ high += lowpass_width * 2;
+ dst += pic->linesize[act_plane];
+ }
}
}
diff --git a/libavcodec/cfhd.h b/libavcodec/cfhd.h
index 2573e750a6..7cd251fca7 100644
--- a/libavcodec/cfhd.h
+++ b/libavcodec/cfhd.h
@@ -68,6 +68,12 @@ typedef struct Plane {
SubBand band[DWT_LEVELS][4];
} Plane;
+typedef struct Peak {
+ int level;
+ int offset;
+ const int16_t *base;
+} Peak;
+
typedef struct CFHDContext {
AVCodecContext *avctx;
@@ -83,6 +89,7 @@ typedef struct CFHDContext {
int coded_height;
int cropped_height;
enum AVPixelFormat coded_format;
+ int progressive;
int a_width;
int a_height;
@@ -98,12 +105,14 @@ typedef struct CFHDContext {
int pshift;
int codebook;
+ int difference_coding;
int subband_num;
int level;
int subband_num_actual;
uint8_t prescale_shift[3];
Plane plane[4];
+ Peak peak;
} CFHDContext;
int ff_cfhd_init_vlcs(CFHDContext *s);
--
2.14.1
6
7
While integrating my encryption info changes, I noticed a problem with
the init info structs. I implemented them as side-data on the Stream.
But this means there can only be one per stream. However, there can
be multiple 'pssh' atoms in a single stream (e.g. for key rotation or
multiple key systems). (sorry for not noticing sooner)
Attached is a patch to fix this by making the init info a
singly-linked-list. It is ABI compatible and is still easy to use and
understand. The alternative would be to break ABI and have the
side-data methods return an array of pointers. I could do that
instead if that is preferable.
2
18
21 Jun '18
The plan is to eventually be able to apply effects and encode entirely
on the GPU.
Rostislav Pehlivanov (8):
hwcontext_internal: add ff_hwframe_map_replace
hwcontext_opencl: use ff_hwframe_map_replace()
lavu: add a Vulkan hwcontext
lavfi: add common Vulkan filtering code
lavfi: add a Vulkan avgblur filter
lavfi: add a Vulkan chromatic aberration filter
lavfi: add a Vulkan scale filter
lavfi: add a Vulkan overlay filter
configure | 24 +-
doc/APIchanges | 3 +
libavfilter/Makefile | 4 +
libavfilter/allfilters.c | 4 +
libavfilter/vf_avgblur_vulkan.c | 343 +++
libavfilter/vf_chromaticaberration_vulkan.c | 342 +++
libavfilter/vf_overlay_vulkan.c | 458 ++++
libavfilter/vf_scale_vulkan.c | 386 ++++
libavfilter/vulkan.c | 1450 +++++++++++++
libavfilter/vulkan.h | 234 ++
libavutil/Makefile | 3 +
libavutil/hwcontext.c | 11 +
libavutil/hwcontext.h | 1 +
libavutil/hwcontext_internal.h | 6 +
libavutil/hwcontext_opencl.c | 5 +-
libavutil/hwcontext_vulkan.c | 2125 +++++++++++++++++++
libavutil/hwcontext_vulkan.h | 133 ++
libavutil/pixdesc.c | 4 +
libavutil/pixfmt.h | 4 +
libavutil/version.h | 2 +-
20 files changed, 5536 insertions(+), 6 deletions(-)
create mode 100644 libavfilter/vf_avgblur_vulkan.c
create mode 100644 libavfilter/vf_chromaticaberration_vulkan.c
create mode 100644 libavfilter/vf_overlay_vulkan.c
create mode 100644 libavfilter/vf_scale_vulkan.c
create mode 100644 libavfilter/vulkan.c
create mode 100644 libavfilter/vulkan.h
create mode 100644 libavutil/hwcontext_vulkan.c
create mode 100644 libavutil/hwcontext_vulkan.h
--
2.17.0
1
9
Add opencl version of boxblur filter.
Behaves like existing libavfilter/boxblur filter.
---
configure | 1 +
libavfilter/Makefile | 2 +
libavfilter/allfilters.c | 1 +
libavfilter/opencl/boxblur.cl | 57 +++++
libavfilter/opencl_source.h | 1 +
libavfilter/vf_boxblur_opencl.c | 468 ++++++++++++++++++++++++++++++++++++++++
6 files changed, 530 insertions(+)
create mode 100644 libavfilter/opencl/boxblur.cl
create mode 100644 libavfilter/vf_boxblur_opencl.c
diff --git a/configure b/configure
index e52f8f8..f8a2487 100755
--- a/configure
+++ b/configure
@@ -3302,6 +3302,7 @@ avgblur_opencl_filter_deps="opencl"
azmq_filter_deps="libzmq"
blackframe_filter_deps="gpl"
boxblur_filter_deps="gpl"
+boxblur_opencl_filter_deps="opencl"
bs2b_filter_deps="libbs2b"
colormatrix_filter_deps="gpl"
convolution_opencl_filter_deps="opencl"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index c68ef05..97afdef 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -153,6 +153,8 @@ OBJS-$(CONFIG_BLACKDETECT_FILTER) += vf_blackdetect.o
OBJS-$(CONFIG_BLACKFRAME_FILTER) += vf_blackframe.o
OBJS-$(CONFIG_BLEND_FILTER) += vf_blend.o framesync.o
OBJS-$(CONFIG_BOXBLUR_FILTER) += vf_boxblur.o
+OBJS-$(CONFIG_BOXBLUR_OPENCL_FILTER) += vf_boxblur_opencl.o opencl.o \
+ opencl/boxblur.o
OBJS-$(CONFIG_BWDIF_FILTER) += vf_bwdif.o
OBJS-$(CONFIG_CHROMAKEY_FILTER) += vf_chromakey.o
OBJS-$(CONFIG_CIESCOPE_FILTER) += vf_ciescope.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index b44093d..97d92a0 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -146,6 +146,7 @@ extern AVFilter ff_vf_blackdetect;
extern AVFilter ff_vf_blackframe;
extern AVFilter ff_vf_blend;
extern AVFilter ff_vf_boxblur;
+extern AVFilter ff_vf_boxblur_opencl;
extern AVFilter ff_vf_bwdif;
extern AVFilter ff_vf_chromakey;
extern AVFilter ff_vf_ciescope;
diff --git a/libavfilter/opencl/boxblur.cl b/libavfilter/opencl/boxblur.cl
new file mode 100644
index 0000000..a0d9dcd
--- /dev/null
+++ b/libavfilter/opencl/boxblur.cl
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2018 Danil Iashchenko
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+__kernel void boxblur_horiz(__write_only image2d_t dst,
+ __read_only image2d_t src,
+ int rad)
+{
+ const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
+ CLK_ADDRESS_CLAMP_TO_EDGE |
+ CLK_FILTER_NEAREST);
+
+ int2 loc = (int2)(get_global_id(0), get_global_id(1));
+ float4 acc = (float4)(0,0,0,0);
+ int cnt = 0;
+
+ for (int w = loc.x - rad; w < loc.x + rad + 1; w++) {
+ cnt++;
+ acc += read_imagef(src, sampler, (int2)(w, loc.y));
+ }
+ write_imagef(dst, loc, acc / cnt);
+}
+
+__kernel void boxblur_vertic(__write_only image2d_t dst,
+ __read_only image2d_t src,
+ int radv)
+{
+ const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE |
+ CLK_ADDRESS_CLAMP_TO_EDGE |
+ CLK_FILTER_NEAREST);
+
+ int2 loc = (int2)(get_global_id(0), get_global_id(1));
+ float4 acc = (float4)(0,0,0,0);
+ int cnt = 0;
+
+ for (int h = loc.y - radv; h < loc.y + radv + 1; h++) {
+ cnt++;
+ acc += read_imagef(src, sampler, (int2)(loc.x, h));
+ }
+ write_imagef(dst, loc, acc / cnt);
+}
diff --git a/libavfilter/opencl_source.h b/libavfilter/opencl_source.h
index 4bb9969..2e09770 100644
--- a/libavfilter/opencl_source.h
+++ b/libavfilter/opencl_source.h
@@ -20,6 +20,7 @@
#define AVFILTER_OPENCL_SOURCE_H
extern const char *ff_opencl_source_avgblur;
+extern const char *ff_opencl_source_boxblur;
extern const char *ff_opencl_source_convolution;
extern const char *ff_opencl_source_overlay;
extern const char *ff_opencl_source_unsharp;
diff --git a/libavfilter/vf_boxblur_opencl.c b/libavfilter/vf_boxblur_opencl.c
new file mode 100644
index 0000000..d46fb0f
--- /dev/null
+++ b/libavfilter/vf_boxblur_opencl.c
@@ -0,0 +1,468 @@
+/*
+ * Copyright (c) 2018 Danil Iashchenko
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/common.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/mem.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/avstring.h"
+#include "libavutil/eval.h"
+
+
+#include "avfilter.h"
+#include "internal.h"
+#include "opencl.h"
+#include "opencl_source.h"
+#include "video.h"
+
+
+static const char *const var_names[] = {
+ "w",
+ "h",
+ "cw",
+ "ch",
+ "hsub",
+ "vsub",
+ NULL
+};
+
+
+enum var_name {
+ VAR_W,
+ VAR_H,
+ VAR_CW,
+ VAR_CH,
+ VAR_HSUB,
+ VAR_VSUB,
+ VARS_NB
+};
+
+
+typedef struct FilterParam {
+ int radius;
+ int power;
+ char *radius_expr;
+} FilterParam;
+
+
+typedef struct BoxBlurOpenCLContext {
+ OpenCLFilterContext ocf;
+
+ int initialised;
+ cl_kernel kernel_horiz;
+ cl_kernel kernel_vertic;
+ cl_command_queue command_queue;
+
+ FilterParam luma_param;
+ FilterParam chroma_param;
+ FilterParam alpha_param;
+
+ int hsub, vsub;
+ int radius[4];
+ int power[4];
+} BoxBlurOpenCLContext;
+
+
+#define Y 0
+#define U 1
+#define V 2
+#define A 3
+
+
+static int boxblur_opencl_init(AVFilterContext *avctx)
+{
+ BoxBlurOpenCLContext *ctx = avctx->priv;
+ cl_int cle;
+ int err;
+
+ err = ff_opencl_filter_load_program(avctx, &ff_opencl_source_boxblur, 1);
+ if (err < 0)
+ goto fail;
+
+ ctx->command_queue = clCreateCommandQueue(ctx->ocf.hwctx->context,
+ ctx->ocf.hwctx->device_id,
+ 0, &cle);
+ if (!ctx->command_queue) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to create OpenCL "
+ "command queue: %d.\n", cle);
+ err = AVERROR(EIO);
+ goto fail;
+ }
+
+ ctx->kernel_horiz = clCreateKernel(ctx->ocf.program, "boxblur_horiz", &cle);
+ if (!ctx->kernel_horiz) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to create kernel: %d.\n", cle);
+ err = AVERROR(EIO);
+ goto fail;
+ }
+ ctx->kernel_vertic = clCreateKernel(ctx->ocf.program, "boxblur_vertic", &cle);
+ if (!ctx->kernel_vertic) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to create kernel: %d.\n", cle);
+ err = AVERROR(EIO);
+ goto fail;
+ }
+
+ ctx->initialised = 1;
+ return 0;
+
+fail:
+ if (ctx->command_queue)
+ clReleaseCommandQueue(ctx->command_queue);
+ if (ctx->kernel_horiz)
+ clReleaseKernel(ctx->kernel_horiz);
+ if (ctx->kernel_vertic)
+ clReleaseKernel(ctx->kernel_vertic);
+ return err;
+}
+
+
+static int boxblur_opencl_make_filter_params(AVFilterLink *inlink)
+{
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
+ AVFilterContext *ctx = inlink->dst;
+ BoxBlurOpenCLContext *s = ctx->priv;
+ int w = inlink->w, h = inlink->h;
+ int cw, ch;
+ double var_values[VARS_NB], res;
+ char *expr;
+ int ret;
+
+ if (!s->luma_param.radius_expr) {
+ av_log(s, AV_LOG_ERROR, "Luma radius expression is not set.\n");
+ return AVERROR(EINVAL);
+ }
+
+ /* fill missing params */
+ if (!s->chroma_param.radius_expr) {
+ s->chroma_param.radius_expr = av_strdup(s->luma_param.radius_expr);
+ if (!s->chroma_param.radius_expr)
+ return AVERROR(ENOMEM);
+ }
+ if (s->chroma_param.power < 0)
+ s->chroma_param.power = s->luma_param.power;
+
+ if (!s->alpha_param.radius_expr) {
+ s->alpha_param.radius_expr = av_strdup(s->luma_param.radius_expr);
+ if (!s->alpha_param.radius_expr)
+ return AVERROR(ENOMEM);
+ }
+ if (s->alpha_param.power < 0)
+ s->alpha_param.power = s->luma_param.power;
+
+ s->hsub = desc->log2_chroma_w;
+ s->vsub = desc->log2_chroma_h;
+
+ var_values[VAR_W] = inlink->w;
+ var_values[VAR_H] = inlink->h;
+ var_values[VAR_CW] = cw = w>>s->hsub;
+ var_values[VAR_CH] = ch = h>>s->vsub;
+ var_values[VAR_HSUB] = 1<<s->hsub;
+ var_values[VAR_VSUB] = 1<<s->vsub;
+
+#define EVAL_RADIUS_EXPR(comp) \
+ expr = s->comp##_param.radius_expr; \
+ ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \
+ NULL, NULL, NULL, NULL, NULL, 0, ctx); \
+ s->comp##_param.radius = res; \
+ if (ret < 0) { \
+ av_log(NULL, AV_LOG_ERROR, \
+ "Error when evaluating " #comp " radius expression '%s'\n", expr); \
+ return ret; \
+ }
+ EVAL_RADIUS_EXPR(luma);
+ EVAL_RADIUS_EXPR(chroma);
+ EVAL_RADIUS_EXPR(alpha);
+
+ av_log(ctx, AV_LOG_VERBOSE,
+ "luma_radius:%d luma_power:%d "
+ "chroma_radius:%d chroma_power:%d "
+ "alpha_radius:%d alpha_power:%d "
+ "w:%d chroma_w:%d h:%d chroma_h:%d\n",
+ s->luma_param .radius, s->luma_param .power,
+ s->chroma_param.radius, s->chroma_param.power,
+ s->alpha_param .radius, s->alpha_param .power,
+ w, cw, h, ch);
+
+#define CHECK_RADIUS_VAL(w_, h_, comp) \
+ if (s->comp##_param.radius < 0 || \
+ 2*s->comp##_param.radius > FFMIN(w_, h_)) { \
+ av_log(ctx, AV_LOG_ERROR, \
+ "Invalid " #comp " radius value %d, must be >= 0 and <= %d\n", \
+ s->comp##_param.radius, FFMIN(w_, h_)/2); \
+ return AVERROR(EINVAL); \
+ }
+ CHECK_RADIUS_VAL(w, h, luma);
+ CHECK_RADIUS_VAL(cw, ch, chroma);
+ CHECK_RADIUS_VAL(w, h, alpha);
+
+ s->radius[Y] = s->luma_param.radius;
+ s->radius[U] = s->radius[V] = s->chroma_param.radius;
+ s->radius[A] = s->alpha_param.radius;
+
+ s->power[Y] = s->luma_param.power;
+ s->power[U] = s->power[V] = s->chroma_param.power;
+ s->power[A] = s->alpha_param.power;
+
+ return 0;
+}
+
+
+static int boxblur_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
+{
+ AVFilterContext *avctx = inlink->dst;
+ AVFilterLink *outlink = avctx->outputs[0];
+ BoxBlurOpenCLContext *ctx = avctx->priv;
+ AVFrame *output = NULL;
+ AVFrame *intermediate = NULL;
+ cl_int cle;
+ size_t global_work[2];
+ cl_mem src, dst, inter;
+ int err, p, i;
+
+ av_log(ctx, AV_LOG_DEBUG, "Filter input: %s, %ux%u (%"PRId64").\n",
+ av_get_pix_fmt_name(input->format),
+ input->width, input->height, input->pts);
+
+ if (!input->hw_frames_ctx)
+ return AVERROR(EINVAL);
+
+ if (!ctx->initialised) {
+ err = boxblur_opencl_init(avctx);
+ if (err < 0)
+ goto fail;
+
+ err = boxblur_opencl_make_filter_params(inlink);
+ if (err < 0)
+ goto fail;
+ }
+
+ output = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+ if (!output) {
+ err = AVERROR(ENOMEM);
+ goto fail;
+ }
+ intermediate = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+ if (!intermediate) {
+ err = AVERROR(ENOMEM);
+ goto fail;
+ }
+
+ for (p = 0; p < FF_ARRAY_ELEMS(output->data); p++) {
+ src = (cl_mem) input->data[p];
+ dst = (cl_mem) output->data[p];
+ inter = (cl_mem) intermediate->data[p];
+
+ if (!dst)
+ break;
+
+ err = ff_opencl_filter_work_size_from_image(avctx, global_work, intermediate, p, 0);
+ if (err < 0)
+ goto fail;
+
+ av_log(avctx, AV_LOG_DEBUG, "Run kernel on plane %d "
+ "(%"SIZE_SPECIFIER"x%"SIZE_SPECIFIER").\n",
+ p, global_work[0], global_work[1]);
+
+ cle = clSetKernelArg(ctx->kernel_horiz, 2, sizeof(cl_int), &ctx->radius[p]);
+ if (cle != CL_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to set kernel_horiz "
+ "radius argument: %d.\n", cle);
+ goto fail;
+ }
+
+ for (i = 0; i < ctx->power[p]; i++) {
+ cle = clSetKernelArg(ctx->kernel_horiz, 0, sizeof(cl_mem), &inter);
+ if (cle != CL_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to set kernel_horiz "
+ "destination image argument: %d.\n", cle);
+ goto fail;
+ }
+ cle = clSetKernelArg(ctx->kernel_horiz, 1, sizeof(cl_mem), &src);
+ if (cle != CL_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to set kernel_horiz "
+ "source image argument: %d.\n", cle);
+ goto fail;
+ }
+ cle = clEnqueueNDRangeKernel(ctx->command_queue, ctx->kernel_horiz, 2, NULL,
+ global_work, NULL,
+ 0, NULL, NULL);
+ if (cle != CL_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to enqueue kernel: %d.\n",
+ cle);
+ err = AVERROR(EIO);
+ goto fail;
+ }
+ src = inter;
+ }
+
+ err = ff_opencl_filter_work_size_from_image(avctx, global_work, output, p, 0);
+ if (err < 0)
+ goto fail;
+
+ av_log(avctx, AV_LOG_DEBUG, "Run kernel on plane %d "
+ "(%"SIZE_SPECIFIER"x%"SIZE_SPECIFIER").\n",
+ p, global_work[0], global_work[1]);
+
+ cle = clSetKernelArg(ctx->kernel_vertic, 2, sizeof(cl_int), &ctx->radius[p]);
+ if (cle != CL_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to set kernel_vertic "
+ "radius argument: %d.\n", cle);
+ goto fail;
+ }
+
+ for (i = 0; i < ctx->power[p]; i++) {
+ cle = clSetKernelArg(ctx->kernel_vertic, 0, sizeof(cl_mem), &dst);
+ if (cle != CL_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to set kernel_vertic "
+ "destination image argument: %d.\n", cle);
+ goto fail;
+ }
+ cle = clSetKernelArg(ctx->kernel_vertic, 1, sizeof(cl_mem), &inter);
+ if (cle != CL_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to set kernel_vertic "
+ "source image argument: %d.\n", cle);
+ goto fail;
+ }
+ cle = clEnqueueNDRangeKernel(ctx->command_queue, ctx->kernel_vertic, 2, NULL,
+ global_work, NULL,
+ 0, NULL, NULL);
+ if (cle != CL_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to enqueue kernel: %d.\n",
+ cle);
+ err = AVERROR(EIO);
+ goto fail;
+ }
+ inter = dst;
+ }
+
+ }
+
+ cle = clFinish(ctx->command_queue);
+ if (cle != CL_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to finish command queue: %d.\n",
+ cle);
+ err = AVERROR(EIO);
+ goto fail;
+ }
+
+ err = av_frame_copy_props(output, input);
+ if (err < 0)
+ goto fail;
+
+ av_frame_free(&input);
+ av_frame_free(&intermediate);
+
+ av_log(ctx, AV_LOG_DEBUG, "Filter output: %s, %ux%u (%"PRId64").\n",
+ av_get_pix_fmt_name(output->format),
+ output->width, output->height, output->pts);
+
+ return ff_filter_frame(outlink, output);
+
+fail:
+ clFinish(ctx->command_queue);
+ av_frame_free(&input);
+ av_frame_free(&output);
+ av_frame_free(&intermediate);
+ return err;
+}
+
+static av_cold void boxblur_opencl_uninit(AVFilterContext *avctx)
+{
+ BoxBlurOpenCLContext *ctx = avctx->priv;
+ cl_int cle;
+
+ if (ctx->kernel_horiz) {
+ cle = clReleaseKernel(ctx->kernel_horiz);
+ if (cle != CL_SUCCESS)
+ av_log(avctx, AV_LOG_ERROR, "Failed to release "
+ "kernel: %d.\n", cle);
+ }
+ if (ctx->kernel_vertic) {
+ cle = clReleaseKernel(ctx->kernel_vertic);
+ if (cle != CL_SUCCESS)
+ av_log(avctx, AV_LOG_ERROR, "Failed to release "
+ "kernel: %d.\n", cle);
+ }
+
+ if (ctx->command_queue) {
+ cle = clReleaseCommandQueue(ctx->command_queue);
+ if (cle != CL_SUCCESS)
+ av_log(avctx, AV_LOG_ERROR, "Failed to release "
+ "command queue: %d.\n", cle);
+ }
+
+ ff_opencl_filter_uninit(avctx);
+}
+
+#define OFFSET(x) offsetof(BoxBlurOpenCLContext, x)
+#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
+static const AVOption boxblur_opencl_options[] = {
+ { "luma_radius", "Radius of the luma blurring box", OFFSET(luma_param.radius_expr), AV_OPT_TYPE_STRING, {.str="2"}, .flags = FLAGS },
+ { "lr", "Radius of the luma blurring box", OFFSET(luma_param.radius_expr), AV_OPT_TYPE_STRING, {.str="2"}, .flags = FLAGS },
+ { "luma_power", "How many times should the boxblur be applied to luma", OFFSET(luma_param.power), AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags = FLAGS },
+ { "lp", "How many times should the boxblur be applied to luma", OFFSET(luma_param.power), AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags = FLAGS },
+
+ { "chroma_radius", "Radius of the chroma blurring box", OFFSET(chroma_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
+ { "cr", "Radius of the chroma blurring box", OFFSET(chroma_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
+ { "chroma_power", "How many times should the boxblur be applied to chroma", OFFSET(chroma_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+ { "cp", "How many times should the boxblur be applied to chroma", OFFSET(chroma_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+
+ { "alpha_radius", "Radius of the alpha blurring box", OFFSET(alpha_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
+ { "ar", "Radius of the alpha blurring box", OFFSET(alpha_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
+ { "alpha_power", "How many times should the boxblur be applied to alpha", OFFSET(alpha_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+ { "ap", "How many times should the boxblur be applied to alpha", OFFSET(alpha_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+
+ { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(boxblur_opencl);
+
+static const AVFilterPad boxblur_opencl_inputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .filter_frame = &boxblur_opencl_filter_frame,
+ .config_props = &ff_opencl_filter_config_input,
+ },
+ { NULL }
+};
+
+static const AVFilterPad boxblur_opencl_outputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .config_props = &ff_opencl_filter_config_output,
+ },
+ { NULL }
+};
+
+AVFilter ff_vf_boxblur_opencl = {
+ .name = "boxblur_opencl",
+ .description = NULL_IF_CONFIG_SMALL("Apply boxblur filter to input video"),
+ .priv_size = sizeof(BoxBlurOpenCLContext),
+ .priv_class = &boxblur_opencl_class,
+ .init = &ff_opencl_filter_init,
+ .uninit = &boxblur_opencl_uninit,
+ .query_formats = &ff_opencl_filter_query_formats,
+ .inputs = boxblur_opencl_inputs,
+ .outputs = boxblur_opencl_outputs,
+ .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
+};
--
2.7.4
4
11
[PATCH]lavfi/avfiltergraph: Do not return ENOMEM if filter is missing
by Carl Eugen Hoyos 17 Jun '18
by Carl Eugen Hoyos 17 Jun '18
17 Jun '18
Hi!
OOM is unlikely as a failure for avfilter_graph_alloc_filter(), the
patch avoids a surprising error if a filter was not found.
Please comment, Carl Eugen
4
9
[PATCH 1/2] avcodec/vaapi: slice_vertical_position starts from zero for the second field
by Jerome Borsboom 17 Jun '18
by Jerome Borsboom 17 Jun '18
17 Jun '18
Contrary to VC-1 spec, VAAPI expects the row address of the first
macroblock row in the first slice to start from zero for the second
field in a field interlaced picture.
Signed-off-by: Jerome Borsboom <jerome.borsboom(a)carpalis.nl>
---
This patch set adds support for hardware decoding multi-slice field interlaced
pictures. With this patch set, the SA10180 test file decodes correctly with
VAAPI hardware acceleration. This was succesfully tested on Intel Haswell platform.
libavcodec/vaapi_vc1.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c
index bdb5e24cc5..921ca6391b 100644
--- a/libavcodec/vaapi_vc1.c
+++ b/libavcodec/vaapi_vc1.c
@@ -467,6 +467,7 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
const MpegEncContext *s = &v->s;
VAAPIDecodePicture *pic = s->current_picture_ptr->hwaccel_picture_private;
VASliceParameterBufferVC1 slice_param;
+ int mb_height;
int err;
/* Current bit buffer is beyond any marker for VC-1, so skip it */
@@ -475,12 +476,17 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
size -= 4;
}
+ if (v->fcm == ILACE_FIELD)
+ mb_height = avctx->coded_height + 31 >> 5;
+ else
+ mb_height = avctx->coded_height + 15 >> 4;
+
slice_param = (VASliceParameterBufferVC1) {
.slice_data_size = size,
.slice_data_offset = 0,
.slice_data_flag = VA_SLICE_DATA_FLAG_ALL,
.macroblock_offset = get_bits_count(&s->gb),
- .slice_vertical_position = s->mb_y,
+ .slice_vertical_position = s->mb_y % mb_height,
};
err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
--
2.13.6
5
10