Skip to content

Commit d9a7592

Browse files
committed
Write VLC log to TDLib log
1 parent 2e548c6 commit d9a7592

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

Telegram.Native/Media/AsyncMediaPlayer.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
#include "Media/AsyncMediaPlayer.g.cpp"
55
#endif
66

7+
#include <string>
8+
#include <format>
9+
710
#include <winrt/Windows.Foundation.Collections.h>
11+
#include <winrt/Telegram.Td.h>
12+
#include <winrt/Telegram.Td.Api.h>
813

914
namespace winrt::Telegram::Native::Media::implementation
1015
{
@@ -593,25 +598,25 @@ namespace winrt::Telegram::Native::Media::implementation
593598

594599
void AsyncMediaPlayer::HandleLog(int level, const libvlc_log_t* ctx, const char* fmt, va_list args)
595600
{
596-
if (m_log)
597-
{
598-
int byteLength = vsnprintf(nullptr, 0, fmt, args) + 1;
599-
if (byteLength <= 1)
600-
return;
601+
int byteLength = vsnprintf(nullptr, 0, fmt, args) + 1;
602+
if (byteLength <= 1)
603+
return;
601604

602-
char* buffer = new char[byteLength];
603-
vsprintf_s(buffer, byteLength, fmt, args);
604-
hstring message = winrt::to_hstring(std::string(buffer, byteLength - 1));
605-
delete[] buffer;
605+
char* buffer = new char[byteLength];
606+
vsprintf_s(buffer, byteLength, fmt, args);
607+
std::string message(buffer, byteLength - 1);
608+
delete[] buffer;
606609

607-
const char* module;
608-
const char* file;
609-
unsigned int line = 0;
610-
libvlc_log_get_context(ctx, &module, &file, &line);
610+
const char* module;
611+
const char* file;
612+
unsigned int line = 0;
613+
libvlc_log_get_context(ctx, &module, &file, &line);
611614

612-
// TODO:
613-
m_log(*this, AsyncMediaPlayerLogEventArgs((AsyncMediaPlayerLogLevel)level, message, winrt::to_hstring(module), winrt::to_hstring(file), line));
614-
}
615+
std::stringstream ss;
616+
ss << "[AsyncMediaPlayer.cpp][" << file << ":" << line << "][" << message;
617+
winrt::Telegram::Td::Client::Execute(winrt::Telegram::Td::Api::AddLogMessage(2, winrt::to_hstring(ss.str())));
618+
619+
m_log(*this, AsyncMediaPlayerLogEventArgs((AsyncMediaPlayerLogLevel)level, winrt::to_hstring(message), winrt::to_hstring(module), winrt::to_hstring(file), line));
615620
}
616621

617622
void AsyncMediaPlayer::HandleEvent(const libvlc_event_t* event)

0 commit comments

Comments
 (0)