Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 7fb36b06 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

AUDIO: Finish implementing the AudioContext

parent 7b6182b0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!5Add AudioContext to AudioSubDocument
...@@ -32,11 +32,30 @@ AudioContext::AudioContext(const QString &path) ...@@ -32,11 +32,30 @@ AudioContext::AudioContext(const QString &path)
AVCodec *streamCodec = avcodec_find_decoder(params->codec_id); AVCodec *streamCodec = avcodec_find_decoder(params->codec_id);
if (streamCodec && streamCodec->type == AVMEDIA_TYPE_AUDIO) { if (streamCodec && streamCodec->type == AVMEDIA_TYPE_AUDIO) {
audioStreamIndexes.push_back(i); audioStreamIndexes.push_back(i);
audioCodecs.insert(i, std::make_shared<Stream>(formatPtr, itFormat)); audioStreams.insert(i, std::make_shared<Stream>(formatPtr, itFormat));
} }
} }
} }
// Get the number of audio streams in the audio context
int
AudioContext::getStreamCount() const noexcept
{
return audioStreamIndexes.size();
}
// Get a specific audio stream, try to lock the weak pointer. if the index was
// not present the used_count will be 0 and you won't be able to lock it.
AudioContext::StreamWeakPtr
AudioContext::getStream(uint index) const noexcept
{
if (QMap<uint, StreamPtr>::const_iterator found = audioStreams.find(index);
found != audioStreams.end()) {
return StreamWeakPtr{ *found };
}
return StreamWeakPtr{ spareNullSreamPtr };
}
// AudioContext::Stream class implementation // AudioContext::Stream class implementation
// Constructor, need an AVFormat and an AVStream // Constructor, need an AVFormat and an AVStream
......
...@@ -116,10 +116,10 @@ public: ...@@ -116,10 +116,10 @@ public:
~AudioContext() noexcept = default; ~AudioContext() noexcept = default;
int getStreamCount() const noexcept; int getStreamCount() const noexcept;
StreamWeakPtr getStream(int) const noexcept; StreamWeakPtr getStream(uint) const noexcept;
private: private:
/* Regarding the format */ // Regarding the format
static inline constexpr auto avFormatContextDeleter = static inline constexpr auto avFormatContextDeleter =
[](AVFormatContext *ptr) noexcept -> void { [](AVFormatContext *ptr) noexcept -> void {
if (ptr) if (ptr)
...@@ -128,10 +128,14 @@ private: ...@@ -128,10 +128,14 @@ private:
using AVFormatContextPtr = std::unique_ptr<AVFormatContext, decltype(avFormatContextDeleter)>; using AVFormatContextPtr = std::unique_ptr<AVFormatContext, decltype(avFormatContextDeleter)>;
AVFormatContextPtr format{ avformat_alloc_context() }; AVFormatContextPtr format{ avformat_alloc_context() };
/* Usefull information */ // Usefull information
QString filePath; QString filePath;
QVector<uint> audioStreamIndexes{}; QVector<uint> audioStreamIndexes{};
QMap<uint, StreamPtr> audioCodecs{}; QMap<uint, StreamPtr> audioStreams{};
// Spare always null shared pointer, to be used when the audioStream[i] was
// not found.
StreamPtr spareNullSreamPtr{ nullptr };
}; };
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter