decoder.c 4.79 KB
Newer Older
1
/*****************************************************************************
gbazin's avatar
   
gbazin committed
2
 * decoder.c: dummy decoder plugin for vlc.
3
4
 *****************************************************************************
 * Copyright (C) 2002 VideoLAN
5
 * $Id: decoder.c,v 1.10 2004/01/25 22:16:26 rocky Exp $
6
7
 *
 * Authors: Samuel Hocevar <sam@zoy.org>
Sam Hocevar's avatar
Sam Hocevar committed
8
 *
9
10
11
12
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
Sam Hocevar's avatar
Sam Hocevar committed
13
 *
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <vlc/vlc.h>
#include <vlc/decoder.h>

#ifdef HAVE_UNISTD_H
#   include <unistd.h> /* write(), close() */
gbazin's avatar
   
gbazin committed
32
33
#elif defined( WIN32 ) && !defined( UNDER_CE )
#   include <io.h>
34
#endif
35
36
37
38
39
40
41
42
43
#ifdef HAVE_SYS_TYPES_H
#   include <sys/types.h> /* open() */
#endif
#ifdef HAVE_SYS_STAT_H
#   include <sys/stat.h>
#endif
#ifdef HAVE_FCNTL_H
#   include <fcntl.h>
#endif
44

45
46
47
48
#ifdef HAVE_LIMITS_H
#   include <limits.h> /* PATH_MAX */
#endif

49
50
51
#include <stdio.h> /* sprintf() */

/*****************************************************************************
gbazin's avatar
   
gbazin committed
52
 * decoder_sys_t : theora decoder descriptor
53
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
54
55
56
57
struct decoder_sys_t
{
    int i_fd;
};
58
59

/*****************************************************************************
gbazin's avatar
   
gbazin committed
60
 * Local prototypes
61
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
62
static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block );
63
64

/*****************************************************************************
gbazin's avatar
   
gbazin committed
65
 * OpenDecoder: Open the decoder
66
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
67
int E_(OpenDecoder) ( vlc_object_t *p_this )
68
{
gbazin's avatar
   
gbazin committed
69
70
71
    decoder_t *p_dec = (decoder_t*)p_this;
    decoder_sys_t *p_sys;
    char psz_file[ PATH_MAX ];
gbazin's avatar
   
gbazin committed
72
    vlc_value_t val;
73

gbazin's avatar
   
gbazin committed
74
75
76
77
78
79
80
    /* Allocate the memory needed to store the decoder's structure */
    if( ( p_dec->p_sys = p_sys =
          (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
    {
        msg_Err( p_dec, "out of memory" );
        return VLC_EGENERIC;
    }
81

gbazin's avatar
   
gbazin committed
82
    sprintf( psz_file, "stream.%i", p_dec->i_object_id );
83

84
#ifndef UNDER_CE
gbazin's avatar
   
gbazin committed
85
86
87
    var_Create( p_dec, "dummy-save-es", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
    var_Get( p_dec, "dummy-save-es", &val );
    if( val.b_bool )
88
    {
gbazin's avatar
   
gbazin committed
89
90
91
92
93
94
95
96
97
        p_sys->i_fd = open( psz_file, O_WRONLY | O_CREAT | O_TRUNC, 00644 );

        if( p_sys->i_fd == -1 )
        {
            msg_Err( p_dec, "cannot create `%s'", psz_file );
            return VLC_EGENERIC;
        }

        msg_Dbg( p_dec, "dumping stream to file `%s'", psz_file );
98
    }
gbazin's avatar
   
gbazin committed
99
    else
100
#endif
gbazin's avatar
   
gbazin committed
101
102
103
    {
        p_sys->i_fd = -1;
    }
104

gbazin's avatar
   
gbazin committed
105
106
107
108
109
    /* Set callbacks */
    p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
        DecodeBlock;
    p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))
        DecodeBlock;
110

gbazin's avatar
   
gbazin committed
111
112
    return VLC_SUCCESS;
}
113

gbazin's avatar
   
gbazin committed
114
115
116
117
118
119
120
121
122
/****************************************************************************
 * RunDecoder: the whole thing
 ****************************************************************************
 * This function must be fed with ogg packets.
 ****************************************************************************/
static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
{
    decoder_sys_t *p_sys = p_dec->p_sys;
    block_t *p_block;
123

gbazin's avatar
   
gbazin committed
124
125
    if( !pp_block || !*pp_block ) return NULL;
    p_block = *pp_block;
126

gbazin's avatar
   
gbazin committed
127
    if( p_sys->i_fd >= 0 && p_block->i_buffer )
gbazin's avatar
   
gbazin committed
128
129
130
131
    {
#ifndef UNDER_CE
        write( p_sys->i_fd, p_block->p_buffer, p_block->i_buffer );
#endif
132

gbazin's avatar
   
gbazin committed
133
        msg_Dbg( p_dec, "dumped %i bytes", p_block->i_buffer );
134
135
    }

gbazin's avatar
   
gbazin committed
136
137
138
139
140
141
142
143
144
145
146
    block_Release( p_block );
    return NULL;
}

/*****************************************************************************
 * CloseDecoder: decoder destruction
 *****************************************************************************/
void E_(CloseDecoder) ( vlc_object_t *p_this )
{
    decoder_t *p_dec = (decoder_t *)p_this;
    decoder_sys_t *p_sys = p_dec->p_sys;
147

148
#ifndef UNDER_CE
gbazin's avatar
   
gbazin committed
149
    if( p_sys->i_fd >= 0 ) close( p_sys->i_fd );
150
#endif
151

gbazin's avatar
   
gbazin committed
152
    free( p_sys );
153
}