Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions .github/workflows/build-unienc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.arch }}-pc-windows
path: InstantReplay.Externals/unienc/target/${{ matrix.arch }}-pc-windows-msvc/${{ env._RUST_BUILD_CONFIG }}/libunienc_c.dll
path: |
InstantReplay.Externals/unienc/target/${{ matrix.arch }}-pc-windows-msvc/${{ env._RUST_BUILD_CONFIG }}/libunienc_c.dll
InstantReplay.Externals/unienc/target/${{ matrix.arch }}-pc-windows-msvc/${{ env._RUST_BUILD_CONFIG }}/unienc_c.pdb
retention-days: 1
build-android:
name: Build unienc (Android)
Expand Down Expand Up @@ -171,22 +173,36 @@ jobs:
name: wasm32-unknown-emscripten
path: InstantReplay.Externals/unienc/target/wasm32-unknown-emscripten/${{ env._RUST_BUILD_CONFIG }}-wasm/libunienc_c.a
retention-days: 1
update-unity-native:
name: Push unienc native libraries
needs: [build-wasm, build-windows, build-android, build-ios, build-macos, build-linux, lipo-macos]
update-tpn:
name: Update third-party notices
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: actions/download-artifact@v4
with:
path: ./Packages/jp.co.cyberagent.instant-replay/UniEnc/Plugins/
- run: |
cargo install cargo-about --locked
cargo about generate about.hbs > ../../THIRD-PARTY-NOTICES.md
working-directory: InstantReplay.Externals/unienc
- uses: actions/upload-artifact@v4
with:
name: ~third-party-notices
path: ./THIRD-PARTY-NOTICES.md
update-unity-native:
name: Push unienc native libraries
needs: [build-wasm, build-windows, build-android, build-ios, build-macos, build-linux, lipo-macos, update-tpn]
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: ~third-party-notices
- uses: actions/download-artifact@v4
with:
pattern: '[a-z]*'
path: ./Packages/jp.co.cyberagent.instant-replay/UniEnc/Plugins/
- run: |
git add ./Packages/jp.co.cyberagent.instant-replay/UniEnc/Plugins
git add ./THIRD-PARTY-NOTICES.md
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ ExportedObj/
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ impl VideoFrameBgra32 {
let data = self.buffer.data();
let w = padded_size.map_or(self.width, |(w, _)| w);
let h = padded_size.map_or(self.height, |(_, h)| h);
let w_half = (w + 1) >> 1;
let h_half = (h + 1) >> 1;
let padded_y_size = (w * h) as usize;
let padded_uv_size = (w * h / 4) as usize;
let padded_uv_size = (w_half * h_half) as usize;

// Create padded YUV data arrays
let mut y_data = vec![16u8; padded_y_size]; // Black level for Y
Expand Down
57 changes: 16 additions & 41 deletions InstantReplay.Externals/unienc/crates/unienc_windows_mf/src/mft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use unienc_common::{Runtime, SpawnExt};

pub trait MediaEventGeneratorCustom {
fn get_event(&self) -> impl Future<Output = Result<UnsafeSend<IMFMediaEvent>>>;
fn get_events(&self, runtime: &impl Runtime) -> mpsc::Receiver<Result<UnsafeSend<IMFMediaEvent>>>;
}

impl MediaEventGeneratorCustom for IMFMediaEventGenerator {
Expand Down Expand Up @@ -46,30 +45,6 @@ impl MediaEventGeneratorCustom for IMFMediaEventGenerator {
}
}
}

fn get_events(&self, runtime: &impl Runtime) -> mpsc::Receiver<Result<UnsafeSend<IMFMediaEvent>>> {
let (tx, rx) = mpsc::channel::<Result<UnsafeSend<IMFMediaEvent>>>(32);

let generator: UnsafeSend<IMFMediaEventGenerator> = UnsafeSend((*self).clone());

runtime.spawn(async move {
loop {
match generator.get_event().await {
Ok(event) => {
if tx.send(Ok(event)).await.is_err() {
break; // Receiver dropped
}
}
Err(e) => {
let _ = tx.send(Err(e)).await;
break;
}
}
}
});

rx
}
}

#[implement(IMFAsyncCallback)]
Expand Down Expand Up @@ -105,8 +80,6 @@ where
if let Some(on_invoke) = self.on_invoke.take() {
on_invoke(result);
}
/*
*/
Ok(())
}
}
Expand Down Expand Up @@ -147,11 +120,16 @@ fn process_output(
}

let mut status = 0;
unsafe { transform.ProcessOutput(0, &mut buffers, &mut status) }?;
let result = unsafe { transform.ProcessOutput(0, &mut buffers, &mut status) };

let buffer = &mut buffers[0];

let sample = buffer.pSample.take().ok_or(WindowsError::OutputGetFailed)?;
let sample = unsafe { ManuallyDrop::take(&mut buffer.pSample) };
drop(unsafe { ManuallyDrop::take(&mut buffer.pEvents) });

result?;

let sample = sample.ok_or(WindowsError::OutputGetFailed)?;

Ok(sample.into())
}
Expand Down Expand Up @@ -223,13 +201,13 @@ fn enum_mft(
};

let activates = if num_activate > 0 {
unsafe {
std::slice::from_raw_parts(activate, num_activate as usize)
.iter()
.flatten()
.cloned()
let activates = unsafe {
std::slice::from_raw_parts_mut(activate, num_activate as usize)
.iter_mut()
.filter_map(Option::take)
.collect::<Vec<_>>()
}
};
activates
} else {
vec![]
};
Expand Down Expand Up @@ -367,19 +345,16 @@ impl Transform {
let generator: UnsafeSend<IMFMediaEventGenerator> =
transform.cast::<IMFMediaEventGenerator>()?.into();

let mut rx = generator.get_events(runtime);

unsafe { transform.ProcessMessage(MFT_MESSAGE_NOTIFY_START_OF_STREAM, 0)? };

let (sample_tx, sample_rx) = mpsc::channel::<UnsafeSend<IMFSample>>(32);

let transform = UnsafeSend(transform);

// event loop
runtime.spawn_ret(async move {
let mut sample_rx = sample_rx;
while let Some(event) = rx.recv().await {
match event {
loop {
match generator.get_event().await {
Ok(event) => {
let event_type: u32 = unsafe { event.GetType()? };
match MF_EVENT_TYPE(event_type as i32) {
Expand Down Expand Up @@ -410,7 +385,7 @@ impl Transform {
#[allow(non_upper_case_globals)]
METransformDrainComplete => {
println!("Transform drain complete");
// end
// end - generator and transform are dropped here
break;
}
_ => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ struct Stream {

impl Stream {
pub fn new(stream: IMFStreamSink, runtime: &impl Runtime) -> Result<(Self, oneshot::Receiver<()>)> {
let mut ev_rx = stream.get_events(runtime);
let stream = UnsafeSend(stream);
let stream_cap = UnsafeSend(stream.clone());

Expand All @@ -186,33 +185,31 @@ impl Stream {
runtime.spawn_ret(async move {
let mut sample_rx = sample_rx;
let mut finish_tx = Some(finish_tx);
while let Some(event) = ev_rx.recv().await {
if let Ok(event) = event {
let event_type: u32 = unsafe { event.GetType()? };
match MF_EVENT_TYPE(event_type as i32) {
#[allow(non_upper_case_globals)]
MEStreamSinkRequestSample => {
if let Some(sample) = sample_rx.recv().await {
unsafe { stream_cap.ProcessSample(&*sample)? };
} else {
unsafe {
stream_cap.PlaceMarker(
MFSTREAMSINK_MARKER_ENDOFSEGMENT,
std::ptr::null(),
std::ptr::null(),
)?
};
if let Some(finish_tx) = finish_tx.take() {
finish_tx
.send(())
.map_err(|_e| WindowsError::FinishSignalSendFailed)?
};
}
}
_ => {
println!("Unhandled media sink event type: {:?}", event_type);
while let Ok(event) = stream_cap.get_event().await {
let event_type: u32 = unsafe { event.GetType()? };
match MF_EVENT_TYPE(event_type as i32) {
#[allow(non_upper_case_globals)]
MEStreamSinkRequestSample => {
if let Some(sample) = sample_rx.recv().await {
unsafe { stream_cap.ProcessSample(&*sample)? };
} else {
unsafe {
stream_cap.PlaceMarker(
MFSTREAMSINK_MARKER_ENDOFSEGMENT,
std::ptr::null(),
std::ptr::null(),
)?
};
if let Some(finish_tx) = finish_tx.take() {
finish_tx
.send(())
.map_err(|_e| WindowsError::FinishSignalSendFailed)?
};
}
}
_ => {
println!("Unhandled media sink event type: {:?}", event_type);
}
}
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.