]> git.sesse.net Git - vlc/blob - modules/misc/dummy/decoder.c
* ALL: another bunch of fixes for the MSVC build.
[vlc] / modules / misc / dummy / decoder.c
1 /*****************************************************************************
2  * dec_dummy.c: dummy decoder plugin for vlc.
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: decoder.c,v 1.5 2003/03/03 16:49:14 gbazin 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 #elif defined( WIN32 ) && !defined( UNDER_CE )
33 #   include <io.h>
34 #endif
35 #ifdef HAVE_SYS_TYPES_H
36 #   include <sys/types.h> /* open() */
37 #endif
38 #ifdef HAVE_SYS_STAT_H
39 #   include <sys/stat.h>
40 #endif
41 #ifdef HAVE_FCNTL_H
42 #   include <fcntl.h>
43 #endif
44
45 #include <stdio.h> /* sprintf() */
46
47 /*****************************************************************************
48  * Local prototypes
49  *****************************************************************************/
50 static int Run ( decoder_fifo_t * );
51
52 /*****************************************************************************
53  * OpenDecoder: probe the decoder and return score
54  *****************************************************************************
55  * Always returns 0 because we are the dummy decoder!
56  *****************************************************************************/
57 int E_(OpenDecoder) ( vlc_object_t *p_this )
58 {
59     ((decoder_fifo_t*)p_this)->pf_run = Run;
60
61     return VLC_SUCCESS;
62 }
63
64 /*****************************************************************************
65  * Run: this function is called just after the thread is created
66  *****************************************************************************/
67 static int Run ( decoder_fifo_t *p_fifo )
68 {
69     u8           p_buffer[1024];
70
71     bit_stream_t bit_stream;
72     mtime_t      last_date = mdate();
73     size_t       i_bytes = 0;
74
75     char         psz_file[100];
76 #ifndef UNDER_CE
77     int          i_fd;
78 #endif
79
80     sprintf( psz_file, "stream.%i", p_fifo->i_object_id );
81 #ifndef UNDER_CE
82     i_fd = open( psz_file, O_WRONLY | O_CREAT | O_TRUNC, 00644 );
83
84     if( i_fd == -1 )
85     {
86         msg_Err( p_fifo, "cannot create `%s'", psz_file );
87         p_fifo->b_error = 1;
88         DecoderError( p_fifo );
89         return -1;
90     }
91 #endif
92
93     msg_Dbg( p_fifo, "dumping stream to file `%s'", psz_file );
94
95     if( InitBitstream( &bit_stream, p_fifo, NULL, NULL ) != VLC_SUCCESS )
96     {
97         msg_Err( p_fifo, "cannot initialize bitstream" );
98         p_fifo->b_error = 1;
99         DecoderError( p_fifo );
100 #ifndef UNDER_CE
101         close( i_fd );
102 #endif
103         return -1;
104     }
105
106     while( !p_fifo->b_die && !p_fifo->b_error )
107     {
108         GetChunk( &bit_stream, p_buffer, 1024 );
109 #ifndef UNDER_CE
110         write( i_fd, p_buffer, 1024 );
111
112         i_bytes += 1024;
113 #endif
114
115         if( mdate() < last_date + 2000000 )
116         {
117             continue;
118         }
119
120         msg_Dbg( p_fifo, "dumped %i bytes", i_bytes );
121
122         i_bytes = 0;
123         last_date = mdate();
124     }
125
126     if( i_bytes )
127     {
128         msg_Dbg( p_fifo, "dumped %i bytes", i_bytes );
129     }
130
131 #ifndef UNDER_CE
132     close( i_fd );
133 #endif
134     CloseBitstream( &bit_stream );
135
136     if( p_fifo->b_error )
137     {
138         DecoderError( p_fifo );
139         return -1;
140     }
141
142     return 0;
143 }