-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup: Slightly nicer code for the AV settings form.
- Loading branch information
Showing
7 changed files
with
113 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "scopedavdictionary.h" | ||
|
||
#include <QString> | ||
|
||
extern "C" | ||
{ | ||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wold-style-cast" | ||
#include <libavformat/avformat.h> | ||
#pragma GCC diagnostic pop | ||
} | ||
|
||
void ScopedAVDictionary::Setter::operator=(const char* value) | ||
{ | ||
av_dict_set(dict, key, value, 0); | ||
} | ||
|
||
void ScopedAVDictionary::Setter::operator=(const QString& value) | ||
{ | ||
*this = value.toStdString().c_str(); | ||
} | ||
|
||
void ScopedAVDictionary::Setter::operator=(std::int64_t value) | ||
{ | ||
av_dict_set_int(dict, key, value, 0); | ||
} | ||
|
||
ScopedAVDictionary::~ScopedAVDictionary() | ||
{ | ||
av_dict_free(&options); | ||
} | ||
|
||
ScopedAVDictionary::Setter ScopedAVDictionary::operator[](const char* key) | ||
{ | ||
return {&options, key}; | ||
} | ||
|
||
AVDictionary** ScopedAVDictionary::get() | ||
{ | ||
return &options; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* SPDX-License-Identifier: GPL-3.0-or-later | ||
* Copyright © 2024 The TokTok team. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <array> | ||
#include <cstddef> | ||
#include <cstdint> | ||
|
||
struct AVDictionary; | ||
class QString; | ||
|
||
class ScopedAVDictionary | ||
{ | ||
AVDictionary* options = nullptr; | ||
|
||
struct Setter | ||
{ | ||
AVDictionary** dict; | ||
const char* key; | ||
|
||
void operator=(const char* value); | ||
void operator=(const QString& value); | ||
|
||
template <std::size_t N> | ||
void operator=(const std::array<char, N>& value) | ||
{ | ||
*this = value.data(); | ||
} | ||
|
||
void operator=(std::int64_t value); | ||
}; | ||
|
||
public: | ||
ScopedAVDictionary() = default; | ||
ScopedAVDictionary& operator=(const ScopedAVDictionary&) = delete; | ||
ScopedAVDictionary(const ScopedAVDictionary&) = delete; | ||
|
||
~ScopedAVDictionary(); | ||
|
||
Setter operator[](const char* key); | ||
|
||
AVDictionary** get(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters