]> git.sesse.net Git - vlc/blob - plugins/dummy/dec_dummy.c
9d65097287ecbc40447175f6cdb202360be77f37
[vlc] / plugins / dummy / dec_dummy.c
1 /*****************************************************************************
2  * dec_dummy.c: dummy decoder plugin for vlc.
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: dec_dummy.c,v 1.1 2002/07/23 20:15:41 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *      
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28 #include <vlc/decoder.h>
29
30 #ifdef HAVE_UNISTD_H
31 #   include <unistd.h> /* write(), close() */
32 #endif
33
34 #include <sys/types.h> /* open() */
35 #include <sys/stat.h>
36 #include <fcntl.h>
37
38 #include <stdio.h> /* sprintf() */
39
40 /*****************************************************************************
41  * Local prototypes
42  *****************************************************************************/
43 static int  Probe  ( vlc_fourcc_t * );
44 static int  Run    ( decoder_fifo_t * );
45
46 /*****************************************************************************
47  * Capabilities
48  *****************************************************************************/
49 void _M( dec_getfunctions )( function_list_t * p_function_list )
50 {
51     p_function_list->functions.dec.pf_probe = Probe;
52     p_function_list->functions.dec.pf_run   = Run;
53 }
54
55 /*****************************************************************************
56  * Probe: probe the decoder and return score
57  *****************************************************************************
58  * Always returns 0 because we are the dummy decoder!
59  *****************************************************************************/
60 static int Probe( vlc_fourcc_t *pi_type )
61 {
62     return 0;
63 }
64
65 /*****************************************************************************
66  * Run: this function is called just after the thread is created
67  *****************************************************************************/
68 static int Run ( decoder_fifo_t *p_fifo )
69 {
70     bit_stream_t bit_stream;
71     mtime_t      last_date = mdate();
72     size_t       i_bytes = 0;
73
74     char         psz_file[100];
75     int          i_fd;
76
77     sprintf( psz_file, "stream.%i", p_fifo->i_object_id );
78     i_fd = open( psz_file, O_WRONLY | O_CREAT | O_TRUNC, 00644 );
79
80     if( i_fd == -1 )
81     {
82         msg_Err( p_fifo, "cannot create `%s'", psz_file );
83         p_fifo->b_error = 1;
84         DecoderError( p_fifo );
85         return -1;
86     }
87
88     msg_Dbg( p_fifo, "dumping stream to file `%s'", psz_file );
89
90     InitBitstream( &bit_stream, p_fifo, NULL, NULL );
91
92     while( !p_fifo->b_die && !p_fifo->b_error )
93     {
94         byte_t byte;
95
96         byte = GetBits( &bit_stream, 8 );
97         i_bytes++;
98
99         write( i_fd, &byte, 1 );
100
101         if( mdate() < last_date + 2000000 )
102         {
103             continue;
104         }
105
106         msg_Dbg( p_fifo, "dumped %i bytes", i_bytes );
107
108         i_bytes = 0;
109         last_date = mdate();
110     }
111
112     if( i_bytes )
113     {
114         msg_Dbg( p_fifo, "dumped %i bytes", i_bytes );
115     }
116
117     close( i_fd );
118
119     if( p_fifo->b_error )
120     {
121         DecoderError( p_fifo );
122         return -1;
123     }
124
125     return 0;
126 }
127