[MPlayer-cvslog] r33959 - in trunk: Makefile av_helpers.c av_helpers.h libaf/af_lavcac3enc.c libmpcodecs/ad_ffmpeg.c libmpcodecs/ae_lavc.c libmpcodecs/vd_ffmpeg.c libmpcodecs/vd_ffmpeg.h libmpcodecs/ve_lavc.c libmp...

reimar subversion at mplayerhq.hu
Tue Aug 9 21:57:00 CEST 2011


Author: reimar
Date: Tue Aug  9 21:57:00 2011
New Revision: 33959

Log:
Move code for setting up libav* logging callbacks from vd_ffmpeg to a
separate file and also use it when only initializing libavformat.

Added:
   trunk/av_helpers.c
   trunk/av_helpers.h
Deleted:
   trunk/libmpcodecs/vd_ffmpeg.h
Modified:
   trunk/Makefile
   trunk/libaf/af_lavcac3enc.c
   trunk/libmpcodecs/ad_ffmpeg.c
   trunk/libmpcodecs/ae_lavc.c
   trunk/libmpcodecs/vd_ffmpeg.c
   trunk/libmpcodecs/ve_lavc.c
   trunk/libmpcodecs/vf_fspp.c
   trunk/libmpcodecs/vf_lavc.c
   trunk/libmpcodecs/vf_lavcdeint.c
   trunk/libmpcodecs/vf_mcdeint.c
   trunk/libmpcodecs/vf_spp.c
   trunk/libmpcodecs/vf_uspp.c
   trunk/libmpdemux/demux_lavf.c
   trunk/libmpdemux/demuxer.c
   trunk/libmpdemux/muxer_lavf.c
   trunk/stream/stream_ffmpeg.c

Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/Makefile	Tue Aug  9 21:57:00 2011	(r33959)
@@ -60,6 +60,7 @@ SRCS_COMMON-$(DVDREAD_INTERNAL)      += 
 SRCS_COMMON-$(FAAD)                  += libmpcodecs/ad_faad.c
 SRCS_COMMON-$(FASTMEMCPY)            += libvo/aclib.c
 SRCS_COMMON-$(FFMPEG)                += av_opts.c                   \
+                                        av_helpers.c                \
                                         libaf/af_lavcresample.c     \
                                         libmpcodecs/ad_ffmpeg.c     \
                                         libmpcodecs/vd_ffmpeg.c     \

Added: trunk/av_helpers.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/av_helpers.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -0,0 +1,76 @@
+#include "libavcodec/avcodec.h"
+#include "libavformat/avformat.h"
+#include "mp_msg.h"
+#include "av_helpers.h"
+
+int avcodec_initialized;
+int avformat_initialized;
+
+static void mp_msp_av_log_callback(void *ptr, int level, const char *fmt,
+                                   va_list vl)
+{
+    static int print_prefix=1;
+    AVClass *avc= ptr ? *(AVClass **)ptr : NULL;
+    int type= MSGT_FIXME;
+    int mp_level;
+
+    switch(level){
+    case AV_LOG_VERBOSE: mp_level = MSGL_V ; break;
+    case AV_LOG_DEBUG:  mp_level= MSGL_V   ; break;
+    case AV_LOG_INFO :  mp_level= MSGL_INFO; break;
+    case AV_LOG_ERROR:  mp_level= MSGL_ERR ; break;
+    default          :  mp_level= level > AV_LOG_DEBUG ? MSGL_DBG2 : MSGL_ERR; break;
+    }
+
+    if (ptr && !avc)
+        mp_msg(MSGT_DECVIDEO, MSGL_ERR, "libav* called av_log with context containing a broken AVClass!\n");
+    if (avc) {
+        if(!strcmp(avc->class_name, "AVCodecContext")){
+            AVCodecContext *s= ptr;
+            if(s->codec){
+                if(s->codec->type == AVMEDIA_TYPE_AUDIO){
+                    if(s->codec->decode)
+                        type= MSGT_DECAUDIO;
+                }else if(s->codec->type == AVMEDIA_TYPE_VIDEO){
+                    if(s->codec->decode)
+                        type= MSGT_DECVIDEO;
+                }
+                //FIXME subtitles, encoders (what msgt for them? there is no appropriate ...)
+            }
+        }else if(!strcmp(avc->class_name, "AVFormatContext")){
+            AVFormatContext *s= ptr;
+            if(s->iformat)
+                type= MSGT_DEMUXER;
+            else if(s->oformat)
+                type= MSGT_MUXER;
+        }
+    }
+
+    if (!mp_msg_test(type, mp_level)) return;
+
+    if(print_prefix && avc) {
+        mp_msg(type, mp_level, "[%s @ %p]", avc->item_name(ptr), avc);
+    }
+
+    print_prefix= strchr(fmt, '\n') != NULL;
+    mp_msg_va(type, mp_level, fmt, vl);
+}
+
+void init_avcodec(void)
+{
+    if (!avcodec_initialized) {
+        avcodec_init();
+        avcodec_register_all();
+        avcodec_initialized = 1;
+        av_log_set_callback(mp_msp_av_log_callback);
+    }
+}
+
+void init_avformat(void)
+{
+    if (!avformat_initialized) {
+        av_register_all();
+        avformat_initialized = 1;
+        av_log_set_callback(mp_msp_av_log_callback);
+    }
+}

Added: trunk/av_helpers.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/av_helpers.h	Tue Aug  9 21:57:00 2011	(r33959)
@@ -0,0 +1,7 @@
+#ifndef MPLAYER_AV_HELPERS_H
+#define MPLAYER_AV_HELPERS_H
+
+void init_avcodec(void);
+void init_avformat(void);
+
+#endif /* MPLAYER_AV_HELPERS_H */

Modified: trunk/libaf/af_lavcac3enc.c
==============================================================================
--- trunk/libaf/af_lavcac3enc.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libaf/af_lavcac3enc.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -25,11 +25,11 @@
 #include <string.h>
 #include <inttypes.h>
 
-#include "libmpcodecs/vd_ffmpeg.h"
 #include "config.h"
 #include "af.h"
 #include "help_mp.h"
 #include "reorder_ch.h"
+#include "av_helpers.h"
 
 #include "libavcodec/avcodec.h"
 #include "libavcodec/ac3.h"

Modified: trunk/libmpcodecs/ad_ffmpeg.c
==============================================================================
--- trunk/libmpcodecs/ad_ffmpeg.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libmpcodecs/ad_ffmpeg.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -26,7 +26,7 @@
 
 #include "ad_internal.h"
 #include "dec_audio.h"
-#include "vd_ffmpeg.h"
+#include "av_helpers.h"
 #include "libaf/reorder_ch.h"
 #include "fmt-conversion.h"
 

Modified: trunk/libmpcodecs/ae_lavc.c
==============================================================================
--- trunk/libmpcodecs/ae_lavc.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libmpcodecs/ae_lavc.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -30,7 +30,7 @@
 #include "stream/stream.h"
 #include "libmpdemux/muxer.h"
 #include "ae_lavc.h"
-#include "vd_ffmpeg.h"
+#include "av_helpers.h"
 #include "ve.h"
 #include "help_mp.h"
 #include "av_opts.h"

Modified: trunk/libmpcodecs/vd_ffmpeg.c
==============================================================================
--- trunk/libmpcodecs/vd_ffmpeg.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libmpcodecs/vd_ffmpeg.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -25,6 +25,7 @@
 #include "mp_msg.h"
 #include "help_mp.h"
 #include "av_opts.h"
+#include "av_helpers.h"
 
 #include "libavutil/common.h"
 #include "libavutil/intreadwrite.h"
@@ -32,7 +33,6 @@
 #include "fmt-conversion.h"
 
 #include "vd_internal.h"
-#include "vd_ffmpeg.h"
 
 static const vd_info_t info = {
     "FFmpeg's libavcodec codec family",
@@ -54,8 +54,6 @@ LIBVD_EXTERN(ffmpeg)
 #include "libavcodec/xvmc.h"
 #endif
 
-int avcodec_initialized=0;
-
 typedef struct {
     AVCodecContext *avctx;
     AVFrame *pic;
@@ -181,59 +179,6 @@ static int control(sh_video_t *sh, int c
     return CONTROL_UNKNOWN;
 }
 
-static void mp_msp_av_log_callback(void *ptr, int level, const char *fmt,
-                                   va_list vl)
-{
-    static int print_prefix=1;
-    AVClass *avc= ptr ? *(AVClass **)ptr : NULL;
-    int type= MSGT_FIXME;
-    int mp_level;
-
-    switch(level){
-    case AV_LOG_VERBOSE: mp_level = MSGL_V ; break;
-    case AV_LOG_DEBUG:  mp_level= MSGL_V   ; break;
-    case AV_LOG_INFO :  mp_level= MSGL_INFO; break;
-    case AV_LOG_ERROR:  mp_level= MSGL_ERR ; break;
-    default          :  mp_level= level > AV_LOG_DEBUG ? MSGL_DBG2 : MSGL_ERR; break;
-    }
-
-    if (ptr && !avc)
-        mp_msg(MSGT_DECVIDEO, MSGL_ERR, "libav* called av_log with context containing a broken AVClass!\n");
-    if (avc) {
-        if(!strcmp(avc->class_name, "AVCodecContext")){
-            AVCodecContext *s= ptr;
-            if(s->codec){
-                if(s->codec->type == AVMEDIA_TYPE_AUDIO){
-                    if(s->codec->decode)
-                        type= MSGT_DECAUDIO;
-                }else if(s->codec->type == AVMEDIA_TYPE_VIDEO){
-                    if(s->codec->decode)
-                        type= MSGT_DECVIDEO;
-                }
-                //FIXME subtitles, encoders (what msgt for them? there is no appropriate ...)
-            }
-        }else if(!strcmp(avc->class_name, "AVFormatContext")){
-            type= MSGT_DEMUXER;
-#if 0 //needs libavformat include FIXME iam too lazy to do this cleanly, probably the whole should be moved out of this file ...
-            AVFormatContext *s= ptr;
-            if(s->iformat)
-                type= MSGT_DEMUXER;
-            else if(s->oformat)
-                type= MSGT_MUXER;
-#endif
-        }
-    }
-
-    if (!mp_msg_test(type, mp_level)) return;
-
-    if(print_prefix && avc) {
-        mp_msg(type, mp_level, "[%s @ %p]", avc->item_name(ptr), avc);
-    }
-
-    print_prefix= strchr(fmt, '\n') != NULL;
-    mp_msg_va(type, mp_level, fmt, vl);
-}
-
 static void set_format_params(struct AVCodecContext *avctx, enum PixelFormat fmt){
     int imgfmt;
     if (fmt == PIX_FMT_NONE)
@@ -261,16 +206,6 @@ static void set_format_params(struct AVC
     }
 }
 
-void init_avcodec(void)
-{
-    if (!avcodec_initialized) {
-        avcodec_init();
-        avcodec_register_all();
-        avcodec_initialized = 1;
-        av_log_set_callback(mp_msp_av_log_callback);
-    }
-}
-
 // init driver
 static int init(sh_video_t *sh){
     AVCodecContext *avctx;

Modified: trunk/libmpcodecs/ve_lavc.c
==============================================================================
--- trunk/libmpcodecs/ve_lavc.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libmpcodecs/ve_lavc.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -47,7 +47,7 @@
 #include "mp_image.h"
 #include "ve.h"
 #include "vf.h"
-#include "vd_ffmpeg.h"
+#include "av_helpers.h"
 
 //===========================================================================//
 

Modified: trunk/libmpcodecs/vf_fspp.c
==============================================================================
--- trunk/libmpcodecs/vf_fspp.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libmpcodecs/vf_fspp.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -45,7 +45,7 @@
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
-#include "vd_ffmpeg.h"
+#include "av_helpers.h"
 #include "libvo/fastmemcpy.h"
 
 #include "libavutil/internal.h"

Modified: trunk/libmpcodecs/vf_lavc.c
==============================================================================
--- trunk/libmpcodecs/vf_lavc.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libmpcodecs/vf_lavc.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -28,7 +28,7 @@
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
-#include "vd_ffmpeg.h"
+#include "av_helpers.h"
 #include "libavcodec/avcodec.h"
 
 

Modified: trunk/libmpcodecs/vf_lavcdeint.c
==============================================================================
--- trunk/libmpcodecs/vf_lavcdeint.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libmpcodecs/vf_lavcdeint.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -28,7 +28,7 @@
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
-#include "vd_ffmpeg.h"
+#include "av_helpers.h"
 #include "libavcodec/avcodec.h"
 
 

Modified: trunk/libmpcodecs/vf_mcdeint.c
==============================================================================
--- trunk/libmpcodecs/vf_mcdeint.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libmpcodecs/vf_mcdeint.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -66,7 +66,7 @@ Known Issues:
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
-#include "vd_ffmpeg.h"
+#include "av_helpers.h"
 
 #define MIN(a,b) ((a) > (b) ? (b) : (a))
 #define MAX(a,b) ((a) < (b) ? (b) : (a))

Modified: trunk/libmpcodecs/vf_spp.c
==============================================================================
--- trunk/libmpcodecs/vf_spp.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libmpcodecs/vf_spp.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -49,7 +49,7 @@
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
-#include "vd_ffmpeg.h"
+#include "av_helpers.h"
 #include "libvo/fastmemcpy.h"
 
 #define XMIN(a,b) ((a) < (b) ? (a) : (b))

Modified: trunk/libmpcodecs/vf_uspp.c
==============================================================================
--- trunk/libmpcodecs/vf_uspp.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libmpcodecs/vf_uspp.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -35,7 +35,7 @@
 #include "img_format.h"
 #include "mp_image.h"
 #include "vf.h"
-#include "vd_ffmpeg.h"
+#include "av_helpers.h"
 #include "libvo/fastmemcpy.h"
 
 #define XMIN(a,b) ((a) < (b) ? (a) : (b))

Modified: trunk/libmpdemux/demux_lavf.c
==============================================================================
--- trunk/libmpdemux/demux_lavf.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libmpdemux/demux_lavf.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -27,6 +27,7 @@
 #include "mp_msg.h"
 #include "help_mp.h"
 #include "av_opts.h"
+#include "av_helpers.h"
 
 #include "stream/stream.h"
 #include "aviprint.h"
@@ -154,7 +155,7 @@ static int lavf_check_file(demuxer_t *de
         demuxer->priv=calloc(sizeof(lavf_priv_t),1);
     priv= demuxer->priv;
 
-    av_register_all();
+    init_avformat();
 
     if (opt_format) {
         if (strcmp(opt_format, "help") == 0) {

Modified: trunk/libmpdemux/demuxer.c
==============================================================================
--- trunk/libmpdemux/demuxer.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libmpdemux/demuxer.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -44,7 +44,6 @@
 #include "libmpcodecs/dec_audio.h"
 #include "libmpcodecs/dec_video.h"
 #include "libmpcodecs/dec_teletext.h"
-#include "libmpcodecs/vd_ffmpeg.h"
 
 #ifdef CONFIG_ASS
 #include "libass/ass.h"
@@ -56,6 +55,7 @@
 #if MP_INPUT_BUFFER_PADDING_SIZE < FF_INPUT_BUFFER_PADDING_SIZE
 #error MP_INPUT_BUFFER_PADDING_SIZE is too small!
 #endif
+#include "av_helpers.h"
 #endif
 
 // This is quite experimental, in particular it will mess up the pts values

Modified: trunk/libmpdemux/muxer_lavf.c
==============================================================================
--- trunk/libmpdemux/muxer_lavf.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/libmpdemux/muxer_lavf.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -29,6 +29,7 @@
 #include "aviheader.h"
 #include "ms_hdr.h"
 #include "av_opts.h"
+#include "av_helpers.h"
 
 #include "stream/stream.h"
 #include "muxer.h"
@@ -317,7 +318,7 @@ int muxer_init_muxer_lavf(muxer_t *muxer
 	muxer_priv_t *priv;
 	AVOutputFormat *fmt = NULL;
 
-	av_register_all();
+	init_avformat();
 
 	if (conf_format && strcmp(conf_format, "help") == 0) {
 		list_formats();

Modified: trunk/stream/stream_ffmpeg.c
==============================================================================
--- trunk/stream/stream_ffmpeg.c	Tue Aug  9 21:23:41 2011	(r33958)
+++ trunk/stream/stream_ffmpeg.c	Tue Aug  9 21:57:00 2011	(r33959)
@@ -24,6 +24,7 @@
 #include "stream.h"
 #include "m_option.h"
 #include "m_struct.h"
+#include "av_helpers.h"
 
 static int fill_buffer(stream_t *s, char *buffer, int max_len)
 {
@@ -87,7 +88,7 @@ static int open_f(stream_t *stream, int 
     int64_t size;
     int dummy;
 
-    av_register_all();
+    init_avformat();
     if (mode == STREAM_READ)
         flags = URL_RDONLY;
     else if (mode == STREAM_WRITE)


More information about the MPlayer-cvslog mailing list