vlc_codec.h 7.84 KB
Newer Older
1
/*****************************************************************************
Clément Stenac's avatar
Clément Stenac committed
2
 * vlc_codec.h: Definition of the decoder and encoder structures
3
 *****************************************************************************
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
4
 * Copyright (C) 1999-2003 VLC authors and VideoLAN
5
 * $Id$
6 7 8
 *
 * Authors: Gildas Bazin <gbazin@netcourrier.com>
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
9 10 11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12 13 14 15
 * (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
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
19 20 21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22
 *****************************************************************************/
23

24 25
#ifndef VLC_CODEC_H
#define VLC_CODEC_H 1
26

Clément Stenac's avatar
Clément Stenac committed
27 28
#include <vlc_block.h>
#include <vlc_es.h>
29 30
#include <vlc_picture.h>
#include <vlc_subpicture.h>
Clément Stenac's avatar
Clément Stenac committed
31

32 33 34 35 36
/**
 * \file
 * This file defines the structure and types used by decoders and encoders
 */

37 38
typedef struct decoder_owner_sys_t decoder_owner_sys_t;

39 40 41 42 43 44 45 46
/**
 * \defgroup decoder Decoder
 *
 * The structure describing a decoder
 *
 * @{
 */

47 48 49 50 51
/*
 * BIG FAT WARNING : the code relies in the first 4 members of filter_t
 * and decoder_t to be the same, so if you have anything to add, do it
 * at the end of the structure.
 */
52 53 54 55 56 57 58
struct decoder_t
{
    VLC_COMMON_MEMBERS

    /* Module properties */
    module_t *          p_module;
    decoder_sys_t *     p_sys;
59 60 61 62 63 64 65

    /* Input format ie from demuxer (XXX: a lot of field could be invalid) */
    es_format_t         fmt_in;

    /* Output format of decoder/packetizer */
    es_format_t         fmt_out;

66
    /* Some decoders only accept packetized data (ie. not truncated) */
67
    bool                b_need_packetized;
68 69

    /* Tell the decoder if it is allowed to drop frames */
70
    bool                b_pace_control;
71

72
    /* */
73
    picture_t *         ( * pf_decode_video )( decoder_t *, block_t ** );
74
    block_t *           ( * pf_decode_audio )( decoder_t *, block_t ** );
75 76 77
    subpicture_t *      ( * pf_decode_sub)   ( decoder_t *, block_t ** );
    block_t *           ( * pf_packetize )   ( decoder_t *, block_t ** );

78 79 80 81 82 83
    /* Closed Caption (CEA 608/708) extraction.
     * If set, it *may* be called after pf_decode_video/pf_packetize
     * returned data. It should return CC for the pictures returned by the
     * last pf_packetize/pf_decode_video call only,
     * pb_present will be used to known which cc channel are present (but
     * globaly, not necessary for the current packet */
84
    block_t *           ( * pf_get_cc )      ( decoder_t *, bool pb_present[4] );
85

86 87 88 89 90 91
    /* Meta data at codec level
     *  The decoder owner set it back to NULL once it has retreived what it needs.
     *  The decoder owner is responsible of its release except when you overwrite it.
     */
    vlc_meta_t          *p_description;

92 93
    /*
     * Owner fields
94
     * XXX You MUST not use them directly.
95 96
     */

97
    /* Video output callbacks
98
     * XXX use decoder_NewPicture */
99
    int             (*pf_vout_format_update)( decoder_t * );
100 101
    picture_t      *(*pf_vout_buffer_new)( decoder_t * );

102 103 104 105 106 107
    /**
     * Number of extra (ie in addition to the DPB) picture buffers
     * needed for decoding.
     */
    int             i_extra_picture_buffers;

108 109
    /* Audio output callbacks */
    int             (*pf_aout_format_update)( decoder_t * );
110

111
    /* SPU output callbacks
112
     * XXX use decoder_NewSubpicture */
113
    subpicture_t   *(*pf_spu_buffer_new)( decoder_t *, const subpicture_updater_t * );
114

115 116 117 118 119 120 121 122 123 124 125 126
    /* Input attachments
     * XXX use decoder_GetInputAttachments */
    int             (*pf_get_attachments)( decoder_t *p_dec, input_attachment_t ***ppp_attachment, int *pi_attachment );

    /* Display date
     * XXX use decoder_GetDisplayDate */
    mtime_t         (*pf_get_display_date)( decoder_t *, mtime_t );

    /* Display rate
     * XXX use decoder_GetDisplayRate */
    int             (*pf_get_display_rate)( decoder_t * );

127 128
    /* Private structure for the owner of the decoder */
    decoder_owner_sys_t *p_owner;
Erwan Tulou's avatar
Erwan Tulou committed
129

130
    bool                b_error;
131 132 133 134 135 136 137
};

/**
 * @}
 */

/**
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
138
 * \defgroup encoder Encoder
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
 *
 * The structure describing a Encoder
 *
 * @{
 */

struct encoder_t
{
    VLC_COMMON_MEMBERS

    /* Module properties */
    module_t *          p_module;
    encoder_sys_t *     p_sys;

    /* Properties of the input data fed to the encoder */
154
    es_format_t         fmt_in;
155 156

    /* Properties of the output of the encoder */
157
    es_format_t         fmt_out;
158

159
    block_t *           ( * pf_encode_video )( encoder_t *, picture_t * );
160
    block_t *           ( * pf_encode_audio )( encoder_t *, block_t * );
161 162
    block_t *           ( * pf_encode_sub )( encoder_t *, subpicture_t * );

163 164 165 166 167
    /* Common encoder options */
    int i_threads;               /* Number of threads to use during encoding */
    int i_iframes;               /* One I frame per i_iframes */
    int i_bframes;               /* One B frame per i_bframes */
    int i_tolerance;             /* Bitrate tolerance */
168 169

    /* Encoder config */
170
    config_chain_t *p_cfg;
171 172 173 174 175 176
};

/**
 * @}
 */

177

178 179 180 181 182 183 184 185 186 187 188 189 190
/**
 * This function notifies the video output pipeline of a new video output
 * format (fmt_out.video). If there is currently no video output or if the
 * video output format has changed, a new audio video will be set up.
 * @return 0 if the video output is working, -1 if not. */
static inline int decoder_UpdateVideoFormat( decoder_t *dec )
{
    if( dec->pf_vout_format_update != NULL )
        return dec->pf_vout_format_update( dec );
    else
        return -1;
}

191 192
/**
 * This function will return a new picture usable by a decoder as an output
193
 * buffer. You have to release it using picture_Release() or by returning
194 195
 * it to the caller as a pf_decode_video return value.
 */
196
VLC_API picture_t * decoder_NewPicture( decoder_t * ) VLC_USED;
197

198 199 200 201 202 203 204 205 206 207 208 209 210
/**
 * This function notifies the audio output pipeline of a new audio output
 * format (fmt_out.audio). If there is currently no audio output or if the
 * audio output format has changed, a new audio output will be set up.
 * @return 0 if the audio output is working, -1 if not. */
static inline int decoder_UpdateAudioFormat( decoder_t *dec )
{
    if( dec->pf_aout_format_update != NULL )
        return dec->pf_aout_format_update( dec );
    else
        return -1;
}

211 212
/**
 * This function will return a new audio buffer usable by a decoder as an
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
213 214
 * output buffer. It must be released with block_Release() or returned it to
 * the caller as a pf_decode_audio return value.
215
 */
216
VLC_API block_t * decoder_NewAudioBuffer( decoder_t *, int i_size ) VLC_USED;
217

218 219
/**
 * This function will return a new subpicture usable by a decoder as an output
220
 * buffer. You have to release it using subpicture_Delete() or by returning
221 222
 * it to the caller as a pf_decode_sub return value.
 */
223
VLC_API subpicture_t * decoder_NewSubpicture( decoder_t *, const subpicture_updater_t * ) VLC_USED;
224

225 226 227 228 229
/**
 * This function gives all input attachments at once.
 *
 * You MUST release the returned values
 */
230
VLC_API int decoder_GetInputAttachments( decoder_t *, input_attachment_t ***ppp_attachment, int *pi_attachment );
231 232 233 234 235 236

/**
 * This function converts a decoder timestamp into a display date comparable
 * to mdate().
 * You MUST use it *only* for gathering statistics about speed.
 */
237
VLC_API mtime_t decoder_GetDisplayDate( decoder_t *, mtime_t ) VLC_USED;
238

239 240 241 242
/**
 * This function returns the current input rate.
 * You MUST use it *only* for gathering statistics about speed.
 */
243
VLC_API int decoder_GetDisplayRate( decoder_t * ) VLC_USED;
244

245
#endif /* _VLC_CODEC_H */