Skip to content

Commit 206be68

Browse files
committed
feat: add logic for push hdr file
1 parent b5afc4f commit 206be68

7 files changed

Lines changed: 107 additions & 21 deletions

File tree

windows/APIExample/APIExample/APIExample.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ BEGIN
714714
EDITTEXT IDC_EDIT_CHANNELNAME,71,326,218,13,ES_AUTOHSCROLL
715715
PUSHBUTTON "JoinChannel",IDC_BUTTON_JOINCHANNEL,307,326,50,14
716716
LTEXT "",IDC_STATIC_DETAIL,442,325,181,58
717+
CONTROL "HDR",IDC_CHECK_HDR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,390,327,30,10
717718
END
718719

719720
IDD_DIALOG_MULTI_VIDEO_SOURCE_TRACKS DIALOGEX 0, 0, 632, 400

windows/APIExample/APIExample/APIExample.vcxproj

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ if exist en.ini (copy en.ini $(SolutionDir)$(Configuration))
122122
copy $(SolutionDir)APIExample\Advanced\LocalVideoTranscoding\agora.png $(SolutionDir)$(Configuration)
123123
copy $(SolutionDir)APIExample\Advanced\LocalVideoTranscoding\agora.jpg $(SolutionDir)$(Configuration)
124124
if exist sample.yuv (copy sample.yuv $(SolutionDir)$(Configuration))
125-
if exist $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 (copy $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 $(SolutionDir)$(Configuration))</Command>
125+
if exist $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 (copy $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 $(SolutionDir)$(Configuration))
126+
if exist $(SolutionDir)APIExample\res\hdr_1280_720.yuv (copy $(SolutionDir)APIExample\res\hdr_1280_720.yuv $(SolutionDir)$(Configuration))
127+
</Command>
126128
</PostBuildEvent>
127129
<Manifest>
128130
<AdditionalManifestFiles>
@@ -169,6 +171,7 @@ copy $(SolutionDir)APIExample\Advanced\LocalVideoTranscoding\agora.png $(Solutio
169171
copy $(SolutionDir)APIExample\Advanced\LocalVideoTranscoding\agora.jpg $(SolutionDir)$(Platform)\$(Configuration)
170172
if exist sample.yuv (copy sample.yuv $(SolutionDir)$(Platform)$(Configuration))
171173
if exist $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 (copy $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 $(SolutionDir)$(Configuration))
174+
if exist $(SolutionDir)APIExample\res\hdr_1280_720.yuv (copy $(SolutionDir)APIExample\res\hdr_1280_720.yuv $(SolutionDir)$(Configuration))
172175
</Command>
173176
</PostBuildEvent>
174177
<Manifest>
@@ -215,7 +218,8 @@ copy $(SolutionDir)APIExample\Advanced\LocalVideoTranscoding\agora.png $(Solutio
215218
copy $(SolutionDir)APIExample\Advanced\LocalVideoTranscoding\agora.jpg $(SolutionDir)$(Configuration)
216219

217220
if exist sample.yuv (copy sample.yuv $(SolutionDir)$(Configuration))
218-
if exist $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 (copy $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 $(SolutionDir)$(Configuration))</Command>
221+
if exist $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 (copy $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 $(SolutionDir)$(Configuration))
222+
if exist $(SolutionDir)APIExample\res\hdr_1280_720.yuv (copy $(SolutionDir)APIExample\res\hdr_1280_720.yuv $(SolutionDir)$(Configuration))</Command>
219223
</PostBuildEvent>
220224
<ManifestResourceCompile>
221225
<ResourceOutputFileName>
@@ -263,7 +267,8 @@ if exist en.ini (copy en.ini $(SolutionDir)$(Platform)\$(Configuration))
263267
copy $(SolutionDir)APIExample\Advanced\LocalVideoTranscoding\agora.jpg $(SolutionDir)$(Platform)\$(Configuration)
264268

265269
if exist sample.yuv (copy sample.yuv $(SolutionDir)$(Platform)\$(Configuration))
266-
if exist $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 (copy $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 $(SolutionDir)$(Configuration))</Command>
270+
if exist $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 (copy $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 $(SolutionDir)$(Configuration))
271+
if exist $(SolutionDir)APIExample\res\hdr_1280_720.yuv (copy $(SolutionDir)APIExample\res\hdr_1280_720.yuv $(SolutionDir)$(Configuration))</Command>
267272
</PostBuildEvent>
268273
<Manifest>
269274
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
@@ -408,6 +413,7 @@ if exist $(SolutionDir)APIExample\res\yuvj_full_range_alpha_1280_540_left.mp4 (c
408413
<CopyFileToFolders Include="sample.yuv">
409414
<FileType>Document</FileType>
410415
</CopyFileToFolders>
416+
<None Include="res\hdr_1280_720.yuv" />
411417
<None Include="res\wave2.bin" />
412418
<None Include="zh-cn.ini" />
413419
</ItemGroup>

windows/APIExample/APIExample/APIExample.vcxproj.filters

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,6 @@
266266
</ClInclude>
267267
<ClInclude Include="Basic\JoinChannelVideoByToken\CJoinChannelVideoByTokenDlg.h">
268268
<Filter>Basic\JoinChannelVideoByToken</Filter>
269-
</ClInclude>
270-
<ClInclude Include="Advanced\CrossChannel\CAgoraCrossChannelDlg.h">
271-
<Filter>Advanced\CrossChannel</Filter>
272269
</ClInclude>
273270
<ClInclude Include="Advanced\Metadata\CAgoraMetaDataDlg.h">
274271
<Filter>Advanced\Metadata</Filter>
@@ -440,6 +437,9 @@
440437
<ClCompile Include="Advanced\Beauty\CDlgBeautyEx.cpp">
441438
<Filter>Advanced\Beauty</Filter>
442439
</ClCompile>
440+
<ClCompile Include="Advanced\CrossChannel\CAgoraCrossChannelDlg.cpp">
441+
<Filter>Source Files</Filter>
442+
</ClCompile>
443443
</ItemGroup>
444444
<ItemGroup>
445445
<ResourceCompile Include="APIExample.rc">
@@ -459,6 +459,7 @@
459459
<None Include="res\wave2.bin">
460460
<Filter>Resource Files</Filter>
461461
</None>
462+
<None Include="res\hdr_1280_720.yuv" />
462463
</ItemGroup>
463464
<ItemGroup>
464465
<Image Include="res\APIExample.ico">

windows/APIExample/APIExample/Advanced/PushExternalVideoYUV/PushExternalVideoYUV.cpp

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ BEGIN_MESSAGE_MAP(PushExternalVideoYUV, CDialogEx)
1010
ON_MESSAGE(WM_MSGID(EID_USER_OFFLINE), &PushExternalVideoYUV::OnEIDUserOffline)
1111
ON_MESSAGE(WM_MSGID(EID_REMOTE_VIDEO_STATE_CHANGED), &PushExternalVideoYUV::OnEIDRemoteVideoStateChanged)
1212
ON_BN_CLICKED(IDC_BUTTON_JOINCHANNEL, &PushExternalVideoYUV::OnClickedButtonJoinchannel)
13+
ON_BN_CLICKED(IDC_CHECK_HDR, &PushExternalVideoYUV::OnBnClickedCheckHdr)
1314
END_MESSAGE_MAP()
1415

1516
IMPLEMENT_DYNAMIC(PushExternalVideoYUV, CDialogEx)
1617

1718
PushExternalVideoYUV::PushExternalVideoYUV(CWnd* pParent /*=nullptr*/)
1819
: CDialogEx(PushExternalVideoYUV::IDD, pParent)
1920
{
20-
21+
2122
}
2223

2324
PushExternalVideoYUV::~PushExternalVideoYUV()
@@ -33,6 +34,7 @@ void PushExternalVideoYUV::DoDataExchange(CDataExchange* pDX)
3334
DDX_Control(pDX, IDC_EDIT_CHANNELNAME, m_edtChannel);
3435
DDX_Control(pDX, IDC_BUTTON_JOINCHANNEL, m_btnJoinChannel);
3536
DDX_Control(pDX, IDC_LIST_INFO_BROADCASTING, m_lstInfo);
37+
DDX_Control(pDX, IDC_CHECK_HDR, mCbHdr);
3638
}
3739

3840
//set control text from config.
@@ -81,12 +83,12 @@ bool PushExternalVideoYUV::InitAgora()
8183
m_lstInfo.InsertString(m_lstInfo.GetCount(), _T("setClientRole broadcaster"));
8284
m_rtcEngine->enableVideo();
8385

84-
86+
8587
//query interface agora::AGORA_IID_MEDIA_ENGINE in the engine.
8688
m_mediaEngine.queryInterface(m_rtcEngine, agora::rtc::AGORA_IID_MEDIA_ENGINE);
8789
if (m_mediaEngine.get() == NULL)
8890
return FALSE;
89-
91+
9092
ret = m_mediaEngine->setExternalVideoSource(true, false);
9193
m_lstInfo.InsertString(m_lstInfo.GetCount(), _T("setExternalVideoSource enable=true, useTexture=false"));
9294

@@ -107,7 +109,28 @@ bool PushExternalVideoYUV::InitAgora()
107109
m_videoFrame.cropTop = 0;
108110
m_videoFrame.format = agora::media::base::VIDEO_PIXEL_I420;
109111
m_videoFrame.type = agora::media::base::ExternalVideoFrame::VIDEO_BUFFER_TYPE::VIDEO_BUFFER_RAW_DATA;
110-
m_imgBuffer = new BYTE[YUVReader::VIDEO_FRAME_SIZE]{0};
112+
m_imgBuffer = new BYTE[YUVReader::VIDEO_FRAME_SIZE]{ 0 };
113+
114+
m_imgBuffer16 = new uint16_t[WIDHT_HDR * HEIGHT_HDR * 1.5]{ 0 };
115+
CString videoUrl = GetExePath() + _T("\\hdr_1280_720.yuv");
116+
std::string tmp = cs2utf8(videoUrl);
117+
std::ifstream file(tmp, std::ios::binary);
118+
if (!file) {
119+
AfxMessageBox(_T("open hdr file failed"));
120+
}
121+
file.seekg(0, std::ios::end);
122+
std::streamsize fileSize = file.tellg();
123+
file.seekg(0, std::ios::beg);
124+
if (fileSize % sizeof(uint16_t) != 0) {
125+
AfxMessageBox(_T(" hdr file format is wrong"));
126+
}
127+
std::vector<char> fileBuffer(fileSize);
128+
if (!file.read(fileBuffer.data(), fileSize)) {
129+
AfxMessageBox(_T("read hdr file failed"));
130+
}
131+
file.close();
132+
uint16_t* uint16Buffer = reinterpret_cast<uint16_t*>(fileBuffer.data());
133+
memcpy_s(m_imgBuffer16, fileSize, uint16Buffer, fileSize);
111134

112135
m_rtcEngine->startPreview(VIDEO_SOURCE_CUSTOM);
113136
return true;
@@ -121,10 +144,13 @@ void PushExternalVideoYUV::UnInitAgora()
121144
if (m_rtcEngine) {
122145
yuvReader.stop();
123146
if (m_imgBuffer) {
124-
delete m_imgBuffer;
147+
delete[] m_imgBuffer;
125148
m_imgBuffer = nullptr;
126149
}
127-
150+
if (m_imgBuffer16) {
151+
delete[] m_imgBuffer16;
152+
m_imgBuffer16 = nullptr;
153+
}
128154

129155
if (m_joinChannel)
130156
m_joinChannel = !m_rtcEngine->leaveChannel();
@@ -153,7 +179,7 @@ void PushExternalVideoYUV::UnInitAgora()
153179
BOOL PushExternalVideoYUV::OnInitDialog()
154180
{
155181
CDialogEx::OnInitDialog();
156-
182+
157183
RECT rcArea;
158184
m_staVideoArea.GetClientRect(&rcArea);
159185

@@ -180,6 +206,8 @@ void PushExternalVideoYUV::ResumeStatus()
180206
m_remoteVideoWnd.SetUID(0);
181207
m_localVideoWnd.Reset();
182208
m_localVideoWnd.SetUID(0);
209+
mCbHdr.SetCheck(FALSE);
210+
isUseHdr = false;
183211
}
184212

185213

@@ -259,9 +287,33 @@ void PushExternalVideoYUV::OnClickedButtonJoinchannel()
259287
}
260288

261289
void PushExternalVideoYUV::OnYUVRead(int width, int height, unsigned char* buffer, int size) {
262-
memcpy_s(m_imgBuffer, size, buffer, size);
263-
m_videoFrame.buffer = m_imgBuffer;
264-
m_videoFrame.timestamp = m_rtcEngine->getCurrentMonotonicTimeInMs();
290+
agora::media::base::ColorSpace colorSpace;
291+
if (isUseHdr)
292+
{
293+
m_videoFrame.buffer = m_imgBuffer16;
294+
colorSpace.range= agora::media::base::ColorSpace::RangeID::RANGEID_FULL;
295+
colorSpace.transfer = agora::media::base::ColorSpace::TransferID::TRANSFERID_ARIB_STD_B67;
296+
colorSpace.matrix = agora::media::base::ColorSpace::MatrixID::MATRIXID_BT2020_NCL;
297+
colorSpace.primaries = agora::media::base::ColorSpace::PrimaryID::PRIMARYID_BT2020;
298+
m_videoFrame.stride = WIDHT_HDR;
299+
m_videoFrame.height = HEIGHT_HDR;
300+
m_videoFrame.timestamp = m_rtcEngine->getCurrentMonotonicTimeInMs();
301+
m_videoFrame.format = agora::media::base::VIDEO_PIXEL_I010;
302+
}
303+
else
304+
{
305+
memcpy_s(m_imgBuffer, size, buffer, size);
306+
colorSpace.range = agora::media::base::ColorSpace::RangeID::RANGEID_FULL;
307+
colorSpace.transfer = agora::media::base::ColorSpace::TransferID::TRANSFERID_BT709;
308+
colorSpace.matrix = agora::media::base::ColorSpace::MatrixID::MATRIXID_BT709;
309+
colorSpace.primaries = agora::media::base::ColorSpace::PrimaryID::PRIMARYID_BT709;
310+
m_videoFrame.stride = width;
311+
m_videoFrame.height = height;
312+
m_videoFrame.buffer = m_imgBuffer;
313+
m_videoFrame.timestamp = m_rtcEngine->getCurrentMonotonicTimeInMs();
314+
m_videoFrame.format = agora::media::base::VIDEO_PIXEL_I420;
315+
}
316+
265317
if (m_joinChannel && m_mediaEngine.get() != nullptr) {
266318
m_mediaEngine->pushVideoFrame(&m_videoFrame);
267319
}
@@ -385,7 +437,7 @@ LRESULT PushExternalVideoYUV::OnEIDRemoteVideoStateChanged(WPARAM wParam, LPARAM
385437
is called without a user ID specified. The server will automatically assign one
386438
parameters:
387439
channel:channel name.
388-
uid: user ID¡£If the UID is specified in the joinChannel, that ID is returned here;
440+
uid: user ID��If the UID is specified in the joinChannel, that ID is returned here;
389441
Otherwise, use the ID automatically assigned by the Agora server.
390442
elapsed: The Time from the joinChannel until this event occurred (ms).
391443
*/
@@ -407,7 +459,7 @@ void PushExternalVideoYUVEventHandler::onJoinChannelSuccess(const char* channel,
407459
parameters:
408460
uid: remote user/anchor ID for newly added channel.
409461
elapsed: The joinChannel is called from the local user to the delay triggered
410-
by the callback£¨ms).
462+
by the callback��ms).
411463
*/
412464
void PushExternalVideoYUVEventHandler::onUserJoined(uid_t uid, int elapsed)
413465
{
@@ -477,3 +529,20 @@ void PushExternalVideoYUVEventHandler::onRemoteVideoStateChanged(uid_t uid, REMO
477529
::PostMessage(m_hMsgHanlder, WM_MSGID(EID_REMOTE_VIDEO_STATE_CHANGED), (WPARAM)stateChanged, 0);
478530
}
479531
}
532+
533+
534+
void PushExternalVideoYUV::OnBnClickedCheckHdr()
535+
{
536+
agora::rtc::HDR_CAPABILITY capability = agora::rtc::HDR_CAPABILITY::HDR_CAPABILITY_SUPPORTED;
537+
538+
int flag = m_rtcEngine->queryHDRCapability(VIDEO_MODULE_CAPTURER, capability);
539+
540+
if (flag == 0) {
541+
isUseHdr = !isUseHdr;
542+
}
543+
else {
544+
isUseHdr = false;
545+
mCbHdr.SetCheck(FALSE);
546+
}
547+
548+
}

windows/APIExample/APIExample/Advanced/PushExternalVideoYUV/PushExternalVideoYUV.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "DirectShow/AGDShowVideoCapture.h"
55
#include "YUVReader.h"
66
#include <IAgoraRtcEngine.h>
7+
#include <stdint.h>
78

89

910
class PushExternalVideoYUVEventHandler : public IRtcEngineEventHandler {
@@ -18,7 +19,7 @@ class PushExternalVideoYUVEventHandler : public IRtcEngineEventHandler {
1819
is called without a user ID specified. The server will automatically assign one
1920
parameters:
2021
channel:channel name.
21-
uid: user ID¡£If the UID is specified in the joinChannel, that ID is returned here;
22+
uid: user ID��If the UID is specified in the joinChannel, that ID is returned here;
2223
Otherwise, use the ID automatically assigned by the Agora server.
2324
elapsed: The Time from the joinChannel until this event occurred (ms).
2425
*/
@@ -124,7 +125,10 @@ class PushExternalVideoYUV : public CDialogEx
124125
bool m_joinChannel = false;
125126
bool m_initialize = false;
126127
BYTE* m_imgBuffer = nullptr;
127-
128+
uint16_t* m_imgBuffer16 = nullptr;
129+
const int WIDHT_HDR = 1280;
130+
const int HEIGHT_HDR = 720;
131+
bool isUseHdr = false;
128132

129133
DECLARE_MESSAGE_MAP()
130134
public:
@@ -142,4 +146,7 @@ class PushExternalVideoYUV : public CDialogEx
142146

143147
private:
144148
YUVReader yuvReader;
149+
public:
150+
afx_msg void OnBnClickedCheckHdr();
151+
CButton mCbHdr;
145152
};
2.64 MB
Binary file not shown.

windows/APIExample/APIExample/resource.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
#define IDC_CHECK_REPORT 1054
170170
#define IDC_CHECK_AUDIO_SOURCE_MUTE 1054
171171
#define IDC_CHECK_VIRTUAL_BG 1054
172+
#define IDC_CHECK_HDR 1054
172173
#define IDC_STATIC_ADUIO_PROFILE 1055
173174
#define IDC_CHK_REPLACE_MICROPHONE 1055
174175
#define IDC_STATIC_ADUIO_SCENARIO 1056
@@ -444,6 +445,7 @@
444445
#define IDC_CHECK4 1167
445446
#define IDC_CHECK_EXTENTION 1167
446447
#define IDC_SLIDER__SHAPE_STYLE_INTENSITY 1168
448+
#define IDC_COMBO1 1168
447449
#define IDC_COMBO_LASH_STYLE 1169
448450
#define IDC_SLIDER__LASH_STRENGTH 1170
449451
#define IDC_COMBO_LASH_COLOR 1171
@@ -466,7 +468,7 @@
466468
#ifndef APSTUDIO_READONLY_SYMBOLS
467469
#define _APS_NEXT_RESOURCE_VALUE 181
468470
#define _APS_NEXT_COMMAND_VALUE 32771
469-
#define _APS_NEXT_CONTROL_VALUE 1168
471+
#define _APS_NEXT_CONTROL_VALUE 1169
470472
#define _APS_NEXT_SYMED_VALUE 101
471473
#endif
472474
#endif

0 commit comments

Comments
 (0)