Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlapa committed Nov 13, 2024
1 parent 550b5bd commit 68c9676
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 212 deletions.
204 changes: 2 additions & 202 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: ["main"]
branches: ["main", "debug"]
tags: ["*"]
pull_request:
branches: ["main"]
Expand All @@ -24,8 +24,6 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}
needs:
- build
- build-linux
- clippy
- dartanalyze
- dartfmt
- ktfmt
Expand All @@ -44,35 +42,6 @@ jobs:
# Linting and formatting #
##########################

clippy:
strategy:
fail-fast: false
matrix:
platform:
- linux
- macos
- windows
runs-on: ${{ (matrix.platform == 'linux' && 'ubuntu-latest')
|| (matrix.platform == 'windows' && 'windows-latest')
|| 'macos-latest' }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
components: clippy

- name: Install `${{ matrix.platform }}` platform dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libgtk-3-dev libpulse-dev libudev-dev libxcomposite-dev \
libxdamage-dev libxfixes-dev libxrandr-dev libxtst-dev \
ninja-build
if: ${{ matrix.platform == 'linux' }}

- run: make cargo.lint

dartanalyze:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -162,39 +131,6 @@ jobs:
name: build-${{ matrix.platform }}
path: ${{ matrix.platform }}/rust/

build-linux:
name: build (linux)
runs-on: ubuntu-latest
# Pin glibc to 2.31 version for better compatibility.
container: debian:bullseye
steps:
- uses: actions/checkout@v4
- name: Install Linux platform dependencies
run: |
apt-get update
apt-get install -y \
curl jq xz-utils git make clang libssl-dev cmake \
libgtk-3-dev libpulse-dev libudev-dev libxcomposite-dev \
libxdamage-dev libxfixes-dev libxrandr-dev libxtst-dev \
ninja-build
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
# Container doesn't pick `~` (tilde) in `PATH`.
- run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- run: git config --global --add safe.directory '*'
- run: make rustup.targets only=linux
- uses: subosito/flutter-action@v2
- run: flutter config --enable-linux-desktop

- run: make cargo.build platform=linux debug=no
- run: make flutter.build platform=linux

- uses: actions/upload-artifact@v4
with:
name: build-linux
path: linux/rust/




Expand All @@ -204,7 +140,7 @@ jobs:

test-flutter:
name: test (example, ${{ matrix.platform }})
needs: ["build", "build-linux"]
needs: ["build"]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -349,139 +285,3 @@ jobs:
if: ${{ matrix.platform == 'linux' }}

- run: make cargo.doc




#############
# Releasing #
#############

release-dart:
name: dart pub publish (pub.dev)
if: ${{ startsWith(github.ref, 'refs/tags/')
|| github.ref_name == 'main'
|| (github.event_name == 'pull_request'
&& github.event.pull_request.head.repo.owner.login == 'instrumentisto') }}
needs:
- build
- build-linux
- clippy
- dartanalyze
- dartfmt
- ktfmt
- rustdoc
- rustfmt
- swiftformat
- test-flutter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # for PRs only

- name: Parse pubspec version
id: pubspec
run: echo "version=$(grep -m1 'version:' pubspec.yaml | cut -d' ' -f2)"
>> $GITHUB_OUTPUT
- name: Parse release version
id: release
run: echo "version=${GITHUB_REF#refs/tags/}"
>> $GITHUB_OUTPUT
if: ${{ startsWith(github.ref, 'refs/tags/') }}
- name: Verify release version matches pubspec version
run: |
test "${{ steps.release.outputs.version }}" \
== "${{ steps.pubspec.outputs.version }}"
if: ${{ startsWith(github.ref, 'refs/tags/') }}

- name: Retrieve commit message and hash
id: commit
run: |
echo "message=$(git log --grep='\[publish\]' --format=%s)" \
>> $GITHUB_OUTPUT
echo "sha=${{ (github.event_name == 'pull_request'
&& github.event.pull_request.head.sha)
|| github.sha }}" \
>> $GITHUB_OUTPUT
- name: Check whether should be skipped
id: skip
run: echo "no=${{ !(
(!startsWith(github.ref, 'refs/tags/')
&& !contains(steps.pubspec.outputs.version, '-'))
||
(github.event_name == 'pull_request'
&& !contains(steps.commit.outputs.message, '[publish]'))
) }}" >> $GITHUB_OUTPUT

- uses: subosito/flutter-action@v2
if: ${{ steps.skip.outputs.no == 'true' }}

- uses: actions/download-artifact@v4
with:
name: build-linux
path: linux/rust/
if: ${{ steps.skip.outputs.no == 'true' }}
- uses: actions/download-artifact@v4
with:
name: build-macos
path: macos/rust/
if: ${{ steps.skip.outputs.no == 'true' }}
- uses: actions/download-artifact@v4
with:
name: build-windows
path: windows/rust/
if: ${{ steps.skip.outputs.no == 'true' }}

- name: Append package version with commit SHA
run: |
sed -i "s/^version: \(.*\)$/version: \1+rev.${{ steps.commit.outputs.sha }}/g" \
pubspec.yaml
if: ${{ steps.skip.outputs.no == 'true'
&& !startsWith(github.ref, 'refs/tags/') }}

- name: Login to pub.dev
run: |
echo "$PUB_CREDENTIALS" > ~/pub-credentials.json
mkdir -p ${XDG_CONFIG_HOME:-${HOME:-default}}/dart/
cp -f ~/pub-credentials.json \
${XDG_CONFIG_HOME:-${HOME:-default}}/dart/pub-credentials.json
env:
PUB_CREDENTIALS: ${{ secrets.PUBDEV_CREDS }}
if: ${{ steps.skip.outputs.no == 'true' }}

- run: flutter pub publish --force
if: ${{ steps.skip.outputs.no == 'true' }}

- name: Logout from pub.dev
run: |
rm -rf ~/pub-credentials.json \
${XDG_CONFIG_HOME:-${HOME:-default}}/dart/pub-credentials.json
if: ${{ always()
&& steps.skip.outputs.no == 'true' }}

release-github:
name: release (GitHub)
if: ${{ startsWith(github.ref, 'refs/tags/') }}
needs: ["release-dart"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Parse release version
id: release
run: echo "version=${GITHUB_REF#refs/tags/}"
>> $GITHUB_OUTPUT
- name: Parse CHANGELOG link
id: changelog
run: echo "link=${{ github.server_url }}/${{ github.repository }}/blob/${{ steps.release.outputs.version }}/CHANGELOG.md#$(sed -n '/^## \[${{ steps.release.outputs.version }}\]/{s/^## \[\(.*\)\][^0-9]*\([0-9].*\)/\1--\2/;s/[^0-9a-z-]*//g;p;}' CHANGELOG.md)"
>> $GITHUB_OUTPUT

- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.release.outputs.version }}
body: |
[pub.dev](https://pub.dev/packages/medea_flutter_webrtc/versions/${{ steps.release.outputs.version }})
[Changelog](${{ steps.changelog.outputs.link }})
prerelease: ${{ contains(steps.release.outputs.version, '-') }}
28 changes: 28 additions & 0 deletions crates/native/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
sync::atomic::{AtomicPtr, Ordering},
};

use std::hash::{DefaultHasher, Hash, Hasher};
#[cfg(target_os = "windows")]
use std::{ffi::OsStr, mem, os::windows::prelude::OsStrExt, thread};

Expand Down Expand Up @@ -172,11 +173,16 @@ impl Webrtc {
// Returns a list of all available video input devices.
let mut video = {
let count = self.video_device_info.number_of_devices();
println!("enumerate_devices start, have {count} devices");
let mut result = Vec::with_capacity(count as usize);

for i in 0..count {
let (label, device_id) =
self.video_device_info.device_name(i)?;
println!(
"enumerate_devices, {i} = {device_id}({})",
hsh(&device_id)
);

result.push(api::MediaDeviceInfo {
device_id,
Expand All @@ -185,6 +191,7 @@ impl Webrtc {
});
}

println!("enumerate_devices end");
result
};

Expand All @@ -206,12 +213,24 @@ impl Webrtc {
device_id: &VideoDeviceId,
) -> anyhow::Result<Option<u32>> {
let count = self.video_device_info.number_of_devices();

println!(
"get_index_of_video_device for id: {device_id}({}), \
have {count} devices",
hsh(&device_id.0)
);
for i in 0..count {
let (_, id) = self.video_device_info.device_name(i)?;

println!("get_index_of_video_device, {i} = {id}({})", hsh(&id));

if id == device_id.to_string() {
println!("get_index_of_video_device, return Ok({i})");
return Ok(Some(i));
}
}

println!("get_index_of_video_device, return None");
Ok(None)
}

Expand Down Expand Up @@ -768,3 +787,12 @@ pub unsafe fn init() {
}
});
}

fn hsh<T>(obj: T) -> u64
where
T: Hash,
{
let mut hasher = DefaultHasher::new();
obj.hash(&mut hasher);
hasher.finish()
}
27 changes: 17 additions & 10 deletions crates/native/src/user_media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ impl Webrtc {
&mut self,
constraints: api::MediaStreamConstraints,
) -> Result<Vec<api::MediaStreamTrack>, api::GetMediaError> {
println!("get_media video: {:?}", constraints.video);

let mut tracks = Vec::new();

let inner_get_media = || -> Result<(), api::GetMediaError> {
Expand Down Expand Up @@ -196,14 +198,19 @@ impl Webrtc {
device_id,
)
} else {
println!("get_or_create_video_source 000");

let (index, device_id) =
if let Some(device_id) = caps.device_id.clone() {
println!("get_or_create_video_source 111 {device_id}");
let device_id = VideoDeviceId(device_id);

if let Some(index) =
self.get_index_of_video_device(&device_id)?
{
(index, device_id)
} else {
println!("get_index_of_video_device returns None");
bail!(
"Cannot find video device with the specified ID: \
{device_id}",
Expand Down Expand Up @@ -623,7 +630,7 @@ pub struct MediaStreamId(u64);
/// ID of an video input device that provides data to some [`VideoSource`].
#[derive(AsRef, Clone, Debug, Display, Eq, Hash, PartialEq)]
#[as_ref(forward)]
pub struct VideoDeviceId(String);
pub struct VideoDeviceId(pub String);

/// ID of an `AudioDevice`.
#[derive(AsRef, Clone, Debug, Default, Display, Eq, From, Hash, PartialEq)]
Expand Down Expand Up @@ -853,9 +860,9 @@ impl AudioDeviceModule {
+ (f64::from(max_volume - min_volume) * (f64::from(level) / 100.0));

#[expect( // intentional
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
reason = "size fits and non-negative"
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
reason = "size fits and non-negative"
)]
self.inner.set_microphone_volume(volume as u32)
}
Expand Down Expand Up @@ -884,9 +891,9 @@ impl AudioDeviceModule {
let max_volume = self.inner.max_microphone_volume()?;

#[expect( // intentional
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
reason = "size fits and non-negative"
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
reason = "size fits and non-negative"
)]
let level = (f64::from(volume - min_volume)
/ f64::from(max_volume - min_volume)
Expand Down Expand Up @@ -1568,9 +1575,9 @@ struct AudioSourceAudioLevelHandler(StreamSink<api::TrackEvent>);

impl AudioSourceAudioLevelHandler {
#[expect( // intentional
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
reason = "size fits and non-negative"
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
reason = "size fits and non-negative"
)]
fn on_audio_level_change(&self, level: f32) {
_ = self.0.add(api::TrackEvent::AudioLevelUpdated(cmp::min(
Expand Down

0 comments on commit 68c9676

Please sign in to comment.