]> git.sesse.net Git - vlc/blob - modules/codec/avcodec/avutil.h
d7e55488271f657b8d7635c2c9875e175cc96b26
[vlc] / modules / codec / avcodec / avutil.h
1 /*****************************************************************************
2  * avutil.h: avutil helper functions
3  *****************************************************************************
4  * Copyright (C) 1999-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Export libavutil messages to the VLC message system
27  *****************************************************************************/
28 void LibavutilCallback( void *p_opaque, int i_level,
29                         const char *psz_format, va_list va )
30 {
31     int i_vlc_level;
32     AVCodecContext *p_avctx = (AVCodecContext *)p_opaque;
33     AVClass *p_avc;
34     vlc_object_t *p_this;
35     char *psz_new_format;
36     const char *psz_item_name;
37
38     p_avc = p_avctx ? p_avctx->av_class : 0;
39
40 #define cln p_avc->class_name
41     /* Make sure we can get p_this back */
42     if( !p_avctx || !p_avc || !cln ||
43         cln[0]!='A' || cln[1]!='V' || cln[2]!='C' || cln[3]!='o' ||
44         cln[4]!='d' || cln[5]!='e' || cln[6]!='c' )
45     {
46         if( i_level == AV_LOG_ERROR ) vfprintf( stderr, psz_format, va );
47         return;
48     }
49 #undef cln
50
51     p_this = (vlc_object_t *)p_avctx->opaque;
52
53     switch( i_level )
54     {
55     case AV_LOG_QUIET:
56         i_vlc_level = VLC_MSG_ERR;
57         break;
58     case AV_LOG_ERROR:
59         i_vlc_level = VLC_MSG_WARN;
60         break;
61     case AV_LOG_INFO:
62         i_vlc_level = VLC_MSG_DBG;
63         break;
64     case AV_LOG_DEBUG:
65         /* Print debug messages if they were requested */
66         if( p_avctx->debug ) vfprintf( stderr, psz_format, va );
67         return;
68     default:
69         return;
70     }
71
72     psz_item_name = p_avc->item_name(p_opaque);
73     psz_new_format = malloc( strlen(psz_format) + strlen(psz_item_name)
74                               + 18 + 5 );
75     snprintf( psz_new_format, strlen(psz_format) + strlen(psz_item_name)
76               + 18 + 5, "%s (%s@%p)", psz_format, p_avc->item_name(p_opaque), p_opaque );
77     msg_GenericVa( p_this, i_vlc_level,
78                     MODULE_STRING, psz_new_format, va );
79     free( psz_new_format );
80 }