/*****************************************************************************1* source.c: source video filter2*****************************************************************************3* Copyright (C) 2010-2016 x264 project4*5* Authors: Steven Walters <[email protected]>6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License, or10* (at your option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.20*21* This program is also available under a commercial proprietary license.22* For more information, contact us at [email protected].23*****************************************************************************/2425#include "video.h"2627/* This filter converts the demuxer API into the filtering API for video frames.28* Backseeking is prohibited here as not all demuxers are capable of doing so. */2930typedef struct31{32cli_pic_t pic;33hnd_t hin;34int cur_frame;35} source_hnd_t;3637cli_vid_filter_t source_filter;3839static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string )40{41source_hnd_t *h = calloc( 1, sizeof(source_hnd_t) );42if( !h )43return -1;44h->cur_frame = -1;4546if( cli_input.picture_alloc( &h->pic, *handle, info->csp, info->width, info->height ) )47return -1;4849h->hin = *handle;50*handle = h;51*filter = source_filter;5253return 0;54}5556static int get_frame( hnd_t handle, cli_pic_t *output, int frame )57{58source_hnd_t *h = handle;59/* do not allow requesting of frames from before the current position */60if( frame <= h->cur_frame || cli_input.read_frame( &h->pic, h->hin, frame ) )61return -1;62h->cur_frame = frame;63*output = h->pic;64return 0;65}6667static int release_frame( hnd_t handle, cli_pic_t *pic, int frame )68{69source_hnd_t *h = handle;70if( cli_input.release_frame && cli_input.release_frame( &h->pic, h->hin ) )71return -1;72return 0;73}7475static void free_filter( hnd_t handle )76{77source_hnd_t *h = handle;78cli_input.picture_clean( &h->pic, h->hin );79cli_input.close_file( h->hin );80free( h );81}8283cli_vid_filter_t source_filter = { "source", NULL, init, get_frame, release_frame, free_filter, NULL };848586