~ubuntu-branches/ubuntu/natty/vlc/natty

« back to all changes in this revision

Viewing changes to modules/stream_out/transcode/spu.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-06-25 01:09:16 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: james.westby@ubuntu.com-20100625010916-asxhep2mutg6g6pd
Tags: 1.1.0-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - build and install the libx264 plugin
  - add Xb-Npp header to vlc package
  - Add apport hook to include more vlc dependencies in bug reports
* Drop xulrunner patches.
* Drop 502_xulrunner_191.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 * spu.c: transcoding stream output module (spu)
 
3
 *****************************************************************************
 
4
 * Copyright (C) 2003-2009 the VideoLAN team
 
5
 * $Id: e493b6ff62a05d747cd054fe7d12e18a18e02454 $
 
6
 *
 
7
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 
8
 *          Gildas Bazin <gbazin@videolan.org>
 
9
 *          Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
 
10
 *          Antoine Cellerier <dionoea at videolan dot org>
 
11
 *
 
12
 * This program is free software; you can redistribute it and/or modify
 
13
 * it under the terms of the GNU General Public License as published by
 
14
 * the Free Software Foundation; either version 2 of the License, or
 
15
 * (at your option) any later version.
 
16
 *
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 *
 
22
 * You should have received a copy of the GNU General Public License
 
23
 * along with this program; if not, write to the Free Software
 
24
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 
25
 *****************************************************************************/
 
26
 
 
27
/*****************************************************************************
 
28
 * Preamble
 
29
 *****************************************************************************/
 
30
 
 
31
#include "transcode.h"
 
32
 
 
33
#include <vlc_meta.h>
 
34
#include <vlc_osd.h>
 
35
#include <assert.h>
 
36
 
 
37
static subpicture_t *spu_new_buffer( decoder_t *p_dec )
 
38
{
 
39
    VLC_UNUSED( p_dec );
 
40
    return subpicture_New();
 
41
}
 
42
 
 
43
static void spu_del_buffer( decoder_t *p_dec, subpicture_t *p_subpic )
 
44
{
 
45
    VLC_UNUSED( p_dec );
 
46
    subpicture_Delete( p_subpic );
 
47
}
 
48
int transcode_spu_new( sout_stream_t *p_stream, sout_stream_id_t *id )
 
49
{
 
50
    sout_stream_sys_t *p_sys = p_stream->p_sys;
 
51
 
 
52
    /*
 
53
     * Open decoder
 
54
     */
 
55
 
 
56
    /* Initialization of decoder structures */
 
57
    id->p_decoder->pf_decode_sub = NULL;
 
58
    id->p_decoder->pf_spu_buffer_new = spu_new_buffer;
 
59
    id->p_decoder->pf_spu_buffer_del = spu_del_buffer;
 
60
    id->p_decoder->p_owner = (decoder_owner_sys_t *)p_stream;
 
61
    /* id->p_decoder->p_cfg = p_sys->p_spu_cfg; */
 
62
 
 
63
    id->p_decoder->p_module =
 
64
        module_need( id->p_decoder, "decoder", "$codec", false );
 
65
 
 
66
    if( !id->p_decoder->p_module )
 
67
    {
 
68
        msg_Err( p_stream, "cannot find spu decoder" );
 
69
        return VLC_EGENERIC;
 
70
    }
 
71
 
 
72
    if( !p_sys->b_soverlay )
 
73
    {
 
74
        /* Open encoder */
 
75
        /* Initialization of encoder format structures */
 
76
        es_format_Init( &id->p_encoder->fmt_in, id->p_decoder->fmt_in.i_cat,
 
77
                        id->p_decoder->fmt_in.i_codec );
 
78
 
 
79
        id->p_encoder->p_cfg = p_sys->p_spu_cfg;
 
80
 
 
81
        id->p_encoder->p_module =
 
82
            module_need( id->p_encoder, "encoder", p_sys->psz_senc, true );
 
83
 
 
84
        if( !id->p_encoder->p_module )
 
85
        {
 
86
            module_unneed( id->p_decoder, id->p_decoder->p_module );
 
87
            msg_Err( p_stream, "cannot find spu encoder (%s)", p_sys->psz_senc );
 
88
            return VLC_EGENERIC;
 
89
        }
 
90
    }
 
91
 
 
92
    if( !p_sys->p_spu )
 
93
    {
 
94
        p_sys->p_spu = spu_Create( p_stream );
 
95
        spu_Init( p_sys->p_spu );
 
96
    }
 
97
 
 
98
    return VLC_SUCCESS;
 
99
}
 
100
 
 
101
void transcode_spu_close( sout_stream_id_t *id)
 
102
{
 
103
    /* Close decoder */
 
104
    if( id->p_decoder->p_module )
 
105
        module_unneed( id->p_decoder, id->p_decoder->p_module );
 
106
    if( id->p_decoder->p_description )
 
107
        vlc_meta_Delete( id->p_decoder->p_description );
 
108
 
 
109
    /* Close encoder */
 
110
    if( id->p_encoder->p_module )
 
111
        module_unneed( id->p_encoder, id->p_encoder->p_module );
 
112
}
 
113
 
 
114
int transcode_spu_process( sout_stream_t *p_stream,
 
115
                                  sout_stream_id_t *id,
 
116
                                  block_t *in, block_t **out )
 
117
{
 
118
    sout_stream_sys_t *p_sys = p_stream->p_sys;
 
119
    subpicture_t *p_subpic;
 
120
    *out = NULL;
 
121
 
 
122
    p_subpic = id->p_decoder->pf_decode_sub( id->p_decoder, &in );
 
123
    if( !p_subpic )
 
124
        return VLC_EGENERIC;
 
125
 
 
126
    sout_UpdateStatistic( p_stream->p_sout, SOUT_STATISTIC_DECODED_SUBTITLE, 1 );
 
127
 
 
128
    if( p_sys->b_master_sync && p_sys->i_master_drift )
 
129
    {
 
130
        p_subpic->i_start -= p_sys->i_master_drift;
 
131
        if( p_subpic->i_stop ) p_subpic->i_stop -= p_sys->i_master_drift;
 
132
    }
 
133
 
 
134
    if( p_sys->b_soverlay )
 
135
    {
 
136
        spu_DisplaySubpicture( p_sys->p_spu, p_subpic );
 
137
    }
 
138
    else
 
139
    {
 
140
        block_t *p_block;
 
141
 
 
142
        p_block = id->p_encoder->pf_encode_sub( id->p_encoder, p_subpic );
 
143
        spu_del_buffer( id->p_decoder, p_subpic );
 
144
        if( p_block )
 
145
        {
 
146
            block_ChainAppend( out, p_block );
 
147
            return VLC_SUCCESS;
 
148
        }
 
149
    }
 
150
 
 
151
    return VLC_EGENERIC;
 
152
}
 
153
 
 
154
bool transcode_spu_add( sout_stream_t *p_stream, es_format_t *p_fmt,
 
155
                        sout_stream_id_t *id )
 
156
{
 
157
    sout_stream_sys_t *p_sys = p_stream->p_sys;
 
158
 
 
159
    if( p_sys->i_scodec || p_sys->psz_senc )
 
160
    {
 
161
        msg_Dbg( p_stream, "creating subtitles transcoding from fcc=`%4.4s' "
 
162
                 "to fcc=`%4.4s'", (char*)&p_fmt->i_codec,
 
163
                 (char*)&p_sys->i_scodec );
 
164
 
 
165
        /* Complete destination format */
 
166
        id->p_encoder->fmt_out.i_codec = p_sys->i_scodec;
 
167
 
 
168
        /* build decoder -> filter -> encoder */
 
169
        if( transcode_spu_new( p_stream, id ) )
 
170
        {
 
171
            msg_Err( p_stream, "cannot create subtitles chain" );
 
172
            return false;
 
173
        }
 
174
 
 
175
        /* open output stream */
 
176
        id->id = sout_StreamIdAdd( p_stream->p_next, &id->p_encoder->fmt_out );
 
177
        id->b_transcode = true;
 
178
 
 
179
        if( !id->id )
 
180
        {
 
181
            transcode_spu_close( id );
 
182
            return false;
 
183
        }
 
184
    }
 
185
    else
 
186
    {
 
187
        assert( p_sys->b_soverlay );
 
188
        msg_Dbg( p_stream, "subtitles (fcc=`%4.4s') overlaying",
 
189
                 (char*)&p_fmt->i_codec );
 
190
 
 
191
        id->b_transcode = true;
 
192
 
 
193
        /* Build decoder -> filter -> overlaying chain */
 
194
        if( transcode_spu_new( p_stream, id ) )
 
195
        {
 
196
            msg_Err( p_stream, "cannot create subtitles chain" );
 
197
            return false;
 
198
        }
 
199
    }
 
200
 
 
201
    return true;
 
202
}