@@ -21,6 +21,9 @@ int main()
21
21
options.width = 640 ;
22
22
options.height = 480 ;
23
23
options.frame_timebase = { 1 , 60 };
24
+ options.encoder = " h264_pyro" ;
25
+ options.low_latency = true ;
26
+ options.realtime = true ;
24
27
25
28
if (!Vulkan::Context::init_loader (nullptr ))
26
29
return 1 ;
@@ -29,12 +32,8 @@ int main()
29
32
Vulkan::Context ctx;
30
33
ctx.set_system_handles (handles);
31
34
if (!ctx.init_instance_and_device (nullptr , 0 , nullptr , 0 ,
32
- #ifdef VK_ENABLE_BETA_EXTENSIONS
33
35
Vulkan::CONTEXT_CREATION_ENABLE_VIDEO_ENCODE_BIT |
34
36
Vulkan::CONTEXT_CREATION_ENABLE_VIDEO_H264_BIT))
35
- #else
36
- 0 ))
37
- #endif
38
37
{
39
38
return 1 ;
40
39
}
@@ -57,7 +56,42 @@ int main()
57
56
LOGE (" Failed to open /tmp/test.ogg.\n " );
58
57
#endif
59
58
60
- if (!encoder.init (&device, " /tmp/test.mkv" , options))
59
+ struct CB : Granite::MuxStreamCallback
60
+ {
61
+ void set_codec_parameters (const pyro_codec_parameters &) override
62
+ {
63
+ LOGI (" Setting codec parameters.\n " );
64
+ }
65
+
66
+ void write_video_packet (int64_t , int64_t , const void *data, size_t size, bool ) override
67
+ {
68
+ if (fwrite (data, 1 , size, file) != size)
69
+ LOGE (" Failed to write.\n " );
70
+ }
71
+
72
+ void write_audio_packet (int64_t pts, int64_t dts, const void *data, size_t size) override
73
+ {
74
+ LOGI (" Got audio.\n " );
75
+ }
76
+
77
+ bool should_force_idr () override
78
+ {
79
+ return false ;
80
+ }
81
+
82
+ FILE *file = nullptr ;
83
+ } cb;
84
+
85
+ cb.file = fopen (" /tmp/test.h264" , " wb" );
86
+ if (!cb.file )
87
+ {
88
+ LOGE (" Failed to open file.\n " );
89
+ return EXIT_FAILURE;
90
+ }
91
+
92
+ encoder.set_mux_stream_callback (&cb);
93
+
94
+ if (!encoder.init (&device, nullptr , options))
61
95
{
62
96
LOGE (" Failed to init codec.\n " );
63
97
return 1 ;
@@ -74,6 +108,8 @@ int main()
74
108
" builtin://shaders/util/rgb_to_yuv.comp" )->register_variant ({})->get_program ();
75
109
shaders.chroma_downsample = device.get_shader_manager ().register_compute (
76
110
" builtin://shaders/util/chroma_downsample.comp" )->register_variant ({})->get_program ();
111
+ shaders.rgb_scale = device.get_shader_manager ().register_compute (
112
+ " builtin://shaders/util/rgb_scale.comp" )->register_variant ({})->get_program ();
77
113
auto pipe = encoder.create_ycbcr_pipeline (shaders);
78
114
79
115
for (unsigned i = 0 ; i < 1000 ; i++)
@@ -116,6 +152,8 @@ int main()
116
152
device.next_frame_context ();
117
153
}
118
154
155
+ fclose (cb.file );
156
+
119
157
#ifdef HAVE_GRANITE_AUDIO
120
158
Global::stop_audio_system ();
121
159
#endif
0 commit comments