Adrien Beraud | 087d559 | 2023-03-06 11:22:33 -0500 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2004-2023 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> |
| 5 | * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> |
| 6 | * Author: Philippe Gorley <philippe.gorley@savoirfairelinux.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | */ |
| 22 | |
| 23 | #pragma once |
| 24 | |
| 25 | extern "C" { |
| 26 | struct AVFrame; |
| 27 | struct SwrContext; |
| 28 | } |
| 29 | |
| 30 | namespace jami { |
| 31 | |
| 32 | /** |
| 33 | * @brief Wrapper class for libswresample |
| 34 | */ |
| 35 | class Resampler |
| 36 | { |
| 37 | public: |
| 38 | Resampler(); |
| 39 | ~Resampler(); |
| 40 | |
| 41 | /** |
| 42 | * @brief Resample a frame. |
| 43 | * |
| 44 | * Resample from @input format to @output format. |
| 45 | * |
| 46 | * NOTE: sample_rate, ch_layout, and format should be set on @output |
| 47 | */ |
| 48 | int resample(const AVFrame* input, AVFrame* output); |
| 49 | private: |
| 50 | /** |
| 51 | * @brief Reinitializes filter according to new format. |
| 52 | * |
| 53 | * Reinitializes the resampler when new settings are detected. As long as both input and |
| 54 | * output formats don't change, this will only be called once. |
| 55 | */ |
| 56 | void reinit(const AVFrame* in, const AVFrame* out); |
| 57 | |
| 58 | /** |
| 59 | * @brief Libswresample resampler context. |
| 60 | * |
| 61 | * NOTE SwrContext is an imcomplete type and cannot be stored in a smart pointer. |
| 62 | */ |
| 63 | SwrContext* swrCtx_; |
| 64 | |
| 65 | /** |
| 66 | * @brief Number of times @swrCtx_ has been initialized with no successful audio resampling. |
| 67 | * |
| 68 | * 0: Uninitialized |
| 69 | * 1: Initialized |
| 70 | * >1: Invalid frames or formats, reinit is going to be called in an infinite loop |
| 71 | */ |
| 72 | unsigned initCount_; |
| 73 | }; |
| 74 | } // namespace jami |