Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ bool StreamerNode::initialize(const std::string &input_url) {
}

if (!openInput(input_url)) {
if (VERBOSE)
printf("Failed to open input\n");
return false;
}

if (!findAudioStream() || !setupDecoder() || !setupResampler()) {
if (VERBOSE)
printf("Failed to find/setup audio stream\n");
cleanup();
return false;
}
Expand All @@ -56,6 +60,8 @@ bool StreamerNode::initialize(const std::string &input_url) {
frame_ = av_frame_alloc();

if (pkt_ == nullptr || frame_ == nullptr) {
if (VERBOSE)
printf("Failed to allocate packet or frame\n");
cleanup();
return false;
}
Expand Down Expand Up @@ -119,29 +125,24 @@ void StreamerNode::streamAudio() {
while (streamFlag.load()) {
if (pendingFrame_ != nullptr) {
if (!processFrameWithResampler(pendingFrame_)) {
cleanup();
return;
}
} else {
if (av_read_frame(fmtCtx_, pkt_) < 0) {
cleanup();
return;
}
if (pkt_->stream_index == audio_stream_index_) {
if (avcodec_send_packet(codecCtx_, pkt_) != 0) {
cleanup();
return;
}
if (avcodec_receive_frame(codecCtx_, frame_) != 0) {
cleanup();
return;
}
if (!processFrameWithResampler(frame_)) {
cleanup();
return;
}
av_packet_unref(pkt_);
}
av_packet_unref(pkt_);
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
Expand Down Expand Up @@ -174,6 +175,13 @@ std::shared_ptr<AudioBus> StreamerNode::processNode(
(maxBufferSize_ - offsetLength) * sizeof(float));
}
bufferedBusIndex_ -= offsetLength;
} else {
if (VERBOSE)
printf(
"Buffer underrun: have %zu, need %zu\n",
bufferedBusIndex_,
(size_t)framesToProcess);
processingBus->zero();
}

return processingBus;
Expand Down Expand Up @@ -273,6 +281,8 @@ bool StreamerNode::setupDecoder() {

void StreamerNode::cleanup() {
streamFlag.store(false);
// cleanup cannot be called from the streaming thread so there is no need to
// check if we are in the same thread
streamingThread_.join();
if (swrCtx_ != nullptr) {
swr_free(&swrCtx_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ extern "C" {
#include <string>
#include <atomic>

static bool constexpr VERBOSE = false;

namespace audioapi {

class AudioBus;
Expand Down Expand Up @@ -94,7 +96,7 @@ class StreamerNode : public AudioScheduledSourceNode {

/**
* @brief Open the input stream
* @param input_url The URL of the input stream
* @param inputUrl The URL of the input stream
* @return true if successful, false otherwise
* @note This function initializes the FFmpeg libraries and opens the input stream
*/
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
<key>BinaryPath</key>
<string>libavformat.framework/libavformat</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>libavformat.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>libavformat.framework/libavformat</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>libavformat.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
<key>BinaryPath</key>
<string>libswresample.framework/libswresample</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>libswresample.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>libswresample.framework/libswresample</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>libswresample.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ COMMON_CONFIG="
--disable-audiotoolbox
--disable-videotoolbox
--disable-hwaccels
--enable-protocol=https,tls,tcp
--enable-protocol=https,tls,tcp,http
--enable-demuxer=hls
--enable-demuxer=mov
--enable-demuxer=mp3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class IOSAudioRecorder : public AudioRecorder {
IOSAudioRecorder(
float sampleRate,
int bufferLength,
const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry);
const std::shared_ptr<AudioEventHandlerRegistry>
&audioEventHandlerRegistry);

~IOSAudioRecorder() override;

Expand Down