Skip to content

Instantly share code, notes, and snippets.

View polymonster's full-sized avatar
🦀
refactoring...

Alex Dixon polymonster

🦀
refactoring...
View GitHub Profile
@polymonster
polymonster / vec.rs
Last active April 22, 2022 19:14
Vec<T, const N: usize>
pub struct Vec<T, const N: usize> {
v: [T; N]
}
impl<T, const N: usize> Vec<T, N> where T: std::ops::AddAssign + std::fmt::Display {
fn print(&self) {
for i in 0..N {
print!("{}, ", self.v[i]);
}
print!("\n");
@polymonster
polymonster / winpix.rs
Last active February 19, 2023 14:58
Calling WinPixEvenRuntime ABI from Rust and windows-rs
#[derive(Copy, Clone)]
struct WinPixEventRuntime {
begin_event: BeginEventOnCommandList,
end_event: EndEventOnCommandList,
set_marker: SetMarkerOnCommandList,
}
impl WinPixEventRuntime {
pub fn create() -> Option<WinPixEventRuntime> {
unsafe {
@polymonster
polymonster / minimal_amedia_codec.cpp
Last active February 4, 2022 22:17
A minimal example to show how to decode and extract frames using NDK AMediaCodec
// Deconding a h264 video stream... There are a few caveats which can cause some confusion.
// 1. 15 frames of 0 need flushing before we actually start pogressing.
// 2. Frames are extracted in chunks of 4 and appear in a swizzled order 4, 2, 1, 3,
// 3. The order seems consistent in blocks of 4, with the frames increasing from the middle entry rotating anti-clockwise.
// 4. Care needs to be taken when using frame numbers or timestamps to flag AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM
// Otherwise the decode may skip 4 frames (as the final frame will be delivered as the first in a block of 4).
// Havent experimented much yet but the blocks of 4 can also appear as blocks of 5, this may be due to frquency of keyframes
// tight loop will extract and decode all video frames