]> git.sesse.net Git - casparcg/commitdiff
[ffmpeg] Let our log level decide whether to log or not in the ffmpeg log callback
authorHelge Norberg <helge.norberg@svt.se>
Mon, 3 Oct 2016 19:43:42 +0000 (21:43 +0200)
committerHelge Norberg <helge.norberg@svt.se>
Mon, 3 Oct 2016 19:43:42 +0000 (21:43 +0200)
modules/ffmpeg/ffmpeg.cpp

index ab500c3e050240558ef1f511dd7689283cfaa1dc..9073fdc393969ed96abd70227bce56d4eea4d5eb 100644 (file)
@@ -100,54 +100,40 @@ int ffmpeg_lock_callback(void **mutex, enum AVLockOp op)
 
 static void sanitize(uint8_t *line)
 {
-    while(*line)
+       while(*line)
        {
-        if(*line < 0x08 || (*line > 0x0D && *line < 0x20))
-            *line='?';
-        line++;
-    }
+               if(*line < 0x08 || (*line > 0x0D && *line < 0x20))
+                       *line='?';
+               line++;
+       }
 }
 
 void log_callback(void* ptr, int level, const char* fmt, va_list vl)
 {
-    static int print_prefix=1;
-    //static int count;
-    static char prev[1024];
-    char line[8192];
-    //static int is_atty;
-    AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
-    if(level > av_log_get_level())
-        return;
-    line[0]=0;
+       static int print_prefix=1;
+       static char prev[1024];
+       char line[8192];
+       AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
+       line[0]=0;
 
 #undef fprintf
-    if(print_prefix && avc)
+       if(print_prefix && avc)
        {
-        if (avc->parent_log_context_offset)
+               if (avc->parent_log_context_offset)
                {
-            AVClass** parent= *(AVClass***)(((uint8_t*)ptr) + avc->parent_log_context_offset);
-            if(parent && *parent)
-                std::sprintf(line, "[%s @ %p] ", (*parent)->item_name(parent), parent);
-        }
-        std::sprintf(line + strlen(line), "[%s @ %p] ", avc->item_name(ptr), ptr);
-    }
-
-    std::vsprintf(line + strlen(line), fmt, vl);
-
-    print_prefix = strlen(line) && line[strlen(line)-1] == '\n';
-
-    //if(print_prefix && !strcmp(line, prev)){
-    //    count++;
-    //    if(is_atty==1)
-    //        fprintf(stderr, "    Last message repeated %d times\r", count);
-    //    return;
-    //}
-    //if(count>0){
-    //    fprintf(stderr, "    Last message repeated %d times\n", count);
-    //    count=0;
-    //}
-    strcpy(prev, line);
-    sanitize((uint8_t*)line);
+                       AVClass** parent= *(AVClass***)(((uint8_t*)ptr) + avc->parent_log_context_offset);
+                       if(parent && *parent)
+                               std::sprintf(line, "[%s @ %p] ", (*parent)->item_name(parent), parent);
+               }
+               std::sprintf(line + strlen(line), "[%s @ %p] ", avc->item_name(ptr), ptr);
+       }
+
+       std::vsprintf(line + strlen(line), fmt, vl);
+
+       print_prefix = strlen(line) && line[strlen(line)-1] == '\n';
+
+       strcpy(prev, line);
+       sanitize((uint8_t*)line);
 
        auto len = strlen(line);
        if(len > 0)
@@ -165,49 +151,8 @@ void log_callback(void* ptr, int level, const char* fmt, va_list vl)
                CASPAR_LOG(fatal) << L"[ffmpeg] " << line;
        else
                CASPAR_LOG(trace) << L"[ffmpeg] " << line;
-
-    //colored_fputs(av_clip(level>>3, 0, 6), line);
 }
 
-//static int query_yadif_formats(AVFilterContext *ctx)
-//{
-//    static const int pix_fmts[] = {
-//        PIX_FMT_YUV444P,
-//        PIX_FMT_YUV422P,
-//        PIX_FMT_YUV420P,
-//        PIX_FMT_YUV410P,
-//        PIX_FMT_YUV411P,
-//        PIX_FMT_GRAY8,
-//        PIX_FMT_YUVJ444P,
-//        PIX_FMT_YUVJ422P,
-//        PIX_FMT_YUVJ420P,
-//        AV_NE( PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE ),
-//        PIX_FMT_YUV440P,
-//        PIX_FMT_YUVJ440P,
-//        AV_NE( PIX_FMT_YUV444P16BE, PIX_FMT_YUV444P16LE ),
-//        AV_NE( PIX_FMT_YUV422P16BE, PIX_FMT_YUV422P16LE ),
-//        AV_NE( PIX_FMT_YUV420P16BE, PIX_FMT_YUV420P16LE ),
-//        PIX_FMT_YUVA420P,
-//        PIX_FMT_NONE
-//    };
-//    avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
-//
-//    return 0;
-//}
-//
-//#pragma warning (push)
-//#pragma warning (disable : 4706)
-//void fix_yadif_filter_format_query()
-//{
-//     AVFilter** filter = nullptr;
-//    while((filter = av_filter_next(filter)) && *filter)
-//     {
-//             if(strstr((*filter)->name, "yadif") != 0)
-//                     (*filter)->query_formats = query_yadif_formats;
-//     }
-//}
-//#pragma warning (pop)
-
 std::wstring make_version(unsigned int ver)
 {
        std::wstringstream str;
@@ -291,17 +236,17 @@ void init(core::module_dependencies dependencies)
        av_lockmgr_register(ffmpeg_lock_callback);
        av_log_set_callback(log_for_thread);
 
-    avfilter_register_all();
+       avfilter_register_all();
        //fix_yadif_filter_format_query();
        av_register_all();
-    avformat_network_init();
-    avcodec_register_all();
+       avformat_network_init();
+       avcodec_register_all();
        avdevice_register_all();
 
        auto info_repo = dependencies.media_info_repo;
 
        dependencies.consumer_registry->register_consumer_factory(L"FFmpeg Consumer", create_consumer, describe_consumer);
-       dependencies.consumer_registry->register_consumer_factory(L"Streaming Consumer",  create_streaming_consumer, describe_streaming_consumer);
+       dependencies.consumer_registry->register_consumer_factory(L"Streaming Consumer", create_streaming_consumer, describe_streaming_consumer);
        dependencies.consumer_registry->register_preconfigured_consumer_factory(L"file", create_preconfigured_consumer);
        dependencies.consumer_registry->register_preconfigured_consumer_factory(L"stream", create_preconfigured_streaming_consumer);
        dependencies.producer_registry->register_producer_factory(L"FFmpeg Producer", boost::bind(&create_producer, _1, _2, info_repo), describe_producer);
@@ -337,7 +282,7 @@ void init(core::module_dependencies dependencies)
 void uninit()
 {
        avfilter_uninit();
-    avformat_network_deinit();
+       avformat_network_deinit();
        av_lockmgr_register(nullptr);
 }
 }}