]> git.sesse.net Git - x264/blob - filters/video/source.c
Bump dates to 2016
[x264] / filters / video / source.c
1 /*****************************************************************************
2  * source.c: source video filter
3  *****************************************************************************
4  * Copyright (C) 2010-2016 x264 project
5  *
6  * Authors: Steven Walters <kemuri9@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
21  *
22  * This program is also available under a commercial proprietary license.
23  * For more information, contact us at licensing@x264.com.
24  *****************************************************************************/
25
26 #include "video.h"
27
28 /* This filter converts the demuxer API into the filtering API for video frames.
29  * Backseeking is prohibited here as not all demuxers are capable of doing so. */
30
31 typedef struct
32 {
33     cli_pic_t pic;
34     hnd_t hin;
35     int cur_frame;
36 } source_hnd_t;
37
38 cli_vid_filter_t source_filter;
39
40 static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string )
41 {
42     source_hnd_t *h = calloc( 1, sizeof(source_hnd_t) );
43     if( !h )
44         return -1;
45     h->cur_frame = -1;
46
47     if( cli_input.picture_alloc( &h->pic, *handle, info->csp, info->width, info->height ) )
48         return -1;
49
50     h->hin = *handle;
51     *handle = h;
52     *filter = source_filter;
53
54     return 0;
55 }
56
57 static int get_frame( hnd_t handle, cli_pic_t *output, int frame )
58 {
59     source_hnd_t *h = handle;
60     /* do not allow requesting of frames from before the current position */
61     if( frame <= h->cur_frame || cli_input.read_frame( &h->pic, h->hin, frame ) )
62         return -1;
63     h->cur_frame = frame;
64     *output = h->pic;
65     return 0;
66 }
67
68 static int release_frame( hnd_t handle, cli_pic_t *pic, int frame )
69 {
70     source_hnd_t *h = handle;
71     if( cli_input.release_frame && cli_input.release_frame( &h->pic, h->hin ) )
72         return -1;
73     return 0;
74 }
75
76 static void free_filter( hnd_t handle )
77 {
78     source_hnd_t *h = handle;
79     cli_input.picture_clean( &h->pic, h->hin );
80     cli_input.close_file( h->hin );
81     free( h );
82 }
83
84 cli_vid_filter_t source_filter = { "source", NULL, init, get_frame, release_frame, free_filter, NULL };