-
Notifications
You must be signed in to change notification settings - Fork 341
/
filter_postprocess.c
146 lines (118 loc) · 3.39 KB
/
filter_postprocess.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* filter_postprocess
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "mythconfig.h"
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#include "libavcodec/avcodec.h"
#include "filter.h"
#include "frame.h"
#include "libpostproc/postprocess.h"
//static const char FILTER_NAME[] = "PostProcess";
typedef struct ThisFilter
{
VideoFilter vf;
pp_mode *mode;
pp_context *context;
int width;
int height;
int ysize;
int csize;
unsigned char *src[3];
unsigned char *dst[3];
int srcStride[3];
int dstStride[3];
int eprint;
TF_STRUCT;
} ThisFilter;
static int pp(VideoFilter *vf, VideoFrame *frame, int field)
{
(void)field;
ThisFilter* tf = (ThisFilter*)vf;
TF_VARS;
TF_START;
tf->src[0] = tf->dst[0] = frame->buf;
tf->src[1] = tf->dst[1] = frame->buf + tf->ysize;
tf->src[2] = tf->dst[2] = frame->buf + tf->ysize + tf->csize;
if (frame->qscale_table == NULL)
frame->qstride = 0;
tf->ysize = (frame->width) * (frame->height);
tf->csize = tf->ysize / 4;
tf->width = frame->width;
tf->height = frame->height;
tf->srcStride[0] = tf->ysize / (tf->height);
tf->srcStride[1] = tf->csize / (tf->height) * 2;
tf->srcStride[2] = tf->csize / (tf->height) * 2;
tf->dstStride[0] = tf->ysize / (tf->height);
tf->dstStride[1] = tf->csize / (tf->height) * 2;
tf->dstStride[2] = tf->csize / (tf->height) * 2;
pp_postprocess( (const uint8_t**)tf->src, tf->srcStride,
tf->dst, tf->dstStride,
frame->width, frame->height,
(signed char *)(frame->qscale_table), frame->qstride,
tf->mode, tf->context, PP_FORMAT_420);
TF_END(tf, "PostProcess: ");
return 0;
}
static void cleanup(VideoFilter *filter)
{
pp_free_context(((ThisFilter*)filter)->context);
pp_free_mode(((ThisFilter*)filter)->mode);
}
static VideoFilter *new_filter(VideoFrameType inpixfmt,
VideoFrameType outpixfmt,
int *width, int *height, char *options,
int threads)
{
(void) threads;
ThisFilter *filter;
if ( inpixfmt != FMT_YV12 || outpixfmt != FMT_YV12 )
return NULL;
filter = (ThisFilter*) malloc(sizeof(ThisFilter));
if (filter == NULL)
{
fprintf(stderr,"Couldn't allocate memory for filter\n");
return NULL;
}
filter->context = pp_get_context(*width, *height,
PP_CPU_CAPS_MMX|PP_CPU_CAPS_MMX2|PP_CPU_CAPS_3DNOW);
if (filter->context == NULL)
{
fprintf(stderr,"PostProc: failed to get PP context\n");
free(filter);
return NULL;
}
printf("Filteroptions: %s\n", options);
filter->mode = pp_get_mode_by_name_and_quality(options, PP_QUALITY_MAX);
if (filter->mode == NULL)
{
printf("%s", pp_help);
free(filter);
return NULL;
}
filter->eprint = 0;
filter->vf.filter = &pp;
filter->vf.cleanup = &cleanup;
TF_INIT(filter);
return (VideoFilter *)filter;
}
FmtConv FmtList[] =
{
{ FMT_YV12, FMT_YV12 },
FMT_NULL
};
const FilterInfo filter_table[] =
{
{
.filter_init= &new_filter,
.name= (char*)"postprocess",
.descript= (char*)"FFMPEG's postprocessing filters",
.formats= FmtList,
.libname= NULL
},
FILT_NULL
};