]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/producer/video/video_decoder.cpp
2.0. Updated namespaces.
[casparcg] / modules / ffmpeg / producer / video / video_decoder.cpp
index a15da2bd482a9d77837a50773d3b369e631d0c86..4e2ba9664fb22d640905e8b52af3b6ac04de1e31 100644 (file)
 #include "../../ffmpeg_error.h"\r
 #include "../../tbb_avcodec.h"\r
 \r
-#include <core/producer/frame/image_transform.h>\r
+#include <core/producer/frame/frame_transform.h>\r
 #include <core/producer/frame/frame_factory.h>\r
 \r
 #include <boost/range/algorithm_ext/push_back.hpp>\r
+#include <boost/filesystem.hpp>\r
 \r
 #include <queue>\r
 \r
@@ -47,8 +48,8 @@ extern "C"
 #pragma warning (pop)\r
 #endif\r
 \r
-namespace caspar {\r
-               \r
+namespace caspar { namespace ffmpeg {\r
+       \r
 struct video_decoder::implementation : boost::noncopyable\r
 {\r
        const safe_ptr<core::frame_factory>             frame_factory_;\r
@@ -61,12 +62,18 @@ struct video_decoder::implementation : boost::noncopyable
 \r
        double                                                                  fps_;\r
        int64_t                                                                 nb_frames_;\r
+\r
+       size_t                                                                  width_;\r
+       size_t                                                                  height_;\r
+\r
 public:\r
        explicit implementation(const safe_ptr<AVFormatContext>& context, const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filter) \r
                : frame_factory_(frame_factory)\r
                , filter_(filter)\r
                , fps_(frame_factory_->get_video_format_desc().fps)\r
                , nb_frames_(0)\r
+               , width_(0)\r
+               , height_(0)\r
        {\r
                try\r
                {\r
@@ -80,16 +87,17 @@ public:
                        CASPAR_LOG(debug) << "[video_decoder] " << context->streams[index_]->codec->codec->long_name;\r
 \r
                        // Some files give an invalid time_base numerator, try to fix it.\r
-                       if(codec_context_ && codec_context_->time_base.num == 1)\r
-                               codec_context_->time_base.num = static_cast<int>(std::pow(10.0, static_cast<int>(std::log10(static_cast<float>(codec_context_->time_base.den)))-1));    \r
-               \r
-                       nb_frames_ = context->streams[index_]->nb_frames;\r
-                       if(nb_frames_ == 0)\r
-                               nb_frames_ = context->streams[index_]->duration;// * context->streams[index_]->time_base.den;\r
 \r
+                       fix_meta_data(*context);\r
+                       \r
                        fps_ = static_cast<double>(codec_context_->time_base.den) / static_cast<double>(codec_context_->time_base.num);\r
+                       nb_frames_ = context->streams[index_]->nb_frames;\r
+\r
                        if(double_rate(filter))\r
                                fps_ *= 2;\r
+\r
+                       width_  = codec_context_->width;\r
+                       height_ = codec_context_->height;\r
                }\r
                catch(...)\r
                {\r
@@ -183,7 +191,7 @@ public:
                        return std::vector<std::shared_ptr<AVFrame>>();\r
 \r
                if(decoded_frame->repeat_pict % 2 > 0)\r
-                               CASPAR_LOG(warning) << "[video_decoder]: Field repeat_pict not implemented.";\r
+                       CASPAR_LOG(warning) << "[video_decoder]: Field repeat_pict not implemented.";\r
                \r
                return std::vector<std::shared_ptr<AVFrame>>(1 + decoded_frame->repeat_pict/2, decoded_frame);\r
        }\r
@@ -205,4 +213,7 @@ std::vector<std::shared_ptr<AVFrame>> video_decoder::poll(){return impl_->poll()
 bool video_decoder::ready() const{return impl_->ready();}\r
 double video_decoder::fps() const{return impl_->fps();}\r
 int64_t video_decoder::nb_frames() const{return impl_->nb_frames_;}\r
-}
\ No newline at end of file
+size_t video_decoder::width() const{return impl_->width_;}\r
+size_t video_decoder::height() const{return impl_->height_;}\r
+\r
+}}
\ No newline at end of file