FFmpegfs Fuse Multi Media Filesystem 2.19
Loading...
Searching...
No Matches
ffmpeg_swrcontext.cc
1/*
2 * This file is part of FFmpegfs.
3 *
4 * FFmpegfs 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
10#include "ffmpeg_swrcontext.h"
11
12extern "C" {
13#include <libswresample/swresample.h>
14}
15
17 : m_ctx(nullptr)
18{
19}
20
22 : m_ctx(ctx)
23{
24}
25
30
32 : m_ctx(ctx.release())
33{
34}
35
36FFmpeg_SwrContext& FFmpeg_SwrContext::operator=(FFmpeg_SwrContext&& ctx) noexcept
37{
38 if (this != &ctx)
39 {
40 reset(ctx.release());
41 }
42 return *this;
43}
44
45SwrContext *FFmpeg_SwrContext::get() const
46{
47 return m_ctx;
48}
49
51{
52 reset();
53 return &m_ctx;
54}
55
57{
58 SwrContext *ctx = m_ctx;
59 m_ctx = nullptr;
60 return ctx;
61}
62
63bool FFmpeg_SwrContext::reset(SwrContext *ctx)
64{
65 bool closed = false;
66
67 if (m_ctx != nullptr)
68 {
69 swr_free(&m_ctx);
70 closed = true;
71 }
72
73 m_ctx = ctx;
74
75 return closed;
76}
77
79{
80 return m_ctx == nullptr;
81}
82
83FFmpeg_SwrContext::operator bool() const
84{
85 return m_ctx != nullptr;
86}
87
88FFmpeg_SwrContext::operator SwrContext *() const
89{
90 return m_ctx;
91}
92
94{
95 return m_ctx;
96}
RAII wrapper for SwrContext.
FFmpeg_SwrContext()
Construct an empty resampler-context wrapper.
~FFmpeg_SwrContext()
Release the owned resampler context, if any.
bool empty() const
Check whether the wrapper currently owns a resampler context.
bool reset(SwrContext *ctx=nullptr)
Replace the owned context.
SwrContext * m_ctx
Pointer to underlying SwrContext.
SwrContext * release()
Release ownership without freeing the resampler context.
SwrContext ** address()
Get a writable pointer-to-pointer for FFmpeg allocation APIs.
SwrContext * get() const
Get the owned FFmpeg resampler context pointer.
SwrContext * operator->() const
Access members of the underlying resampler context.
FFmpeg SwrContext RAII wrapper.