]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/producer/util/util.h
[ffmpeg] Reimplemented support for playing all audio streams in a clip and treating...
[casparcg] / modules / ffmpeg / producer / util / util.h
index 270cb7fa4406f6d9900025e5c88f1e5c64a03afc..4c1f45c06c51d294562a89ed3ef4409b55eab79d 100644 (file)
-/*\r
-* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
-*\r
-* This file is part of CasparCG (www.casparcg.com).\r
-*\r
-* CasparCG is free software: you can redistribute it and/or modify\r
-* it under the terms of the GNU General Public License as published by\r
-* the Free Software Foundation, either version 3 of the License, or\r
-* (at your option) any later version.\r
-*\r
-* CasparCG is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
-*\r
-* Author: Robert Nagy, ronag89@gmail.com\r
-*/\r
-\r
-#pragma once\r
-\r
-#include <common/forward.h>\r
-#include <common/spl/memory.h>\r
-\r
-#include <core/video_format.h>\r
-#include <core/frame/pixel_format.h>\r
-#include <core/mixer/audio/audio_mixer.h>\r
-\r
-#include <array>\r
-\r
-enum PixelFormat;\r
-struct AVFrame;\r
-struct AVFormatContext;\r
-struct AVPacket;\r
-struct AVRational;\r
-struct AVCodecContext;\r
-\r
-FORWARD2(caspar, core, struct pixel_format_desc);\r
-FORWARD2(caspar, core, class write_frame);\r
-FORWARD2(caspar, core, class data_frame);\r
-FORWARD2(caspar, core, class frame_factory);\r
-\r
-namespace caspar { namespace ffmpeg {\r
-               \r
-std::shared_ptr<core::audio_buffer> flush_audio();\r
-std::shared_ptr<core::audio_buffer> empty_audio();\r
-std::shared_ptr<AVFrame>                       flush_video();\r
-std::shared_ptr<AVFrame>                       empty_video();\r
-\r
-// Utils\r
-\r
-static const int CASPAR_PIX_FMT_LUMA = 10; // Just hijack some unual pixel format.\r
-\r
-core::field_mode                                       get_mode(const AVFrame& frame);\r
-int                                                                    make_alpha_format(int format); // NOTE: Be careful about CASPAR_PIX_FMT_LUMA, change it to PIX_FMT_GRAY8 if you want to use the frame inside some ffmpeg function.\r
-spl::shared_ptr<core::write_frame>     make_write_frame(const void* tag, const spl::shared_ptr<AVFrame>& decoded_frame, double fps, const spl::shared_ptr<core::frame_factory>& frame_factory, int flags);\r
-spl::shared_ptr<AVFrame>                       make_av_frame(caspar::core::data_frame& frame);\r
-spl::shared_ptr<AVFrame>                       make_av_frame(std::array<void*, 4> data, const core::pixel_format_desc& pix_desc);\r
-\r
-template<typename C>\r
-std::shared_ptr<AVFrame> make_av_frame(const C& container, const core::pixel_format_desc& pix_desc)\r
-{      \r
-       std::array<void*, 4> data = {};\r
-       int n = 0;\r
-       for(auto it = std::begin(container); it != std::end(container); ++it)\r
-               data[n++] = (*it)->data();\r
-       return make_av_frame(data, pix_desc);\r
-}\r
-\r
-core::pixel_format_desc                                pixel_format_desc(PixelFormat pix_fmt, int width, int height);\r
-\r
-spl::shared_ptr<AVPacket> create_packet();\r
-\r
-spl::shared_ptr<AVCodecContext> open_codec(AVFormatContext& context,  enum AVMediaType type, int& index);\r
-spl::shared_ptr<AVFormatContext> open_input(const std::wstring& filename);\r
-\r
-bool is_sane_fps(AVRational time_base);\r
-AVRational fix_time_base(AVRational time_base);\r
-\r
-double read_fps(AVFormatContext& context, double fail_value);\r
-\r
-std::wstring print_mode(int width, int height, double fps, bool interlaced);\r
-\r
-std::wstring probe_stem(const std::wstring stem);\r
-bool is_valid_file(const std::wstring filename);\r
-\r
-}}
\ No newline at end of file
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Robert Nagy, ronag89@gmail.com
+*/
+
+#pragma once
+
+#include <common/forward.h>
+#include <common/memory.h>
+
+#include <core/video_format.h>
+#include <core/frame/pixel_format.h>
+#include <core/frame/audio_channel_layout.h>
+#include <core/frame/frame.h>
+#include <core/fwd.h>
+
+#include <boost/rational.hpp>
+
+#include <array>
+#include <vector>
+#include <utility>
+
+#if defined(_MSC_VER)
+#pragma warning (push)
+#pragma warning (disable : 4244)
+#endif
+extern "C"
+{
+#include <libavutil/avutil.h>
+}
+#if defined(_MSC_VER)
+#pragma warning (pop)
+#endif
+
+struct AVFrame;
+struct AVFormatContext;
+struct AVPacket;
+struct AVRational;
+struct AVCodecContext;
+
+namespace caspar { namespace ffmpeg {
+
+typedef std::vector<std::pair<std::string, std::string>> ffmpeg_options;
+
+// Utils
+
+core::field_mode                                       get_mode(const AVFrame& frame);
+core::mutable_frame                                    make_frame(const void* tag, const spl::shared_ptr<AVFrame>& decoded_frame, core::frame_factory& frame_factory, const core::audio_channel_layout& channel_layout);
+spl::shared_ptr<AVFrame>                       make_av_frame(core::mutable_frame& frame);
+spl::shared_ptr<AVFrame>                       make_av_frame(std::array<uint8_t*, 4> data, const core::pixel_format_desc& pix_desc);
+
+core::pixel_format_desc                                pixel_format_desc(PixelFormat pix_fmt, int width, int height);
+
+spl::shared_ptr<AVPacket> create_packet();
+spl::shared_ptr<AVFrame>  create_frame();
+
+spl::shared_ptr<AVCodecContext> open_codec(AVFormatContext& context, AVMediaType type, int& index, bool single_threaded);
+spl::shared_ptr<AVFormatContext> open_input(const std::wstring& filename);
+
+bool is_sane_fps(AVRational time_base);
+AVRational fix_time_base(AVRational time_base);
+
+std::shared_ptr<core::mutable_audio_buffer>    flush_audio();
+std::shared_ptr<core::mutable_audio_buffer>    empty_audio();
+std::shared_ptr<AVFrame>                                       flush_video();
+std::shared_ptr<AVFrame>                                       empty_video();
+
+double read_fps(AVFormatContext& context, double fail_value);
+boost::rational<int> read_framerate(AVFormatContext& context, const boost::rational<int>& fail_value);
+
+std::wstring print_mode(int width, int height, double fps, bool interlaced);
+
+std::wstring probe_stem(const std::wstring& stem, bool only_video);
+bool is_valid_file(const std::wstring& filename, bool only_video);
+bool try_get_duration(const std::wstring filename, std::int64_t& duration, boost::rational<std::int64_t>& time_base);
+
+core::audio_channel_layout get_audio_channel_layout(int num_channels, std::uint64_t layout, const std::wstring& channel_layout_spec);
+
+// av_get_default_channel_layout does not work for layouts not predefined in ffmpeg. This is needed to support > 8 channels.
+std::uint64_t create_channel_layout_bitmask(int num_channels);
+
+std::vector<int> find_audio_cadence(const boost::rational<int>& framerate);
+
+}}