Skip to content

Commit

Permalink
Temp Revert decoder changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsEeleeya committed Nov 3, 2024
1 parent cc87ebc commit 0fdbb0b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 65 deletions.
1 change: 0 additions & 1 deletion apps/desktop/src-tauri/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ impl CapWindow {
let window = window_builder.build()?;

window.set_ignore_cursor_events(true).unwrap();
window.open_devtools();

#[cfg(target_os = "macos")]
{
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ serde_json = "1.0.128"
axum = { version = "0.7.5", features = ["ws"] }
ffmpeg.workspace = true
specta.workspace = true
serde = { version = "1", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
66 changes: 3 additions & 63 deletions crates/rendering/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ use ffmpeg_sys_next::{

pub type DecodedFrame = Arc<Vec<u8>>;

#[cfg(target_os = "windows")]
const TARGET_HWDEVICE: AVHWDeviceType = AVHWDeviceType::AV_HWDEVICE_TYPE_D3D11VA;
#[cfg(target_os = "macos")]
const TARGET_HWDEVICE: AVHWDeviceType = AVHWDeviceType::AV_HWDEVICE_TYPE_VIDEOTOOLBOX;

enum VideoDecoderMessage {
GetFrame(u32, tokio::sync::oneshot::Sender<Option<Arc<Vec<u8>>>>),
}
Expand Down Expand Up @@ -58,8 +53,6 @@ impl AsyncVideoDecoder {
let mut context = codec::context::Context::new_with_codec(decoder_codec);
context.set_parameters(input_stream.parameters()).unwrap();

// context.print_supported_hw_modes();

let hw_device: Option<HwDevice> = {
#[cfg(target_os = "macos")]
{
Expand All @@ -70,22 +63,11 @@ impl AsyncVideoDecoder {
)
.ok()
}
#[cfg(target_os = "windows")]
{
context
.try_use_hw_device(AVHWDeviceType::AV_HWDEVICE_TYPE_D3D11VA, Pixel::NV12)
.ok()
}

#[cfg(not(any(target_os = "macos", target_os = "windows")))]
#[cfg(not(target_os = "macos"))]
None
};

println!(
"-t HW Device: {:?}",
hw_device.as_ref().and_then(|hwd| Some(hwd.device_type))
);

let input_stream_index = input_stream.index();
let time_base = input_stream.time_base();
let frame_rate = input_stream.rate();
Expand All @@ -101,11 +83,6 @@ impl AsyncVideoDecoder {
.map(|d| d.pix_fmt)
.unwrap_or(decoder.format());

// println!("-t Scalar input pixel format");
// dbg!(scaler_input_format);
// println!("-t HWDevice input pixel format");
// dbg!(hw_device.as_ref().map(|d| d.pix_fmt));

let mut scaler = Context::get(
scaler_input_format,
decoder.width(),
Expand Down Expand Up @@ -195,7 +172,7 @@ impl AsyncVideoDecoder {
let start_offset = stream.start_time();
let packet_frame =
ts_to_frame(packet.pts().unwrap(), time_base, frame_rate);
println!("sending frame {packet_frame} packet");
// println!("sending frame {packet_frame} packet");

decoder.send_packet(&packet).ok(); // decode failures are ok, we just fail to return a frame

Expand Down Expand Up @@ -449,8 +426,6 @@ trait CodecContextExt {
device_type: AVHWDeviceType,
pix_fmt: Pixel,
) -> Result<HwDevice, &'static str>;

fn print_supported_hw_modes(&mut self);
}

impl CodecContextExt for codec::context::Context {
Expand All @@ -462,22 +437,16 @@ impl CodecContextExt for codec::context::Context {
let codec = self.codec().ok_or("no codec")?;

unsafe {
println!("Codec is: {}", codec.name());
let mut i = 0;
loop {
let config = avcodec_get_hw_config(codec.as_ptr(), i);
// println!("-t AVCodecHWConfig: ");

if config.is_null() {
dbg!(*config);
return Err("no hw config");
}

if (*config).methods & (AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX as i32) == 1
&& (*config).device_type == TARGET_HWDEVICE
&& (*config).device_type == AVHWDeviceType::AV_HWDEVICE_TYPE_VIDEOTOOLBOX
{
// println!("Setting PIX_FMT to ");
// dbg!((*config).pix_fmt);
HW_PIX_FMT.set((*config).pix_fmt);
break;
}
Expand All @@ -504,33 +473,4 @@ impl CodecContextExt for codec::context::Context {
})
}
}

fn print_supported_hw_modes(&mut self) {
println!("Checking supported hardware acceleration modes:");

let codec = self.codec().ok_or("no codec").unwrap();
println!("T---- Context Codec is: {}", codec.name());
unsafe {
for i in 0.. {
let config = avcodec_get_hw_config(codec.as_ptr(), i);
if config.is_null() {
break;
}

println!("Got AVCodecHWConfig: ");
dbg!(*config);

if (*config).methods & (AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX as i32) == 1
&& (*config).device_type == TARGET_HWDEVICE
{
println!("Can set PIX_FMT for config: ");
dbg!((*config).pix_fmt);
// break;
}
println!("T--");
}
}

println!("T---- End of HW devices");
}
}

0 comments on commit 0fdbb0b

Please sign in to comment.