Ring Daemon
Loading...
Searching...
No Matches
filter_transpose.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2026 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>
25getTransposeFilter(int rotation, std::string inputName, int width, int height, int format, bool rescale)
26{
27 JAMI_WARN("Rotation set to %d", rotation);
28 if (rotation == 0) {
29 return {};
30 }
31
32 std::stringstream ss;
33 ss << "[" << inputName << "] ";
34
35 switch (rotation) {
36 case 90:
37 case -270:
38 ss << "transpose=2";
39 if (rescale) {
40 if (width > height)
41 ss << ", scale=w=-1:h=" << height << ", pad=" << width << ":" << height << ":(ow-iw)/2";
42 else
43 ss << ", scale=w=" << width << ":h=-1" << ", pad=" << width << ":" << height << ":0:(oh-ih)/2";
44 }
45 break;
46 case 180:
47 case -180:
48 ss << "transpose=1, transpose=1";
49 break;
50 case 270:
51 case -90:
52 ss << "transpose=1";
53 if (rescale) {
54 if (width > height)
55 ss << ", scale=w=-1:h=" << height << ", pad=" << width << ":" << height << ":(ow-iw)/2";
56 else
57 ss << ", scale=w=" << width << ":h=-1" << ", pad=" << width << ":" << height << ":0:(oh-ih)/2";
58 }
59 break;
60 default:
61 return {};
62 }
63
64 constexpr auto one = rational<int>(1);
65 std::vector<MediaStream> msv;
66 msv.emplace_back(inputName, format, one, width, height, 0, one);
67
68 std::unique_ptr<MediaFilter> filter(new MediaFilter);
69 auto ret = filter->initialize(ss.str(), msv);
70 if (ret < 0) {
71 JAMI_ERR() << "filter init fail";
72 return {};
73 }
74 return filter;
75}
76
77} // namespace video
78} // namespace jami
Provides access to libavfilter.
Naive implementation of the boost::rational interface, described here: https://www....
Definition rational.h:39
#define JAMI_ERR(...)
Definition logger.h:230
#define JAMI_WARN(...)
Definition logger.h:229
std::unique_ptr< MediaFilter > getTransposeFilter(int rotation, std::string inputName, int width, int height, int format, bool rescale)
void emitSignal(Args... args)
Definition jami_signal.h:64