Skip to content

Commit

Permalink
[CHORE] Move debug function to decode header
Browse files Browse the repository at this point in the history
  • Loading branch information
nots1dd committed Feb 25, 2025
1 parent 02d622b commit 4c24bcc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 21 deletions.
46 changes: 45 additions & 1 deletion include/decode.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "../include/macros.hpp"
#include "macros.hpp"
#include "logger.hpp"
#include <iostream>
#include <vector>

Expand All @@ -13,6 +14,43 @@ extern "C"
#include <libavutil/opt.h>
}

auto write_transport_segments_to_file(const std::vector<std::string>& transport_segments,
const std::string& filename) -> bool
{
std::ofstream output_file(filename, std::ios::binary);
if (!output_file)
{
LOG_ERROR << "Failed to open output file: " << filename;
return false;
}

for (const auto& segment : transport_segments)
{
output_file.write(segment.data(), segment.size());
}

output_file.close();
LOG_INFO << "Successfully wrote transport streams to " << filename;
return true;
}

auto write_transport_segments_to_file(const std::vector<unsigned char>& transport_segment,
const std::string& filename) -> bool
{
std::ofstream output_file(filename, std::ios::binary);
if (!output_file)
{
LOG_ERROR << "Failed to open output file: " << filename << std::endl;
return false;
}

output_file.write(reinterpret_cast<const char*>(transport_segment.data()), transport_segment.size());

output_file.close();
LOG_INFO << "Successfully wrote transport stream to " << filename << std::endl;
return true;
}

// Custom AVIO read function
static int custom_read_packet(void* opaque, uint8_t* buf, int buf_size)
{
Expand Down Expand Up @@ -190,6 +228,12 @@ class MediaDecoder
av_packet_unref(&packet);
}

if (!write_transport_segments_to_file(output_audio, "audioo.raw"))
{
LOG_ERROR << "Error writing transport segments to file";
return false;
}

// Cleanup
av_frame_free(&frame);
avcodec_free_context(&codec_ctx);
Expand Down
20 changes: 0 additions & 20 deletions src/client_receive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,6 @@ auto perform_https_request(net::io_context& ioc, ssl::context& ctx, const std::s
}
}

bool write_transport_segments_to_file(const std::vector<std::string>& transport_segments,
const std::string& filename)
{
std::ofstream output_file(filename, std::ios::binary);
if (!output_file)
{
LOG_ERROR << "Failed to open output file: " << filename;
return false;
}

for (const auto& segment : transport_segments)
{
output_file.write(segment.data(), segment.size());
}

output_file.close();
LOG_INFO << "Successfully wrote transport streams to " << filename;
return true;
}

auto fetch_transport_segments(const std::string& ip_id, const std::string& audio_id,
GlobalState& gs, const std::string& server, bool& flac_found) -> bool
{
Expand Down

0 comments on commit 4c24bcc

Please sign in to comment.