-
Notifications
You must be signed in to change notification settings - Fork 4
/
RawVideoDelegate.cpp
122 lines (89 loc) · 3.13 KB
/
RawVideoDelegate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//added for raw data access
#include "stdafx.h"
#include "rawdata/rawdata_video_source_helper_interface.h"
#include "RawVideoDelegate.h"
#include "zoom_sdk_def.h"
#include <iostream>
#include <fstream>
#include <cstdint>
#include <cstring>
#include <cstdio>
//added for raw data access
using namespace std;
using namespace ZOOM_SDK_NAMESPACE;
//added for raw data access
void RawVideoDelegate::onRawDataFrameReceived(YUVRawDataI420* data)
{
cout << "onRawDataFrameReceived." << endl;
cout << "width." << data->GetStreamWidth() << endl;
cout << "height." << data->GetStreamHeight() << endl;
/////////////////////////////////////////////////////////////////////////
////traditional method 2
// // Open the output file
//std::ofstream outFileY("outputY.yuv", ios::out | ios::binary | ios::app);
//if (!outFileY.is_open())
//{
// std::cerr << "Failed to open the output file" << std::endl;
// return;
//}
//// Write the video data
//outFileY.write((char*)data->GetBuffer(), data->GetBufferLen());
//// Close the file
////outFileY.close();
//outFileY.flush();
////cout << "YUV420 buffer saved to file." << endl;
////end traditional method 2
///////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// traditional method 1
std::string filename="output.yuv";
// Open the file for writing
if (data->GetStreamHeight() == 1080) {
filename = "1080.yuv";
}
if (data->GetStreamHeight() == 720) {
filename = "720.yuv";
}
else if (data->GetStreamHeight() == 360) {
filename = "360.yuv";
}
else if (data->GetStreamHeight() == 180) {
filename = "180.yuv";
}
else if (data->GetStreamWidth() == 90) {
filename = "90.yuv";
}
ofstream outputFile1(filename, ios::out | ios::binary | ios::app);
if (!outputFile1.is_open())
{
cout << "Error opening file." << endl;
return;
}
char* _data1 = new char[data->GetStreamHeight() * data->GetStreamWidth() * 3 / 2];
memset(_data1, 0, data->GetStreamHeight() * data->GetStreamWidth() * 3 / 2);
// Copy Y buffer
memcpy(_data1, data->GetYBuffer(), data->GetStreamHeight() * data->GetStreamWidth());
// Copy U buffer
size_t loc1 = data->GetStreamHeight() * data->GetStreamWidth();
memcpy(&_data1[loc1], data->GetUBuffer(), data->GetStreamHeight() * data->GetStreamWidth() / 4);
// Copy V buffer
loc1 = (data->GetStreamHeight() * data->GetStreamWidth()) + (data->GetStreamHeight() * data->GetStreamWidth() / 4);
memcpy(&_data1[loc1], data->GetVBuffer(), data->GetStreamHeight() * data->GetStreamWidth() / 4);
//outputFile.write((char*)data->GetBuffer(), data->GetBufferLen());
// Write the Y plane
outputFile1.write(_data1, data->GetStreamHeight() * data->GetStreamWidth() * 3 / 2);
// Close the file
//outputFile1.close();
outputFile1.flush();
//cout << "YUV420 buffer saved to file." << endl;
//end traditional method
/////////////////////////////////////////////////////////////////////
}
void RawVideoDelegate::onRawDataStatusChanged(RawDataStatus status)
{
cout << "onRawDataStatusChanged." << endl;
}
void RawVideoDelegate::onRendererBeDestroyed()
{
cout << "onRendererBeDestroyed ." << endl;
}