]> git.sesse.net Git - casparcg/blob - modules/ffmpeg/producer/muxer/display_mode.h
3a469d8e122da656b08851eb5a2f2de2f0d972f5
[casparcg] / modules / ffmpeg / producer / muxer / display_mode.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Robert Nagy, ronag89@gmail.com
20 */
21
22 #pragma once
23
24 #include <core/video_format.h>
25
26 #include <ostream>
27
28 namespace caspar { namespace ffmpeg {
29         
30 enum class display_mode
31 {
32         simple,
33         duplicate,
34         half,
35         interlace,
36         deinterlace_bob,
37         deinterlace_bob_reinterlace,
38         deinterlace,
39         count,
40         invalid
41 };
42
43 template< typename CharT, typename TraitsT >
44 std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream<CharT, TraitsT>& o, display_mode value)
45 {       
46         switch(value)
47         {
48         case display_mode::simple:                                              return o << L"simple";
49         case display_mode::duplicate:                                   return o << L"duplicate";
50         case display_mode::half:                                                return o << L"half";
51         case display_mode::interlace:                                   return o << L"interlace";
52         case display_mode::deinterlace_bob:                             return o << L"deinterlace_bob";
53         case display_mode::deinterlace_bob_reinterlace: return o << L"deinterlace_bob_reinterlace";
54         case display_mode::deinterlace:                                 return o << L"deinterlace";
55         default:                                                                                return o << L"invalid";
56         }
57 }
58
59 static display_mode get_display_mode(const core::field_mode in_mode, double in_fps, const core::field_mode out_mode, double out_fps)
60 {               
61         static const auto epsilon = 2.0;
62
63         if(in_fps < 20.0 || in_fps > 80.0)
64         {
65                 //if(out_mode != core::field_mode::progressive && in_mode == core::field_mode::progressive)
66                 //      return display_mode::interlace;
67                 
68                 if(out_mode == core::field_mode::progressive && in_mode != core::field_mode::progressive)
69                 {
70                         if(in_fps < 35.0)
71                                 return display_mode::deinterlace;
72                         else
73                                 return display_mode::deinterlace_bob;
74                 }
75         }
76
77         if(std::abs(in_fps - out_fps) < epsilon)
78         {
79                 if(in_mode != core::field_mode::progressive && out_mode == core::field_mode::progressive)
80                         return display_mode::deinterlace;
81                 //else if(in_mode == core::field_mode::progressive && out_mode != core::field_mode::progressive)
82                 //      simple(); // interlace_duplicate();
83                 else
84                         return display_mode::simple;
85         }
86         else if(std::abs(in_fps/2.0 - out_fps) < epsilon)
87         {
88                 if(in_mode != core::field_mode::progressive)
89                         return display_mode::invalid;
90
91                 if(out_mode != core::field_mode::progressive)
92                         return display_mode::interlace;
93                 else
94                         return display_mode::half;
95         }
96         else if(std::abs(in_fps - out_fps/2.0) < epsilon)
97         {
98                 if(out_mode != core::field_mode::progressive)
99                         return display_mode::invalid;
100
101                 if(in_mode != core::field_mode::progressive)
102                         return display_mode::deinterlace_bob;
103                 else
104                         return display_mode::duplicate;
105         }
106
107         return display_mode::invalid;
108 }
109
110 }}