Ring Daemon 16.0.0
Loading...
Searching...
No Matches
filter_transpose.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#include "filter_transpose.h"
19#include "logger.h"
20
21namespace jami {
22namespace video {
23
24std::unique_ptr<MediaFilter>
26 int rotation, std::string inputName, int width, int height, int format, bool rescale)
27{
28 JAMI_WARN("Rotation set to %d", rotation);
29 if (rotation == 0) {
30 return {};
31 }
32
33 std::stringstream ss;
34 ss << "[" << inputName << "] ";
35
36 switch (rotation) {
37 case 90:
38 case -270:
39 ss << "transpose=2";
40 if (rescale) {
41 if (width > height)
42 ss << ", scale=w=-1:h=" << height << ", pad=" << width << ":" << height
43 << ":(ow-iw)/2";
44 else
45 ss << ", scale=w=" << width << ":h=-1"
46 << ", pad=" << width << ":" << height << ":0:(oh-ih)/2";
47 }
48 break;
49 case 180:
50 case -180:
51 ss << "transpose=1, transpose=1";
52 break;
53 case 270:
54 case -90:
55 ss << "transpose=1";
56 if (rescale) {
57 if (width > height)
58 ss << ", scale=w=-1:h=" << height << ", pad=" << width << ":" << height
59 << ":(ow-iw)/2";
60 else
61 ss << ", scale=w=" << width << ":h=-1"
62 << ", pad=" << width << ":" << height << ":0:(oh-ih)/2";
63 }
64 break;
65 default:
66 return {};
67 }
68
69 constexpr auto one = rational<int>(1);
70 std::vector<MediaStream> msv;
71 msv.emplace_back(inputName, format, one, width, height, 0, one);
72
73 std::unique_ptr<MediaFilter> filter(new MediaFilter);
74 auto ret = filter->initialize(ss.str(), msv);
75 if (ret < 0) {
76 JAMI_ERR() << "filter init fail";
77 return {};
78 }
79 return filter;
80}
81
82} // namespace video
83} // namespace jami
Provides access to libavfilter.
Naive implementation of the boost::rational interface, described here: http://www....
Definition rational.h:38
#define JAMI_ERR(...)
Definition logger.h:218
#define JAMI_WARN(...)
Definition logger.h:217
std::unique_ptr< MediaFilter > getTransposeFilter(int rotation, std::string inputName, int width, int height, int format, bool rescale)
void emitSignal(Args... args)
Definition ring_signal.h:64