Advertisement
w34

vf_filter.c

w34
Jul 30th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.73 KB | None | 0 0
  1. /* This file is part of FFmpeg, ported from MPlayer.
  2.  *
  3.  * FFmpeg is free software; you can redistribute it and/or modify
  4.  * it under the terms of the GNU General Public License as published by
  5.  * the Free Software Foundation; either version 2 of the License, or
  6.  * (at your option) any later version.
  7.  *
  8.  * FFmpeg is distributed in the hope that it will be useful,
  9.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.  * GNU General Public License for more details.
  12.  *
  13.  * You should have received a copy of the GNU General Public License along
  14.  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  15.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16.  */
  17.  
  18. /**
  19.  * @file
  20.  * field filter, ported from MPlayer
  21.  * libmpcodecs/vf_field.c.
  22.  */
  23.  
  24. // Original includes
  25. /*#include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28.  
  29. #include "config.h"
  30. #include "mp_msg.h"
  31.  
  32. #include "mp_image.h"
  33. #include "vf.h"
  34. */
  35.  
  36. #include "libavutil/pixdesc.h"
  37. #include "avfilter.h"
  38. #include "libavutil/avassert.h"
  39. #include "formats.h"
  40. #include "internal.h"
  41. #include "video.h"
  42.  
  43. typedef struct {
  44.     int field;
  45. } FieldContext;
  46.  
  47. //===========================================================================//
  48.  
  49. /*static int config(struct vf_instance *vf,
  50.         int width, int height, int d_width, int d_height,
  51.         unsigned int flags, unsigned int outfmt){
  52.     return vf_next_config(vf,width,height/2,d_width,d_height,flags,outfmt);
  53. }*/
  54.  
  55. /*static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
  56.     vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
  57.         MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE,
  58.         mpi->width, mpi->height/2);
  59.  
  60.     // set up mpi as a double-stride image of dmpi:
  61.     vf->dmpi->planes[0]=mpi->planes[0]+mpi->stride[0]*vf->priv->field;
  62.     vf->dmpi->stride[0]=2*mpi->stride[0];
  63.     if(vf->dmpi->flags&MP_IMGFLAG_PLANAR){
  64.         vf->dmpi->planes[1]=mpi->planes[1]+
  65.             mpi->stride[1]*vf->priv->field;
  66.         vf->dmpi->stride[1]=2*mpi->stride[1];
  67.         vf->dmpi->planes[2]=mpi->planes[2]+
  68.             mpi->stride[2]*vf->priv->field;
  69.         vf->dmpi->stride[2]=2*mpi->stride[2];
  70.     } else
  71.         vf->dmpi->planes[1]=mpi->planes[1]; // passthru bgr8 palette!!!
  72.  
  73.     return vf_next_put_image(vf,vf->dmpi, pts);
  74. }*/
  75.  
  76. static int end_frame(AVFilterLink *inlink)
  77. {
  78.     FieldContext *field = inlink->dst->priv;
  79.     AVFilterLink *outlink = inlink->dst->outputs[0];
  80.     AVFilterBufferRef *inpic  = inlink ->cur_buf;
  81.     AVFilterBufferRef *outpic = outlink->out_buf;
  82.  
  83.     int ret;
  84.  
  85.     // vf->dmpi->planes[0]=mpi->planes[0]+mpi->stride[0]*vf->priv->field;
  86.  
  87.     outpic->data[0] = inpic->data[0] + inpic->linesize[0] * field->field;
  88.  
  89.     //vf->dmpi->stride[0]=2*mpi->stride[0];
  90.  
  91.     outpic->linesize[0] = 2 * inpic->linesize[0];
  92.  
  93.     //if(vf->dmpi->flags&MP_IMGFLAG_PLANAR){
  94.  
  95.     // This still needs to be ported
  96.     if (vf->dmpi->flags&MP_IMGFLAG_PLANAR) {
  97.  
  98.         //   vf->dmpi->planes[1]=mpi->planes[1]+
  99.         outpic->data[1] = inpic->data[1];
  100.  
  101.         //mpi->stride[1]*vf->priv->field;
  102.  
  103.         inpic->linesize[1] * field->field;
  104.  
  105.         //  vf->dmpi->stride[1]=2*mpi->stride[1];
  106.  
  107.         outpic->linesize[1] = 2 * inpic->linesize[1];
  108.  
  109.         //vf->dmpi->planes[2]=mpi->planes[2]+
  110.  
  111.         outpic->data[2] = inpic->data[2] +
  112.  
  113.                 //  mpi->stride[2]*vf->priv->field;
  114.  
  115.                 inpic->linesize[2] * field->field;
  116.  
  117.         //vf->dmpi->stride[2]=2*mpi->stride[2];
  118.  
  119.         outpic->linesize[2] = 2 * inpic->linesize[2];
  120.  
  121.     } else
  122.         // vf->dmpi->planes[1]=mpi->planes[1]; // passthru bgr8 palette!!!
  123.  
  124.         outpic->data[1] = inpic->data[1]; // passthru bgr8 palette
  125.  
  126.     // return vf_next_put_image(vf,vf->dmpi, pts);
  127.  
  128.     if ((ret = ff_draw_slice(outlink, 0, inpic->video->h, 1)) < 0 ||
  129.             (ret = ff_end_frame(outlink)) < 0)
  130.         return ret;
  131.  
  132.     return 0;
  133.  
  134. }
  135.  
  136. //===========================================================================//
  137.  
  138. /*static void uninit(struct vf_instance *vf)
  139. {
  140.         free(vf->priv);
  141. }*/
  142.  
  143. static av_cold void uninit(AVFilterContext *ctx)
  144. {
  145.     FieldContext *field = ctx->priv;
  146.  
  147.     av_freep(&field->field);
  148. }
  149.  
  150. /*static int vf_open(vf_instance_t *vf, char *args){
  151.     vf->config=config;
  152.     vf->put_image=put_image;
  153.     vf->uninit=uninit;
  154.     vf->default_reqs=VFCAP_ACCEPT_STRIDE;
  155.     vf->priv=calloc(1, sizeof(struct vf_priv_s));
  156.     if (args) sscanf(args, "%d", &vf->priv->field);
  157.     vf->priv->field &= 1;
  158.     return 1;
  159. }
  160.  
  161. const vf_info_t vf_info_field = {
  162.     "extract single field",
  163.     "field",
  164.     "Rich Felker",
  165.     "",
  166.     vf_open,
  167.     NULL
  168. };*/
  169.  
  170. static av_cold int init(AVFilterContext *ctx, const char *args)
  171. {
  172.     FieldContext *field = ctx->priv;
  173.  
  174.     if (args)
  175.         sscanf(args, "%d", field->field);
  176.  
  177.     return 0;
  178. }
  179.  
  180. static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
  181. {
  182.     return 0;
  183. }
  184.  
  185. AVFilter avfilter_vf_field = {
  186.     .name          = "field",
  187.     .description   = NULL_IF_CONFIG_SMALL("Extract a single field."),
  188.  
  189.     .priv_size     = sizeof(FieldContext),
  190.     .init          = init,
  191.     .uninit        = uninit,
  192.     .query_formats = query_formats,
  193.  
  194.     .inputs    = (const AVFilterPad[]) {
  195.         { .name             = "default",
  196.           .type             = AVMEDIA_TYPE_VIDEO,
  197.           .draw_slice       = null_draw_slice,
  198.           .config_props     = config_input,
  199.           .end_frame        = end_frame },
  200.         { .name = NULL}
  201.     },
  202.     .outputs   = (const AVFilterPad[]) {
  203.         { .name             = "default",
  204.           .type             = AVMEDIA_TYPE_VIDEO },
  205.         { .name = NULL}
  206.     },
  207. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement