@@ -17,138 +17,140 @@ using namespace std;
17
17
class stdout_utf16
18
18
{
19
19
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
+ }
31
31
};
32
32
33
- void printStatus (const primo::error::ErrorInfo* e)
33
+ void printStatus (const primo::error::ErrorInfo * e)
34
34
{
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;
55
55
}
56
56
57
- primo::ref<MediaSocket> createInputSocket (Options& opt)
57
+ primo::ref<MediaSocket> createInputSocket (Options & opt)
58
58
{
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;
77
77
}
78
78
79
- primo::ref<MediaSocket> createOutputSocket (Options& opt)
79
+ primo::ref<MediaSocket> createOutputSocket (Options & opt)
80
80
{
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);
85
85
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 ());
88
88
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 ());
91
91
92
- vsi->setStreamType (StreamType::H264);
93
- vsi->setStreamSubType (StreamSubType::AVC_Annex_B);
92
+ vsi->setStreamType (StreamType::H264);
93
+ vsi->setStreamSubType (StreamSubType::AVC_Annex_B);
94
94
95
- return socket;
95
+ return socket;
96
96
}
97
97
98
- bool encode (Options& opt)
98
+ bool encode (Options & opt)
99
99
{
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 ;
135
135
}
136
136
137
- int wmain (int argc, wchar_t * argv[])
137
+ int wmain (int argc, wchar_t * argv[])
138
138
{
139
- Options opt;
139
+ Options opt;
140
140
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
+ }
146
148
147
- Library::initialize ();
149
+ Library::initialize ();
148
150
149
- bool encodeResult = encode (opt);
151
+ bool encodeResult = encode (opt);
150
152
151
- Library::shutdown ();
153
+ Library::shutdown ();
152
154
153
- return encodeResult ? 0 : 1 ;
155
+ return encodeResult ? 0 : 1 ;
154
156
}
0 commit comments