-
-
Notifications
You must be signed in to change notification settings - Fork 65
feat: preloading in audio tag #1075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mdydek
wants to merge
4
commits into
main
Choose a base branch
from
feat/audio-tag-preload
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
1 change: 0 additions & 1 deletion
1
...ges/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/AudioDecoderHostObject.h
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||
| #include <audioapi/core/utils/AudioDecoder.h> | ||||||||||||||
| #include <audioapi/core/utils/AudioDecoding.h> | ||||||||||||||
| #include <audioapi/libs/base64/base64.h> | ||||||||||||||
| #include <audioapi/libs/decoding/IncrementalAudioDecoder.h> | ||||||||||||||
| #include <audioapi/libs/miniaudio/MiniAudioDecoding.h> | ||||||||||||||
|
|
@@ -16,7 +16,7 @@ | |||||||||||||
| #include <utility> | ||||||||||||||
| #include <vector> | ||||||||||||||
|
|
||||||||||||||
| namespace audioapi::audiodecoder { | ||||||||||||||
| namespace audioapi::audiodecoding { | ||||||||||||||
|
|
||||||||||||||
| // Drains an incremental decoder into an AudioBuffer. Total frame count is not | ||||||||||||||
| // known up front for some formats (e.g. Vorbis), so we read in fixed-size | ||||||||||||||
|
|
@@ -113,7 +113,7 @@ AudioBufferResult decodeWithFilePath(const std::string &path, float sampleRate) | |||||||||||||
|
|
||||||||||||||
| if (needsFFmpegByPath(path)) { | ||||||||||||||
| #if !RN_AUDIO_API_FFMPEG_DISABLED | ||||||||||||||
| ffmpegdecoder::FFmpegDecoder decoder; | ||||||||||||||
| ffmpeg_decoder::FFmpegDecoder decoder; | ||||||||||||||
| const auto openResult = decoder.openFile(sr, path); | ||||||||||||||
| if (openResult.is_err()) { | ||||||||||||||
| return Err("Failed to open file with FFmpeg decoder: " + openResult.unwrap_err()); | ||||||||||||||
|
|
@@ -142,7 +142,7 @@ AudioBufferResult decodeWithMemoryBlock(const void *data, size_t size, float sam | |||||||||||||
|
|
||||||||||||||
| if (needsFFmpeg(format)) { | ||||||||||||||
| #if !RN_AUDIO_API_FFMPEG_DISABLED | ||||||||||||||
| ffmpegdecoder::FFmpegDecoder decoder; | ||||||||||||||
| ffmpeg_decoder::FFmpegDecoder decoder; | ||||||||||||||
| const auto openResult = decoder.openMemory(sr, data, size); | ||||||||||||||
| if (openResult.is_err()) { | ||||||||||||||
| return Err("Failed to open memory block with FFmpeg decoder: " + openResult.unwrap_err()); | ||||||||||||||
|
|
@@ -197,4 +197,17 @@ AudioBufferResult decodeWithPCMInBase64( | |||||||||||||
| return Ok(std::move(audioBuffer)); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| } // namespace audioapi::audiodecoder | ||||||||||||||
| template <typename T> | ||||||||||||||
| concept Decoder = std::is_base_of_v<decoding::IncrementalAudioDecoder, T>; | ||||||||||||||
|
|
||||||||||||||
| template <Decoder D> | ||||||||||||||
|
Comment on lines
+200
to
+203
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| std::optional<double> probeDuration(const void *data, size_t size, int outputSampleRate) { | ||||||||||||||
| D decoder; | ||||||||||||||
| const auto openResult = decoder.openMemory(outputSampleRate, data, size); | ||||||||||||||
| if (openResult.is_err()) { | ||||||||||||||
| return std::nullopt; | ||||||||||||||
| } | ||||||||||||||
| return static_cast<double>(decoder.getDurationInSeconds()); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| } // namespace audioapi::audiodecoding | ||||||||||||||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ extern "C" { | |
| #include <libavutil/rational.h> | ||
| } | ||
|
|
||
| namespace audioapi::ffmpegdecoder { | ||
| namespace audioapi::ffmpeg_decoder { | ||
|
|
||
| namespace { | ||
|
|
||
|
|
@@ -555,11 +555,11 @@ std::shared_ptr<AudioBuffer> decodeWithMemoryBlock(const void *data, size_t size | |
| return buildAudioBufferFromInterleaved(acc, dec.outputChannels(), dec.outputSampleRate()); | ||
| } | ||
|
|
||
| } // namespace audioapi::ffmpegdecoder | ||
| } // namespace audioapi::ffmpeg_decoder | ||
|
|
||
| #else | ||
|
|
||
| namespace audioapi::ffmpegdecoder { | ||
| namespace audioapi::ffmpeg_decoder { | ||
| FFmpegDecoder::~FFmpegDecoder() = default; | ||
| void FFmpegDecoder::close() {} | ||
| decoding::DecoderResult FFmpegDecoder::openFile(int, const std::string &) { | ||
|
|
@@ -580,13 +580,16 @@ decoding::DecoderResult FFmpegDecoder::seekToTime(double) { | |
| size_t FFmpegDecoder::readPcmFrames(float *, size_t) { | ||
| return 0; | ||
| } | ||
| std::optional<double> FFmpegDecoder::probeDuration(const void *, size_t, int) { | ||
| return std::nullopt; | ||
| } | ||
|
Comment on lines
+583
to
+585
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not defined in the header. What is this for? |
||
| std::shared_ptr<AudioBuffer> decodeWithFilePath(const std::string &, int) { | ||
| return nullptr; | ||
| } | ||
| std::shared_ptr<AudioBuffer> decodeWithMemoryBlock(const void *, size_t, int) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| } // namespace audioapi::ffmpegdecoder | ||
| } // namespace audioapi::ffmpeg_decoder | ||
|
|
||
| #endif // !RN_AUDIO_API_FFMPEG_DISABLED | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.