Skip to content

Commit 379b675

Browse files
committed
Auto push on 2021-09-10 23:09
1 parent 7a9dff8 commit 379b675

File tree

2 files changed

+256
-262
lines changed

2 files changed

+256
-262
lines changed

samples/windows/enc_avc_file/enc_avc_file.cpp

Lines changed: 112 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -17,138 +17,140 @@ using namespace std;
1717
class stdout_utf16
1818
{
1919
public:
20-
stdout_utf16()
21-
{
22-
// change stdout to Unicode. Cyrillic and Ideographic characters will appear in the console (console font is unicode).
23-
_setmode(_fileno(stdout), _O_U16TEXT);
24-
}
25-
26-
~stdout_utf16()
27-
{
28-
// restore ANSI mode
29-
_setmode(_fileno(stdout), _O_TEXT);
30-
}
20+
stdout_utf16()
21+
{
22+
// change stdout to Unicode. Cyrillic and Ideographic characters will appear in the console (console font is unicode).
23+
_setmode(_fileno(stdout), _O_U16TEXT);
24+
}
25+
26+
~stdout_utf16()
27+
{
28+
// restore ANSI mode
29+
_setmode(_fileno(stdout), _O_TEXT);
30+
}
3131
};
3232

33-
void printStatus(const primo::error::ErrorInfo* e)
33+
void printStatus(const primo::error::ErrorInfo *e)
3434
{
35-
if (primo::error::ErrorFacility::Success == e->facility())
36-
{
37-
wcout << L"Success";
38-
}
39-
else
40-
{
41-
wcout << L"facility: " << e->facility() << L", error: " << e->code();
42-
43-
if (e->message())
44-
{
45-
wcout << L", " << e->message();
46-
}
47-
48-
if (e->hint())
49-
{
50-
wcout << L", " << e->hint();
51-
}
52-
}
53-
54-
wcout << endl;
35+
if (primo::error::ErrorFacility::Success == e->facility())
36+
{
37+
wcout << L"Success";
38+
}
39+
else
40+
{
41+
wcout << L"facility: " << e->facility() << L", error: " << e->code();
42+
43+
if (e->message())
44+
{
45+
wcout << L", " << e->message();
46+
}
47+
48+
if (e->hint())
49+
{
50+
wcout << L", " << e->hint();
51+
}
52+
}
53+
54+
wcout << endl;
5555
}
5656

57-
primo::ref<MediaSocket> createInputSocket(Options& opt)
57+
primo::ref<MediaSocket> createInputSocket(Options &opt)
5858
{
59-
auto socket = primo::make_ref(Library::createMediaSocket());
60-
socket->setStreamType(StreamType::UncompressedVideo);
61-
socket->setFile(opt.yuv_file.c_str());
62-
63-
auto pin = primo::make_ref(Library::createMediaPin());
64-
socket->pins()->add(pin.get());
65-
66-
auto vsi = primo::make_ref(Library::createVideoStreamInfo());
67-
pin->setStreamInfo(vsi.get());
68-
69-
vsi->setStreamType(StreamType::UncompressedVideo);
70-
vsi->setFrameWidth(opt.frame_size.width_);
71-
vsi->setFrameHeight(opt.frame_size.height_);
72-
vsi->setColorFormat(opt.yuv_color.Id);
73-
vsi->setFrameRate(opt.fps);
74-
vsi->setScanType(ScanType::Progressive);
75-
76-
return socket;
59+
auto socket = primo::make_ref(Library::createMediaSocket());
60+
socket->setStreamType(StreamType::UncompressedVideo);
61+
socket->setFile(opt.yuv_file.c_str());
62+
63+
auto pin = primo::make_ref(Library::createMediaPin());
64+
socket->pins()->add(pin.get());
65+
66+
auto vsi = primo::make_ref(Library::createVideoStreamInfo());
67+
pin->setStreamInfo(vsi.get());
68+
69+
vsi->setStreamType(StreamType::UncompressedVideo);
70+
vsi->setFrameWidth(opt.frame_size.width_);
71+
vsi->setFrameHeight(opt.frame_size.height_);
72+
vsi->setColorFormat(opt.yuv_color.Id);
73+
vsi->setFrameRate(opt.fps);
74+
vsi->setScanType(ScanType::Progressive);
75+
76+
return socket;
7777
}
7878

79-
primo::ref<MediaSocket> createOutputSocket(Options& opt)
79+
primo::ref<MediaSocket> createOutputSocket(Options &opt)
8080
{
81-
auto socket = primo::make_ref(Library::createMediaSocket());
82-
socket->setFile(opt.h264_file.c_str());
83-
socket->setStreamType(StreamType::H264);
84-
socket->setStreamSubType(StreamSubType::AVC_Annex_B);
81+
auto socket = primo::make_ref(Library::createMediaSocket());
82+
socket->setFile(opt.h264_file.c_str());
83+
socket->setStreamType(StreamType::H264);
84+
socket->setStreamSubType(StreamSubType::AVC_Annex_B);
8585

86-
auto pin = primo::make_ref(Library::createMediaPin());
87-
socket->pins()->add(pin.get());
86+
auto pin = primo::make_ref(Library::createMediaPin());
87+
socket->pins()->add(pin.get());
8888

89-
auto vsi = primo::make_ref(Library::createVideoStreamInfo());
90-
pin->setStreamInfo(vsi.get());
89+
auto vsi = primo::make_ref(Library::createVideoStreamInfo());
90+
pin->setStreamInfo(vsi.get());
9191

92-
vsi->setStreamType(StreamType::H264);
93-
vsi->setStreamSubType(StreamSubType::AVC_Annex_B);
92+
vsi->setStreamType(StreamType::H264);
93+
vsi->setStreamSubType(StreamSubType::AVC_Annex_B);
9494

95-
return socket;
95+
return socket;
9696
}
9797

98-
bool encode(Options& opt)
98+
bool encode(Options &opt)
9999
{
100-
auto inSocket = createInputSocket(opt);
101-
102-
// create output socket
103-
auto outSocket = createOutputSocket(opt);
104-
105-
// create transcoder
106-
auto transcoder = primo::make_ref(Library::createTranscoder());
107-
transcoder->setAllowDemoMode(TRUE);
108-
transcoder->inputs()->add(inSocket.get());
109-
transcoder->outputs()->add(outSocket.get());
110-
111-
// transcoder will fail if output exists (by design)
112-
deleteFile(opt.h264_file.c_str());
113-
114-
wcout << L"Transcoder open: ";
115-
if(transcoder->open())
116-
{
117-
printStatus(transcoder->error());
118-
if(!transcoder->run())
119-
return false;
120-
121-
wcout << L"Transcoder run: ";
122-
printStatus(transcoder->error());
123-
124-
transcoder->close();
125-
wcout << L"Transcoder close: ";
126-
printStatus(transcoder->error());
127-
}
128-
else
129-
{
130-
printStatus(transcoder->error());
131-
return false;
132-
}
133-
134-
return true;
100+
auto inSocket = createInputSocket(opt);
101+
102+
// create output socket
103+
auto outSocket = createOutputSocket(opt);
104+
105+
// create transcoder
106+
auto transcoder = primo::make_ref(Library::createTranscoder());
107+
transcoder->setAllowDemoMode(TRUE);
108+
transcoder->inputs()->add(inSocket.get());
109+
transcoder->outputs()->add(outSocket.get());
110+
111+
// transcoder will fail if output exists (by design)
112+
deleteFile(opt.h264_file.c_str());
113+
114+
wcout << L"Transcoder open: ";
115+
if (transcoder->open())
116+
{
117+
printStatus(transcoder->error());
118+
if (!transcoder->run())
119+
return false;
120+
121+
wcout << L"Transcoder run: ";
122+
printStatus(transcoder->error());
123+
124+
transcoder->close();
125+
wcout << L"Transcoder close: ";
126+
printStatus(transcoder->error());
127+
}
128+
else
129+
{
130+
printStatus(transcoder->error());
131+
return false;
132+
}
133+
134+
return true;
135135
}
136136

137-
int wmain(int argc, wchar_t* argv[])
137+
int wmain(int argc, wchar_t *argv[])
138138
{
139-
Options opt;
139+
Options opt;
140140

141-
switch(prepareOptions( opt, argc, argv))
142-
{
143-
case Command: return 0;
144-
case Error: return 1;
145-
}
141+
switch (prepareOptions(opt, argc, argv))
142+
{
143+
case Command:
144+
return 0;
145+
case Error:
146+
return 1;
147+
}
146148

147-
Library::initialize();
149+
Library::initialize();
148150

149-
bool encodeResult = encode(opt);
151+
bool encodeResult = encode(opt);
150152

151-
Library::shutdown();
153+
Library::shutdown();
152154

153-
return encodeResult ? 0 : 1;
155+
return encodeResult ? 0 : 1;
154156
}

0 commit comments

Comments
 (0)