copy.c 9.66 KB
Newer Older
1
2
3
4
/*****************************************************************************
 * copy.c
 *****************************************************************************
 * Copyright (C) 2001, 2002 VideoLAN
5
 * $Id$
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 *          Eric Petit <titer@videolan.org>
 *
 * 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.
 *
 * 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
 *****************************************************************************/
28
29
#include <stdlib.h>                                      /* malloc(), free() */

30
31
32
#include <vlc/vlc.h>
#include <vlc/decoder.h>
#include <vlc/input.h>
33
34
35
36

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
Laurent Aimar's avatar
Laurent Aimar committed
37
38
static int  Open ( vlc_object_t * );
static void Close( vlc_object_t * );
39
40

vlc_module_begin();
41
    set_description( _("Copy packetizer") );
42
    set_capability( "packetizer", 1 );
Laurent Aimar's avatar
Laurent Aimar committed
43
    set_callbacks( Open, Close );
44
45
vlc_module_end();

46
47
48
/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
Laurent Aimar's avatar
Laurent Aimar committed
49
struct decoder_sys_t
50
{
Laurent Aimar's avatar
Laurent Aimar committed
51
52
    block_t *p_block;
};
53

54
static block_t *Packetize ( decoder_t *, block_t ** );
55

56
/*****************************************************************************
57
 * Open: probe the packetizer and return score
58
59
60
61
62
63
 *****************************************************************************
 * Tries to launch a decoder and return score so that the interface is able
 * to choose.
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
Laurent Aimar's avatar
Laurent Aimar committed
64
65
    decoder_t     *p_dec = (decoder_t*)p_this;
    decoder_sys_t *p_sys;
66

67
68
69
    if( p_dec->fmt_in.i_cat != AUDIO_ES &&
        p_dec->fmt_in.i_cat != VIDEO_ES &&
        p_dec->fmt_in.i_cat != SPU_ES )
70
    {
Laurent Aimar's avatar
Laurent Aimar committed
71
72
        msg_Err( p_dec, "invalid ES type" );
        return VLC_EGENERIC;
73
74
    }

75
76
    p_dec->pf_packetize = Packetize;

Laurent Aimar's avatar
Laurent Aimar committed
77
    /* Create the output format */
78
    es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
79

Laurent Aimar's avatar
Laurent Aimar committed
80
81
    /* Fix the value of the fourcc */
    switch( p_dec->fmt_in.i_codec )
82
    {
83
        /* video */
84
85
86
87
        case VLC_FOURCC( 'm', '4', 's', '2'):
        case VLC_FOURCC( 'M', '4', 'S', '2'):
        case VLC_FOURCC( 'm', 'p', '4', 's'):
        case VLC_FOURCC( 'M', 'P', '4', 'S'):
88
89
90
91
92
93
        case VLC_FOURCC( 'D', 'I', 'V', 'X'):
        case VLC_FOURCC( 'd', 'i', 'v', 'x'):
        case VLC_FOURCC( 'X', 'V', 'I', 'D'):
        case VLC_FOURCC( 'X', 'v', 'i', 'D'):
        case VLC_FOURCC( 'x', 'v', 'i', 'd'):
        case VLC_FOURCC( 'D', 'X', '5', '0'):
94
95
        case VLC_FOURCC( 0x04, 0,   0,   0):
        case VLC_FOURCC( '3', 'I', 'V', '2'):
Laurent Aimar's avatar
Laurent Aimar committed
96
            p_dec->fmt_out.i_codec = VLC_FOURCC( 'm', 'p', '4', 'v');
97
            break;
Laurent Aimar's avatar
Laurent Aimar committed
98

99
100
        case VLC_FOURCC( 'm', 'p', 'g', '1' ):
        case VLC_FOURCC( 'm', 'p', 'g', '2' ):
101
102
        case VLC_FOURCC( 'm', 'p', '1', 'v' ):
        case VLC_FOURCC( 'm', 'p', '2', 'v' ):
Laurent Aimar's avatar
Laurent Aimar committed
103
            p_dec->fmt_out.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'v' );
104
            break;
105
106
107
108

        case VLC_FOURCC( 'd', 'i', 'v', '1' ):
        case VLC_FOURCC( 'M', 'P', 'G', '4' ):
        case VLC_FOURCC( 'm', 'p', 'g', '4' ):
Laurent Aimar's avatar
Laurent Aimar committed
109
            p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '1' );
110
            break;
Laurent Aimar's avatar
Laurent Aimar committed
111

112
113
114
        case VLC_FOURCC( 'd', 'i', 'v', '2' ):
        case VLC_FOURCC( 'M', 'P', '4', '2' ):
        case VLC_FOURCC( 'm', 'p', '4', '2' ):
Laurent Aimar's avatar
Laurent Aimar committed
115
            p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '2' );
116
            break;
Laurent Aimar's avatar
Laurent Aimar committed
117

118
119
120
121
122
123
124
125
126
127
128
129
        case VLC_FOURCC( 'd', 'i', 'v', '3' ):
        case VLC_FOURCC( 'd', 'i', 'v', '4' ):
        case VLC_FOURCC( 'D', 'I', 'V', '4' ):
        case VLC_FOURCC( 'd', 'i', 'v', '5' ):
        case VLC_FOURCC( 'D', 'I', 'V', '5' ):
        case VLC_FOURCC( 'd', 'i', 'v', '6' ):
        case VLC_FOURCC( 'D', 'I', 'V', '6' ):
        case VLC_FOURCC( 'M', 'P', '4', '3' ):
        case VLC_FOURCC( 'm', 'p', '4', '3' ):
        case VLC_FOURCC( 'm', 'p', 'g', '3' ):
        case VLC_FOURCC( 'M', 'P', 'G', '3' ):
        case VLC_FOURCC( 'A', 'P', '4', '1' ):
Laurent Aimar's avatar
Laurent Aimar committed
130
            p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '3' );
131
            break;
Laurent Aimar's avatar
Laurent Aimar committed
132

133
134
135
        case VLC_FOURCC( 'h', '2', '6', '3' ):
        case VLC_FOURCC( 'U', '2', '6', '3' ):
        case VLC_FOURCC( 'u', '2', '6', '3' ):
Laurent Aimar's avatar
Laurent Aimar committed
136
            p_dec->fmt_out.i_codec = VLC_FOURCC( 'H', '2', '6', '3' );
137
            break;
Laurent Aimar's avatar
Laurent Aimar committed
138

139
        case VLC_FOURCC( 'i', '2', '6', '3' ):
Laurent Aimar's avatar
Laurent Aimar committed
140
            p_dec->fmt_out.i_codec = VLC_FOURCC( 'I', '2', '6', '3' );
141
            break;
Laurent Aimar's avatar
Laurent Aimar committed
142

143
144
145
146
147
        case VLC_FOURCC( 'm', 'j', 'p', 'g' ):
        case VLC_FOURCC( 'm', 'j', 'p', 'a' ):
        case VLC_FOURCC( 'j', 'p', 'e', 'g' ):
        case VLC_FOURCC( 'J', 'P', 'E', 'G' ):
        case VLC_FOURCC( 'J', 'F', 'I', 'F' ):
Laurent Aimar's avatar
Laurent Aimar committed
148
            p_dec->fmt_out.i_codec = VLC_FOURCC( 'M', 'J', 'P', 'G' );
149
            break;
Laurent Aimar's avatar
Laurent Aimar committed
150

151
152
153
        case VLC_FOURCC( 'd', 'v', 's', 'd' ):
        case VLC_FOURCC( 'D', 'V', 'S', 'D' ):
        case VLC_FOURCC( 'd', 'v', 'h', 'd' ):
Laurent Aimar's avatar
Laurent Aimar committed
154
            p_dec->fmt_out.i_codec = VLC_FOURCC( 'd', 'v', 's', 'l' );
gbazin's avatar
   
gbazin committed
155
            break;
156

157
158
        /* audio */
        case VLC_FOURCC( 'a', 'r', 'a', 'w' ):
Laurent Aimar's avatar
Laurent Aimar committed
159
            switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
160
            {
Laurent Aimar's avatar
Laurent Aimar committed
161
162
163
164
165
166
167
168
169
170
171
172
173
                case 1:
                    p_dec->fmt_out.i_codec = VLC_FOURCC('u','8',' ',' ');
                    break;
                case 2:
                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l');
                    break;
                case 3:
                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l');
                    break;
                case 4:
                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l');
                    break;
                default:
174
                    msg_Err( p_dec, "unknown raw audio sample size" );
Laurent Aimar's avatar
Laurent Aimar committed
175
                    return VLC_EGENERIC;
176
177
            }
            break;
Laurent Aimar's avatar
Laurent Aimar committed
178

179
        case VLC_FOURCC( 't', 'w', 'o', 's' ):
Laurent Aimar's avatar
Laurent Aimar committed
180
            switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
181
            {
Laurent Aimar's avatar
Laurent Aimar committed
182
183
184
185
186
187
188
189
190
191
192
193
194
                case 1:
                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' ');
                    break;
                case 2:
                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','b');
                    break;
                case 3:
                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','b');
                    break;
                case 4:
                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','b');
                    break;
                default:
195
                    msg_Err( p_dec, "unknown raw audio sample size" );
Laurent Aimar's avatar
Laurent Aimar committed
196
                    return VLC_EGENERIC;
197
198
            }
            break;
Laurent Aimar's avatar
Laurent Aimar committed
199

200
        case VLC_FOURCC( 's', 'o', 'w', 't' ):
Laurent Aimar's avatar
Laurent Aimar committed
201
            switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
202
            {
Laurent Aimar's avatar
Laurent Aimar committed
203
204
205
206
207
208
209
210
211
212
213
214
215
                case 1:
                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' ');
                    break;
                case 2:
                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l');
                    break;
                case 3:
                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l');
                    break;
                case 4:
                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l');
                    break;
                default:
216
                    msg_Err( p_dec, "unknown raw audio sample size" );
Laurent Aimar's avatar
Laurent Aimar committed
217
                    return VLC_EGENERIC;
218
219
            }
            break;
220
    }
221

Laurent Aimar's avatar
Laurent Aimar committed
222
223
    p_dec->p_sys = p_sys = malloc( sizeof( block_t ) );
    p_sys->p_block    = NULL;
224

Laurent Aimar's avatar
Laurent Aimar committed
225
226
    return VLC_SUCCESS;
}
227

Laurent Aimar's avatar
Laurent Aimar committed
228
229
230
231
232
233
/*****************************************************************************
 * Close:
 *****************************************************************************/
static void Close( vlc_object_t *p_this )
{
    decoder_t     *p_dec = (decoder_t*)p_this;
234

Laurent Aimar's avatar
Laurent Aimar committed
235
    if( p_dec->p_sys->p_block )
236
    {
Laurent Aimar's avatar
Laurent Aimar committed
237
        block_ChainRelease( p_dec->p_sys->p_block );
238
    }
239

Laurent Aimar's avatar
Laurent Aimar committed
240
    free( p_dec->p_sys );
241
242
243
}

/*****************************************************************************
Laurent Aimar's avatar
Laurent Aimar committed
244
 * PacketizeStd: packetize an unit (here copy a complete block )
245
 *****************************************************************************/
246
static block_t *Packetize ( decoder_t *p_dec, block_t **pp_block )
247
{
Laurent Aimar's avatar
Laurent Aimar committed
248
249
    block_t *p_block;
    block_t *p_ret = p_dec->p_sys->p_block;
250

Laurent Aimar's avatar
Laurent Aimar committed
251
    if( pp_block == NULL || *pp_block == NULL )
252
    {
Laurent Aimar's avatar
Laurent Aimar committed
253
        return NULL;
254
    }
Laurent Aimar's avatar
Laurent Aimar committed
255
256
    p_block = *pp_block;
    *pp_block = NULL;
257

258
    if( p_block->i_dts <= 0 )
259
260
261
262
    {
        p_block->i_dts = p_block->i_pts;
    }

263
    if( p_block->i_dts <= 0 )
264
    {
265
        msg_Dbg( p_dec, "need dts > 0" );
Laurent Aimar's avatar
Laurent Aimar committed
266
267
        block_Release( p_block );
        return NULL;
268
    }
269

270
271
    if( p_dec->fmt_in.i_cat != SPU_ES &&
        p_ret != NULL && p_block->i_pts > p_ret->i_pts )
272
    {
Laurent Aimar's avatar
Laurent Aimar committed
273
        p_ret->i_length = p_block->i_pts - p_ret->i_pts;
274
    }
Laurent Aimar's avatar
Laurent Aimar committed
275
    p_dec->p_sys->p_block = p_block;
276

Laurent Aimar's avatar
Laurent Aimar committed
277
    return p_ret;
278
}