Skip to content

Commit

Permalink
バッファサイズの見直し・チャンネル列挙の実装・BonDriverの信号強度の実装
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuki0824 committed Dec 26, 2023
1 parent 059fb97 commit b4d6d9d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 9 deletions.
15 changes: 15 additions & 0 deletions recisdb-rs/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,20 @@ pub(crate) fn process_command(
info!("Decoding...");
(body, None, input_sz.map(|sz| (sz, progress)))
}
#[cfg(windows)]
Commands::Enumerate { device, space } => {
// Open tuner
let untuned = UnTunedTuner::new(device)
.map_err(|e| utils::error_handler::handle_opening_error(e.into()))
.unwrap();
if let Some(spacename_channels) = untuned.enum_channels(space) {
for item in spacename_channels {
println!("{}", item)
}
std::process::exit(0)
} else {
std::process::exit(1)
}
}
}
}
7 changes: 7 additions & 0 deletions recisdb-rs/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,11 @@ pub(crate) enum Commands {
#[clap(required = true)]
output: Option<String>,
},
#[cfg(windows)]
Enumerate {
#[clap(short = 'i', long, value_name = "CANONICAL_PATH", required = true)]
device: String,
#[clap(short, long, required = true)]
space: u32,
},
}
2 changes: 1 addition & 1 deletion recisdb-rs/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pin_project! {
}

impl AsyncInOutTriple {
const CAP: usize = 16000000;
const CAP: usize = 1600000;
pub fn new(
i: Box<dyn AsyncBufRead + Unpin>,
o: Box<dyn Write>,
Expand Down
16 changes: 10 additions & 6 deletions recisdb-rs/src/tuner/windows/IBonDriver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mod ib_utils {
}

impl BonDriver {
pub fn create_interface<const BUF_SZ: usize>(&self) -> IBon<BUF_SZ> {
pub fn create_interface(&self) -> IBon {
let IBon1 = unsafe {
let ptr = self.CreateBonDriver();
NonNull::new(ptr).unwrap()
Expand All @@ -113,7 +113,7 @@ impl BonDriver {
)
};

IBon([0; BUF_SZ], IBon1, IBon2, IBon3)
IBon(vec![0; 100000].into_boxed_slice(), IBon1, IBon2, IBon3)
}
}

Expand All @@ -137,14 +137,14 @@ impl DynamicCast<IBonDriver3> for IBonDriver2 {
}
}

pub struct IBon<const SZ: usize>(
[u8; SZ],
pub struct IBon(
Box<[u8]>, // FIXME: Remove it
pub(crate) NonNull<IBonDriver>,
pub(crate) Option<NonNull<IBonDriver2>>,
pub(crate) Option<NonNull<IBonDriver3>>,
);

impl<const SZ: usize> Drop for IBon<SZ> {
impl Drop for IBon {
fn drop(&mut self) {
self.3 = None;
self.2 = None;
Expand All @@ -154,7 +154,7 @@ impl<const SZ: usize> Drop for IBon<SZ> {

type E = crate::tuner::error::BonDriverError;

impl<const SZ: usize> IBon<SZ> {
impl IBon {
//automatically select which version to use, like https://github.com/DBCTRADO/LibISDB/blob/519f918b9f142b77278acdb71f7d567da121be14/LibISDB/Windows/Base/BonDriver.cpp#L175
//IBon1
pub(crate) fn OpenTuner(&self) -> Result<(), std::io::Error> {
Expand Down Expand Up @@ -216,6 +216,10 @@ impl<const SZ: usize> IBon<SZ> {
let received = self.0[0..size].to_vec(); //Copying is necessary in order to avoid simultaneous access caused by next call
Ok((received, remaining))
}
pub(crate) fn GetSignalLevel(&self) -> Result<f32, io::Error> {
let iface = self.1.as_ptr();
return Ok(unsafe { ib1::C_GetSignalLevel(iface) });
}
//IBon2
pub(crate) fn SetChannelBySpace(&self, space: u32, ch: u32) -> Result<(), io::Error> {
unsafe {
Expand Down
27 changes: 25 additions & 2 deletions recisdb-rs/src/tuner/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod IBonDriver;

struct BonDriverInner {
dll_imported: ManuallyDrop<BonDriver>,
pub interface: ManuallyDrop<IBon<10000>>,
pub interface: ManuallyDrop<IBon>,
}

impl Drop for BonDriverInner {
Expand Down Expand Up @@ -103,6 +103,24 @@ impl UnTunedTuner {
}),
})
}

pub fn enum_channels(&self, space: u32) -> Option<Vec<String>> {
let interface = &self.inner.get_ref().interface;
interface.EnumTuningSpace(space).and_then(|chs| {
let mut ret = vec![chs];

for i in 0..31 {
if let Some(ch) = interface.EnumChannelName(space, i) {
ret.push(ch)
} else if i == 0 {
return None;
} else {
break;
}
}
Some(ret)
})
}
}

impl Tunable for UnTunedTuner {
Expand Down Expand Up @@ -168,7 +186,12 @@ impl Tunable for Tuner {

impl Tuner {
pub fn signal_quality(&self) -> f64 {
todo!()
self.inner
.get_ref()
.interface
.GetSignalLevel()
.unwrap()
.into()
}
}

Expand Down

0 comments on commit b4d6d9d

Please sign in to comment.