1 /*
2 * Copyright (c) 2013 Georg Martius <georg dot martius at web dot de>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "vidstabutils.h"
22
23 const enum AVPixelFormat ff_vidstab_pix_fmts[] = {
24 AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
25 AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUVA420P,
26 AV_PIX_FMT_YUV440P, AV_PIX_FMT_GRAY8,
27 AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24, AV_PIX_FMT_RGBA,
28 AV_PIX_FMT_NONE
29 };
30
31 /** convert AV's pixelformat to vid.stab pixelformat */
ff_av2vs_pixfmt(AVFilterContext * ctx,enum AVPixelFormat pf)32 VSPixelFormat ff_av2vs_pixfmt(AVFilterContext *ctx, enum AVPixelFormat pf)
33 {
34 switch (pf) {
35 case AV_PIX_FMT_YUV420P: return PF_YUV420P;
36 case AV_PIX_FMT_YUV422P: return PF_YUV422P;
37 case AV_PIX_FMT_YUV444P: return PF_YUV444P;
38 case AV_PIX_FMT_YUV410P: return PF_YUV410P;
39 case AV_PIX_FMT_YUV411P: return PF_YUV411P;
40 case AV_PIX_FMT_YUV440P: return PF_YUV440P;
41 case AV_PIX_FMT_YUVA420P: return PF_YUVA420P;
42 case AV_PIX_FMT_GRAY8: return PF_GRAY8;
43 case AV_PIX_FMT_RGB24: return PF_RGB24;
44 case AV_PIX_FMT_BGR24: return PF_BGR24;
45 case AV_PIX_FMT_RGBA: return PF_RGBA;
46 default:
47 av_log(ctx, AV_LOG_ERROR, "cannot deal with pixel format %i\n", pf);
48 return PF_NONE;
49 }
50 }
51
52 /** struct to hold a valid context for logging from within vid.stab lib */
53 typedef struct VS2AVLogCtx {
54 const AVClass *class;
55 } VS2AVLogCtx;
56
57 /** wrapper to log vs_log into av_log */
vs2av_log(int type,const char * tag,const char * format,...)58 static int vs2av_log(int type, const char *tag, const char *format, ...)
59 {
60 va_list ap;
61 VS2AVLogCtx ctx;
62 AVClass class = {
63 .class_name = tag,
64 .item_name = av_default_item_name,
65 .option = 0,
66 .version = LIBAVUTIL_VERSION_INT,
67 .category = AV_CLASS_CATEGORY_FILTER,
68 };
69 ctx.class = &class;
70 va_start(ap, format);
71 av_vlog(&ctx, type, format, ap);
72 va_end(ap);
73 return VS_OK;
74 }
75
76 /** sets the memory allocation function and logging constants to av versions */
ff_vs_init(void)77 void ff_vs_init(void)
78 {
79 vs_malloc = av_malloc;
80 vs_zalloc = av_mallocz;
81 vs_realloc = av_realloc;
82 vs_free = av_free;
83
84 VS_ERROR_TYPE = AV_LOG_ERROR;
85 VS_WARN_TYPE = AV_LOG_WARNING;
86 VS_INFO_TYPE = AV_LOG_INFO;
87 VS_MSG_TYPE = AV_LOG_VERBOSE;
88
89 vs_log = vs2av_log;
90
91 VS_ERROR = 0;
92 VS_OK = 1;
93 }
94