Line data Source code
1 : /* 2 : * Copyright (C) 2004-2024 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 : 21 : namespace jami { 22 : namespace video { 23 : 24 : std::unique_ptr<MediaFilter> 25 0 : getTransposeFilter( 26 : int rotation, std::string inputName, int width, int height, int format, bool rescale) 27 : { 28 0 : JAMI_WARN("Rotation set to %d", rotation); 29 0 : if (rotation == 0) { 30 0 : return {}; 31 : } 32 : 33 0 : std::stringstream ss; 34 0 : ss << "[" << inputName << "] "; 35 : 36 0 : switch (rotation) { 37 0 : case 90: 38 : case -270: 39 0 : ss << "transpose=2"; 40 0 : if (rescale) { 41 0 : if (width > height) 42 0 : ss << ", scale=w=-1:h=" << height << ", pad=" << width << ":" << height 43 0 : << ":(ow-iw)/2"; 44 : else 45 0 : ss << ", scale=w=" << width << ":h=-1" 46 0 : << ", pad=" << width << ":" << height << ":0:(oh-ih)/2"; 47 : } 48 0 : break; 49 0 : case 180: 50 : case -180: 51 0 : ss << "transpose=1, transpose=1"; 52 0 : break; 53 0 : case 270: 54 : case -90: 55 0 : ss << "transpose=1"; 56 0 : if (rescale) { 57 0 : if (width > height) 58 0 : ss << ", scale=w=-1:h=" << height << ", pad=" << width << ":" << height 59 0 : << ":(ow-iw)/2"; 60 : else 61 0 : ss << ", scale=w=" << width << ":h=-1" 62 0 : << ", pad=" << width << ":" << height << ":0:(oh-ih)/2"; 63 : } 64 0 : break; 65 0 : default: 66 0 : return {}; 67 : } 68 : 69 0 : constexpr auto one = rational<int>(1); 70 0 : std::vector<MediaStream> msv; 71 0 : msv.emplace_back(inputName, format, one, width, height, 0, one); 72 : 73 0 : std::unique_ptr<MediaFilter> filter(new MediaFilter); 74 0 : auto ret = filter->initialize(ss.str(), msv); 75 0 : if (ret < 0) { 76 0 : JAMI_ERR() << "filter init fail"; 77 0 : return {}; 78 : } 79 0 : return filter; 80 0 : } 81 : 82 : } // namespace video 83 : } // namespace jami