• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavfilter/vsink_buffer.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Stefano Sabatini
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00026 #include "avfilter.h"
00027 #include "vsink_buffer.h"
00028 
00029 typedef struct {
00030     AVFilterBufferRef *picref;   
00031     enum PixelFormat *pix_fmts;  
00032 } BufferSinkContext;
00033 
00034 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
00035 {
00036     BufferSinkContext *buf = ctx->priv;
00037 
00038     if (!opaque) {
00039         av_log(ctx, AV_LOG_ERROR, "No opaque field provided, which is required.\n");
00040         return AVERROR(EINVAL);
00041     }
00042 
00043     buf->pix_fmts = opaque;
00044     return 0;
00045 }
00046 
00047 static av_cold void uninit(AVFilterContext *ctx)
00048 {
00049     BufferSinkContext *buf = ctx->priv;
00050 
00051     if (buf->picref)
00052         avfilter_unref_buffer(buf->picref);
00053     buf->picref = NULL;
00054 }
00055 
00056 static void end_frame(AVFilterLink *inlink)
00057 {
00058     BufferSinkContext *buf = inlink->dst->priv;
00059 
00060     if (buf->picref)            /* drop the last cached frame */
00061         avfilter_unref_buffer(buf->picref);
00062     buf->picref = inlink->cur_buf;
00063 }
00064 
00065 static int query_formats(AVFilterContext *ctx)
00066 {
00067     BufferSinkContext *buf = ctx->priv;
00068 
00069     avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(buf->pix_fmts));
00070     return 0;
00071 }
00072 
00073 int av_vsink_buffer_get_video_buffer_ref(AVFilterContext *ctx,
00074                                          AVFilterBufferRef **picref, int flags)
00075 {
00076     BufferSinkContext *buf = ctx->priv;
00077     AVFilterLink *inlink = ctx->inputs[0];
00078     int ret;
00079     *picref = NULL;
00080 
00081     /* no picref available, fetch it from the filterchain */
00082     if (!buf->picref) {
00083         if ((ret = avfilter_request_frame(inlink)) < 0)
00084             return ret;
00085     }
00086 
00087     if (!buf->picref)
00088         return AVERROR(EINVAL);
00089 
00090     *picref = buf->picref;
00091     if (!(flags & AV_VSINK_BUF_FLAG_PEEK))
00092         buf->picref = NULL;
00093 
00094     return 0;
00095 }
00096 
00097 AVFilter avfilter_vsink_buffersink = {
00098     .name      = "buffersink",
00099     .priv_size = sizeof(BufferSinkContext),
00100     .init      = init,
00101     .uninit    = uninit,
00102 
00103     .query_formats = query_formats,
00104 
00105     .inputs    = (AVFilterPad[]) {{ .name          = "default",
00106                                     .type          = AVMEDIA_TYPE_VIDEO,
00107                                     .end_frame     = end_frame,
00108                                     .min_perms     = AV_PERM_READ, },
00109                                   { .name = NULL }},
00110     .outputs   = (AVFilterPad[]) {{ .name = NULL }},
00111 };

Generated on Wed Apr 11 2012 07:31:36 for FFmpeg by  doxygen 1.7.1