]> git.sesse.net Git - casparcg/commitdiff
2.0.0.2: filter: Use null filter with empty filter string. Fixed memory leak.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 28 Jul 2011 16:04:24 +0000 (16:04 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 28 Jul 2011 16:04:24 +0000 (16:04 +0000)
         ffmpeg: Use caspar log API instead of av_log to avoid conflicts.

git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1006 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

core/mixer/gpu/device_buffer.cpp
core/mixer/gpu/host_buffer.cpp
modules/decklink/producer/decklink_producer.cpp
modules/ffmpeg/ffmpeg.cpp
modules/ffmpeg/producer/filter/filter.cpp

index 64e07b4a7e7a341cb86de2f041b8dd88e637ae74..fa4699b4742f97ea28d53f7cc3fc4a01d35f9a54 100644 (file)
@@ -52,7 +52,7 @@ public:
                GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));\r
                GL(glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT[stride_], width_, height_, 0, FORMAT[stride_], GL_UNSIGNED_BYTE, NULL));\r
                GL(glBindTexture(GL_TEXTURE_2D, 0));\r
-               CASPAR_LOG(trace) << "[device_buffer] allocated size:" << width*height*stride;  \r
+               CASPAR_LOG(debug) << "[device_buffer] allocated size:" << width*height*stride;  \r
                clear();\r
        }       \r
 \r
index 6eb2ec6d92ba8172d407d7ad335d71ddb91bca0b..05b698498af9541989ea7dde3c2f4132a387311e 100644 (file)
@@ -52,7 +52,7 @@ public:
                if(!pbo_)\r
                        BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to allocate buffer."));\r
 \r
-               CASPAR_LOG(trace) << "[host_buffer] allocated size:" << size_ << " usage: " << (usage == write_only ? "write_only" : "read_only");\r
+               CASPAR_LOG(debug) << "[host_buffer] allocated size:" << size_ << " usage: " << (usage == write_only ? "write_only" : "read_only");\r
        }       \r
 \r
        ~implementation()\r
index 088596da319ce3d92d032ce95efbf6d2da4fa0e2..de51381ca2cd2fe940e0d4086154c8b8842c8a56 100644 (file)
@@ -93,7 +93,7 @@ class decklink_producer : public IDeckLinkInputCallback
        safe_ptr<core::basic_frame>                                                                     tail_;\r
 \r
        std::exception_ptr                                                                                      exception_;\r
-       std::unique_ptr<filter>                                                                         filter_;\r
+       filter                                                                                                          filter_;\r
                \r
        core::frame_muxer                                                                                       muxer_;\r
 \r
@@ -106,7 +106,7 @@ public:
                , device_index_(device_index)\r
                , frame_factory_(frame_factory)\r
                , tail_(core::basic_frame::empty())\r
-               , filter_(filter.empty() ? nullptr : new caspar::filter(filter))\r
+               , filter_(filter)\r
                , muxer_(double_rate(filter) ? format_desc.fps * 2.0 : format_desc.fps, frame_factory->get_video_format_desc().mode, frame_factory->get_video_format_desc().fps)\r
        {\r
                frame_buffer_.set_capacity(2);\r
@@ -189,15 +189,10 @@ public:
                        av_frame->height                        = video->GetHeight();\r
                        av_frame->interlaced_frame      = format_desc_.mode != core::video_mode::progressive;\r
                        av_frame->top_field_first       = format_desc_.mode == core::video_mode::upper ? 1 : 0;\r
-                                               \r
-                       if(filter_)\r
-                       {\r
-                               filter_->push(av_frame);\r
-                               BOOST_FOREACH(auto& av_frame2, filter_->poll())\r
-                                       muxer_.push(make_write_frame(this, av_frame2, frame_factory_));\r
-                       }\r
-                       else                    \r
-                               muxer_.push(make_write_frame(this, av_frame, frame_factory_));                  \r
+                                       \r
+                       filter_.push(av_frame);\r
+                       BOOST_FOREACH(auto& av_frame2, filter_.poll())\r
+                               muxer_.push(make_write_frame(this, av_frame2, frame_factory_));         \r
                                                                        \r
                        // It is assumed that audio is always equal or ahead of video.\r
                        if(audio && SUCCEEDED(audio->GetBytes(&bytes)))\r
index 837b8376dde126c9bddcb057f4d79711632f9c8e..8508c74b4ee727b12b78d3b9362bf2c93bdbb438 100644 (file)
 *    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
 *\r
 */\r
+\r
 #include "StdAfx.h"\r
 \r
 #include "consumer/ffmpeg_consumer.h"\r
 #include "producer/ffmpeg_producer.h"\r
 \r
+#include <common/log/log.h>\r
+\r
 #include <core/consumer/frame_consumer.h>\r
 #include <core/producer/frame_producer.h>\r
 \r
@@ -29,6 +32,8 @@
 \r
 #if defined(_MSC_VER)\r
 #pragma warning (disable : 4244)\r
+#pragma warning (disable : 4603)\r
+#pragma warning (disable : 4996)\r
 #endif\r
 \r
 extern "C" \r
@@ -79,6 +84,62 @@ int ffmpeg_lock_callback(void **mutex, enum AVLockOp op)
        return 0; \r
 } \r
 \r
+static void sanitize(uint8_t *line)
+{
+    while(*line)
+       {
+        if(*line < 0x08 || (*line > 0x0D && *line < 0x20))
+            *line='?';
+        line++;
+    }
+}\r
+\r
+void log_callback(void* ptr, int level, const char* fmt, va_list vl)\r
+{
+    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;
+       
+#undef fprintf
+    if(print_prefix && avc) 
+       {
+        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);
+       
+       CASPAR_LOG(trace) << L"[FFMPEG] [" << av_clip(level>>3, 0, 6) << L"] " << line;
+
+    //colored_fputs(av_clip(level>>3, 0, 6), line);\r
+}\r
+\r
 void init_ffmpeg()\r
 {\r
     avfilter_register_all();\r
@@ -86,6 +147,7 @@ void init_ffmpeg()
        avcodec_init();\r
     avcodec_register_all();\r
        av_lockmgr_register(ffmpeg_lock_callback);\r
+       av_log_set_callback(log_callback);\r
        \r
        core::register_consumer_factory([](const std::vector<std::wstring>& params){return create_ffmpeg_consumer(params);});\r
        core::register_producer_factory(create_ffmpeg_producer);\r
index ffc3af220e1fdbeaf3c223559439c7e30c51a0b4..b90420661c43eef49588cd92ddef7e90a188234e 100644 (file)
@@ -37,7 +37,7 @@ struct filter::implementation
        AVFilterContext*                                buffersrc_ctx_;\r
        \r
        implementation(const std::wstring& filters) \r
-               : filters_(narrow(filters))\r
+               : filters_(filters.empty() ? "null" : narrow(filters))\r
        {\r
                std::transform(filters_.begin(), filters_.end(), filters_.begin(), ::tolower);\r
        }\r
@@ -95,6 +95,10 @@ struct filter::implementation
                        inputs->next                    = NULL;\r
                        \r
                        errn = avfilter_graph_parse(graph_.get(), filters_.c_str(), &inputs, &outputs, NULL);\r
+\r
+                       avfilter_inout_free(&inputs);\r
+                       avfilter_inout_free(&outputs);\r
+\r
                        if(errn < 0)\r
                        {\r
                                BOOST_THROW_EXCEPTION(caspar_exception() <<     msg_info(av_error_str(errn)) <<\r
@@ -133,23 +137,22 @@ struct filter::implementation
                                safe_ptr<AVFrame> frame(avcodec_alloc_frame(), [=](AVFrame* p)\r
                                {\r
                                        av_free(p);\r
-                                  avfilter_unref_buffer(picref);\r
+                                       avfilter_unref_buffer(picref);\r
                                });\r
 \r
                                avcodec_get_frame_defaults(frame.get());        \r
 \r
-                               for(size_t n = 0; n < 4; ++n)\r
-                               {\r
-                                       frame->data[n]          = picref->data[n];\r
-                                       frame->linesize[n]      = picref->linesize[n];\r
-                               }\r
-                               \r
-                               frame->format                   = picref->format;\r
-                               frame->width                    = picref->video->w;\r
-                               frame->height                   = picref->video->h;\r
-                               frame->interlaced_frame = picref->video->interlaced;\r
-                               frame->top_field_first  = picref->video->top_field_first;\r
-                               frame->key_frame                = picref->video->key_frame;\r
+                               memcpy(frame->data,     picref->data,     sizeof(frame->data));\r
+                               memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize));\r
+                               frame->format                           = picref->format;\r
+                               frame->width                            = picref->video->w;\r
+                               frame->height                           = picref->video->h;\r
+                               frame->pkt_pos                          = picref->pos;\r
+                               frame->interlaced_frame         = picref->video->interlaced;\r
+                               frame->top_field_first          = picref->video->top_field_first;\r
+                               frame->key_frame                        = picref->video->key_frame;\r
+                               frame->pict_type                        = picref->video->pict_type;\r
+                               frame->sample_aspect_ratio      = picref->video->sample_aspect_ratio;\r
 \r
                                result.push_back(frame);\r
             }\r