]> git.sesse.net Git - casparcg/blob - modules/ffmpeg/producer/util/util.h
2.1.0: Refactored away "write_frame", only "data_frame" and "draw_frame" are needed.
[casparcg] / modules / ffmpeg / producer / util / util.h
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\r
5 *\r
6 * CasparCG is free software: you can redistribute it and/or modify\r
7 * it under the terms of the GNU General Public License as published by\r
8 * the Free Software Foundation, either version 3 of the License, or\r
9 * (at your option) any later version.\r
10 *\r
11 * CasparCG is distributed in the hope that it will be useful,\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 * GNU General Public License for more details.\r
15 *\r
16 * You should have received a copy of the GNU General Public License\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #pragma once\r
23 \r
24 #include <common/forward.h>\r
25 #include <common/spl/memory.h>\r
26 \r
27 #include <core/video_format.h>\r
28 #include <core/frame/pixel_format.h>\r
29 #include <core/mixer/audio/audio_mixer.h>\r
30 \r
31 #include <array>\r
32 \r
33 enum PixelFormat;\r
34 struct AVFrame;\r
35 struct AVFormatContext;\r
36 struct AVPacket;\r
37 struct AVRational;\r
38 struct AVCodecContext;\r
39 \r
40 FORWARD2(caspar, core, struct pixel_format_desc);\r
41 FORWARD2(caspar, core, class data_frame);\r
42 FORWARD2(caspar, core, class data_frame);\r
43 FORWARD2(caspar, core, class frame_factory);\r
44 \r
45 namespace caspar { namespace ffmpeg {\r
46                 \r
47 std::shared_ptr<core::audio_buffer> flush_audio();\r
48 std::shared_ptr<core::audio_buffer> empty_audio();\r
49 std::shared_ptr<AVFrame>                        flush_video();\r
50 std::shared_ptr<AVFrame>                        empty_video();\r
51 \r
52 // Utils\r
53 \r
54 static const int CASPAR_PIX_FMT_LUMA = 10; // Just hijack some unual pixel format.\r
55 \r
56 core::field_mode                                        get_mode(const AVFrame& frame);\r
57 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
58 spl::shared_ptr<core::data_frame>       make_data_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
59 spl::shared_ptr<AVFrame>                        make_av_frame(caspar::core::data_frame& frame);\r
60 spl::shared_ptr<AVFrame>                        make_av_frame(std::array<void*, 4> data, const core::pixel_format_desc& pix_desc);\r
61 \r
62 template<typename C>\r
63 std::shared_ptr<AVFrame> make_av_frame(const C& container, const core::pixel_format_desc& pix_desc)\r
64 {       \r
65         std::array<void*, 4> data = {};\r
66         int n = 0;\r
67         for(auto it = std::begin(container); it != std::end(container); ++it)\r
68                 data[n++] = (*it)->data();\r
69         return make_av_frame(data, pix_desc);\r
70 }\r
71 \r
72 core::pixel_format_desc                         pixel_format_desc(PixelFormat pix_fmt, int width, int height);\r
73 \r
74 spl::shared_ptr<AVPacket> create_packet();\r
75 \r
76 spl::shared_ptr<AVCodecContext> open_codec(AVFormatContext& context,  enum AVMediaType type, int& index);\r
77 spl::shared_ptr<AVFormatContext> open_input(const std::wstring& filename);\r
78 \r
79 bool is_sane_fps(AVRational time_base);\r
80 AVRational fix_time_base(AVRational time_base);\r
81 \r
82 double read_fps(AVFormatContext& context, double fail_value);\r
83 \r
84 std::wstring print_mode(int width, int height, double fps, bool interlaced);\r
85 \r
86 std::wstring probe_stem(const std::wstring stem);\r
87 bool is_valid_file(const std::wstring filename);\r
88 \r
89 }}