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